Integer Decompiler

Find the shortest program for a number

What is this tool?

The Integer Decompiler allows you to find the shortest program that outputs a given integer. In technical terms, it computes the time-bounded Kolmogorov complexity of that integer.

Short programs are interesting as they can provide insight about numbers. Running a computation and getting 1073741825 as a result does not teach us much, but knowing that 1073741825=230+1 can hint at the structure of the solution.

The long, trivial description corresponds to a long program ("print 1073741825"), while the short description means that there's a short program outputting the same number ("print 230+1"). Having a short program generating it indicates that a number is special - that it has structure.

Example

Let's say we're studying perfect numbers (numbers that are equal to the sum of their divisors). We write some code, and manage to find the first few:

6, 28, 496, 8128, 33550336

The numbers are all even, but apart from that, no special structure is immediately apparent. Let's look at their shortest programs.

For each number, the Integer Decompiler shows the low-level program ("raw program") and a somewhat easier-to-understand translation ("high-level program"). For the first four numbers, we get "trivial" programs, that simply list the digits of the number:

Number High-level program
6 6
28 28
496 496
8128 8128
The fifth number, however, has a more interesting program:
33550336 3 2 [ -1 12 [ ×2 ] ]

Let's see what this program does (see the language reference):

3 Pushes 3 into the stack
2 Pushes 2 into the stack
[ Pops the 2 and executes the loop body (-1 12 [ ×2 ]) two times
 -1 Subtracts 1 from the number at the top of the stack
 12 Pushes 12 into the stack
 [ Pops the 12 and executes the inner loop (×2) 12 times
  ×2 Multiplies the number at the top of the stack by 2
 ] End of the inner loop
] End of the outer loop

So, the program builds 33550336 as (((3 - 1) ⋅ 212) - 1) ⋅ 212 = ((2 ⋅ 212) - 1) ⋅ 212 = (213 - 1) ⋅ 212. Looking at the other numbers, they also have this form:

6 = (22 - 1) ⋅ 21
28 = (23 - 1) ⋅ 22
496 = (25 - 1) ⋅ 24
8128 = (27 - 1) ⋅ 26

This leads to an interesting conjecture: perfect numbers have the form (2n+1 - 1) ⋅ 2n. In this case, the conjecture turns out to be true, and we've just discovered (part of) the Euclid-Euler theorem.