I'm looking for a algorithm that can compute an approximation of the Kolmogorov complexity of given input string. So if K is the Kolmogorov complexity of a string S, and t represents time, then the function would behave something like this.. limit(t->inf)[K_approx(t,S)] = K.
-
2For those unfamiliar with the topic, the Kolmogorov complexity of a string is, in essence, "the length of the shortest program that generates the string". For instance, a 9x9 multiplication table can be produced in 8 characters ( `*/~1+i.9` ) with the J programming language ( [see here](http://stackoverflow.com/questions/3412730/code-golf-output-multiplication-table-to-the-console) ). From this, you could say that a 9x9 multiplication table has a Kolmogorov complexity of 8 or less with respect to the J programming language. – Joey Adams Aug 19 '10 at 14:45
-
If you are trying to proof something formally, you'll have to write your proof independently of (completely disregarding) the method used to approximate it. If you're just looking for fun, how about try a data compression algorithm? – rwong Aug 19 '10 at 14:50
-
No, I'm not looking for a proof. I'm looking for an algorithim that satisfies the above stated properties. I haven't been able to find one, and I wanted to know if anybody has done it already. I don't know of any Data compression algorithims that can in principal find the exact Kolmogorov Complexity given enough time. I suppose at first glance since you are always working with finite strings an enumeration search of all possible Turing machines might work... But the problem might be undecidable. I'm looking for an algorithim like this for machine learning applications. – Tony Aug 19 '10 at 14:57
-
Nowadays machine learning applications focus on compressed sensing, model reduction algorithms, etc. KC is too theoretical. – rwong Aug 19 '10 at 15:07
-
Seems homeworky...but Joey Adams is right. You have your answer. – PeterAllenWebb Aug 19 '10 at 16:23
-
@rwong, KC is theoretical, but people like Ray Solomonoff pushed ideas like this as the foundation for machine learning. I think it is a logical step to go from a theoretical optimal solution, to an approximate practical solution. – Tony Aug 19 '10 at 16:40
5 Answers
In theory, a program could converge on the Kolmogorov complexity of its input string as the running time approaches infinity. It could work by running every possible program in parallel that is the length of the input string or shorter. When a program of a given length is found, that length is identified as the minimum length known for now, is printed, and no more programs >= that length are tried. This algorithm will (most likely) run forever, printing shorter and shorter lengths, converging on the exact Kolmogorov complexity given infinite time.
Of course, running an exponential number of programs is highly intractible. A more efficient algorithm is to post a code golf on StackOverflow. A few drawbacks:
- It can take a few days before good results are found.
- It uses vast amounts of our most valuable computing resources, costing thousands of dollars in productivity loss.
- Results are produced with less frequency over time as resources are diverted to other computations.
- The algorithm terminates prematurely for many inputs, meaning it does not work in general.

- 1
- 1

- 41,996
- 18
- 86
- 115
-
Or you will soon hit a single program that runs forever, and you can't decide whether to stop it or let it run a few more seconds (decades). – rwong Aug 19 '10 at 15:08
-
2@rwong: Right, that's why you run them in parallel. For the many programs that do seem to run forever, they are allowed to keep running until a shorter solution is found (if ever). – Joey Adams Aug 19 '10 at 15:12
-
I suppose it would be resonable to add another parameter to the function that specifies the maximum length of the Turing machine.. so we could have a function that has a property like this perhaps ??? limit(t->inf)[limit(T_max->inf)[K_approx(t,S,T_max)]] = K – Tony Aug 19 '10 at 15:15
-
Worms come to my mind ... (for those not familiar with code-golf: http://meta.stackexchange.com/questions/20736/what-is-code-golf-on-stack-overflow) – rwong Aug 19 '10 at 15:18
-
1@Tony: As in, a space limitation, or a limitation of program length? You only need finite time to find the shortest program of a given running time (because they all terminate, duh). Less obviously, you only need finite time to find the shortest program using limited space. The latter is true because the halting problem is decidable for programs running in finite space (think about it). Thus, you can limit as running time -> infinity or as space -> infinity. You need not do both. – Joey Adams Aug 19 '10 at 15:28
-
@Joey this would be a limitation in the maximum "size" of the Turing machines being checked. If I understand you, you are saying that given a finite set of TM's of a set max "size" you can always determine if the program will halt or not.. because the program doing the termination analysis can be "larger" than all of the TM's in question thus eliminating the possiblity of giving the termination analysis program itself as input. I know that one of the proofs for undecidablity involves giving a program itself as input. – Tony Aug 19 '10 at 15:41
-
@Joey your proposed solution isn't really practical for real life. I can't run an infinite number of parallel turing machines in real life. Besides, I'm only looking for an approximation. – Tony Aug 19 '10 at 16:27
-
@Joey: are you referring to http://en.wikipedia.org/wiki/State_space_enumeration ? – rwong Aug 20 '10 at 11:02
-
@Tony To prevent the program from running forever, the approximation could be limited to programs that are [provably terminating](https://en.wikipedia.org/wiki/Termination_analysis). – Anderson Green Oct 02 '20 at 00:59
I think this might work? If somebody sees an error, please point it out.
function KApprox(S:string,t:integer,TapeSizeMax:integer) : Turing Machine of size k
begin
// An abstract data type that represents a turing machine of size k
var TM(k:integer) : Turing Machine of size k;
var TMSmallest(k:integer) : Turing Machine of size k;
var j : integer;
var i : integer;
for (j = t to 0 step -1) // reduce the time counter by 1
begin
for (i = TMax to 1 step -1) // go to the next smaller size of TM
begin
foreach (TM(i)) // enumerate each TM of size i
begin
if (TM(i).halt(TapeSizeMax) == true) and (TM(i).output() == S) then
begin
if (sizeof(TM(i)) < sizeof(TMSmallest(i))) then
TMSmallest(i): = TM(i);
end;
end;
end;
end;
return TMSmallest;
end;

- 151
- 1
- 6
-
-
-
1The problem now is that there is no such thing as the `halts()` function. You can write one that works for some machines, but not all of them. – Gabe Aug 19 '10 at 17:10
-
@ok, so I specified that the halts function will work for only thoes machines that are of size TMax. hence .halts(TMax) – Tony Aug 19 '10 at 17:23
-
1But you can't write a `halts()` function for TMax > 4. See http://mathworld.wolfram.com/HaltingProblem.html – Gabe Aug 19 '10 at 17:32
-
Ok, then will have to restrict the tape size of the TM... TM.halts(TapeSizeMax) == true. – Tony Aug 19 '10 at 18:08
It looks like Ray Solomonoff did a lot of work in this field.
Publications of Ray Solomonoff
Does Algorithmic Probability Solve the Problem of Induction?

- 151
- 1
- 6
The wikipedia page for Kolmogorov complexity has a subsection entitled "Incomputability of Kolmogorov complexity", under the "Basic results" section. This is not intended to be a basic measure that you can compute, or even approximate productively.
There are better ways of achieving what you want, without a doubt. If a measure of randomness is what you want, you could try the binary entropy function. Compressibility by one of the standard algorithms might also fit the bill.

- 14,289
- 5
- 49
- 99
-
1The Wiki article doesn't even mention the phrase "approximate productively" anywhere. The question of computing the KC of a string isn't being asked. It's undecidable.. end of story. All I'm looking for is a function that will lead to better and better approximations by giving it more time and space resources. – Tony Aug 19 '10 at 16:56
-
@Tony: Your algorithm isn't fully specified. I'm not sure how you plan to test every possible Turing Machine up to some size with every possible input string, but even if you could do this in some meaningful way, the Time cost would be exponential on input. However nice the theory might seem, it's just not something which will work for you in practice. – Rob Lachlan Aug 19 '10 at 17:06
-
@Rob, the function only takes 1 string as input "S:String", and will only test turing machines of size TMax. so we're not testing all turing machines, and hence cannot get the exact KC of the input string. – Tony Aug 19 '10 at 17:24
-
@Tony - I think it is pretty much taken as read that small randomly generated Turing machines will not be solutions (i.e. valid compressors) for the vast majority of input strings. – Stephen C Aug 19 '10 at 18:23
-
@Stephen. The Turning machines are not to be randomly generated. They are to be enumerated. Any notion of optmization must only be considered when an algorithim is decided on. – Tony Aug 19 '10 at 18:32
-
@Tony - I think it is pretty much taken as read that **no** small Turing machines will be solutions (i.e. valid compressors) for the vast majority of input strings. Any algorithm for calculating approximate KC that enumerates Turing machines will be exponential on the size of the Turing machines. In short, such an algorithm would be impractical. – Stephen C Aug 19 '10 at 18:40
-
@Stephen, i see this as being true. When the first resolution based automated theorem proves were made, they had semi-decidable running times, and still do. However, progress was made to improve the runtime in specific cases. The reason I make this analogy is because ATP's are sound (and for the most part) complete. I would like a machine learning method that isn't going to miss some fundamental inferences because of a lack of completeness in it's search method. I hope this helps understand what I'm looking for. – Tony Aug 19 '10 at 18:52
The first issue that I notice is that "the Kolmogorov Complexity" isn't well defined. It depends to some degree on the choice of how to represent programs. So, the first thing you would need to do is fix some encoding of programs (for example, Joey Adams' specification that programs be written in J).
Once you have the encoding, the algorithm you are looking for is quite simple. See Joey's answer for that.
But the situation is even worse than having to run exponentially many programs. Each of those programs could run as long as you could possibly imagine (technically: running time as a function input size could grow faster than any recursive function). What's more, it could be the case that some of the shortest programs are the ones that run the longest. So while the parallel approach will approach the correct value as time goes to infinity, it will do so unimaginably slowly.
You could stop the program prematurely, figuring that the approximation at that point is good enough. However, you have no idea in general how good that approximation is. In fact, there are theorems that show you can never know.
So the short answer is "easy, just use Joey's algorithm", but by any measure of practicality, the answer is, "you don't have a chance". As has been recommended by rwong, you are better off just using a heavy-duty compression algorithm.

- 496
- 2
- 8