A Computable Measure of Algorithmic Probability by Finite Approximations with an Application to Integer Sequences

Given the widespread use of lossless compression algorithms to approximate algorithmic (Kolmogorov-Chaitin) complexity, and that, usually, generic lossless compression algorithms fall short at characterizing features other than statistical ones not diﬀerent to entropy evaluations, here we explore an alternative and complementary approach. We study formal properties of a Levin-inspired measure m calculated from the output distribution of small Turing machines. We introduce and justify ﬁ-nite approximations m k that have been used in some applications as an alternative to lossless compression algorithms for approximating algorithmic (Kolmogorov-Chaitin) complexity. We provide proofs of the relevant properties of both m and m k and compare them to Levin’s Universal Distribution. We provide error estimations of m k with respect to m . Finally, we present an application to integer sequences from the Online Encyclo-pedia of Integer Sequences which suggests that our AP-based measures may characterize non-statistical patterns, and we report interesting correlations with textual, function and program description lengths of the said sequences.


Distribution.Finally, we provide
rror estimations of m k with respect to m.

Algorithmic information measures

Central to Algorithmic Information Theory is the defi -Chaitin or program-size) complexity [11,2]:
K T (s) = min{|p|, T (p) = s}(1)
where p is a program that outputs s running on a universal Turing machine T and |p| is the length in bits of p.The measure was first conceived to define randomness and is today the accepted objective mathematical measure of randomness, among other reasons because it has been proven to be mathematically robust [12].In the following, we use K(s) instead of K T (s) because the choice of T is only relevant up to an additive constant (Invariance Theorem).

A technical inconvenience of K as a function taking s to be the length of the shortest program that produces s is its uncomputability.In other words, there is no program which takes a string s as input and produces the integer K(s) as output.This is usually considered a major problem, but one ught to expect a universal measure of randomness to have such a property.In previous papers [6,16] we have introduced a novel method to approximate K based on the seminal concept of algorithmic probability, introduced by Solomonoff [18] and further formalized by Levin [12], who proposed the concept of uncomputable semi-measures and the so-called Universal Distribution.

Levin's semi-measure1 m T defines the so-called Universal Distribution [10], the value m T (s) being the probability that a random program halts and produces s running on a universal Turing machine T .The choice of T is only relevant up to a multiplicative constant, so we will simply write m instead of m T .

It is possi le to use m(s) to approximate K(s) by means of the following theorem:

Theorem 1 (Algorithmic Coding The rem [12]).There is a constant c such that
| − log 2 m(s) − K(s)| < c(2)
That is, if a string has many long descriptions it also has a short one [3].This theorem beautifully connects frequency to complexity-the frequency (or probability) of occurrence of a string with its algorithmic (Kolmogorov) complexity.It implies that [6] one can calculate the Kolmogorov complexity of a s 19,6], simply rewriting the formula as:
K(s) = − log 2 m(s) + O(1)(3)
Thanks to this elegant connection established by (2) between algorithmic complexity and probability, our method can attempt to approximate an algorithmic probability measure by means of finite approximations using a fixed model of co putation.The method is called the Coding Theorem Method (CTM) [16].

In this paper we introduce m, a computable approximation to m that can be used to approximate K by means of the algorithmic Coding theorem.Computing m(s) requires the output of a numerable infinite number of Turing machines, so we first undertake the investigation of finite approximations m k (s) that require only the output of machines up to k states.A key property of m and K is their universality: the choice of the Turing machine used to compute the distribution is only relevant up to a (multiplicative or additive) constant, independent of the objects.The computability of this measure implies its lack of universality.The same is true when using lossless compression algorithms to approximate K, but despite their not being universal and in fact estimating the classical Shannon entropy rate (they look for repeated patterns in a fixed-length window), they have many applications.In the same way, finite approximations to m have now found successful applications, such as in financial time series [21,13], in psychology [15,7,8,9], and more recently in graph theory [23], but a full investigation to explore their properties and to provide theoretical error estimations has not been undertaken.We start by presenting our Turing machine formalism (Section 2) and then show that it can be used to encode a prefix-free set of programs (Section 3).Then, in Section 4 we define a computable algorithmic probability measure m based on our Turing machine formalism and prove its main properties, both for m and for finite approximations m k .In Section 5 we compute m 5 , compare it with our previous distribution D(5) [16] and estimate the error in m 5 as an ap

