5

Edit: Decided to add visual previews of patterns instead of extracting all the polynomials.
Perhaps you have seen something that behaves similarly somewhere else?



For a given $b,d\in\mathbb N$, how can we effectively find all numbers that are $(2d+1)$ digit palindromes in number bases $b+1$ and $b+3$ ?

For example, solutions for case $(d,b)=(1,9)$ are $\{181, 555, 616, 676, 737, 797\} $ since they are palindromic in number bases $10$ and $12$ and have three digits in those number bases.

For arbitrary $b$ and $d$, I generate palindromes computationally. But this does not scale well and gets very inefficient for $(d=3,b\ge200),(d\ge4,b\ge100)$ cases, because there are too many palindromic candidates that need to be checked.

I'm hoping that one could exclude a significant amount of palindromes from the search to make generating these examples for such cases, efficiently plausible.



But more importantly, instead of relying on computations,

Can we solve this problem mathematically for arbitrary $(d,b)$ cases? Because I believe managed to solve it for $(d\in\{1,2\},b\in\mathbb N)$ cases, but I'm not sure how to extend the generating patterns to $d\ge3$, nor how to prove them as they were obtained from computed data only.

It seems that for very small $b$, it is not clear how to predict solutions, but for every $d$ there seems to exist some number base $B_d$ such that for all $b\ge B_d$ the pattern can be used to predict solutions exactly. ($B_d$ is negligible for small $d$)

The best way to visualize patterns is to observe $P_n(d,b)$ which stands for $n^{\text{th}}$ $2d+1$ digit palindrome in number base $b$. Now, every solution $\{x_1,x_2,\dots,x_i\}$ for some $(d,b)$ case can be expressed as $P_n(d,b+1)=x_j=P_m(d,b+3)$, so we can assign corresponding palindrome index $n$ to every $x_j$ and observe $n$s instead of decimal values $x_j$s.

I filled the excel sheets with differences $\{n_1,n_2-n_1,n_3-n_2,\dots,n_i-n_{i-1}\}$ of solution indexes $\{n_1,\dots,n_i\}$ for cases $(d,b)$ where different columns represent different bases $b$ in order, filled with solutions in order, where $d$ is fixed per excel sheet. Then within each column, color the same values with the same color.

Case $d=1$ sheet can be seen below:

enter image description here

Where we can pick every second column, and sort the data (number bases) in two cases:

enter image description here

Notice that the first case has fixed amount of solutions per base, and alternates between "red" and "green" types of solutions. These are easy to calculate/predict for the $n^{\text{th}}$ column. The second case is also easy to predict for the arbitrary column/base as all red values follow one polynomial equation, all greens the second, all blue solutions a third, and all yellows a fourth.

Now we see that we do not need to check every palindrome for $d=1$ cases, but can directly obtain desired solutions following these simple patterns.

Similarly, for $d=2$ we have established a pattern (more detailed than previous case) that can be split up in four cases by taking every fourth number base:

enter image description here

Again, same colored values can be described by same polynomials, which can be extracted from the data. As you can see, we have one finite-column pattern, two patterns similar to the previous case of $d$, and one very long pattern - which are all fully predictable at this point.

It seems that patterns for every next cases of $d$ are more detailed cases of the previous case. But I have no idea how to generalize this to all $d$, thus I'm trying to compute more data for $d=3$ and $d=4$ at the moment, where $d\ge5$ is simply unreachable because of the absurd number of palindromes and cases that would need to be computed.

Here is a part of $d=3$ data so far, visualized:

enter image description here

This case can be split in six separate pattern cases (by taking every sixth column), if I'm not mistaken so far as I've observed only one of the predicted six clearly, so far. I expect these will become fully clear after some more data is computed. But I do not see how to extend these so far to next $d$ cases.

Full patterns for $d\ge5$ are computationally out of reach by my current methods, and for $d=4$ will take time and patience at best, if I'm not underestimating them.


The mentioned $P_n(d,b)$ can be defined as:

$$1 + b^{2 d} + b^dn + b^{d - 1}\left\lfloor \frac{n}{b} \right\rfloor - \sum_{i=1}^{d - 1} \left((b^{i + 1} - b^{i - 1})\left\lfloor \frac{n}{b^{d - i + 1}} \right\rfloor \right), 0\le n\lt b^{d+1}-b^d$$

Problem becomes: find all $n$ for which there exists $m$ such that $P_n(d,b+1)=P_m(d,b+3)$.

