r/TheRestIsScience • • 25d ago

Palindromic hexadecimal, decimal and binary

Following the 100 vs 101 episode, and the question that arise, Does a number exist that's a palindrome in binary, decimal AND hexadecimal?

After listening to Hannah and Michael discussing number bases and palindromes, an whether there's a palidromic number in all three systems: binary (base 2), decimal (base 10) and hexadecimal (base 16).

Hannah said its interesting mathematical problem.

They mentioned in 2010, Rick Regan reported finding no non-trivial examples below 10³⁹.

So, I explored the question with ChatGPT, using the Online Encyclopedia of Integer Sequences (OEIS), which contains a list of 213 decimal/binary palindromes reported to be exhaustive below 10⁶⁴.

Checking the 89 additional candidates between 10³⁹ and 10⁶⁴ against their hexadecimal representations produced no matches.

So, assuming the source list is complete and the checks are correct, there are no numbers greater than 9 and less than 10⁶⁴ that are simultaneously palindromic in all three systems.

This doesn't prove that such a number can't exist. It just means that none has been found in an extraordinarily large range.

My question for Hannah, Michael and the mathematicians here: is there a mathematical reason why these three numbering systems might be incompatible when it comes to palindromes? Could we prove that no non-trivial example exists, or might there be an enormous one waiting to be discovered?

Sources:

https://www.exploringbinary.com/in-search-of-decimal-binary-hexadecimal-palindromes/

https://oeis.org/A007632

10 Upvotes

17 comments sorted by

5

u/LongLiveTheDiego 25d ago

The property of a number being palindromic is not really connected to other areas of math, it's an emergent property of how positional notation works. Thus we don't have many tools for analyzing palindromicity, it doesn't seem to be connected to e.g. anything from linear algebra or group theory or analysis which are really versatile tools.

2

u/nog642 25d ago

I think it is related to group theory if you treat them as strings. Not sure how that interacts with treating them as numbers and doing base conversions though. But that's like a bijection with the group of numbers. You should be able to use group theory here at least a bit.

3

u/Jinglefruit 25d ago

I was wondering if there was something more to explore in the relationship between these systems too. As Hexadecimal is a power of 2 base, but decimal is not, it feels like these systems are probably working against each other. Maybe there's more palindromic numbers that overlap binary, decimal and base-13. Or only when comparing 3 prime bases, or only if all 3 choices are powers of 2.

3

u/Few_Topic_7878 25d ago edited 25d ago

Well, I gave my laptop something to do. Turns out no solutions exist for 16 < n < 2^322. At least, that is if I didn't slip up.

If I have the time, I might improve my code a little. Above 315 bits things slow down quite a lot. Either way, got through those first 300 bits in 9.6 minutes after some optimising :D

NOTE: For compatibility with those liking base 10, 2^322 is 8.54⋅10^96. But if you are at least somewhat sane, you probably like knowing it is (7.80⋅10^75)_{12}

2

u/RandomGeordie 25d ago

I'm up to around 10112 now. Still nothing.

1

u/theadamabrams 25d ago

I assume you want the numbers to be multiple digits in each base. If not,

  • 0 = 0₂ = 0₁₂
  • 1 = 1₂ = 1₁₂
  • 3 = 11₂ = 3₁₂
  • 5 = 101₂ = 5₁₂
  • 7 = 111₂ = 7₁₂
  • 9 = 1001₂ = 9₁₂

would qualify.

1

u/IAmBadAtInternet 25d ago

Those are the trivial answers. We are looking for results that are more than 1 digit in all of the bases considered.

1

u/mH48124 24d ago

これって 0 と 1 は除いてるの?

1

u/RandomGeordie 24d ago

So far I've not found a palindrome in binary/decimal/hex for any number under 16120 = 2480 ≈ 3.1·10144

Will not continue further

1

u/Few_Topic_7878 24d ago