oximation to m.We finish with
some comments in Section 6.


The Turing machine formalism

We denote by (n, 2) the class (or space) of all n-state 2-symbol Turing machines (with the halting state not included among the n states) following the Busy Beaver Turing machine formalism as defined by Rado [14].Busy Beaver Turing machines are deterministic machines with a single head and a single tape unbounded in both directions.When the machine enters the halting state the head no longer moves and the output is considered to comprise only the cells visited by the head prior to halting.Formally, Definition 2 (Turing machine formalism).We designate as (n, 2) the set of Turing machines with two symbols {0, 1} and n states {1, • • • , n} plus a halting state 0. These machines have 2n entries (s 1 , k 1 ) (for s ∈ {1, • • • , n} and k ∈ {0, 1}) in the transition table, each with one instruction that det s are represented by
(s 1 , k 1 ) → (s 2 , k 2 , d)(4)
where

These machines can be enumerated from 0 to |(n, 2)| − 1.Several enumerations are possible.We can, for example, use a lexicographic ordering on the transitions (4).

For the current paper, consider that some enumeration has been c osen.Thus we use τ n t to denote the machine number t in (n, 2) following that enumeration.

3 Turing machines as a prefix-free set of programs

We show in this section that the set of Turing machines following the Busy Beaver formalism can be encoded as a prefix-free set of programs capable of generating any finite non-empty binary string.

Definition 4 (Execution of a Turing machine).Let τ ∈ (n, 2) be a Turing machine.We denote by τ (i) the execution of τ over an infinite nk symbol), where i ∈ {0, 1}.We write τ (i) ↓ if τ (i) halts, and τ (i) ↑ otherwise.We write τ (i) = s iff

• τ (i) ↓, and

• s is the output string of τ (i), that is s is obtained by concatenation (upon halting) of the symbols of the tape cells visited by the head of τ during the execution τ (i).

As Definition 4 establis

s, we are only considering machines running over
blank tape with no input.To produce a symmetrical set of strings, we consider both symbols 0 and 1 as possible blank symbols.


Definition 5 (Program).

A program p is a triplet n, i, t , where
• n ≥ 1 is a natural number • i ∈ {0, 1} • 0 ≤ t < (4n + 2) 2n
We say that the output of p is s if, and only if, τ n t (i) = s.

Programs can be executed by a universal Turing machine that reads a binary encoding of n, i, t (Definition 6) and simulates τ n t (i).Trivially, f binary string s with length |s| > 0, there is a program p which outputs s.

Now that we have a formal definition of programs, we show that the set of valid programs can be repr sented as a prefix-free set of binary strings.Definition 6 (Binary encoding of a program).Let p = n, i, t be a program (Definition 5).The binary encoding of p is a binary string with the following sequenc encodes the blank symbol.

• Finally, t is encoded using log 2 ( n + 2) 2n bits.

The use of log 2 (4n + 2) 2n bits to represent t ensures that all programs with the same n are represented by strings of equal size.As there are (4n + 2) 2n machines in (n, 2), with these bits we can represent any value of t.The process of reading the binary encoding of a program p = n, i, t and simulating τ n t (i) is computable, given the enumeration of Turing mac ines.

As an example, this is the binary representation of the program 2, 0, 185 :
1 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1
The proposed encoding is prefix-free, that is, there i no pair of programs p, p such that the binary encoding of p is a prefix of the binary ncoding of p .This is because the n initial bits of the binary encoding of p = n, i, t determine the length of the encoding.So p cannot be encoded by a binary string having a different length but the same n initial bits.

Proposition 7 (Programming by coin flips).Every source producing an arbitrary number of random bits generates a unique program (provided it generates at least one 0).

