# Chaitin's construction

(Difference between revisions)
 Revision as of 17:06, 3 August 2006 (edit)m (Small corrections)← Previous diff Current revision (21:34, 14 March 2009) (edit) (undo) (Workpage template'', warning about missing substantial details) (39 intermediate revisions not shown.) Line 1: Line 1: + :'''''Correction in process. There is a substantial point that is lacking yet, the formulae and the concepts are not correct without it.''''' + __TOC__ __TOC__ Line 4: Line 6: Are there any real numbers which are defined exactly, but cannot be computed? Are there any real numbers which are defined exactly, but cannot be computed? - This question leads us to [[exact real arithmetic]], foundations of [[mathematics]] and [[computer science]]. + This question leads us to [[exact real arithmetic]], and [[algorithmic information theory]], and foundations of [[mathematics]] and [[computer science]]. See Wikipedia article on [http://en.wikipedia.org/wiki/Chaitin%27s_constant Chaitin's construction], referring to e.g. See Wikipedia article on [http://en.wikipedia.org/wiki/Chaitin%27s_constant Chaitin's construction], referring to e.g. Line 25: Line 27: Having seen this, decoding is rather straightforward. Having seen this, decoding is rather straightforward. - Let us represent it e.g with the following LL1 parser. Of course, we can build it on top of more sophisticated parser libraries (Parsec, arrow parsers) + [[/Parser|Here is a parser]] for illustration, but it serves only didactical purposes: it will not be used in the final implementation, because a good term generator makes parsing superfluous at this task. - ==== Decoding module ==== + === Chaitin's construction === - + Now, Chaitin's construction will be here - module Decode (clP) where + :\sum_{p\in \mathrm{Dom}_\mathrm{dc},\;\mathrm{hnf}\left(\mathrm{dc}\;p\right)} 2^{-\left|p\right|}[/itex] + where + ;$\mathrm{hnf}$ + :should denote an unary predicate “has normal form” (“terminates”) + ;$\mathrm{dc}$ + :should mean an operator “decode” (a function from finite bit sequences to [[combinatory logic]] terms) + ;$2\!\;^{*}$ + :should denote the set of all finite bit sequences + ;$\mathrm{Dom}_\mathrm{dc}$ + :should denote the set of syntactically correct bit sequences (semantically, they may either terminate or diverge), i.e. the domain of the decoding function, i.e. the range of the coding function. Thus, $\left\{00, 01, 1\;00\;00, 1\;00\;01, 1\;01\;00, 1\;01\;01, \dots\right\} = \mathrm{Dom}_{\mathrm{dc}} = \mathrm{Rng}_{\widehat\ }$ + ;“Absolute value” + :should mean the length of a bit sequence (not [[combinatory logic]] term evaluation!) - import Parser (Parser, item) + === Table for small legths === - import CL (CL, k, s, apply) + {| border="1" cellspacing="0" cellpadding="5" align="center" - import CLExt ((>>^)) + ! Length ($n$) - import PreludeExt (bool) + ! All strings ($2^n$) + ! Decodable strings, ratio, their sum till now + ! Terminating, ratio, their sum till now + ! \Omega approximated till now: mantissa -- binary, length-fitting binary, decimal + |- + | 0 + | 1 + | 0, 0, 0 + | 0, 0, 0 + | -, -, - + |- + | 1 + | 2 + | 0, 0, 0 + | 0, 0, 0 + | -, 0, 0 + |- + | 2 + | 4 + | 2, $\frac12$, $\frac12$ + | 2, $\frac12$, $\frac12$ + | 1, 10, 5 + |- + | 3 + | 8 + | 0, 0, $\frac12$ + | 0, 0, $\frac12$ + | 1, 100, 5 + |- + | 4 + | 16 + | 0, 0, $\frac12$ + | 0, 0, $\frac12$ + | 1, 1000, 5 + |- + | 5 + | 32 + | 4, $\frac18$, $\frac58$ + | 4, $\frac18$, $\frac58$ + | 101, 10100, 625 + |} + It illustrates nicely, that Chaitin's construction is a [http://en.wikipedia.org/wiki/Normal_number normal number], as if its digits (in binary representation) were generated by tossing a coin. - clP :: Parser Bool CL + == Eliminating any concept of code by handling [[combinatory logic]] terms directly == - clP = item (bool applicationP baseP) + - applicationP :: Parser Bool CL + Chaitin's construction can be grasped also as - applicationP = clP >>^ clP + :\sum_{p\in \mathrm{CL},\;\mathrm{hnf}\;p} 2^{-\left|\mathrm{dc}^{-1}\;p\right|}[/itex] - baseP :: Parser Bool CL + We can avoid referring to any code notion, if we modularize out function - baseP = item (bool k s) + :$\left|\cdot\right|\circ\mathrm{dc}^{-1}$ + and give it a separate name, e.g. + :$\left\Vert\cdot\right\Vert : \mathrm{CL}\to\mathbb N$ + and notice that it can be defined directly in terms of CL-terms (we need not use any decoding concept any longer): - kP, sP :: Parser Bool CL + :$\left\Vert\mathbf K\right\Vert = 2$ - kP = return k + :$\left\Vert\mathbf S\right\Vert = 2$ - sP = return s + :$\left\Vert\left(x\;y\right)\right\Vert = 1 + \left\Vert x\right\Vert + \left\Vert y\right\Vert - + - ==== Combinatory logic term modules ==== + Thus, we transfer (lift) the notion of “length” from bit sequences to [[combinatory logic]] terms in an appropriate way. Let us call it, e.g. the “norm” of the term. - ===== CL ===== + Thus, Chaitin's construction is grasped also as + :[itex]\sum_{p \in \mathrm{Dom}_{\mathrm{nf}}} 2^{-\left\Vert p\right\Vert}$ + where + :$\mathrm{nf} : \mathrm{CL} \supset\!\to \mathrm{CL}$ + is a partial function defined on CL terms, it attributes to each "terminating" term its normal form. - + Thus, we have no notions of “bit sequence”,“code”, “coding”, “decoding” at all. But their ghosts still haunt us: the definition of norm function looks rather strange without thinking on the fact that is was transferred from a concept of coding. - module CL (CL, k, s, apply) where + - import Tree (Tree (Leaf, Branch)) + === More natural norm functions (from CL terms) === - import BaseSymbol (BaseSymbol, kay, ess) + - type CL = Tree BaseSymbol + Question: + If we already move away from the approaches referring to any code concept, then + could we define norm in other ways? E.g. + :$\left\Vert\cdot\right\Vert : \mathrm{CL}\to\mathbb N$ + :$\left\Vert\mathbf K\right\Vert = 1$ + :$\left\Vert\mathbf S\right\Vert = 1$ + :$\left\Vert\left(x\;y\right)\right\Vert = 1 + \left\Vert x\right\Vert + \left\Vert y\right\Vert$ + And is it worth doing it at all? The former one, at leat, had a good theoretical foundation (based on analysis, arithmetic and probability theory). This latter one is not so cleaner, that we should prefer it, so, lacking theoretical grounds. - k, s :: CL + What I really want is to exclude conceptually the notion of coding, and with it the notion of “syntactically incorrect versus syntactically correct but diverging”. Thus, taking into account only syntactically correct things, seeing only the choice of terminating versus non-terminating. Thus taking only termination vs nontermination into account, when calculating Chaitin's construction. - k = Leaf kay + - s = Leaf ess + - apply :: CL -> CL -> CL + What I want to preserve: - apply = Branch + * it can be interpreted as a probability - + * it is a [http://en.wikipedia.org/wiki/Normal_number normal number], as if its digits (in binary representation) were generated by tossing a coin + thus I do not want to spoil these features. - ===== CL extension ===== + ==== Table for simpler CL-terms ==== + Let us not take into account coding and thus excluding the notion of “syntactically incorrect coding” even ''conceptually''. + Can we guess a good norm? + {| border="1" cellspacing="0" cellpadding="5" align="center" + ! Binary tree pattern + ! Maximal depth, vertices, edges + ! Leafs, branches + ! So many CL-terms = how to count it + ! Terminating, ratio + ! So many till now, ratio till now + |- + | $\cdot$ + | 0, 1, 0 + | 1, 0 + | $2 = 2$ + | 2, 1 + | 2, 1 + |- + | $\left(\right)$ + | 1, 3, 2 + | 2, 1 + | $4 = 2\cdot2$ + | 4, 1 + | 6, 1 + |- + | $\cdot\left(\right)$ + | 2, 5, 4 + | 3, 2 + | $8 = 2\cdot2^2$ + | 8, 1 + | 14, 1 + |- + | $\left(\right)\cdot$ + | 2, 5, 4 + | 3, 2 + | $8 = 2^2\cdot2$ + | 8, 1 + | 22, 1 + |- + | $\left(\right)\left(\right)$ + | 2, 7, 6 + | 4, 3 + | $16 = 2^2\cdot2^2$ + | 16, 1 + | 38, 1 + |} - + == Implementation == - module CLExt ((>>^)) where + - import CL (CL, apply) + To do: - import Control.Monad (Monad, liftM2) + Writing a program in Haskell -- or in [[combinatory logic]]:-) -- which could help in making conjectures on [[combinatory logic]]-based Chaitin's constructions. It would make only approximations, in a similar way that most Mandelbrot plotting softwares work. The analogy: + * they ask for a maximum limit of iterations, so that they can make a conjecture on convergence of a series; + * this program will ask for the maximum limit of reducton steps, so that it can make a conjecture on termination (having-normal-form) of a CL term. + Explanation for this: non-termination of each actually examined CL-term cannot be proven by the program, but a good conjecture can be made: if termination does not take place in the given limit of reduction steps, then the actually examined CL-term is regarded as non-terminating. - (>>^) :: Monad m => m CL -> m CL -> m CL + === Architecture === - (>>^) = liftM2 apply + - + - ===== Base symbol ===== + A CL term generator generates CL terms in “ascending order” (in terms of a theoretically appropriate “norm”), and by computing the norm of each CL-term, it approximates Chaitin's construction (at a given number of digits, and according to the given maximal limit of reduction steps). - + === User interface === - module BaseSymbol (BaseSymbol, kay, ess) where + - data BaseSymbol = K | S + chaitin --model-of-computation=cl --encoding=tromp --limit-of-reduction-steps=500 --digits=9 --decimal + chaitin --model-of-computation=cl --encoding=direct --limit-of-reduction-steps=500 --digits=9 --decimal - kay, ess :: BaseSymbol + === Term generator === - kay = K + - ess = S + - + - ==== Utility modules ==== + + module CLGen where - ===== Binary tree ===== + import Generator (gen0) - + import CL (k, s, apply) - + - module Tree (Tree (Leaf, Branch)) where + - data Tree a = Leaf a | Branch (Tree a) (Tree a) + direct :: [CL] + direct = gen0 apply [s, k] - ===== Parser ===== + See [[/Combinatory logic|combinatory logic term modules here]]. - module Parser (Parser, item) where + module Generator (gen0) where - import Control.Monad.State (StateT, get, put) + import PreludeExt (cross) - type Parser token a = StateT [token] [] a + gen0 :: (a -> a -> a) -> [a] -> [a] + gen0 f c = gen f c 0 - item :: Parser a + gen :: (a -> a -> a) -> [a] -> Integer -> [a] - item = do + gen f c n = sizedGen f c n ++ gen f c (succ n) - token : tokens <- get + - put tokens + sizedGen :: (a -> a -> a) -> [a] -> Integer -> [a] - return token + sizedGen f c 0 = c + sizedGen f c (n + 1) = map (uncurry f) + $+ concat [sizedGen f c i cross sizedGen f c (n - i) | i <- [0..n]] - - ===== Prelude extension ===== - module PreludeExt (bool) where + module PreludeExt (cross) where - bool :: a -> a -> Bool -> a + cross :: [a] -> [a] -> [(a, a)] - bool thenC elseC t = if t then thenC else elseC + cross xs ys = [(x, y) | x <- xs, y <- ys] - + - + - === Partial function approach === + - + - Now, Chaitin's construction will be here + - :$\sum_{p\in \mathrm{Dom}_\mathrm{dc},\;\mathrm{hnf}\left(\mathrm{dc}\;p\right)} 2^{-\left|p\right|}$ + - where + - ;$\mathrm{hnf}$ + - :should denote an unary predicate “has normal form” (“terminates”) + - ;$\mathrm{dc}$ + - :should mean an operator “decode” (a function from finite bit sequences to [[combinatory logic]] terms) + - ;$2\!\;^{*}$ + - :should denote the set of all finite bit sequences + - ;$\mathrm{Dom}_\mathrm{dc}$ + - :should denote the set of syntactically correct bit sequences (semantically, they may either terminate or diverge), i.e. the domain of the decoding function, i.e. the range of the coding function. Thus, \left\{00, 01, 1\;00\;00, 1\;00\;01, 1\;01\;00, 1\;01\;01, \dots\right\} = \mathrm{Dom}_{\mathrm{dc}} = \mathrm{Rng}_{\widehat\ } + - ;“Absolute value” + - :should mean the length of a bit sequence (not [[combinatory logic]] term evaluation!) + - + - === Total function approach === + - + - Here, $\mathrm{dc}$ is a partial function (from finite bit sequences). If this is confusing or annoying, then we can choose a more Haskell-like approach, making $\mathrm{dc}$ a total function: + - + - dc :: [Bit] -> Maybe CL + - then, Chaitin's construction will be - :$\sum_{p\in 2^*,\;\mathrm{maybe}\;\downarrow\;\mathrm{hnf}\;\left(\mathrm{dc}\;p\right)} 2^{-\left|p\right|}$ - where $\downarrow$ should denote false truth value. == Related concepts == == Related concepts == Line 167: Line 248: == To do == == To do == - Writing a program in Haskell -- or in [[combinatory logic]]:-) -- which could help in making conjectures on [[combinatory logic]]-based Chaitin's constructions. It would make only approximations, in a similar way that most Mandelbrot plotting softwares work: it would ask for a maximum limit of iterations. + * Making tasks described in [[#Implementation]] - chaitin --computation=cl --coding=tromp --limit-of-iterations=5000 --digits=10 --decimal + * Making more natural norm functions (from CL-terms), see [[#More natural norm functions (from CL terms)]] ## Current revision Correction in process. There is a substantial point that is lacking yet, the formulae and the concepts are not correct without it. ## Contents ## 1 Introduction Are there any real numbers which are defined exactly, but cannot be computed? This question leads us to exact real arithmetic, and algorithmic information theory, and foundations of mathematics and computer science. See Wikipedia article on Chaitin's construction, referring to e.g. ## 2 Basing it on combinatory logic Some more direct relatedness to functional programming: we can base Ω on combinatory logic (instead of a Turing machine). ### 2.1 Coding See the prefix coding system described in Binary Lambda Calculus and Combinatory Logic (page 20) written by John Tromp: $\widehat{\mathbf S} \equiv 00$ $\widehat{\mathbf K} \equiv 01$ $\widehat{\left(x y\right)} \equiv 1 \widehat x \widehat y$ of course, c, d are meta-variables, and also some other notations are changed slightly. ### 2.2 Decoding Having seen this, decoding is rather straightforward. Here is a parser for illustration, but it serves only didactical purposes: it will not be used in the final implementation, because a good term generator makes parsing superfluous at this task. ### 2.3 Chaitin's construction Now, Chaitin's construction will be here $\sum_{p\in \mathrm{Dom}_\mathrm{dc},\;\mathrm{hnf}\left(\mathrm{dc}\;p\right)} 2^{-\left|p\right|}$ where hnf should denote an unary predicate “has normal form” (“terminates”) dc should mean an operator “decode” (a function from finite bit sequences to combinatory logic terms) $2\!\;^{*}$ should denote the set of all finite bit sequences Domdc should denote the set of syntactically correct bit sequences (semantically, they may either terminate or diverge), i.e. the domain of the decoding function, i.e. the range of the coding function. Thus, $\left\{00, 01, 1\;00\;00, 1\;00\;01, 1\;01\;00, 1\;01\;01, \dots\right\} = \mathrm{Dom}_{\mathrm{dc}} = \mathrm{Rng}_{\widehat\ }$ “Absolute value” should mean the length of a bit sequence (not combinatory logic term evaluation!) ### 2.4 Table for small legths Length (n) All strings (2n) Decodable strings, ratio, their sum till now Terminating, ratio, their sum till now Ω approximated till now: mantissa -- binary, length-fitting binary, decimal 0 1 0, 0, 0 0, 0, 0 -, -, - 1 2 0, 0, 0 0, 0, 0 -, 0, 0 2 4 2, $\frac12$, $\frac12$ 2, $\frac12$, $\frac12$ 1, 10, 5 3 8 0, 0, $\frac12$ 0, 0, $\frac12$ 1, 100, 5 4 16 0, 0, $\frac12$ 0, 0, $\frac12$ 1, 1000, 5 5 32 4, $\frac18$, $\frac58$ 4, $\frac18$, $\frac58$ 101, 10100, 625 It illustrates nicely, that Chaitin's construction is a normal number, as if its digits (in binary representation) were generated by tossing a coin. ## 3 Eliminating any concept of code by handling combinatory logic terms directly Chaitin's construction can be grasped also as $\sum_{p\in \mathrm{CL},\;\mathrm{hnf}\;p} 2^{-\left|\mathrm{dc}^{-1}\;p\right|}$ We can avoid referring to any code notion, if we modularize out function $\left|\cdot\right|\circ\mathrm{dc}^{-1}$ and give it a separate name, e.g. $\left\Vert\cdot\right\Vert : \mathrm{CL}\to\mathbb N$ and notice that it can be defined directly in terms of CL-terms (we need not use any decoding concept any longer): $\left\Vert\mathbf K\right\Vert = 2$ $\left\Vert\mathbf S\right\Vert = 2$ $\left\Vert\left(x\;y\right)\right\Vert = 1 + \left\Vert x\right\Vert + \left\Vert y\right\Vert$ Thus, we transfer (lift) the notion of “length” from bit sequences to combinatory logic terms in an appropriate way. Let us call it, e.g. the “norm” of the term. Thus, Chaitin's construction is grasped also as $\sum_{p \in \mathrm{Dom}_{\mathrm{nf}}} 2^{-\left\Vert p\right\Vert}$ where $\mathrm{nf} : \mathrm{CL} \supset\!\to \mathrm{CL}$ is a partial function defined on CL terms, it attributes to each "terminating" term its normal form. Thus, we have no notions of “bit sequence”,“code”, “coding”, “decoding” at all. But their ghosts still haunt us: the definition of norm function looks rather strange without thinking on the fact that is was transferred from a concept of coding. ### 3.1 More natural norm functions (from CL terms) Question: If we already move away from the approaches referring to any code concept, then could we define norm in other ways? E.g. $\left\Vert\cdot\right\Vert : \mathrm{CL}\to\mathbb N$ $\left\Vert\mathbf K\right\Vert = 1$ $\left\Vert\mathbf S\right\Vert = 1$ $\left\Vert\left(x\;y\right)\right\Vert = 1 + \left\Vert x\right\Vert + \left\Vert y\right\Vert$ And is it worth doing it at all? The former one, at leat, had a good theoretical foundation (based on analysis, arithmetic and probability theory). This latter one is not so cleaner, that we should prefer it, so, lacking theoretical grounds. What I really want is to exclude conceptually the notion of coding, and with it the notion of “syntactically incorrect versus syntactically correct but diverging”. Thus, taking into account only syntactically correct things, seeing only the choice of terminating versus non-terminating. Thus taking only termination vs nontermination into account, when calculating Chaitin's construction. What I want to preserve: • it can be interpreted as a probability • it is a normal number, as if its digits (in binary representation) were generated by tossing a coin thus I do not want to spoil these features. #### 3.1.1 Table for simpler CL-terms Let us not take into account coding and thus excluding the notion of “syntactically incorrect coding” even conceptually. Can we guess a good norm? Binary tree pattern Maximal depth, vertices, edges Leafs, branches So many CL-terms = how to count it Terminating, ratio So many till now, ratio till now $\cdot$ 0, 1, 0 1, 0 2 = 2 2, 1 2, 1 $\left(\right)$ 1, 3, 2 2, 1 $4 = 2\cdot2$ 4, 1 6, 1 $\cdot\left(\right)$ 2, 5, 4 3, 2 $8 = 2\cdot2^2$ 8, 1 14, 1 $\left(\right)\cdot$ 2, 5, 4 3, 2 $8 = 2^2\cdot2$ 8, 1 22, 1 $\left(\right)\left(\right)$ 2, 7, 6 4, 3 $16 = 2^2\cdot2^2$ 16, 1 38, 1 ## 4 Implementation To do: Writing a program in Haskell -- or in combinatory logic:-) -- which could help in making conjectures on combinatory logic-based Chaitin's constructions. It would make only approximations, in a similar way that most Mandelbrot plotting softwares work. The analogy: • they ask for a maximum limit of iterations, so that they can make a conjecture on convergence of a series; • this program will ask for the maximum limit of reducton steps, so that it can make a conjecture on termination (having-normal-form) of a CL term. Explanation for this: non-termination of each actually examined CL-term cannot be proven by the program, but a good conjecture can be made: if termination does not take place in the given limit of reduction steps, then the actually examined CL-term is regarded as non-terminating. ### 4.1 Architecture A CL term generator generates CL terms in “ascending order” (in terms of a theoretically appropriate “norm”), and by computing the norm of each CL-term, it approximates Chaitin's construction (at a given number of digits, and according to the given maximal limit of reduction steps). ### 4.2 User interface chaitin --model-of-computation=cl --encoding=tromp --limit-of-reduction-steps=500 --digits=9 --decimal chaitin --model-of-computation=cl --encoding=direct --limit-of-reduction-steps=500 --digits=9 --decimal  ### 4.3 Term generator module CLGen where import Generator (gen0) import CL (k, s, apply) direct :: [CL] direct = gen0 apply [s, k] module Generator (gen0) where import PreludeExt (cross) gen0 :: (a -> a -> a) -> [a] -> [a] gen0 f c = gen f c 0 gen :: (a -> a -> a) -> [a] -> Integer -> [a] gen f c n = sizedGen f c n ++ gen f c (succ n) sizedGen :: (a -> a -> a) -> [a] -> Integer -> [a] sizedGen f c 0 = c sizedGen f c (n + 1) = map (uncurry f)$
concat [sizedGen f c i cross sizedGen f c (n - i) | i <- [0..n]]
module PreludeExt (cross) where
cross xs ys = [(x, y) | x <- xs, y <- ys]