Show HN: Integer Decompiler – Get the shortest program generating a given number (integer-decompiler.neocities.org)

1 points by mdl_principle ↗ HN
A project I've been working on every once in a while over the last ~10 years.

Given an integer, this tool shows its shortest "description" - the shortest program that computes it, written in a simple stack-based language. The idea is that short programs generating certain data equal insights about that data. It is not a new idea [0], but I couldn't find any implementations, so I decided to start with the simplest case: programs that output a single positive integer.

This can be useful when doing a computation and getting some "random" large number, like 1047552, as a result. The Integer Decompiler will tell you that 1047552 is not "random": it is 2**20 - 2**10 (more precisely, the shortest program outputting 1047552 does it by computing 2**20 - 2**10). This can allow better understanding of the problem: If the input was N=10, maybe the general formula is (2**(2*N) - 2**N).

[0] https://en.wikipedia.org/wiki/Minimum_description_length

2 comments

[ 4.8 ms ] story [ 119 ms ] thread
That's neat!

A number of years ago I attempted to create a program that would exhaustively evaluate short, digitless "dc" programs to find the shortest programs for all numbers under a million: https://emergent.unpythonic.net/01518231512 & a database of all my results for numbers up to 1 million: https://emergent.unpythonic.net/01525128151

While dc does have looping and function calls, my program didn't investigate their use; only straight-line dc programs are checked.

(dc is an rpn calculator available on many unix systems)

Cool - looks like we both walked similar paths: Using a stack-based language, pruning invalid programs, even having similar bugs (I too had one related to excluded prefixes).

It's sad that things like this are nearly impossible to find on Google unless you already know the exact title.