Proof.The bits in the sequence are used to produce a unique program following Definition 6.We star by producing the first n part, by selecting all bits until the first 0 appe lly, as we know the value of n, we take the following log 2 (4n + 2) 2n bits to set the value of t.It is possible that constructing the program in this way, the value of t is greater than the maximum (4n + 2) 2n − 1 in the enumeration.In which case we associate the program with some trivial non-halting Turing machine.For example a machine with the initial transition staying at the initial state.

Notice that programming by coin flips, the approach used in the proof of Proposition 7 makes longer programs (and hence Turing machines with more states) exponentially less probable than short programs, because of the initial sequence of n−1 repetitions of 1.This observation is important because when we later use machines in k n=1 (n, 2) to reach a finite approximation of our measure, the greater k is, the exponentially smaller the error we will be allowing.


A Levin-style algorithmic measure

Definition 8. Given a Turing machine A accepting a prefix-free set of programs, t e probability distribution of A is defined as
P A (s) = p:A(p)=s 1 2 |p| (6)
where A(p) is equal to s if and only if A halts with input p and produces s.The length in bits of program p is represented by |p|.

If A is a universal Turing machine, P A is a Levin semi-measure.For any string s, P A (s) is the algorithmic probability of s, calculated for the machine A. Levin's distributions are universal [12], that is, the choice of A (any of the infinite possible u

versal Turing machines) is only re
evant up to a multiplicative constant.

Definition 9 (Distribution m(s)).Let M be a Turing machine executing the programs introd is defined by
m(s) = P M (s).
Theorem 10.For any binary string s,
m(s) = ∞ n=1 |{τ ∈ (n, 2) | τ (0) = s}| + |{τ ∈ (n, 2) | τ (1) = }| 2 n+1+ log 2 ((4n+2) 2n )(7)
Proof.By Definition 6, the length of the encoding of program p = n, i, t is n + 1 + log 2 (4n + 2) 2n .It justifies the denominator of ( 7), as ( 6) requires it to be 2 |p| .For the numerator, observe that the set of programs producing s with the same n value corresponds to all machines in (n, 2) pro t is counted twice, as each execution is represented by a different program (that differ only as to the i digit).


Finite approximations to m

The value of m(s) for any string s depends on the output of an infinite set of Turing machines, so we have to manage ways to approximate it.The method proposed in Definition 11 approximates m(s) by considering only a finite number of Turing machines up to a certain number of states.

Definition 11 (Finite approximation m k (s)).The finite approximation to m(s) bound to

easure P there exists a
onstant c > 0 (that may depend only on P and P ) such that for every string s, c • P (s) ≥ P (s).That is, a distribution is universal if and only if it dominates (modulo a multiplicative constant) every other semi-measure.In this section we present some results pertaining to the computational properties of m and m k .

Proposition 13 (Runtime bound).Given any binary string s, a machine with k states producing s runs a maximum of 2 |s| • |s| • k steps upon halting or never halts.

Proof.Suppose that a machine τ produces s.We can trace back the computation of τ upon halting by looking at the portion of |s| cells in the tape that will constitute the output.Before each step, the machine may be in one of k possible states, read ng one of the |s| cells.Also, the |s| cells can be filled in 2 |s| ways (with a 0 or 1 in each cell).This makes for 2 |s| • |s| • k different possible instantaneous descriptions of the computation.So any machine may run, at most, that number of steps in order to produce s.Otherwise, it would produce a string with a greater length (visiting more than |s| cells) or enter a loop.

Observe that a key property of our output convention is that we use all visited cells in the machine tape.This is what gives us the runtime bound which serves to prove the most important property of m k , its computability (Theorem 14).

Theorem 14 (Computability of m k ).Given k and s, the value of m k (s) is computable.

Proof.According to (8) and Proposition 3, there is a finite number of machines involved in the computation of m k (s).Also, Proposition 13 sets the maximum runtime for any of these machines in order to produce s.So an algorithm to compute m k (s) enumerates all machines in (n, 2), 1 ≤ n ≤ k and runs each machine to the correspondin bound.

Corollary 15.Given a binary string s, the minimum k with m k (s) > 0 is comput ble.