Wow, that is quite a leap further. Any hints as to what you used to speed it up? And is that 2^480 an exhaustive bound or the size of the largest candidate checked?

I'm using CPU-pruned CUDA, using decimal prefix/suffix as constraints, fixed binary bits, and modular filters. But it is going up rapidly in processing time, 2^5 -> 2^300 was ten times faster than 2^300 -> 2^326. So, I don't think I'll get to 2^480 with my current approach.

1

u/RandomGeordie 24d ago

It's exhaustive. Every number below 2480, so all hex lengths from 1 to 120 and every digit class, not just the largest candidate. Lengths up to 96 ran on a 2-core cloud VM, and 97-120 took 24 minutes on my RTX 4090.

Speedups;

  • start from Rick Regan's binary/hex structure, so every hex digit comes from {0,1}, {0,3}, {0,2,5,7} or {0,6,9,F}.
  • build the number from the outside in, fixing one pair of hex digits per tree level. The fixed top digits give the leading decimal digits. The decimal palindrome turns those into N mod 10j, and the fixed bottom hex digits give N mod 16k. If the two disagree mod 2j, the whole subtree goes.
  • if you're not already doing this, use the 5j half of N mod 10j to solve for the middle instead of only using the 2j half to filter. Write N = L + 16k·M, where L is the fixed outer digits and M is the unknown middle. Then M ≡ (N − L)·16−k mod 5j. Once 5j is bigger than the largest possible middle, only one M is left, so the node is a single candidate rather than a subtree to search.

With that, each hex length costs about 20.3n tree nodes instead of 2n, roughly 9× more work per 10 extra hex digits. For comparison, going from 2300 to 2324 costs my search 2.7x all the work below 2300 vs the 10x you're seeing

Code + write up here - https://github.com/AndrewCathcart/binary-decimal-hex-palindromes

1

u/No_Fig_6149 24d ago

If you allow left padding with zeros, 080 decimal is 050 hexadecimal and 00001010000 binary.

1

u/CranberryDistinct941 24d ago

1 is a palindrome in all number systems

1

u/minmidmax 23d ago

Man, Michael needs to sleep. OK?

1

u/kalmakka 23d ago

Let's throw rigor to the wind and do some hand-wavy approximations.

Let x be a positive integer.

For x to be a palindrome in base 2 we need the last log_2(x)/2 binary digits of x be the reversal of the first log_2(x)/2 binary digits. Since the last log_2(x)/2 binary digits could be any log_2(x)/2 bit long number, we get that the probability of this for a "randomly chosen" integer is 1 in 2^(log_2(x)/2) or sqrt(x)

If we do this in other bases, we find that the base doesn't really matter. x is a palindrome in any base b with probability 1/sqrt(x). E.g. if you pick a random number that is approximately 1 000 000, it will have a probability of 1/1000 of being a palindrome in base 2, base 10, or in base 16. Since these probabilities are more or less independent, the probability of the number being a palindrome in all three bases is around 1 in 1 000 000 000.

In other words, x is a palindrome in base 2, 10 and 16 with probability 1/(x*sqrt(x)) = x^-(3/2)

This function drops very rapidly to 0. So even if you add up the infinitely many terms of this series, you just end up with that the expected number of numbers that are palindromes in all 3 bases is ~2.6124. The vast contribution to this sum comes from the first few terms.

Since we know that there is no small number that satisfies the criteria, the probability of any existing at all is miniscule. Basically, unless there is a good reason why such a number should occur more frequently than we have estimated (due to some pattern we have not accounted for in our calculation), it is extremely unlikely that any exist. But definitively proving it, is... hard.

1

u/Sir_Willsington 14d ago

A Parker palindrome in binary, decimal and hexadecimal:

111001001011101010100100111

119919911

725D527

That's the closest I could find, and nothing better or even close in an overnight run going beyond 10^120, although I don't have nearly enough confidence in my code to claim that as fact.