I believe I could so far generate all solutions for $d\in\{1,2,3\}$ and chosen $b$s if I were to extract all the polynomials from the patterns - but this won't help solve more cases of $d$. What is needed, is a mathematical approach that could lead to a way of generating these patterns for some arbitrary $d$.

Vepir
  • 12,516
  • 1
    Generating palindromes in one base and checking if they are also palindromes in a second base should not be "extremely slow". How do you check whether an integer is a palindrome in some base? Anyway, since you want the number to have the same number of digits in both bases, you can save some work by only generating palindromes in the smaller base that have the right number of digits in the larger base. The larger $d$ is (for fixed $b$), the more work that saves. – Daniel Fischer Mar 29 '18 at 20:10
  • @DanielFischer It is fast indeed to check individual examples for being palindromic in selected bases, but as the $d,b$ grow, the total amount to be checked grows so much. If you could compute examples faster, that'll be very helpful. Essentially, I'm generating palindromes in one base and converting to another. I uploaded something to repl.it if you want to check out the python code. - for example, finding all examples for $(4,b>100)$ takes days. Similar code was posted to codereview.SE for optimization, but nothing significant was found. – Vepir Mar 29 '18 at 21:09
  • Working with numbers instead of string-like representations of numbers should be faster. But I'll need to write some code to check. – Daniel Fischer Mar 29 '18 at 21:23
  • 2
    This becomes a Diophantine problem over positive integers if we fix three consecutive bases and it seems to be hard. – Shalom Mar 29 '18 at 21:50
  • Okay, I've done some coding. First up, though, a general observation. For $d = 4$ and $b > 100$, you're looking at north of $10^{10}$ palindromes to check, that will require some time regardless of implementation details. Concerning the code, I've tested the Python implementations with $d = 3$, generating palindromes in base $113$, testing which of them are also palindromes in base $115$. Working with numbers rather than lists of digits gave me a speedup factor of almost $4$, using Python 2 rather than Python 3 raised the factor to a little over $5$. Your code ran in just under 20 minutes here – Daniel Fischer Mar 30 '18 at 21:53
  • and my version just above 5 minutes (P 3) and a little less than 4 (P 2). Extrapolating, that would be around 8 (or 10 for Python 3) hours for $d = 4$ (i.e., 9-digit palindromes) and bases $113,115$. Better than "days", but still a long time. Switching to a language with a faster implementation than the default Python interpreters seems advisable. I've implemented my version in Haskell, compiled with optimisations but didn't fine-tune the code, that ran the $d = 4$, bases $113,115$ check in about 95 minutes. So it spent approximately $3\cdot 10^{-7}$ seconds per base-$113$ palindrome, – Daniel Fischer Mar 30 '18 at 21:54
  • which ain't too terrible, I think. Still, checking $11$-or-more-digit-palindromes in bases of that size with that would require strong determination and much patience. – Daniel Fischer Mar 30 '18 at 21:54
  • @DanielFischer I appreciate your analysis. I'll look into Haskell and try to implement the search there to compute more terms for $d=3,4$ cases. I've managed so far to extract patterns for $d=1,2$ cases which allow direct generation of examples for arbitrary $b$ without needing to check any palindromes. I'm hoping to be able to compute enough terms for $d=3,4$ to extract patterns for these too. This is my only options so far, as I do not know any approach that would allow me to solve for those patterns for arbitrary $d$. – Vepir Mar 30 '18 at 22:37
  • @DanielFischer would you mind sharing your implementation in haskell? I implemented now in c++11, while numerically generating palindromes in first base, and converting to list (vector) of integers to check if palindromic in the second base: it is faster than python implementation for sure, but still takes few hours for bases $113,115$ and $d=4$, which is still slower than your hour and a half you mention. – Vepir Mar 31 '18 at 20:14
  • 1
    Here's Haskell, and Python 2. I've only implemented the creation of palindromes with an odd number of digits, but doing even numbers if wanted is no problem. Converting to a list/vector of digits to check for palindromicity is slow and unnecessary. Avoid that. It's fine to do that for the handful of multi-base palindromes one finds, but not for all candidates. – Daniel Fischer Mar 31 '18 at 20:26
  • @DanielFischer I ended up implementing your numerical functions in c++11 which seems to be good enough for now. I'm not sure what else I could do but leave my laptop on 24/7 and be patient. – Vepir Apr 01 '18 at 18:19

0 Answers0