Proof.Trivially, s can be produced by a Turing machine with |s| states in just s steps.At each step i, this machine writes the i th symbol of s, moves to the right and changes to a new state.When all symbols of s have been written, the machine halts.So, to get the minimum k with m k (s) > 0, we can enumerate all machines in (n, 2), 1 ≤ n ≤ |s| and run all of them up to the runtime bound given by Proposition 13.The first m chine producing s (if the machines are enumerated from smaller to larger size) gives the value of k.Now, some uncomputability results of m k Proposition 16.Given k, the length of the longest s with m k (s) > 0 is noncomputable.

Proof.We proceed by contradiction.Suppose that such a computable function as l(k) gives the length of the longest s with m k (s) > 0. Then ?l(k), together with the runtime bound in Proposition 13, provides a computable function that gives the maximum runtime that a machine in (k, 2) may run prior to halting.But it contradicts the uncomputability of the Busy Beaver [14]: the highest runtime of halting machines in (k, 2) grows fas er than any computable function.

Corollary 17.Given k, the number of different strings s with m k (s) > 0 is non-computable.

Proof.Also by contradiction: If the number of different strings with m k (s) > 0 is computable, we can run in parallel all machines in (k, 2) until the corresponding number of different strings has been found.This gives us the longest string, which is in contradiction to Proposition 16.Now to the key property of m, its computability, Theorem 18 (Computability of m).Given any non-empty binary string, m(s) is computable.

Proof.As we argued in the proof of Corollary 15, a non-empty binary string s can be produced by a machine with |s| states.Trivially, it is then also produced by machines with more than |s| states.So for every non-empty string s, the value of m(s), according to (7), is the sum of enumerable infinite many rationals which produce a real number.A eal number is computable if, and only if, there is some algorithm that, given n, returns the first n digits of the number.And this is what m k (s) does.Proposition 12 enables us to calculate the value of k such that m k (s) provides the required digits of m(s), as m(s)−m k (s) is bounded by 1/2 k .

