{"id":2078,"date":"2013-02-07T11:14:38","date_gmt":"2013-02-07T16:14:38","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/?p=2078"},"modified":"2014-08-23T18:49:25","modified_gmt":"2014-08-23T22:49:25","slug":"gdel-numbering-encoding-logic-as-numbers","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2013\/02\/07\/gdel-numbering-encoding-logic-as-numbers\/","title":{"rendered":"G&amp;oum;del Numbering: Encoding Logic as Numbers"},"content":{"rendered":"<p> The first step in G&ouml;del&#8217;s incompleteness proof was finding a way of taking logical statements and encoding them numerically. Looking at this today, it seems sort-of obvious. I mean, I&#8217;m writing this stuff down in a text file &#8211; that text file is a stream of numbers, and it&#8217;s trivial to convert that stream of numbers into a single number. But when G&ouml;del was doing it, it wasn&#8217;t so obvious. So he created a really clever mechanism for numerical encoding. The advantage of G&ouml;del&#8217;s encoding is that it makes it much easier to express properties of the encoded statements numerically.<\/p>\n<p> Before we can look at how G&ouml;del encoded his logic into numbers, we need to look at the logic that he used. G&ouml;del worked with the specific logic variant used by the Principia Mathematica. The Principia logic is minimal and a bit cryptic, but it was built for a specific purpose: to have a minimal syntax, and a complete but minimal set of axioms.<\/p>\n<p> The whole idea of the Principia logic is to be purely syntactic. The logic is expected to have a valid model, but you shouldn&#8217;t need to know anything about the model to use the logic. Russell and Whitehead were deliberately building a pure logic where you didn&#8217;t need to know what anything meant to use it. I&#8217;d really like to use G&ouml;del&#8217;s exact syntax &#8211; I think it&#8217;s an interestingly different way of  writing logic &#8211; but I&#8217;m working from a <a href=\"http:\/\/www.research.ibm.com\/people\/h\/hirzel\/papers\/canon00-goedel.pdf\">translation<\/a>, and the translator updated the syntax. I&#8217;m afraid that switching between the older G&ouml;del syntax, and the more modern syntax from the translation would just lead to errors and confusion. So I&#8217;m going to stick with the translation&#8217;s modernization of the syntax.<\/p>\n<p> The basic building blocks of the logic are variables. Already this is a bit different from what you&#8217;re probably used to in a logic. When we think of logic, we usually consider predicates to be a fundamental thing. In this logic, they&#8217;re not. A predicate is just a shorthand for a set, and a set is represented by a variable.<\/p>\n<p> Variables are <em>stratified<\/em>. Again, it helps to remember where Russell and Whitehead were coming from when they were writing the Principia. One of their basic motivations was avoiding self-referential statements like Russell&#8217;s paradox. In order to prevent that, they thought that they could create a stratified logic, where on each level, you could only reason about objects from the level below. A first-order predicate would be a second-level object could only reason about first level objects. A second-order predicate would be a third-level object which could reason about second-level objects. No predicate could ever reason about itself or anything on its on level. This leveling property is a fundamental property built into their logic. The way the levels work is:<\/p>\n<ul>\n<li> Type one variables, which range over simple atomic values, like specific single natural numbers. Type-1 variables are written as a<sub>1<\/sub>, b<sub>1<\/sub>.<\/li>\n<li> Type two variables, which range over sets of atomic values, like sets of natural numbers. A predicate, like <em>IsOdd<\/em>, about specific natural numbers would be represented as a type-2 variable. Type-2 variables are written a<sub>2<\/sub>, b<sub>2<\/sub>, &#8230;<\/li>\n<\/li>\n<li> Type three variables range over sets of sets of atomic values. The mappings of a function could be represented as type-3 variables: in set theoretic terms, a function is set of ordered pairs. Ordered pairs, in turn, can be represented as sets of sets &#8211; for example, the ordered pair (1, 4) would be represented by the set { {1}, {1, 4} }.  A function, in turn, would be represented by a type-4 variable &#8211; a set  of ordered pairs, which is a set of sets of sets of values.<\/li>\n<\/ul>\n<p> Using variables, we can form simple atomic expressions, which in G&ouml;del&#8217;s terminology are called <em>signs<\/em>. As with variables, the signs are divided into stratified levels: <\/p>\n<ul>\n<li> Type-1 signs are variables, and successor expressions. Successor expressions are just Peano numbers written with &#8220;succ&#8221;: 0, succ(0), succ(succ(0)), succ(a<sub>1<\/sub>), etc.<\/li>\n<li> Signs of any type greater than 1 are just variables of that type\/level.<\/li>\n<\/ul>\n<p> Now we can assemble the basic signs into formulae. G&ouml;del explained how to build formulae in a classic logicians form, which I think is hard to follow, so I&#8217;ve converted it into a grammar:<\/p>\n<pre>\n elementary_formula &rarr; sign<sub>n+1<\/sub>(sign<sub>n<\/sub>)\n formula &rarr; &not;(elementary_formula)\n formula &rarr; (elementary_formula) or (elementary_formula)\n formula &rarr; &forall; sign<sub>n<\/sub> (elementary_formula)\n<\/pre>\n<p> That&#8217;s all that&#8217;s really included in G&ouml;del&#8217;s logic. It&#8217;s enough: everything else can be defined in terms of combinatinos of these. For example, you can define logical and in terms of negation and logical or: <em>(a &and; b) &hArr; &not; (&not; a &or; &not; b)<\/em>.<\/p>\n<p> Next, we need to define the axioms of the system. In terms of logic the way I think of it, these axioms include both &#8220;true&#8221; axioms, and the inference rules defining how the logic works. There are five families of axioms.<\/p>\n<p>&lt;<\/p>\n<p>ol><\/p>\n<li> First, there&#8217;s the Peano axioms, which  define the natural numbers.\n<ol>\n<li> <em>&not;(succ(x<sub>1<\/sub>) = 0)<\/em>: 0 is a natural number, and it&#8217;s not the successor of anything.<\/li>\n<li> <em>succ(x<sub>1<\/sub>) = succ(y<sub>1<\/sub>) &rArr; x<sub>1<\/sub> = y<sub>1<\/sub><\/em>: Successors are unique.<\/li>\n<li> <em>(x<sub>2<\/sub>(0) &and; &forall; x<sub>1<\/sub> (x<sub>2<\/sub>(x<sub>1<\/sub>) &rArr; x<sub>2<\/sub>(succ(x<sub>1<\/sub>)))) &rArr; &forall; x<sub>1<\/sub>(x<sub>2<\/sub>(x<sub>1<\/sub>))<\/em>: induction works on the natural numbers.<\/li>\n<\/ol>\n<\/li>\n<li> Next, we&#8217;ve got a set of basic inference rules about simple propositions. These are defined as axiom schemata, which can be instantiated for any set of formalae <em>p<\/em>, <em>q<\/em>, and <em>r<\/em>.\n<pre><code>&lt;ol&gt;\n   &lt;li&gt; &lt;em&gt;p &amp;or; p &amp;rArr; p&lt;\/em&gt;&lt;\/li&gt;\n   &lt;li&gt; &lt;em&gt;p &amp;rArr; p &amp;or; q&lt;\/em&gt;&lt;\/li&gt;\n   &lt;li&gt; &lt;em&gt;p &amp;or; q &amp;rArr; q &amp;or; p&lt;\/em&gt;&lt;\/li&gt;\n   &lt;li&gt; &lt;em&gt;(p &amp;rArr; q) &amp;rArr; (p &amp;or; r) &amp;rArr; (q &amp;or; r)&lt;\/em&gt;&lt;\/li&gt;\n<\/code><\/pre>\n<\/ol>\n<\/li>\n<li> Axioms that define inference over quantification. <em>v<\/em> is a variable, <em>a<\/em> is any formula, <em>b<\/em> is any formula where <em>v<\/em> is not a free variable, and <em>c<\/em> is a sign of the same level as <em>v<\/em>, and which doesn&#8217;t have any free variables that would be bound if it were inserted as a replacement for <em>v<\/em>.\n<ol>\n<li> <em>&forall; v (a) &rArr; subst[v\/c](a)<\/em>: if formula <em>a<\/em> is true for all values of <em>v<\/em>, then you can substitute any specific value <em>c<\/em> for <em>v<\/em> in <em>a<\/em>, and <em>a<\/em> must still be true.<\/li>\n<li> <em>(&forall; v (b &or; a)) &rArr; (b &or; &forall; v (a))<\/em><\/li>\n<\/ol>\n<\/li>\n<li> The Principia&#8217;s version of the set theory axiom of comprehension: <em>&exists; u (&forall; v (  u(v) &hArr; a  ))<\/em>.<\/li>\n<pre><code>&lt;li&gt; And last but not least, an axiom defining set equivalence:       &lt;em&gt;&amp;forall; x&lt;sub&gt;i&lt;\/sub&gt; (x&lt;sub&gt;i+1&lt;\/sub&gt;(x&lt;sub&gt;i&lt;\/sub&gt;) &amp;hArr; y&lt;sub&gt;i+1&lt;\/sub&gt;(y&lt;sub&gt;i&lt;\/sub&gt;)) &amp;rArr; x&lt;sub&gt;i+1&lt;\/sub&gt; = y&lt;sub&gt;i+1&lt;\/sub&gt;&lt;\/em&gt;   &lt;\/li&gt;\n<\/code><\/pre>\n<\/ul>\n<p> So, now, finally, we can get to the numbering. This is quite clever. We&#8217;re going to use the simplest encoding: for every possible string of symbols in the logic, we&#8217;re going to define a representation as a number. So in this representation, we are <em>not<\/em> going to get the property that every natural number is a valid formula: lots of natural numbers won&#8217;t be. They&#8217;ll be strings of nonsense symbols. (If we wanted to, we could make every number be a valid formula, by using a parse-tree based numbering, but it&#8217;s much easier to just let the numbers be strings of symbols, and then define a predicate over the numbers to identify the ones that are valid formulae.)<\/p>\n<p> We start off by assigning numbers to the constant symbols:<\/p>\n<table>\n<tr>\n<th>Symbols<\/th>\n<th>Numeric Representation<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>succ<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>&not;<\/td>\n<td>5<\/td>\n<\/tr>\n<tr>\n<td>&or;<\/td>\n<td>7<\/td>\n<\/tr>\n<tr>\n<td>&forall;<\/td>\n<td>9<\/tr>\n<tr>\n<td>(<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>)<\/td>\n<td>13<\/td>\n<\/tr>\n<\/table>\n<p> Variables will be represented by powers of prime numbers, for prime numbers greater that 13. For a prime number <em>p<\/em>, <em>p<\/em> will represent a type one variable, <em>p<sup>2<\/sub><\/em> will represent a type two variable, <em>p<sup>3<\/sup><\/em> will represent a type-3 variable, etc.<\/p>\n<p> Using those symbol encodings, we can take a formula written as symbols <em>x<sub>1<\/sub>x<sub>2<\/sub>x<sub>3<\/sub>&#8230;x<sub>n<\/sub><\/em>, and encode it numerically as the product  <em>2<sup>x<sub>1<\/sub><\/sup>3<sup>x<sub>2<\/sub><\/sup>5<sup>x<sub>2<\/sub><\/sup>&#8230;p<sub>n<\/sub><sup>x<sub>n<\/sub><\/sup><\/em>, where <em>p<sub>n<\/sub><\/em> is the <em>n<\/em>th prime number.<\/p>\n<p> For example, suppose I wanted to encode the formula: <em>&forall; x<sub>1<\/sub> (y<sub>2<\/sub>(x<sub>1<\/sub>)) &or; x<sub>2<\/sub>(x<sub>1<\/sub>)<\/em>.<\/p>\n<p> First, I&#8217;d need to encode each symbol:<\/p>\n<ol>\n<li>&#8220;&forall;&#8221; would be 9.<\/li>\n<li>&#8220;x<sub>1<\/sub>&#8220;&#8221; = 17<\/li>\n<li> &#8220;(&#8221; = 11<\/li>\n<li>&#8220;y<sub>2<\/sub>&#8221; = 19<sup>2<\/sup> = 361<\/li>\n<li>&#8220;(&#8221; = 11<\/li>\n<li>&#8220;x<sub>1<\/sub>&#8221; = 17<\/li>\n<li>&#8220;)&#8221; = 13<\/li>\n<li>&#8220;&or;&#8221; = 7<\/li>\n<li>&#8220;x<sub>2<\/sub>&#8221; = 17<sup>2<\/sup> = 289<\/li>\n<li>&#8220;(&#8221; = 11<\/li>\n<li> &#8220;x<sub>1<\/sub>&#8221; = 17<\/li>\n<li>&#8220;)&#8221; = 13<\/li>\n<li> &#8220;)&#8221; = 13<\/li>\n<\/ol>\n<p> The formula would thus be turned into the sequence: [9, 17, 11, 361, 11, 17, 13, 7, 289, 11, 17, 13, 13]. That sequence would then get turned into a single number 2<sup>9<\/sup> 3<sup>17<\/sup> 5<sup>11<\/sup> 7<sup>361<\/sup> 11<sup>11<\/sup> 13<sup>17<\/sup> 17<sup>13<\/sup> 19<sup>7<\/sup> 23<sup>289<\/sup> 29<sup>11<\/sup> 31<sup>17<\/sup> 37<sup>13<\/sup> 41<sup>13<\/sup>, which according to Hugs is the number (warning: you need to scroll to see it. a lot!):<\/p>\n<p> 1,821,987,637,902,623,701,225,904,240,019,813,969,080,617,900,348,538,321,073,935,587,788,506,071,830,879,280,904,480,021,357,988,798,547,730,537,019,170,876,649,747,729,076,171,560,080,529,593,160,658,600,674,198,729,426,618,685,737,248,773,404,008,081,519,218,775,692,945,684,706,455,129,294,628,924,575,925,909,585,830,321,614,047,772,585,327,805,405,377,809,182,961,310,697,978,238,941,231,290,173,227,390,750,547,696,657,645,077,277,386,815,869,624,389,931,352,799,230,949,892,054,634,638,136,137,995,254,523,486,502,753,268,687,845,320,296,600,343,871,556,546,425,114,643,587,820,633,133,232,999,109,544,763,520,253,057,252,248,982,267,078,202,089,525,667,161,691,850,572,084,153,306,622,226,987,931,223,193,578,450,852,038,578,983,945,920,534,096,055,419,823,281,786,399,855,459,394,948,921,598,228,615,703,317,657,117,593,084,977,371,635,801,831,244,944,526,230,994,115,900,720,026,901,352,169,637,434,441,791,307,175,579,916,097,240,141,893,510,281,613,711,253,660,054,258,685,889,469,896,461,087,297,563,191,813,037,946,176,250,108,137,458,848,099,487,488,503,799,293,003,562,875,320,575,790,915,778,093,569,309,011,025,000,000,000.<\/p>\n<p> Next, we&#8217;re going to look at how you can express interesting mathematical properties in terms of numbers. G&ouml;del used a property called primitive recursion as an example, so we&#8217;ll walk through a definition of primitive recursion, and show how G&ouml;del expressed primitive recursion numerically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first step in G&ouml;del&#8217;s incompleteness proof was finding a way of taking logical statements and encoding them numerically. Looking at this today, it seems sort-of obvious. I mean, I&#8217;m writing this stuff down in a text file &#8211; that text file is a stream of numbers, and it&#8217;s trivial to convert that stream of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[90],"tags":[],"class_list":["post-2078","post","type-post","status-publish","format-standard","hentry","category-incompleteness-logic"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-xw","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/2078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=2078"}],"version-history":[{"count":2,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/2078\/revisions"}],"predecessor-version":[{"id":3060,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/2078\/revisions\/3060"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=2078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=2078"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=2078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}