I am reposting a question I posted on r/mathematics. It was suggested I ask it here.
My son was jotting down some multiplications for school and asked me if there were many numbers that, when multiplied by their mirror image, resulted in a palindromic number (e.g. 221 x 122 = 26962).
I made a quick Python script to test this and found the results rather surprising.
For 3-digit numbers, there are 11 results. For 4-digit number, there are 23. The number of positive results doubles approximately with each addition of a digit, reaching 642 results with 9-digit numbers and 1118 results with 10-digit numbers. As you can see from the table below, the ratio of 2 seems to decrease with every iteration after the 6th.
This is the longest number we could test because calculating time increases exponentially by a factor of approximately 10, reaching 3 hours for the last example.
What I find interesting is that in all of the above results, with no exception, the factors are invariably composed of zeros, ones and twos. There's never anything else.
For example: 2100110011 x 1100110012 = 2310352049402530132.
I asked a mathematician friend — not remotely involved with number theory or arithmetic – and he said it might be related to "carry digits" messing things up. It's true that for 1-digit numbers, excluding the trivial zero, there are only 3 possible examples (1, 2 and 3) before the symmetry breaks (4 x 4 is 16 which isn't palindromic). But when multiplying huge 10-digit numbers you get tons of "carry digits" as can clearly be seen from the results: these can include any digit as seen in the example above.
It does seem to have some impact, though. For a test for n digits, all the multiplication results have the exact same number of digits, which is always 2n-1. e.g. 4-digit numbers always give 7-digit results.
I am sure there must be a deep reason for never seeing digits above 2 in the factors, but for the life of me I can't understand what it is.
Like I wrote I've only tested this up to ten digits, so my conclusion could be wrong.
Any insights are welcome. I'm not a mathematician, so please forgive me if this seems trivial to you.
I hope the table below is clear. Thanks a lot.
digits digits number ratio calc
in in of with time
factors results palindromes previous
1 1 3
2 3 4 1,333 0,001
3 5 11 2,750 0,001
4 7 23 2,091 0,011
5 9 46 2,000 0,110
6 11 93 2,022 1,081
7 13 185 1,989 10,973
8 15 353 1,908 108,295
9 17 642 1,819 1132,420
10 19 1118 1,741 11227,896
And BTW the script is below in case someone cares. I'm not a programmer either, so I wouldn't know how to multithread or otherwise optimize this, but it's a bit besides the point I think — the pattern here *does* seem to confirm itself, although of course it's no proof.
def mirror(length):
print('Working...')
count = 0
start = time.time()
for i in range(1, pow(10,length)):
a = str(i).zfill(length)
b = a[::-1]
result = str(int(a) * int(b))
if (result == result[::-1]):
print(a, b, result)
count += 1
end = time.time()
print(f'-----------\nSize : {length}\nTotal : {count}\nTime : {round(end-start, 3)}')
mirror(6)
You can see it more clearly when you use polynomials instead of base-10 numbers. If you have one polynomial that is $4x^3+6x^2-3x+5$ and the other is the "reverse" $5x^3-3x^2+6x+4$, the product would be $$20 x^6 + 18 x^5 - 9 x^4 + 86 x^3 - 9 x^2 + 18 x + 20$$ whose coefficients are palindromic. You are only getting a certain number of them when you multiply numbers instead of polynomials because, as noted, eventually you will get coefficients over 10 that will gum up the works.
In the end, it's because if you multiply $\sum a_ix^i$ by $\sum b_ix^i$, the coefficient of the $x^k$ term will be $$\sum_{i=0}^n a_ib_{k-i}$$ and those will "echo" back if the coefficients of $a$ and $b$ are the reverses each other.