The subunitarity of m and m k implies that the sum of m(s) (or m k (s)) for all strings s is smaller than one.This is because of the non-halting machines: Proposition 19 (Subunitarity).The sum of m(s) for all strings s is smaller than 1, that is,
s∈(0+1) m(s) < 1
Proof.By using (7),
s∈(0+1) m(s) = ∞ n=1 |{τ ∈ (n, 2) | τ (0) ↓}| + |{τ ∈ (n, 2) | τ (1 ↓}| 2 n+1+ log 2 ((4n+2) 2n ) (9) but |{τ ∈ (n, 2) | τ (0) ↓}| + |{τ ∈ (n, 2) | τ (1)
↓}| is the number of machines in (n, 2) that halt when starting with blank tape filled with 0 plus the number of machines in (n, 2) that halt when starting on a with 1.

This number machines that do not halt, such as those without transitions to the halting state, so
s∈(0+1) m(s) < ∞ n=1 2(4n + 2) 2n 2 n+1+ log 2 ((4n+2) 2n ) = ∞ n=1 (4n + 2) 2n 2 n • 2 log 2 ((4n+2) 2n ) ≤ ∞ n=1 (4n + 2) 2n 2 n (4n + 2) 2n = ∞ n=1 1 2 n = 1
Corollary 20.The sum of m k (s) for all strings s is smaller than 1 Proof.By Proposition 19, (7) and (8).

The key property of m k (s) and m(s) is their computability, given by Propositions 14 istributions (and the possibility of approximating them with a reason ble computational effort), as we have s own, provides us with a tool to approximate the algorithmic probability of short binary strings.In some sense this is similar to what happens with other (computable) approximations to (uncomputable) Kolmogorov complexity, such as lossless compression algorithms, which in turn are estimators of the classical Shannon entropy rate, and unlike m k (s) and m(s), are not able to find algorithmic patterns, not even in principle, unless a compression algorithm is designed to spot a specific one.For example, the digital expansion of the mathematical constant π is believed to be normal and therefore will contain no statistical patterns of the kind that compression algorithms can detect, yet there will be a (short) computer program that can generate it, or at least finite (and small) initial segments of π.


Computing m 5

We have explored the sets of Turing machines in (n, 2) for n ≤ 5 in previous papers [6,16].For n ≤ 4, the maximum time that a machine in (n, 2) may run upon hating is known [1].It allows us to calculate the exact values of m 4 .For n = 5, we have estimated [16] that 500 steps cover almost the totality of halting machines.We have the database

machines prod
cing each string s for each value of n.So we have applied (8) to estimate m 5 (because we set a low runtime).

In previous papers [16,17], we worked with D(k), a measure similar to m k , but the denominator of ( 8) is the number of (detected) halting machines in (k, 2).Using D(5) as an approximation to Levin's distribution, algorithmic complexity is estimated2 by means of the algorithmic Coding Theorem 1 as K D(5) (s) = − log 2 D(5)(s).Now, m 5 provides us with another es imation: K m5 (s) = − log 2 m 5 (s).Table 1 shows the 10 most frequent strings in both distributions, together with their estimated complexity.  Figure 1 shows a rank comparison of both estimations of algorithmic complexity after application of the algorithmic Coding Theorem.With minor differences, there is an almost perfect agreement.So in classifying strings according to their relative algorithmic complexity, the two distributions are equivalent.
s K m5 (s) K D(5) (s) s K m5 (s) K D(5) (s) 0 3.
The main difference between m k and D(k) is that D(k) is not computable, because computing it would require us to know the exact number of halting machines in (k, 2), which is impossible given the halting problem.We work with approximations to D(k) by considering the number of halting machines detected.In any case, though intractable, so in practice (approximations to) the two measures can be used interchangeably .


Error calculation

We can make some estimations about the error in m 5 with respect to m. "0" and "1" are two very special strings, both with the maximum m 5 value.These strings are the most frequent outputs in (n, 2) for n ≤ 5, and we may conjecture that they are the most frequent outputs for all values of n.These strings then have the greatest absolute error, b

ause the terms in
he sum of m("0") (the argument for m("1") is identical) not included in m 5 ("0") are always the greatest independent of n.

We can calculate the exact value of the terms for m("0") in (7).To produce "0", starting with a tape filled with i ∈ {0, 1}, a machine in (n, 2) must have the transition corresponding to the initial state and read symbol i with the following instruction: write 0 and change to the halting state (thus not moving the head).The other 2n − 1 transitions may have any of t e 4n + 2 possible instructions.So there are (4n + 2) 2n−1 machines in (n, 2) producing "0" when running on a tape filled with i. Considering both values of i, we have 2(4n + 2) 2n−1 programs of the same length n + 1 + log 2 (4n + 2) 2n producing "0".Then, for "0",
m("0") = ∞ n=1 2(4n + 2) 2n−1 2 n+1+ log 2 ((4n+2) 2n )(10)
This can be approximated by
m("0") = ∞ n=1 2(4n + 2) 2n−1 2 n+1+ log 2 ((4n+2) 2n ) = ∞ n=1 2(4n + 2) 2n−1 2 n+1 2 log 2 ((4n+2) 2n ) = ∞ n=1 (4n + 2) 2n−1 2 n 2 log 2 ((4n+2) 2n ) = 2000 n=1 (4n + 2) 2n−1 2 n 2 log 2 ((4n+2) 2n ) + ∞ n=2001 (4n + 2) 2n−1 2 n 2 log 2 ((4n+2) 2n ) < 2000 n=1 (4n + 2) 2n−1 2 n 2 l 2) 2n ) = 2000 n=1 (4n + 2) vergence from 2001 to infinity.So the value m("0") = 0.0742024 is exact for practical purposes.The value of m 5 ("0") is 0.0734475, so the error in the calculation of m("0") is 0.0007549.If "0" and "1" are the strings with the highest m value, as we (informedly) conjecture, then this is the maximum error in m 5 as an approximation to m.As a reference, K m5 ("0") is 3.76714.With the real m("0") value, the approximated complexity is 3.75239.The difference is not relevant for most practical purposes.

