PreprintPDF Available

Quotients of Palindromic and Antipalindromic Numbers

Authors:
Preprints and early-stage research may not have been peer reviewed yet.

Abstract

A natural number N is said to be palindromic if its binary representation reads the same forwards and backwards. In this paper we study the quotients of two palindromic numbers and answer some basic questions about the resulting sets of integers and rational numbers. For example, we show that the following problem is algorithmically decidable: given an integer N, determine if we can write N = A/B for palindromic numbers A and B. Given that N is representable, we find a bound on the size of the numerator of the smallest representation. We prove that the set of unrepresentable integers has positive density in N. We also obtain similar results for quotients of antipalindromic numbers (those for which the first half of the binary representation is the reverse complement of the second half). We also provide examples, numerical data, and a number of intriguing conjectures and open problems.
arXiv:2202.13694v1 [math.NT] 28 Feb 2022
Quotients of Palindromic and Antipalindromic Numbers
James Haoyu Bai, Joseph Meleshko, Samin Riasat,and Jeffrey Shallit
School of Computer Science
University of Waterloo
Waterloo, ON N2L 3G1
Canada
{jhbai,jmeleshko,sriasat,shallit}@uwaterloo.ca
March 1, 2022
Abstract
A natural number Nis said to be palindromic if its binary representation reads the
same forwards and backwards. In this paper we study the quotients of two palindromic
numbers and answer some basic questions about the resulting sets of integers and
rational numbers. For example, we show that the following problem is algorithmically
decidable: given an integer N, determine if we can write N=A/B for palindromic
numbers Aand B. Given that Nis representable, we find a bound on the size of the
numerator of the smallest representation. We prove that the set of unrepresentable
integers has positive density in N. We also obtain similar results for quotients of
antipalindromic numbers (those for which the first half of the binary representation
is the reverse complement of the second half). We also provide examples, numerical
data, and a number of intriguing conjectures and open problems.
1 Introduction
Let N={0,1,2,...}denote the natural numbers, and let P, Q Nbe two given subsets.
Define the quotient set
P/Q ={p/q :pP, q Q− {0}}.
In the special case where P=Q, the set P/P is also known as a ratio set in the literature
[4,5,13,15,17,18,19,23,24,25,29,30]. Given Pand Q, six classical problems of number
theory are as follows:
Author’s current address: Department of Electrical Engineering and Computer Science, University of
Michigan, 2260 Hayward Street, Ann Arbor, MI 48109-2121, USA.
Research supported in part by NSERC grant 2018-04118.
1
1. What is the topological closure of P /Q in R+? In particular, is P/Q dense in the
positive reals R+?
2. Consider the following computational problem: given an integer N, is NP/Q? Is it
algorithmically decidable? Efficiently decidable?
3. Suppose NP /Q. What are good upper and lower bounds on the size of the smallest
representation N=A/B for AP,BQ?
4. What are the integers in P/Q? Are there infinitely many? Are there infinitely many
integers not so representable? What are the lower and upper densities of repre-
sentable and unrepresentable integers in N? (The lower density of a set SNis
lim infn→∞ 1
n|S{1,2,...,n}| and the upper density is lim supn→∞ 1
n|S{1,2,...,n}|.)
5. Given that an integer Nbelongs to P/Q, how many such representations are there?
6. What are the rational numbers in P/Q?
These are, in general, very difficult questions to answer; for some sets P,Q, we can even
prove that some variations are undecidable [8, Thm. 5]. Let us look at some examples of
each of these problems in the literature.
1.1 Problem 1: denseness
As an example of Problem 1, Sierpi´nski [25, p. 165] proved that if P=Q=P={2,3,5,...},
the set of prime numbers, then P/Q is dense in R+. Also see [11,27]. More generally, there
is a criterion originally due to Narkiewicz and ˇ
Sal´at [20], as follows:
Theorem 1. Suppose P={a1, a2,...} ⊆ Nwith ai< ai+1 for all i. If limn→∞ an+1/an= 1,
then P/P is dense in the positive reals.
As another example, one of the basic steps in the proof of Cobham’s famous theorem [7]
is the following observation: if Pk:= {ki:i0}is the set of powers of an integer k2,
then Pk/Pis dense in R+if and only if kand 2 are multiplicatively independent. Also
see [9, Prop. 9].
Let sq(n) be the sum of the base-qdigits of n. Madritsch and Stoll [16] showed that if P1
and P2are polynomials with integer coefficients, of distinct degrees, such that P1(N), P2(N)
N, then the sequence of quotients (sq(P1(n))/sq(P2(n)))n1is dense in R+.
Brown et al. [3] proved that if we take P=Qto be the set of integers whose base-k
representation starts with 1, then P/Q is dense in the positive reals if and only if k∈ {2,3,4}.
Recently, Athreya, Reznick, and Tyson [1] solved Problem 1 for P=Q=C, the Cantor
numbers (the natural numbers having no digit “1” in their base-3 representation).
2
1.2 Problem 2: deciding if an integer is representable
Let S1, S2be sets of natural numbers and L1, L2the corresponding sets of their canonical
base-brepresentations. If L1and L2are both regular languages (that is, recognized by finite
automata), then we can decide whether a given NS1/S2in O(N) time.
To see this, build an automaton Mthat accepts, in parallel, the base-brepresentation of
two natural numbers (A, B) if A=BN, starting with the least significant digits. For this
we only need Nstates, to keep track of the possible carries. Now use the direct product
construction to intersect Mwith L1in the first component (corresponding to A) and L2in
the second component (corresponding to B), getting an automaton M. If some final state
Mis reachable from the start, then Nhas a representation; otherwise it does not. This gives
an algorithm running in O(N) time to decide whether NS1/S2. (The implicit constant
depends on the size of the finite automata recognizing L1and L2.)
Of course, is not necessary to construct the entire automaton. We can use a queue-based
algorithm to do breadth-first search on the underlying directed graph of the automaton,
implicitly. If Nis representable, we can often find a representation A/B in much less than
O(N) time.
1.3 Problem 3: size of the smallest representation
Continuing the example of regular languages, if Nhas a representation as A/B, then A=
bO(N). This follows from the fact that the automaton Mconstructed there has tstates, so
if Maccepts an input, it must accept an input of length at most t1. The corresponding
integer is then at most bt11, and t=O(N).
1.4 Problem 4: characterizing representable integers
In 1987, Loxton and van der Poorten [14] considered the set Lof integers that can be
represented in base 4 using just the digits 0,1,and 1. They showed that every odd integer
can be represented as the quotient of two elements of L.
Recall the definition of the Cantor numbers Cfrom Section 1.1. The problem of com-
pletely characterizing the ratio set V=NC/C was proposed by Richard Guy [10, Section
F31] and is still unsolved. Let
D={N:i1 such that N2·3i1(mod 3i)}={2,5,6,8,11,14,15,17,18,20, . . .}.
By considering the numerator and denominator modulo 3i, it is easy to see that if ND,
then N6∈ V. Let
E=N[
i0
[(3/2) ·3i,2·3i] = {2,5,6,14,15,16,17,18,41,42,43,44,45,46,47, . . .}.
By considering the first few bits in the base-3 representation of numerator and denominator
(or using the results in [1]), it is easy to see that if NE, then N6∈ V. It is tempting to
3
conjecture that V=N(DE), but this is false. Using the algorithm given above for
Problem 3, Sajed Haque and the fourth author of this article found the following examples
of integers in F:= N(VDE):
{529,592,601,616,5368,50281,4072741,4074361,4088941,4245688}.
We do not know if there are infinitely many such examples. It seems at least possible that
numbers of the form 621 ·34k20 might all belong to F.
A related conjecture was made by Selfridge and Lacampagne [14,§7]. If we let B=
{1,2,4,5,7,11,13,14,16,20,22, . . .}be the set of natural numbers having no 0 in their bal-
anced ternary representation, then they conjectured that every n6≡ 0 (mod 3) belongs to
B/B. However, we found the counterexamples
{247,277,967,977,1211,1219,1895,1937,1951,1961,2183,2191,2911,2921,3029,3641,3649},
the first of which was also found by Coppersmith [10, Section F31]. It seems likely that there
are infinitely many such counterexamples, but we have no proof.
For a different example, let U={2k+1 +i: 1 i2k1}.ˇ
Sal´at [23] observed that U/U
has lower density 1/4 and upper density 2/5.
1.5 Problem 5: counting number of representations
Consider S={1,2,4,5,8,9,10,...}, the set of integers that can be written as the sum of two
squares of natural numbers. Then it follows from Fermat’s classical two-square theorem that
S/S =S. Hence every NS/S has infinitely many representations of the form N=A/B
with A, B S.
1.6 Problem 6: which rationals are representable?
As an example, Sierpi´nski observed [25, p. 254] that if we take P=Q={ϕ(n) : n1},
the range of Euler’s totient function, then P/Q contains every positive rational number.
On the other hand, it is a nice exercise in elementary number theory to show that every
non-negative rational number belongs to N/T , where T={(2i1)2j:i1, j 0}. See
[22, Example 7].
Define E={0,3,5,6, . . .}={nN:t(n) = 0}and O={1,2,4,7,...}={nN:
t(n) = 1}, where tis the Thue-Morse sequence. Stoll [28] showed that for odd natural
numbers p > q there are integers n1, n2< p such that t(n1p), t(n1q)∈ E, and t(n2p), t(n2q)
O. Since t(2n) = t(n), we immediately get that E/Eand O/Oboth contain all positive
rational numbers.
2 Palindromic and antipalindromic numbers
Now that we have motivated the study of the properties of P /Q for sets P, Q, we turn to
considering Problems 1–6 above for P=Qin a novel context: the palindromic and an-
4
tipalindromic numbers. These two classes have previously been studied by number theorists;
see, e.g., [2,6,21].
We say that a natural number is palindromic if its base-brepresentation is a palin-
drome (reads the same forwards and backwards). For base 2, the palindromic numbers
PAL ={1,3,5,7,9,15,17, . . .}form sequence A006995 in the On-Line Encyclopedia of Inte-
ger Sequences (OEIS).
Analogously, we say that a natural number is antipalindromic if its base-2 representation
is of even length, and the second half is the reverse complement of the first half. For example,
52 (which is 110100 in binary) is antipalindromic. The antipalindromic numbers APAL =
{2,10,12,38,42,52,56,...}form sequence A035928 in the OEIS. This can be generalized to
base bby demanding that if ais a digit in the first half of a number’s representation, and a
is the corresponding digit in the reverse of the second half, then a+a=b1.
As it turns out, the study of the palindromic and antipalindromic numbers is particularly
amenable to tools from automata theory and formal languages. These tools have previously
been used to solve other kinds of number theory problems (see, e.g., [21]).
Our principal interest in this paper is base 2, although nearly everything we say can
be generalized to other bases. We let Qpal =NPAL/PAL, the integers representable as
quotients of palindromic numbers, and Qapal =NAPAL/APAL, the integers representable
as quotients of antipalindromic numbers.
Throughout the paper we must distinguish between an integer and its base-krepresenta-
tion. For n1, define (n)kto be the string of digits representing nin base k, starting with
the most significant digit, which must be nonzero. If wis a string of digits over the alphabet
Σk={0,1,...,k1}, then by [w]kwe mean the integer represented by win base k. Thus,
for example, (43)2= 101011 and [101011]2= 43.
For a string x, by xnwe mean the string
n
z}| {
xx ···x. In some cases (for example, an equality
such as 14= 1111) there could be ambiguity between this notation and the ordinary notation
for powers of integers, but the context should make it clear which interpretation is meant.
We use the notation ato denote the binary complement of the bit a: 0 = 1 and 1 = 0.
This can be extended to strings win the obvious way. Another extension is that if we are
working over base b, then we can define a=b1a. Here the choice of bshould be clear
from the context.
The Hamming distance h(x, w) between two identical-length strings, xand w, is defined
to be the number of positions on which xand wdiffer.
2.1 Denseness
Theorem 2. The ratio set PAL/PAL is dense in the positive reals.
Proof. Let α > 0 be a real number that we want to approximate as the quotient of two
palindromic natural numbers. Without loss of generality, we can assume α1 (otherwise,
we represent the reciprocal 1). Let k0 be an integer such that 1
2<2kα1, and set
β= 2kα.
5
We now approximate βby forming a palindrome from the first nbits of the binary
expansion of β(duplicating the bits, then reversing and appending them), and dividing
by the palindromic number B= 22n+k+ 1. More formally, let γ=2nβ, and define
A= [(γ)2(γ)R
2]2. Then A/B α, and it remains to see how good this approximation is.
Clearly γA/2n< γ + 1. Therefore
2nβ1<2nβ=γA/2n< γ + 1 = 2nβ+ 1 2nβ+ 1.
Multiplying through by 2n/B gives
22nβ2n
22n+k+ 1 <A
B<22nβ+ 2n
22n+k+ 1 ,
or equivalently,
β2n
2k+ 22n<A
B<β+ 2n
2k+ 22n<β
2k+ 2nk.(1)
Now
β2n
2k+ 22n=β2n
2k1
1 + 22nk
>β2n22nkβ+ 23nk
2k
>β2n22nk
2k,
where we have used the fact that β < 1 and the estimate 1/(1 + x)>1x. Substituting in
Eq. (1), we see that
α2nk22n2k<A
B< α + 2nk.
Hence, as n→ ∞, the quotient of palindromes A/B gets as close as desired to α.
Remark 3.We could have also proved Theorem 2using the criterion in Theorem 1.
2.2 Testing if Nis the quotient of palindromic numbers
We now turn to the question of deciding, given a natural number N, whether there exist
palindromes A, B such that N=A/B. Since a positive number must be odd for its base-2
representation to be a palindrome, it is clear that only odd integers are representable.
The set Qpal
1,3,5,7,9,11,13,15,17,19,21,27,31,33,39,...
of positive integers having such a representation is sequence A305468 in the OEIS.
The sequence
23,25,29,35,37,41,47,49,59, . . .
6
of odd positive integers having no representation as the quotient of palindromic numbers is
sequence A305469 in the OEIS.
Evidently, if there exist such A, B we can find one through a brute-force search, so for
the moment we focus on how we might establish that there is no such solution. We describe
three algorithms: a heuristic algorithm that does not always terminate; a rigorous algorithm
based on context-free languages; and finally, a fast rigorous algorithm based on deterministic
finite automata.
2.2.1 A heuristic algorithm
There is a fast and relatively simple heuristic method to solve this problem that works in
many cases, but is not guaranteed to terminate. If it does terminate, the answer it gives is
guaranteed to be correct. We describe it now. Suppose we are considering a candidate Tfor
the first kbits of B. Since A=BN , these kbits of Bdetermine all the possibilities for the
first kbits of A.
On the other hand, the first kbits of Bdetermine the last kbits of B. By considering
the equation A=BN modulo 2k, the last kbits of Aare also completely determined. Hence
the first kbits of Aare completely determined, and must match one of the possibilities in
the preceding paragraph. If they do not, we have ruled out Tas the possibility for the first
kbits of A.
We now do a breadth-first search over the tree of possible prefixes of B. The hope is that
we either find a solution, or are able to rule out all possibilities for the solution of A/B =N.
This will be the case if the following heuristic principle holds:
Heuristic Principle 1. If there is no solution in palindromes A, B to the equation A/B =
N, then this fact can be proved by examining all possible k-bit prefixes of Bfor some fixed
integer k(which might depend on N) .
We illustrate the basic idea for N= 35. Suppose A, B are palindromes with A/B = 35.
Then the first three bits of Bare either 100,101,110,111.
Let’s assume the first three bits are 100. Then, since A= 35B, we see that the first
three bits of Aare either 100 or 101. On the other hand the last three bits of Bare 001, so
from A= 35Bwe see the last three bits of Aare 011. So the first three bits of Aare 110,
contradicting what we found earlier.
Similar contradictions occur for the other three possibilities, so we have proved that there
is no solution in palindromic numbers to the equation A/B = 35.
Using our heuristic algorithm, we were able to determine the representability of all odd
N2000. The data for N239 is given in Table 1. Here kdenotes the length of the
largest bit strings that were needed to prove that N=A/B has no solutions in palindromic
numbers.
7
N A B k N A B k N A B k
1 1 1 81 3 161 3
3 3 1 83 3735 45 163 7335 45
5 5 1 85 85 1 165 165 1
7 7 1 87 4 167 5
9 9 1 89 3 169 3
11 33 3 91 273 3 171 513 3
13 65 5 93 93 1 173 5709 33
15 15 1 95 2565 27 175 — 8
17 17 1 97 3 177 3
19 513 27 99 99 1 179 11277 63
21 21 1 101 5 181 16833 93
23 4 103 7 183 4
25 3 105 6 185 3
27 27 1 107 107 1 187 561 3
29 8 109 2289 21 189 189 1
31 31 1 111 6 191 29223 153
33 33 1 113 4 193 3
35 3 115 3 195 195 1
37 6 117 585 5 197 6
39 195 5 119 119 1 199 — 9
41 3 121 11253 93 201 3
43 129 3 123 3 203 1421 7
45 45 1 125 5 205 1025 5
47 6 127 127 1 207 6
49 3 129 129 1 209 4
51 51 1 131 3 211 633 3
53 3339 63 133 3591 27 213 54315 255
55 165 3 135 4 215 645 3
57 513 9 137 — 8 217 — 8
59 3 139 3 219 219 1
61 427 7 141 6 221 1105 5
63 63 1 143 2145 15 223 2965677 13299
65 65 1 145 4 225 4
67 3 147 6 227 3
69 7 149 5887437 39513 229 3435 15
71 54315 765 151 1057 7 231 231 1
73 73 1 153 153 1 233 59415 255
75 4 155 7 235 3
77 231 3 157 471 3 237 6
79 888987 11253 159 3339 21 239 717 3
Table 1: Results of the heuristic algorithm for odd N239
8
Unfortunately, the heuristic principle does not hold in all cases. We found six examples
less than 20000 for which a failure to terminate occurs. They are summarized in Table 2. For
each entry we have N·[rsn(sR)nrR]2= [tunivwvR(uR)nitR]2for n2, and furthermore
pald(w) = d. Here pald(w) = h(w, wR), the Hamming distance between wand wR. For
these numbers there is an infinite sequence (f(n)) of palindromic numbers whose product
with Nis “almost” palindromic, and furthermore the first bit position where this product
differs from being a palindrome is located arbitrarily far in (and hence will never be detected
by an algorithm that focuses only on fixed-size prefixes).
N r s t u v w i d
2551 ǫ10100010000 1100100 11110001011 111 0010110001011 1 12
14765 ǫ111011110110 1101011111000 110000010111 1100000101101 1011010110 2 8
15247 ǫ11001101110011001000 10111111100 00100011001101110011 0010001 011100000011000101 1 10
17093 ǫ110111001000 11100110000 110010001101 ǫ0110000000010101 1 6
19277 11 0000100011100111110111000110 1110010010000101 1001101101001101100100101100 10011011010011 11001111100100 1 8
19831 ǫ11101010111100 1000111000110 00100000011111 0010000001111 0111010111111010101 2 12
Table 2: Some Nfor which the heuristic principle fails.
Let’s verify the claim for N= 2551. For the given r, s, t, u, v, w we have
[sn(sR)n]2= 1296 ·211n·211n1
211 1+ 69 ·211n1
211 1
while
[tun1vwvR(uR)n1tR]2= [t]2·2|un1vw vR(uR)n1tR|+ [u]2·2|vwvR(uR)n1tR|2(n1)|u|1
2|u|1
+ [v]2·2|wvR(uR)n1tR|+ [w]2·2|vR(uR)n1tR|+ [vR]2·2|(uR)n1tR|+ [uR]2·2|tR|2(n1)|uR|1
2|uR|1+ [tR]
= 100 ·211(n1)+3+13+3+11(n1)+7 + 1931 ·23+13+3+11(n1)+7 211(n1) 1
211 1+
7·213+3+11(n1)+7 + 1419 ·23+11(n1)+7 + 7 ·211(n1)+7 + 1679 ·27211(n1) 1
211 1+ 19.
The expression for [sn(sR)n]2simplifies to
1296
211 1·222n1227
211 1·211n,
while the expression for [tun1vwvR(uR)n1tR]2simplifies to
3306096
211 1·222n3130077
211 1·211n.
It is now easily verified that the second is 2551 times the first.
Conjecture 1. There are infinitely many natural numbers Nfor which the heuristic algo-
rithm fails to terminate.
9
2.2.2 A provable decision procedure
In contrast to the fast method presented in Section 2.2.1, in this section we describe another
technique that provides a provable decision procedure. This method is based on formal
language theory.
Here is a brief sketch of the idea: first, given N, we construct a pushdown automaton
(PDA) MNthat, on input Aand Bexpressed in binary, and read in parallel, determines
if Aand Bare both palindromes and if A=BN. Next, we convert MNto an equivalent
context-free grammar (CFG) GN. Finally, we use a standard decision procedure for context-
free grammars to decide if GNgenerates any string, and if so, to find the shortest string
generated by GN.
However, there are some complications. While determining if Ais palindromic with a
PDA is easy, making the same determination for Aand Bsimultaneously (when they are of
different lengths) is harder. To align Aand Baround their center, we multiply Bby 2kfor
some appropriate power of 2. Thus, instead of checking whether A=BN , we are actually
checking if 2kA=BN. Now there are four separate cases to examine, depending on the
parity of the length of (A)2and (B)2.
Our solution consists of five parts:
ConstructPDA(N): on input a positive integer N, constructs four PDAs that accept
the base-2 representation of all (A, B) in parallel such that A=BN and both A
and Bare palindromes. This PDA has O(N3/2) states, where O(N) states are used
to keep track of the multiplication by N, and an additional multiplicative factor of
O(N1/2) states required to keep track of the symbols required to “line up” the binary
representation of Awith B.
CanonicalPDA(M): on input Mreturns a new PDA Mthat is in Sipser normal form:
it has at most one final state, empties the stack before accepting, and each transition
either pushes exactly one symbol onto the stack or pops one off.
PDA-to-Grammar(M): takes a PDA Min Sipser normal form and returns an equiv-
alent CFG Gusing the algorithm in [26]. This blows up the number of states by at
most a cubic factor, so the size of the grammar is O(N9/2).
Remove-Useless-Symbols(G): takes a CFG Gand removes useless symbols (both
variables and terminals) following the algorithm in Hopcroft and Ullman [12]. If noth-
ing is left, we know L(G) is the empty set.
Shortest-String-Generated(G): given that the CFG Ggenerates at least one
string, this routine returns the shortest string (or perhaps strings) generated by G,
using dynamic programming.
Using these ideas we were able to prove
Theorem 4. There exists an algorithm to determine if Ncan be written as the quotient of
palindromic numbers that runs in O(N9/2)time.
10
This method was programmed up by the first author in 2019, and with it we were
able to determine the solvability of N=A/B in palindromes for all odd numbers 600.
Unfortunately, it was too slow to resolve the cases we were interested in (such as N= 2551,
which the heuristic algorithm could not solve), so we turned to another method described in
the next section.
2.2.3 A different provable decision procedure based on finite automata
We developed another method that is based on finite automata (instead of pushdown au-
tomata). Of course, finite automata cannot recognize palindromes, so we have to be a bit
more clever.
Let Nand kbe integers. The case of the representability of N=A/B with A, B
palindromes in base kis easy to decide in the cases where N < k or k|N, so we assume
neither of these holds.
We construct a nondeterministic finite automaton MN,k to check whether Ncan be
expressed as the quotient of palindromic numbers in base k. This automaton accepts certain
pairs of strings aand b, from which we derive integers Aand B, where (A)kand (B)kare
palindromes and A/B =N. This is accomplished by interpreting the input each aand bas
half of a palindrome (A)kand (B)k, respectively, and then verifying the equation A=BN .
The automaton verifies the equation from both the left-hand and right-hand halves of the
digits of (A)kand (B)ksimultaneously. From the size of the constructed MN,k we can also
obtain a bound on the maximum size of A.
Verifying a multiplication with a system of equations
To verify the equation A=B·Nwe will compare N·Bto Adigit by digit. Let (A)k=
AiAi1···A1and (B)k=BjBj1···B1. We begin by checking
A1= (N·B1) mod k.
This leaves a carry to contribute to the next equation
c1=N·B1A1
k.
We call these cvalues the carries. We then subsequently verify each equation
A= (N·B+c1) mod k
for ∈ {2,3,...,|(A)k|}. When ℓ > |(B)k|we continue with B= 0. At each step we get a
new equation
c=N·B+c1A
k
for the next step. If at the end of the process we have that ci= 0, then all the equations are
valid and indeed A=N·B.
11
We can also obtain a bound on the size of c. This contributes to the bound on the size
of MN,k . We have
c(k1) ·N+c10
k.
Since the carry starts at 0, c1includes c0= 0 so we have that
c1k1
k·N < N.
We can then assume for the sake of induction that c1< N and get that
c=N·B+c1A
k
(k1) ·N+c10
k
<(k1) ·N+N
k
<k·NN+N
k
<k·N
k
< N,
as A0 and Bk1. We can use the fact that cis bounded by Nto constrain the
states we have to consider in MN,k . Any state with a left carry larger than or equal to N
cannot lead to an accepting state, so we can safely omit it.
The automaton MN,k simultaneously checks the equations starting with = 1 in ascend-
ing order and the equations starting with =iin descending order. The ascending equations
have a carry computed as previously described. The descending equations start with the
assumption that ci= 0 and compute the required preceding carry value that would result in
the equation being satisfied. We compute c1from the relation
c1=k·cN·B+A.
The states of the automaton keep track of the value of the largest index carry computed
from the right and the smallest index carry computed from the left. An accepting state is
one where the top and bottom carries are equal. This implies that each equation is satisfied
from = 1 up to =i.
Palindromes as input to an automaton
There are two main challenges regarding the input specification when trying to design an
automaton that verifies an equation and ensures that the inputs are palindromes. The first
challenge is that it is impossible to recognize a palindrome with a finite automaton. To
remedy this issue we take, as input, half of a palindrome and implicitly determine the other
12
half. A naive approach is to interpret the input pair ha, bias referring to the equation
[aaR]k= [bbR]k·N.
This means all even-length palindromes have an associated string that is a valid input to
our automaton. However, this does not cover the case of odd-length palindromes. Therefore,
on input ha, bi, the automaton MN,k simultaneously checks each equation [aaR]k= [bbR]k·
Nwhere σa, σb∈ {ǫ} ∪ Σk. If any of the equations are valid, then the automaton accepts
the input.
The second challenge is that the strings (A)kand (B)khave, in general, different lengths.
Furthermore, the difference in length between them could be either the floor or the ceiling
of logkN. To accommodate both possibilities, MN,k begins by nondeterministically guessing
the difference in length between (A)kand (B)k. Since |(A)k|>|(B)k|, it follows that |a| ≥ |b|.
If |(N)k|= 2, then it is possible that there is a satisfying aand bwhere |a|=|b|. However,
in general we need to pad bto provide it as input to the automaton simultaneously with a.
We use Xas a padding character to indicate the end of input for b. We format the input a
and bas ha, bi ∈ Σk×k{X}). The automaton MN,k rejects any input not of the form
ha, bi=xy where xk×Σk)and yk×{X}). Additionally, the automaton rejects
an input that begins with either a[1] or b[1] being zero. This would result in a palindrome
representing a number that would not be a palindrome in canonical representation.
Checking equations for the first component of the input
This section describes the states that read the component of the input composed of symbols
in Σk×Σk. The automaton is able to directly check the equations and compute the carries
for the right-hand side, since each input from Σk×Σkcontains all the information for one
set of equations. The first symbol of ha, biis (a[1], b[1]). Since A1=a[1] and B1=b[1],
(a[1], b[1]) has all the information required for the equations
A1= (N·B1) mod k
and
c1=N·B1A1
k.
Afterwards, the automaton saves the carry for the next equation. On receiving each input
(a[], b[]) = (A, B), the automaton is able to check the equation
A= (N·B+c1) mod k
and compute
c=N·B+c1A
k.
Therefore, the only information that MN,k must preserve between states in order to verify
these equations is the current value of the carry. We call this saved value the right carry.
The left-hand side requires more careful handling. The automaton does not verify the
equations on the left side, instead it asserts that they will be valid and computes the carry
13
required from the right to satisfy the current step. Since (A)kis a palindrome in canonical
notation and there is a difference in length between it and (B)k, we must have Ai=a[1]
and Bi= 0. Using ci= 0 from the assumption of satisfaction, MN,k computes ci1with the
equation
ci1=k·ciN·Bi+Ai=k·0N·0 + Ai=Ai.
The automaton preserves the carry for the next equation and we call this saved value the
left carry. The automaton proceeds with calculating c1with A=a[i+ 1], B= 0, and
cfrom the previous step with the equation
c1=k·cN·B+A=k·cN·0 + A=k·c+A.
The equation using a[] to compute the left carry is computed concurrently with the cor-
responding equation on the right-hand side to compute the right carry that also uses a[].
(This event is upon reading (a[], b[])). We call this the loading phase.
The left-hand side continues as described until trying to compute cj1. At this step,
MN,k needs Bj=b[1] along with a[ij+ 1] to compute
cj1=k·cjN·Bj+Aj.
In order to compute an equation requiring information contained in different input symbols
the automaton saves some additional information beyond the two carries. After the first
input symbol (a[1], b[1]) is read and the right and left carries are computed, MN,k preserves
b[1]. The automaton keeps b[1] until it has to compute cj1and at that point discards it
as it won’t need it for any other calculations. Similarly, to compute cj2,MN ,k needs b[2]
which gets preserved after reading (a[2], b[2]) and discarded at the step computing cj2. Each
time that an (a[], b[]) is read the b[] must be saved for a later equation. This process of
using, discarding, and then subsequently replacing a saved symbol continues while the input
symbols are of the form (a[], b[]). (This means this phase continues until we’ve seen all of
b.) We call the section of computation where MN,k consumes and discards saved symbols
while still saving new ones the shifting phase.
The number of symbols of bthat need to be saved is the difference in length between
(A)kand (B)k. As stated previously, this difference can vary between the floor and ceiling
of logkN. To accommodate both possibilities, MN,k nondeterministically assumes that the
difference is a fixed value mand the loading phase saves that many symbols of bbefore
starting to consume and replace them in the shifting phase. We call the currently saved
section of bthe queue of saved symbols.
Each state of MN,k is therefore identified by the msymbols saved, the integer mitself,
the left and right carries, and what phase the automaton is in. The automaton also has a
special start state, with an ǫtransition to the two states with no symbols saved, left and
right carries set to 0, and each possibility for m. For all other states, the automaton has a
transition to the resulting state when the equations are checked, carries updated, and saved
symbols updated as per the input on the transition and the current status as given by the
original state. If the associated equation on the right-hand side isn’t verified or it results in
14
a carry larger than N, then the transition is omitted. The loading stage is characterized by
having less than msaved symbols and the shifting phase having exactly msaved symbols
that it cycles through.
Checking equations for the second component of the input
Once MN,k has seen all of the input b, the input changes to being of the form (a[], X ). We
call this final section of processing the unloading phase. Any transition with an input of the
form (a[], X) pushes the automaton directly into the unloading phase This can lead to not
having msaved symbols in the queue of saved symbols despite having read all of b. If this
occurs, MN,k implicitly pads the front of the queue of saved symbols with enough zeroes to
have msaved symbols. At this point the automaton has all the digits of (B)k(except σb),
and has yet to examine the middle section of (A)kthat corresponds to the remainder of a.
At this point, when the automaton reads a symbol (a[], X), it represents a[] which is both
the leftmost and rightmost digit of the unexamined middle of (A)k. This middle section lines
up with the queue of saved symbols to supply the bsymbols that are no longer coming from
the input.
The automaton must now contend with the possibility that (B)khas odd length and
there may be a symbol of (B)knot given in b. It nondeterministically decides what the
central symbol σbΣk∪ {X}is for (B)k. If σb6=ǫ, then it proceeds using the input a[]
as the symbol from (A)kfor both the left and right side equations. The automaton uses the
chosen symbol as the (B)ksymbol for the right-hand side equations since we have already
processed the entire right-hand side of (B)k. The left-hand side, as usual, pops the first in
symbol in the queue of saved symbols but doesn’t add anything else to the queue since there
is no new b[]. The left and right carries are updated as usual and the automaton continues
with a reduced queue of saved symbols. If MN,k decides that σb=ǫ, then it skips the step
described in this paragraph and proceeds directly with the subsequent steps.
At this point, MN,k consumes both ends of the queue of saved symbols to compute the
usual equations for the left-hand and right-hand sides with the input a[]. This proceeds,
consuming two symbols of the queue of saved symbols each time. Once the automaton has
less than 2 symbols left, there are two remaining cases. If there are 0 saved symbols remaining
and the left and right carries are equal, then the automaton accepts the input. In this case,
the entire series of equations are satisfied and the input represents a valid A/B =Nwith
(A)kand (B)kpalindromes. Alternatively, if the automaton has one saved symbol left, then
this is the case where (A)khas an odd number of symbols. If there is an assignment for the
middle symbol σathat results in the carries being equal, then the automaton accepts the
input.
Algorithm implementation
We implemented an algorithm for computing the desired Aand Bfor a given Nand base
kin Python. We build the automaton as described and afterwards run Dijkstra’s algorithm
using the symbols of Bas edge weights to get the shortest Bfrom the start to accept state.
15
Computing the automaton is O(k2N3) as it has O(kN 3) states with O(k) transitions out
of each state. Given the size of the automaton and a binary heap handling the Dijkstra’s
algorithm, our algorithm runs in O(k2N3log(k2N3)). The existence of Aand Bcan be
shown in O(k2N3) with a simple breadth first search of the automaton for the accept state
but due to the nondeterminism and variability in the difference of lengths, it can’t guarantee
a minimal example.
The code is available at
https://github.com/josephmeleshko/Palindrome-Ratio-Set-Automata-Generator
This guaranteed decision algorithm can prove that there are no solutions for a va-
riety of integers that the heuristic algorithm fails to determine. For example, our al-
gorithm was able to prove that there are no solutions to the equation N=A/B for
N∈ {2551,14765,15247,17093,19277,19831}.
Let Qpal ={1,3,5,7,9,11,13,15,17,19,21,27,31, . . .}be the set of integers representable
as the quotient of palindromic numbers. With this code we computed the data in Table 3
showing the distribution of elements of Qpal according to the number of bits.
i|Qpal [2i1,2i)|
1 1
21
3 2
4 4
55
6 10
717
8 33
9 55
10 98
11 165
12 309
13 571
Table 3: Number of i-bit numbers representable as the quotient of palindromes
This numerical data suggests that perhaps roughly 0.34 ·1.76ii-bit numbers are repre-
sentable.
We can easily prove the following lower bound on the number of representable i-bit
numbers.
Theorem 5. There are Ω(2i)i-bit integers representable as the quotient of palindromic
numbers.
Proof. Every i-bit palindromic number Ncan be written as N/1, and there are Ω(2i/2) of
them.
16
Even the following seems hard to prove.
Conjecture 2. The set of integers representable as quotients of palindromic numbers is of
zero density.
2.3 Size of smallest representation for palindromes
The sequence
1,1,1,1,1,3,5,1,1,27,1,1,1,1,5,3,1,...
of the minimal size of denominators Bfor those Nhaving a representation A/B as a quotient
of palindromes forms sequence A305470 in the OEIS.
Suppose N=A/B for palindromic numbers A, B. We can use our algorithm based on
finite automata to upper bound the size of the numerator and denominator of the smallest
such representation using the following simple idea:
Proposition 6. If an NFA of tstates accepts the base-krepresentation of the first halves of
strings (A)kand (B)kfor palindromic numbers A, B such that N=A/B, then A, B < k2t1.
Proof. By the pigeonhole principle applied to the sequence of states traversed by an input,
if an NFA of tstates accepts at least one string, then it must accept a string of length at
most t1. Hence if we have an NFA as given in the hypothesis, it must accept at least one
pair of inputs in parallel of length t1. Thus |(A)k|,|(B)k| ≤ 2(t1) + 1 = 2t1, and
so A, B < k2t1.
A naive bound on the size of the automata MN,k observes that each of the three phases
has unique states that are characterized by one of two maximum numbers of saved symbols
s, up to logkNsaved symbols each taking one of kvalues, and two carries each ranging
from 0 to N1. This means there are at most
3·2·klogk(N)·N26·k·N·N2O(k·N3)
states in MN,k .
More strongly, we have that the loading phase takes at most logkNtransitions since
the automaton adds one symbol to the queue of saved symbols at a time. The shifting phase
takes at most klogk(N)·N2transitions since the automaton at worst goes through every
state once. The unloading phase takes at most llogkN
2m=llogkN
2mtransitions since the
automaton removes two symbols from the queue of saved symbols at a time. However, the
unloading phase can also require an extra check that implicitly uses the central symbol of
(A)kif logkNis even and both (A)kand (B)khave an extra central symbol.
Since each transition adds two digits to Aand the unloading phase can may implicitly
use one additional symbol from (A)k, we have therefore shown:
Theorem 7. If there exists an Aand Bsuch that (A)kand (B)kare palindromes and
A/B =N, then for the smallest A,
|(A)k| ≤ 2·logkN+klogkN·N2+logkN
2+ 1.
17
Record-setting values of the smallest representation A, B are given in Table 4.
NA B
1 1 1
11 33 3
13 65 5
19 513 27
53 3339 63
71 54315 765
79 888987 11253
149 5887437 39513
319 224725611 704469
575 147606740625 256707375
1823 394070635302093 216166009491
2597 96342506397593044197 37097615093412801
5155 324903223321029232798074465 63026813447338357477803
10627 9300753824529071312360470246068903 875200322247960036921094405389
22331 79377444895975693055708664734623129867563975 3554585325152285748766677029001080554725
Table 4: Record-setting values of smallest representation N=A/B in palindromic numbers.
Conjecture 3. The size of the smallest solution to N=A/B in palindromes A, B, if it
exists, is not bounded by any polynomial in N.
The available numerical data suggest that perhaps the smallest solution, when one exists,
is bounded by NO(log N).
2.4 Infinitely many integers with no representation
Since 2n+1 is a palindrome for every n1, it is clear that infinitely many integers belong to
Qpal. We now prove that there are infinitely many odd integers in the complement NQpal.
Theorem 8. There are infinitely many odd positive integers Nfor which there is no solution
to N=A/B in palindromes A, B.
Proof. We prove that if 5·2k< N < 6·2kand N1 (mod 8), then Nhas no representation.
We prove this by considering the four possibilities for the first three bits of A:
A= 100 ...001. Then A1 (mod 8) and 4 ·2j+3 < A < 5·2j+3 for some j. Hence
2
3·2jk< B < 2jk, i.e., Bstarts with 101, 110 or 111. Therefore Bends with 101,
011 or 111, i.e., B5,3 or 7 (mod 8), i.e., A5,3 or 7 (mod 8), a contradiction.
A= 101 ...101. Then A5 (mod 8) and 5 ·2j+3 < A < 6·2j+3 for some j. Hence
5
6·2jk< B < 6
5·2jk, i.e., Bstarts with 110, 111 or 100. Therefore Bends with 011,
111 or 001, i.e., B3,7 or 1 (mod 8), i.e., A3,7 or 1 (mod 8), a contradiction.
A= 110 ...011. Then A3 (mod 8) and 6 ·2j+3 < A < 7·2j+3 for some j. Hence
2jk< B < 7
5·2jk, i.e., Bstarts with 100 or 101. Therefore Bends with 001 or 101,
i.e., B1 or 5 (mod 8), i.e., A1 or 5 (mod 8), a contradiction.
18
A= 111 ...111. Then A7 (mod 8) and 7 ·2j+3 < A < 8·2j+3 for some j. Hence
7
6·2jk< B < 8
5·2jk, i.e., Bstarts with 100, 101 or 110. Therefore Bends with 001,
101 or 011, i.e., B1,5 or 3 (mod 8), i.e., A1,5 or 3 (mod 8), a contradiction.
In fact, we’ve proved something more:
Corollary 9. The set of unrepresentable Nhas positive density in the natural numbers.
Proof. From the result above, a number Nis unrepresentable if N1 (mod 8) and the first
three bits of Nin base 2 are 101. Let us count the number f(x) of integers xsatisfying
these two conditions. Clearly f(x)/x achieves a local minimum when x= 5 ·2n. In this case
f(x) = 2n31. It follows that lim inf x→∞ f(x)/x = 1/40.
Remark 10.This bound 1/40 for the lower density can easily be improved by considering
other intervals.
2.5 Infinitely many different representations
Theorem 11. Suppose there is one solution in palindromes A, B to the equation N=A/B.
Then there are infinitely many solutions.
Proof. Suppose there is one solution N=A/B. Let d=|(A)2| − |(B)2|. For each i0
define Ai= [(A)20i(A)2]2and Bi= [(B)20i+d(B)2]2. Then Aiand Biare clearly palindromic
numbers, and N=Ai/Bi.
2.6 Rational solutions to p/q =A/B in palindromes
Our automaton method, discussed in Section 2.2.3, can be modified to get a solution A, B
in palindromes where A/B =p/q for integers p/q. Instead of computing N·B=A, the
automaton computes p·B=q·A. For simplicity, we assume that p > q as p=qis trivial
and if p < q then solutions to p/q can be derived from the solutions to q/p.
The structure of the automaton is similar but each state has a few modifications. In
place of the right carry, we have a carry cA,ℓ for Aand a carry cB,ℓ for B. At each step, the
automaton verifies
q·A+cA,ℓ1=p·B+cB,ℓ1mod k.
Let mbe the remainder of p·B+cB,ℓ1divided by k. The automaton then computes
cA,ℓ =q·A+cA,ℓ1m
k
and
cB,ℓ =p·B+cB,1m
k.
We get familiar bounds on the size of the carries, 0 cA,ℓ < q and 0 cB ,ℓ < p.
19
There is still just a single left carry, but it has to implicitly track the left carry for both
Aand B. To accomplish this, it tracks the difference between the left carry of Band the left
carry of A. Let c=cB,ℓ cA,ℓ. We can then derive an equation for computing c1from c.
c=cB,ℓ cA,ℓ
c=p·B+cB,ℓ1m
kq·A+cA,ℓ1m
k
k·c=p·B+cB,ℓ1mq·AcA,ℓ1+m
k·c=p·B+cB,ℓ1q·AcA,ℓ1
k·cp·B+q·A=cB,ℓ1cA,ℓ1
k·cp·B+q·A=c1
From the bounds on cA,ℓ and cB,ℓ we get that q < c< p.
The remaining structure is essentially identical. An accepting state is one where the left
carry is equal to the difference of the two right carries. (With the nondeterminism around
the middle symbols handled as usual.) The automaton nondeterministically chooses the
difference in size of Aand Bto be either the floor or ceiling of logk
p
q. Since 1 < p/q < k
can be a valid input, Aand Bcould have the same length. However, this only simplifies the
construction as we ignore the loading and unloading phase entirely since all of the symbols
in the equations line up perfectly.
Given the constraints on all the information we track, (and p > q,) there are at most
6·(p+q1) ·p·q·klogk
p
qO(kp3)
states in the new automaton which gives analogous bounds for computation of the minimal
p/q =A/B.
Conjecture 4. For all odd numbers p > 1, p6= 23, there exists an odd number q < p such
that p/q =A/B has a solution in palindromes A, B.
We have verified this conjecture for p < 1000. For p= 23 we can definitively prove, using
our automaton method, that there is no odd q < 23 such that p/q =A/B has a solution in
palindromes.
Sometimes the smallest solution to p/q =A/B can be quite large. For example, the
smallest solution to A/B = 979/765 in palindromic numbers is
435964577851526887677597179561025269848009167916543881959761365529045212378773108135544954987
340666907105636434191380840004274087266319727738668099794910566526782009672892163149838499045 .
3 Antipalindromic numbers
In this section we treat the same six problems for the antipalindromic numbers.
20
3.1 Denseness
Theorem 12. The set APAL/APAL is dense in the positive reals.
Proof. The proof is analogous to the proof of Theorem 2. We just outline the basic idea.
Let α,β, and kbe as in that proof.
There are two cases: kodd and keven.
If kis odd, for a given ndefine γ=2nβ. Set A= [(γ)2(γ2)R]2and B= [10c1c0]2
for c=n+ (k1)/2. Then Aand Bare both antipalindromic numbers, and A/B is an
arbitrarily good approximation to α, as n→ ∞.
If kis even, define γ=2n. Set B= [(γ)2(γ2)R]2and A= [10nk/21nk/20]2. Then
A/B is an arbitrarily good approximation to α, as n→ ∞.
Remark 13.Let a1< a2< a3<··· be the antipalindromic numbers. Here the criterion of
Theorem 1would not suffice to prove Theorem 12, since lim supnan+1/an= 2.
3.2 Quotients of antipalindromic numbers
The set Qapal ={1,5,6,15,17,18,19,20,21,24,26, . . .}of integers representable as the quo-
tient of two antipalindromic numbers, forms sequence A351172 in the OEIS. The set N
Qapal ={2,3,4,7,8,9,10,11,12,13,14,16,22, . . .}of unrepresentable integers forms sequence
A351173.
3.2.1 Decision algorithm
We can verify if a given Nis representable as the quotient of antipalindromic numbers Aand
Busing an analogous method to the algorithm given in Section 2.2.3. We build a similar
automaton to the automaton in Section 2.2.3, though it interprets the input ha, bias the
quotient of A=aaRand B=bbR. This interpretation is dependent on the base k, as
the middle character must be such that σ=σ. If kis odd then, σx∈ {ǫ, (k1)/2}and
if kis even then σx=ǫ. When the automaton interprets the input as above and computes
accordingly, it accepts antipalindromes that have quotient N. The algorithm also achieves
the same asymptotic bounds. Thus we have
Theorem 14. There is an algorithm that, given a natural number N, can determine if there
exist antipalindromes in base k A, B such that N=A/B in O(k2N3)time.
With our algorithm we computed the number of representable i-bit integers.
21
i|Qapal [2i1,2i)|
1 1
2 0
32
4 1
5 8
64
7 24
817
9 75
10 50
11 247
12 165
13 903
Table 5: Number of i-bit numbers representable as the quotient of antipalindromes
The available data suggest that perhaps there are roughly .12 ·1.81ii-bit solutions for i
even, and .36 ·1.81ifor iodd.
We can prove the following lower bound.
Theorem 15. There are Ω(2i)i-bit integers representable as the quotient of antipalin-
dromes.
Proof. If iis odd, then we can get O(2i) representable integers of ibits by taking Ato be
an antipalindromic number of i+ 1 bits, and B= 2.
If iis even, say i= 2j, we have to work a bit harder. First we observe that if x, y are
arbitrary binary strings of jbits and yends in 1, and A= [x y x y]2, then Ais divisible by
2(22j1).
To see this, note that
A= [x]2·23j+ [y]2·22j+ [x]2·2j+ [y]2
= [x]2·23j+ [y]2·22j+ (2j1[x]2)·2j+ (2j1[y]2)
= (22j1)([x]2·2j+ [y]2+ 1),
and observe that the second factor of the last line is even if [y]2is odd.
Now take y=xR, so that xstarts with 1. Then Ais an antipalindromic number (because
its base-2 representation is given by x xRx xR). From the previous paragraph we see that A
is divisible by 2(22j1). Since 22j1 is divisible by 3, it follows that Ais divisible by the
antipalindromic number B= 2(22j1)/3 = [(10)j]2.
Finally we need to estimate the number of these quotients A/B that have ibits. Suppose
22
2j1[x]2(2j+1 5)/3. Then
24j1A23j(2j+1 2)/3
3·24j1
2·(22j1) A/B (2j1)23j
22j1=23j
2j+ 1 <22j,
so A/B has 2jbits. Thus there are at least
(2j+1 5)/32j1+ 1 = 2j+1/12 2/3
numbers of 2jbits that are representable as quotients of antipalindromic numbers.
Even the following seems hard to prove.
Conjecture 5. The set of integers representable as quotients of antipalindromic numbers is
of zero density.
3.3 Size of the smallest representation
With our algorithm, we were able to compute the record-setting values of A, B given in
Table 6.
NA B
5 10 2
15 150 10
18 936 52
59 52140188 883732
66 65099232 986352
83 206712630902722 2490513625334
343 841469573210301602 2453264061837614
835 180616526119856633856230 216307216910007944738
991 200428779760870700728006297372550 202249020949415439685172853050
1268 75547761517760569279087608058268904 59580253562902657160163728752578
1290 4395923940796125166581803114404301293837667532540 3407692977361337338435506290235892475843153126
1952 1586681992762659022973996447792006955471260017904473853156544 812849381538247450294055557270495366532407796057619801822
4091 102232724919890518755288528068181989159740544137704480818962816 24989666321166100893495118080709359364395146452628814670976
4460 388987104335534771520764071813224655554298718228899978912430000 87216839537115419623489702200274586447152178975089681370500
4640 85112365674283227507265261996365447811182320230460498 18343182257388626617945099568182208579996189704840624
83220363630941564530051147747252794193043200 74831974920461544079752402531735515989880
4848 16307148112492799707206815760673202828585190069605262924 33636856667683167712885346040992580091966151133674222204
53647949068964670350753495389303768493316355031391840704 07689663921131745773006384878926915208985880840329704424
83231286976 1590612
5840 43493875233140378950672024766781801439773086758844870 74475813755377361216904151997914043561255285545967244
87734362685028948495519190020221259652712554180379503 65298566241487925506026010308598047350535195514348464
2037061443716557960233120 389907781458314719218
6624 33301854653004018709445764603598238453897624842252171 50274539029293506505805804051325843076536269387457987
14065184395426890419279201949902950413217648251363098 83310966780535764521858698595867980696282681538893566
49496826284424060000589698848419903839832345753230313 56849073497016998793160777247010724395882164482533686
683200744371137665623242712430446372631626633794372416 11594315273420541307856689678509416158156194715334
Table 6: Record-setters for smallest solutions A, B to N=A/B in antipalindromes.
23
The size of smallest solutions is somewhat larger than in the case for palindromes, which
is not too surprising, since there are fewer antipalindromes in base 2 than palindromes (since
the length of an antipalindrome must be even).
Conjecture 6. The size of a smallest solution to N=A/B, if it exists, is not bounded by
polynomial in N.
3.4 Numbers representable as quotients of antipalindromes
Theorem 16. There is an infinite set of integers representable as a quotient of antipalin-
dromes in base 2.
Proof. Integers of the form N= 22n+1 2n= (1n+10n)2are representable as a quotient
of antipalindromes. We have that A/B =Nfor A= 22n+2 2n+1 = (1n+10n+1) and
B= 2 = (10)2which are both antipalindromes.
Theorem 17. There is an infinite set of integers that are not representable as a quotient of
antipalindromes in base 2.
Proof. Integers of the form N= 22n+1 aren’t representable as a quotient of antipalindromes.
There are no antipalindromes of odd length in base 2, as the middle digit σmust equal
21σ= 1 σwhich has no solutions in {0,1}. Given any antipalindromic Bof length
2i,N·Bis of length 2i+ 2n+ 1 which is odd and not an antipalindromes. Therefore, there
are no antipalindromic Aand Bsuch that A/B =N.
Theorem 18. There are infinitely many Nfor which there is no representation N=A/B
with A, B APAL.
Proof. We show that if
40 ·4n< N < 48 ·4n(2)
for n0, and N1 (mod 4), then there is no representation N=A/B.
Suppose such a representation exists. Notice that Abeing an antipalindrome means that
(A)2has an even number of bits; that is, that 2 ·4iA < 4i+1 for some i.
Further, the inequality 40 ·4n< N < 48 ·4nimplies that the first three bits of (N)2must
be 101. Since (B)2is an antipalindrome, Bmust be even. If B= 2, then N=A/B implies
that 4iA < 2·4ifor some i, contradicting (2).
So Bis at least 4, and hence (B)2has at least three bits. We now claim that the first
three bits of (A)2must be the same as the first three bits of (B)2. To see this, suppose the
first three bits of (B)2are 1bc. Since (B)2is an antipalindrome, the last three bits of (B)2
must be cb0. Now N1 (mod 4), so by considering BN mod 8, we see that the last 3 bits
of A=BN must also be cb0. Since (A)2is an antipalindrome, the first three bits of (A)2
must also be 1bc, as claimed.
There are now four possibilities to check. These are summarized in Table 7below, where
jis some positive integer.
24
b c inequality
0 0 (4/5)4j< A/B < (5/4)4j
0 1 (5/6)4j< A/B < (6/5)4j
1 0 (6/7)4j< A/B < (7/6)4j
1 1 (7/8)4j< A/B < (8/7)4j
Table 7: Inequalities.
In each case these contradict (2). So Nis not representable.
Corollary 19. The lower density of unrepresentable numbers is 1/60.
Proof. By the previous proof, a number Nis unrepresentable if it has an even number of
bits, is congruent to 1 (mod 4), and begins with 101. If we let g(x) be the number of such
numbers x, then g(x)/x clearly has a local minimum at x= 40 ·4n, and for such xwe
have g(x) = (2 ·4n2)/3. The bound of 1/60 now follows.
3.5 Number of solutions
Another advantage of the finite automaton method is that for a given Nwe can determine
if there are infinitely many solutions to A/B =Nin antipalindromes, or whether there are
any fixed number of solutions.
Given the finite automaton constructed in Section 3.2.1 for antipalindromes, we first
remove all states from which we cannot reach a final state. (The construction ensures that
all states are reachable from the start state.) The resulting automaton has a cycle if and
only if there are infinitely many solutions.
We used this idea to compute the first few terms of the relevant sets. This gives us
sequence A351175, those Nfor which there are infinitely many solutions:
1,6,15,18,19,20,24,28,51,59,61,63,66,67,68,71,72,74, . . . ,
sequence A351176, those Nfor which there is at least one solution, but only finitely many:
5,17,21,26,65,69,70,85,89,92,102,106,116,219,221,233,239,245,249,257, . . . ,
and sequence A351325, those Nfor which there is exactly one solution:
5,21,26,69,85,89,92,102,106,116,219,221,233,239,245, . . . .
Theorem 20. There are infinitely many integers Nfor which there are infinitely many
solutions to the equation N=A/B for antipalindromes A, B.
Proof. Let N= 22n+1 2nfor n1. Define
Bi= [1(0n+21n+2 )i0]2= 22ni+4i+1 + (2n+2 1) ·
i1
X
j=0
22nj+4j+1
25
for i0. Clearly Biis an antipalindrome. We now compute Ai=N·Bi.
N·Bi= (22n+1 2n)· 22ni+4i+1 + (2n+2 1) ·
i1
X
j=0
22nj+4j+1!
= (22ni+4i+2n+2 22ni+4i+n+1) + (23n+3 22n+2 22n+1 + 2n)· i1
X
j=0
22nj+4j+1!
= (22ni+4i+2n+2 22ni+4i+n+1) + (22n+3 2n+2 2n+1 + 1) ·2n· i1
X
j=0
22nj+4j+1!
= (22ni+4i+2n+2 22ni+4i+n+1) + (22n+3 2n+2 2n+1 + 1) · i1
X
j=0
22nj+4j+n+1!
= [1n+102ni+4i+n+1]2+ [1n010n1]2·[(102n+3)i110n+1]2
= [1n+102ni+4i+n+1]2+ [(1n010n10)i11n010n10n+1]2
= [1n+10(1n010n10)i11n010n10n+1]2
= [1n+1(01n010n1)i0n+1]2
=Ai.
Thus Aiis also an antipalindrome for each i0. Therefore, we have an infinite set of
representations Ai/Bi=Nwhere Aiand Biare antipalindromes for each N= 22n+1 2n.
Theorem 21. There are exactly 2i1solutions to N=A/B for N= 4i+ 1 and A, B
antipalindromes.
Proof. Let N= 4i+ 1 = [102i11]2. Consider an antipalindrome B. Let (B)k=βand
|β|=.
If βhas length ℓ < 2i, then (BN )k= (A)k=β02iβ. Since antipalindromes in base
2 have even length, the center of (A)kis at least two zeros which means that Aisn’t an
antipalindrome.
If βhas length = 2i, then (BN)k= (A)k=ββ. Here, Ais an antipalindrome since
(ββ)R=βRβR=ββ.
If βhas length ℓ > 2i, then (BN)kcan be viewed as the binary addition of [β02i]2+ [β]2.
Since βwas sufficiently long, there is some non-trivial overlap in the addition. Let j= 2i.
The overlap has length jand there are jsymbols of βon each side of the overlap.
β[1 : j]β[j+ 1 : ] 0j
+ 0jβ[1 : j]β[j+ 1 : ]
Figure 1: Piecewise addition of [β02i]2+ [β]2.
Since Bis an antipalindrome, we get that β[1 : j] = β[j+ 1 : ]R. This means for
[β02i]2+ [β]2to be an antipalindrome the overlap region must not overflow to the left. We
26
have additional information that further constrains this addition. We know that β[1] = 1
which implies that β[] = β[1] = 0. Additionally, we know that the overlap region can’t
overflow so β[j+ 1] = 0 which subsequently implies that β[j] = β[j+ 1] = 1. As well,
the remaining addition β[j+ 2 : 1] + β[2 : j1] must not overflow either.
β[1 : j]0β[j+ 2 : 1] 0 0j
+ 0j1β[2 : j1] 1 β[j+ 1 : ]
=β[1 : j] 1 β1β[j+ 1 : ]
Figure 2: Piecewise addition of [β02i]2+ [β]2with constraints.
From the result of the addition we see that we have a 1 at j+ 1 symbols from the front
and a 1 at j+ 1 symbols from the back. Therefore, this can’t be an antipalindrome.
Overall, given an antipalindrome B,BN is an antipalindrome if and only if (B)khas
length 2i. There are 2i1antipalindromes of length 2i, so for N= 4i+ 1 there are exactly
2i1solutions to N=A/B for Aand Bantipalindromes.
Theorem 22. There are infinitely many integers Nsuch that N=A/B has exactly one
solution in antipalindromes A, B.
Proof. Consider Nof the form (22n1)/3 for n2. Clearly (2N)2= (10)n, so 2Nand 2
are both antipalindromes. This gives one solution to N=A/B.
Now let us assume there is another solution to N=A/B with A, B antipalindromes.
Since B > 2, and the next larger antipalindrome is 10, we see that Bhas at least 4 bits.
Choose k1 such that 4 ·2kB < 8·2k.
Note that 5 ·22n3N < (16/3) ·22n3. We can use this inequality together with
A=BN to determine the first three bits of A. They are summarized in Table 8, where
=k+ 2n3.
first three inequality inequality first three
bits of Bfor Bfor A=BN bits of A=BN
100 4 ·2kB < 5·2k20 ·2A < 80
3·2101 or 110
101 5·2kB < 6·2k25 ·2A < 32 ·2110 or 111
110 6 ·2kB < 7·2k30 ·2A < 112
3·2111 or 100
111 7·2kB < 8·2k35 ·2A < 128
3·2100 or 101
Table 8: Possibilities for first three bits of A.
On the other hand, if Bstarts with three bits abc, then since Bis an antipalindrome,
it must end with cba. Since N5 (mod 8), one can easily check that A=BN also ends
with cba. Since Ais an antipalindrome, it must begin with abc. So the first three bits of A
and Bare the same. This contradicts the results of Table 8, and proves there are no other
solutions.
27
3.6 Rational solutions to p/q =A/B in antipalindromes
Once again our automaton method for antipalindromes can be generalized to give the fol-
lowing result.
Theorem 23. There is an algorithm that, given integers p, q 1, will decide if there is a
solution to p/q =A/B in antipalindromes A,B.
We used our algorithm to study the rational solutions to p/q =A/B in antipalindromes
for p > q and p1000. Based on our calculations, we make the following conjecture.
Conjecture 7. For all p4 there exists q < p such that p/q =A/B has a solution in
antipalindromes.
We note that there are no solutions for (p, q)∈ {(2,1),(3,1),(3,2)}.
Some solutions to p/q =A/B can be enormously large. For example, the smallest solution
for p/q = 960/527 is A=
1234883355213990975204467140683475994799335003626682427756930130658317
0577845541101597875372665385744362733254798839009872167396310323997903
5640547077917392804795250182028753800174169116477800361082899344465944
5560841114705454770902394470289417027557405950223685182751710075724367
6048238590480983878073501486368624181821560779594741108091349800844282
5679592833678865846036391335428845975712764583827139150178213891564696
4718825426930262288729775928481863474655184300859716583115484263497126
2961706100246193708891656878945533178186000927736300244493837237642640
9349549969820438753161560915890436797199051312068851515357512387981254
4604809069807177738058155380014435541831993909182136704602824634226568
3451444571619483682225669077170879824401082095216563292486986361198314
2620371328966957512364597567158981492432747694245025717455343991855418
3265938974040814493629275353847375559776274838299843008368743842579023
9993356699741468657156369097163207591351729526813712761138142291367822
0794954727600533534516312312331038829749723349859042215544591191317981
8600650852792742320291709382397741664309047654075764338087057307850282
7509649077719055308633225064218430763198619435136533732460140152765958
4251780426995592541451396343086191791838699791485099128013340230974422
4295888043536875650860208149665479650685364073997568860181548161096442
1040420056468998183952438585617409445628800
28
and B=
6778995085393471290966189407710331763117182780325642077373981029759719
6817964585005646670014527690492491254429989459981277418935995216113491
4401753229817354251323925478428679715539449212331258232194666193057841
4693367369268486086099602977526278890862009747582105117814075103195226
3306476428994567747340992534544426498124609696316964207959805677551426
1803598159882940633970606601781269054173197246634399293165820008902031
6737718749919252355839499107395229699409188818261152492727710488156099
5633532446143167547769824741711416509416900926219064883835960669142414
2991800355160116905376485444523543667957292098544632797848010713188761
4653483122795652791215082138204245109848549897281104617975922731639599
1446992596286123963884662538219309036035106918532592241048352211994912
6676413441308193843918155394716492151167271196532589094780898788622973
5220310826244887897319042827891322083355175414416846514690916719157767
1630197716289103982514651189635525006691265214904444011664593620321273
2905636890057095548855172797900598575813585472663700495749995394006004
5859822910643491695768029630454269344696542851020081314290408346219781
3516511082895230704684475092115760543809087940801596635484311046954792
6048836302361221555675894508400240357281195730340075421489898976286673
1290968738999306958368017654934455999074863197882487388704957092685676
966980593499127128065557431896223726923310 .
4 Going further
We have not examined what surprises might await us in other bases. To give just a taste,
the smallest representation of 436 as the quotient of base-10 palindromes is
4062320931846767973606063797676481390232604
9317249843685247645885467425863489427139 .
References
[1] J. S. Athreya, B. Reznick, and J. T. Tyson. Cantor set arithmetic. Amer. Math. Monthly
126 (2019), 4–17.
[2] W. D. Banks. Every natural number is the sum of forty-nine palindromes. INTEGERS:
Elect. J. Combin. Number Theory 16 (2016), #A3 (electronic).
29
[3] B. Brown, M. Dairyko, S. R. Garcia, B. Lutz, and M. Someck. Four quotient set gems.
Amer. Math. Monthly 121 (2014), 590–599.
[4] J. Bukor, P. Erd˝os, T. ˇ
Sal´at, and J. T. T´oth. Remarks on the (R)-density of sets of
numbers. II. Math. Slovaca 47 (1997), 517–526.
[5] J. Bukor and J. T. T´oth. On accumulation points of generalized ratio sets of positive
integers. Acta Acad. Paedagog. Agriensis Sect. Math. 30 (2003), 37–43.
[6] J. Cilleruelo, F. Luca, and L. Baxter. Every positive integer is a sum of three
palindromes. Math. Comp. 87 (2018), 3023–3055. Published electronically at
http://dx.doi.org/10.1090/mcom/3221.
[7] A. Cobham. On the base-dependence of sets of numbers recognizable by finite automata.
Math. Systems Theory 3(1969), 186–192.
[8] J. Endrullis, J. Shallit, and T. Smith. Undecidability and finite automata. In ´
E. Charlier
et al., editors, DLT 2017, Vol. 10396 of Lect. Notes in Comput. Sci., pp. 160–172.
Springer-Verlag, 2017.
[9] S. R. Garcia, D. E. Poore, V. Selhorst-Jones, and N. Simon. Quotient sets and Dio-
phantine equations. Amer. Math. Monthly 118 (2011), 704–711.
[10] R. K. Guy. Unsolved Problems in Number Theory. Springer-Verlag, 2004.
[11] D. Hobby and D. M. Silberger. Quotients of primes. Amer. Math. Monthly 100 (1993),
50–52.
[12] J. E. Hopcroft and J. D. Ullman. Introduction to Automata Theory, Languages, and
Computation. Addison-Wesley, 1979.
[13] V. Kijonka. On relations between f-density and (R)-density. Acta Math. Univ. Ostrav.
15 (2007), 15–20.
[14] J. H. Loxton and A. J. van der Poorten. An awful problem about integers in base four.
Acta Arith. 49 (1987), 193–203.
[15] F. Luca, C. Pomerance, and ˇ
S. Porubsk´y. Sets with prescribed arithmetic densities.
Unif. Distrib. Theory 3(2008), 67–80.
[16] M. Madritsch and T. Stoll. On simultaneous digital expansions of polynomial values.
Acta Math. Hung. 143 (2014), 192–200.
[17] L. Miˇs´ık. Sets of positive integers with prescribed values of densities. Math. Slovaca 52
(2002), 289–296.
[18] L. Miˇs´ık and J. T. T´oth. Logarithmic density of a sequence of integers and density of
its ratio set. J. Th´eorie Nombres Bordeaux 15 (2003), 309–318.
30
[19] P. Miska, J. T. T´oth, and B. ˙
Zmija. On distribution of subsequences of primes hav-
ing prime indices with respect to the (R)-denseness and convergence exponent. Arxiv
preprint, available at https://arxiv.org/abs/1908.10421, 2022.
[20] W. Narkiewicz and T. ˇ
Sal´at. A theorem of H. Steinhaus on (R)-dense sets of positive
integers. Czech. Math. J. 34 (1984), 355–361.
[21] A. Rajasekaran, J. Shallit, and T. Smith. Additive number theory via automata theory.
Theory Comput. Sys. 64 (2020), 542–567.
[22] E. Rowland and J. Shallit. Automatic sets of rational numbers. Internat. J. Found.
Comp. Sci. 26 (2015), 343–365.
[23] T. ˇ
Sal´at. On ratio sets of sets of natural numbers. Acta Arith. 15 (1969), 273–278.
Corrigendum, 16 (1969), 103.
[24] T. ˇ
Sal´at. Remarks on Steinhaus’ property and ratio sets of positive integers. Czech.
Math. J. 50 (2000), 175–183.
[25] W. Sierpi´nski. Elementary Theory of Numbers. North-Holland, 1988.
[26] M. Sipser. Introduction to the Theory of Computation. Cengage Learning, 3rd edition,
2013.
[27] P. Starni. Answers to two questions concerning quotients of primes. Amer. Math.
Monthly 102 (1995), 347–349.
[28] T. Stoll. Thue-Morse along two polynomial subsequences. In Combinatorics on Words,
Vol. 9304 of Lect. Notes in Comput. Sci., pp. 47–58. Springer-Verlag, 2015.
[29] O. Strauch and J. T. T´oth. Asymptotic density of ANand density of the ratio set
R(A). Acta Arith. 87 (1998), 67–78. Corrigendum, 103 (2002), 191–200.
[30] J. T´oth and L. Szilinszky. On density of ratio sets of powers of primes. Nieuw Archief
voor Wiskunde 13 (1995), 205–208.
31
ResearchGate has not been able to resolve any citations for this publication.
Article
Full-text available
We show how some problems in additive number theory can be attacked in a novel way, using techniques from the theory of finite automata. We start by recalling the relationship between first-order logic and finite automata, and use this relationship to solve several problems involving sums of numbers defined by their base-2 and Fibonacci representations. Next, we turn to harder results. Recently, Cilleruelo, Luca, & Baxter proved, for all bases b ≥ 5, that every natural number is the sum of at most 3 natural numbers whose base-b representation is a palindrome (Cilleruelo et al., Math. Comput. 87, 3023–3055, 2018). However, the cases b = 2, 3, 4 were left unresolved. We prove that every natural number is the sum of at most 4 natural numbers whose base-2 representation is a palindrome. Here the constant 4 is optimal. We obtain similar results for bases 3 and 4, thus completely resolving the problem of palindromes as an additive basis. We consider some other variations on this problem, and prove similar results. We argue that heavily case-based proofs are a good signal that a decision procedure may help to automate the proof.
Article
Full-text available
Using a novel rewriting problem, we show that two natural decision problems about finite automata are undecidable (i.e., recursively unsolvable). In contrast, we also prove three related problems are decidable. We apply one result to prove the undecidability of a related problem about k-automatic sets of rational numbers.
Article
Full-text available
For integer g5g\ge 5, we prove that any positive integer can be written as a sum of three palindromes in base g.
Article
Full-text available
It is shown that the set of decimal palindromes is an additive basis for the natural numbers. Specifically, we prove that every natural number can be expressed as the sum of forty-nine (possibly zero) decimal palindromes.
Article
Full-text available
In the paper sufficient conditions for the (R)-density of a set of positive integers in terms of logarithmic densities are given. They differ substantially from those derived previously in terms of asymptotic densities.
Article
Every element u of [0,1] can be written in the form u=x2yu=x^2y, where x,y are elements of the Cantor set C. In particular, every real number between zero and one is the product of three elements of the Cantor set. On the other hand the set of real numbers v that can be written in the form v=xy with x and y in C is a closed subset of [0,1] with Lebesgue measure strictly between 1721\tfrac{17}{21} and 89\tfrac89. We also describe the structure of the quotient of C by itself, that is, the image of C×(C{0})C\times (C \setminus \{0\}) under the function f(x,y)=x/yf(x,y) = x/y.