Represent all palindromic numbers across number bases based on digit count

244 Views Asked by At

I've been looking at plots/graphs of palindromic numbers across number bases, and noticed that we should be able to represent all $d$ digit palindromes across number bases $y$, with some expression $x_y$ where $x,y\in\mathbb N, y\gt1$.


  • Let $P_d\in\mathbb N$ denote an expression $P_d=x_y$ which is always a $d$ digit palindrome and stands for all $d$ digit palindromes ( Represent $x,y$ with $m,n\in\mathbb N$ )

Taking this, I found so far by observing my graphs/plots:

$(1)$ All one digit palindromes are given by following:

$$P_1= (m)_{(m+n)}$$

( Read: $P_1$ stands for all $1$-digit palindromes, where $x=m$ is always $1$-digit palindrome in number base $y=m+n$, where this holds $\forall m,n\in\mathbb N$)

$(2)$ Similarly, all two digit palindromes are given by:

$$P_2=\left(m^2+(n+1)m \right)_{(m+n)}$$

( Read: $P_2$ stands for all $2$-digit palindromes, where $x=m^2+(n+1)m$ is always $2$-digit palindrome in number base $y=m+n$, where this holds $\forall m,n\in\mathbb N$)

How can one find $P_d$ for $d=3,4,5,\dots$ ?

Update: This can be neatly extended to any $P_d$ but with proper introduction of new variables for each new digit needed, as String showed in his answer.