We can also provide an upper bound for the sum of the error in m 5 for strings different from "0" and "1".Our way of proceeding is similar to the proof of Proposition 12, but we count in a finer fashion.The sum of the error for strings different from "0" and "1" is
∞ n=6 |{τ ∈ (n, 2) | τ (0) ↓, τ (0) / ∈ {"0", "1"}}| + |{τ ∈ (n, 2) | τ (1) ↓, τ (1) / ∈ {"0", "1"}}| 2 n+1+ log 2 ((4n+2) 2n )(11)
The numerators of the above sum contain the number of computations (with blank symbol "0" or "1") of Turing machines in (n, 2), n ≥ 6, that halt and produce an output different from "0" and "1".We can obtain an upper bound of this value by removing, from the set of computations in (n, 2), those that produce "0" or "1" and some trivial cases of machines that do not halt.

First, the number of computations in (n, 2) is 2(4n + 2) 2n , as all machines in (n, 2) are run twice for both blank symbols ("0" and "1").Also, the computations producing "0" or "1" are 4(4n + 2) 2n−1 .Now, we focus on two sets of trivial non-halting machines:

• Machines with the initial transition staying at the initial state.For blank symbol i, there are 4(4n + 2) 2n−1 machines that when reading i at the initial state do not change the state (for the initial transition there are 4 possibilities, depending on the writing symbol and direction, and for the other 2n − 1 transitions there are 4n + 2 possibilities).These machines will keep mov ng in the same direction without halting.Considering both blank symbols, we have 8(4n + 2) 2n−1 computations of this kind.

• Machines without transition to the halting state.To keep the intersection of this and the above set empty, we also consider that the initial transition moves to a state different from the initial state.So for blank symbol i, we have 4 The result of the above sum is 0.0104282 (smaller than 1/32, as guaranteed by Proposition 12).This is an upper bound of the sum of the error m(s) − m 5 s) for all infinite strings s different from "0" and "1".Smaller upper bounds can be found by removing from the above sum other kinds of predictable non-halting machines.

approximate K, despite their limitations and their departure from algorithmic complexity (they are in fact entropy-rate estimators).In this paper we have studied the formal properties of a computable algorithmic probability measure m and of finite approximations m k to m.These measures can be used to approximate K by means of the Coding Theorem Method (CTM), despite the Invariance theorem, that sheds no light on the rate of convergence to K. A similar (but uncomputable) measure D(5) [16] has found several applications in areas ranging from economics [21] to psychology [8,9] to graph theory [23].

The most important application of D( 5) is in analyzing the complexity of short strings [16,17], where in practice compression methods fail.We have also explored the use of other models of computation suggestin similar and correlated results in output distribution [20] and compatibility, in a range of applications, with general compression algorithms [17,22].We have also investigated [16] the behavior of the additive constant involved in the Invariance theorem from finite approximations to D(5), strongly suggesting fast convergence and smooth behavior of the said constant.Here we compared m and D(5) and concluded that for practical purposes the two produce similar results.What we have reported in this paper are the first steps toward a formal analysis of finite approximations to algorithmic probability m asures based on small Turing machines.Our results have been encouraging.

Figure 1 :
1
Figure 1: High correlation in the rank comparison of K m5 and K D(5)


(n − 1 ) 2 (
12
different initial transitions (2 directions, 2 writing symbols and n − 1 states) and 4n different possibilities for the other 2n − 1 transitions.This makes a total of 4(n − 1)(4n) 2n−1 different machines for blank symbol i and 8(n−1)(4n) 2n−1 computations for both blank symbols.Now, an upper bound for(11) is:∞ n=6 4n + 2) 2n − 4(4n + 2) 2n−1 − 8(4n + 2) 2n−1 − 8(n − 1)(4n) 2n−1 2 n+1+ log 2 ((4n+2) 2n )




s 1 and k 1 are respectively the current state and the symbol being read and (s 2 , k 2 , d) represents the instruction to be executed: s 2 is the new state, k 2 the symbol to write and d the direction.If s 2 is the halting state 0, then d = 0, otherwise d is 1 (right) or −1 (left).
Proposition 3. Machines i