If we always have $y=m+n$ then:
(I've decremented $k$ by $1$ if you compare this to Strings answer)

$$ P_d = \left(my^{d-1}+(k_1-1)y^{d-2}+(k_2-1)y^{d-3}\dots +(k_2-1)y^{2}+(k_1-1)y^{1}+m \right)_{(y)}$$

Where all $k_r\in\mathbb N\le y$. For example, take $d=3$:

$$P_3 = (my^2+(k_1-1)y+m)_y $$ $$(*) \space\space\space\space P_3 = \left(m^3+(2n)m^2+(n^2+k_1)m+n(k_1-1)\right)_{(m+n)} $$



P.S. I've decided to accept the answer as It turns out I can work with that.
I'll still leave my initial thought below.

My initial approach was trying to not introduce a new variable. But the failed attempt below shows what happens when you limit $k_1$ to only $3$ values:

$(3?)$ Looking at $d=3$ and using $k\in \{ 0,1,2 \} $, the following is almost correct:

$$P_3 = \left(4m^2+(5n-3)m+n^2-3n+1+(n+m)k\right)_{(m+n)}$$

Almost correct, since each $m$ has exceptions, which are more numerous the bigger $m$ is.
For example, all exceptions for $m=1,2,3,4,5,6,7$ below:

If $m=1, n=1, k=2$, then $P_3$ is not a $3$-digit palindrome.

If $m=2$, then increment on $P_3$ for $k=0,1,2$ should be:
For $n=1$: $+1,+1,+1$
For $n=2$: $+0,+1,+1$
For $n=3$: $+0,+0,+1$

If $m=3$, then increment on $P_3$ for $k=0,1,2$ should be:
For $n=1$: $+1,+1,+2$
For $n=2$: $+1,+1,+1$
For $n=3$: $+1,+1,+1$
For $n=4$: $+0,+1,+1$
For $n=5$: $+0,+0,+1$

If $m=4$, then increment on $P_3$ for $k=0,1,2$ should be: (Notice we need to include $n=0$)
(For $n=0$: $+2,+2,+2$)
For $n=1$: $+1,+2,+2$
For $n=2$: $+1,+1,+1$
For $n=3$: $+1,+1,+1$
For $n=4$: $+1,+1,+1$
For $n=5$: $+1,+1,+1$
For $n=6$: $+0,+1,+1$
For $n=7$: $+0,+0,+1$

If $m=5$, then increment on $P_3$ for $k=0,1,2$ should be: (Include $n=0$)
(For $n=0$: $+2,+2,+2$)
For $n=1$: $+2,+2,+2$
For $n=2$: $+1,+1,+2$
For $n=3$: $+1,+1,+1$
For $n=4$: $+1,+1,+1$
For $n=5$: $+1,+1,+1$
For $n=6$: $+1,+1,+1$
For $n=7$: $+1,+1,+1$
For $n=8$: $+0,+1,+1$
For $n=9$: $+0,+0,+1$

If $m=6$, then increment on $P_3$ for $k=0,1,2$ should be: (Include $n=0,-1$)
(For $n=-1$: $+3,+3,+3$)
(For $n=0$: $+2,+2,+2$)
For $n=1$: $+2,+2,+2$
For $n=2$: $+1,+2,+2$
For $n=3$: $+1,+1,+1$
For $n=4$: $+1,+1,+1$
For $n=5$: $+1,+1,+1$
For $n=6$: $+1,+1,+1$
For $n=7$: $+1,+1,+1$
For $n=8$: $+1,+1,+1$
For $n=9$: $+1,+1,+1$
For $n=10$: $+0,+1,+1$
For $n=11$: $+0,+0,+1$

If $m=7$, then increment on $P_3$ for $k=0,1,2$ should be: (Include $n=0,-1,-2$)
(For $n=-2$: $+3,+3,\emptyset$)
(For $n=-1$: $+3,+3,+3$)
(For $n=0$: $+2,+2,+2$)
For $n=1$: $+2,+2,+2$
For $n=2$: $+2,+2,+2$
For $n=3$: $+1,+1,+2$
For $n=4$: $+1,+1,+1$
For $n=5$: $+1,+1,+1$
For $n=6$: $+1,+1,+1$
For $n=7$: $+1,+1,+1$
For $n=8$: $+1,+1,+1$
For $n=9$: $+1,+1,+1$
For $n=10$: $+1,+1,+1$
For $n=11$: $+1,+1,+1$
For $n=12$: $+0,+1,+1$
For $n=13$: $+0,+0,+1$

And so on for all $m\dots$

In $m=7,n=-2,k=2$ you can see I put "$\emptyset$" symbol. That's because that number is not a $3$ digit palindrome for any increment.

As seen here, for the current $P_3$ as seen above; Bigger $m$ tend to need more increments/offsets for more values of $n$ and start missing more palindromes needing values using $n\lt1$, and also we have these irregularities - numbers not being $3$ digit palindrome for $k=2$ sometimes as seen in $m=1$ and $m=7$.

1

There are 1 best solutions below

7
On BEST ANSWER

I am not sure, what you are after. But the number of $d$-digit palindromes in base $y$ must equal $y^{\lceil d/2\rceil}$ if we include those starting with a zero. If we do not include those, the figure becomes $y^{\lceil d/2\rceil}-y^{\lceil d/2\rceil-1}$. So if your formulas must cover all palindromes of a given length, the number of parameter settings $n,m,k,...$ should reflect the number of palindromes.


This works well for $d=2$ using $y=m+n$ since all we need is a choice of base $y$, and a choice of a non-zero digit $m$ in that base, from which we can form: $$ \begin{align} P_2&=my+m\\ &=m^2+(n+1)m \end{align} $$ which becomes the palindrome $mm$ in base $y$.


The formula for $P_3$ could similarly read $$ \begin{align} P_3&=my^2+ky+m\\ &=m^3+m(2mn+n^2+1)+k(m+n) \end{align} $$ which becomes the palindrome $mkm$ in base $y=m+n$. So were we must choose $k$ in the digit range $0,1,...,y-1$.


Regarding $P_4$ we could similarly form $$ P_4=my^3+ky^2+ky+m $$ which gives us the palindrome $mkkm$ in base $y=m+n$. For $P_5$ we would need to introduce an extra variable in order continue this approach. Again, I am not sure whether this is anything like what you had in mind.


UPDATE: From your comment, I see that you rather wanted to express parametrisations in terms of as few variables as possible. This approach in no way achieves this, as it introduces a new variable for every second value of $d$ (i.e. for every new digit introduced).

One major consideration then becomes that the ranges for the "fewer than $\lceil d/\rceil$" variables have to be greater than just $[0,y)$ and $[1,y)$ in order to be able to cover all the cases just by a simple counting argument.

For instance there must be $y^2-y^1=y(y-1)$ $3$-digit palindromes in base $y$, so any choice of variables should be able to range over that many combinations.