{"id":147,"date":"2006-09-08T08:30:13","date_gmt":"2006-09-08T08:30:13","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/09\/08\/pathological-programming-the-worlds-smallest-programming-language\/"},"modified":"2006-09-08T08:30:13","modified_gmt":"2006-09-08T08:30:13","slug":"pathological-programming-the-worlds-smallest-programming-language","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2006\/09\/08\/pathological-programming-the-worlds-smallest-programming-language\/","title":{"rendered":"Pathological Programming: The Worlds Smallest Programming Language"},"content":{"rendered":"<p>For todays dose of pathological programming, we&#8217;re going to hit the worlds simplest language. A Turing-complete programming language with exactly *two* characters, no variables, and no numbers. It&#8217;s called [Iota][iota]. And rather than bothering with the rather annoying Iota compiler, we&#8217;ll just use an even more twisted language called [Lazy-K][lazyk], which can run Iota programs, Unlambda programs, as well as its own syntax.<br \/>\n[unlambda]: http:\/\/scienceblogs.com\/goodmath\/2006\/08\/friday_pathological_programmin_3.php<br \/>\n[lazyk]: http:\/\/esoteric.sange.fi\/essie2\/download\/lazy-k\/<br \/>\n[Iota]: http:\/\/ling.ucsd.edu\/~barker\/Iota\/<\/p>\n<p><!--more--><br \/>\nA few weeks ago, I showed you [Unlambda][unlambda], a programming language based on the SKI combinator calculus. The SKI combinator calculus is a nifty little thing that defines two canonical operators, S and K, called combinators. It&#8217;s easy to show that *any* lambda calculus function *and thus any program* can be written using nothing but two basic combinators: S, and K. Literally, nothing but those two combinators: no variables, no numbers, nothing. To make things easier to write, they also add I, but you can actually write I in terms of S and K:<br \/>\n1. S is the function &#8220;*&lambda; x y z . x z (y z)*&#8221;.<br \/>\n2. K is the function &#8220;*&lambda; x y . x*&#8221;<br \/>\n3. I is the fuction &#8220;*&lambda; x . x*&#8221;; it can also be written &#8220;SKK&#8221;<br \/>\nWell, you can do better than SKI. You can define *one* combinator, &iota;: using iota, and *only* iota, you can write *any* lambda calculus function. What&#8217;s it look like? &iota;=*&lambda;x.xSK*; or stretched out,  *&lambda; x . (&lambda; a b c . a c (b c) (&lambda; d e . d)*.<br \/>\nIf you&#8217;ve got &iota;, then you can define S, K, and I combinators in terms of iota as follows:<br \/>\n1. S = &iota;(&iota;(&iota;(&iota;&iota;)))<br \/>\n2. K = &iota;(&iota;(&iota;&iota;)<br \/>\n3. I = &iota;&iota;<br \/>\nThe *programming language* [Iota][iota] is based on the &iota; combinator. We write the combinator as &#8220;i&#8221;; and we use &#8220;*&#8221; for function application. Like the &#8220;&#8216;&#8221; in Unlambda, we can think of &#8220;*&#8221; as an open-paren, and the close-paren isn&#8217;t needed, since all functions take only one parameter.<br \/>\nSo to repeat the combinators in Iota syntax:<br \/>\n1. S=*i*i*i*ii<br \/>\n2. K=*i*i*ii<br \/>\n3. I=*ii<br \/>\nOf course, there is one problem with Iota as a programming language. It doesn&#8217;t have any input or output statements. But that&#8217;s no problem: the *program itself* is both its input and its output.  When a program stops, you look at what it&#8217;s turned into, and that&#8217;s its output &#8211; just like in lambda calculus: apply a function, do all of the betas, and the program transforms itself into its result. (And actually, the Lazy-K interpreter, which accepts Iota syntax, will generate output, based on an idea of lists of input and output&#8230;)<br \/>\nAs I said before, only &#8220;*&#8221; and &#8220;i&#8221; are part of Iota syntax. So to do numbers, we need to use church numerals. And we can&#8217;t write them in lambda syntax! So we need to work out how to construct them using Iota expressions.<br \/>\nThe church numeral for one in lambda syntax is &#8220;&lambda; s z . s z&#8221;. Translated to iota, that&#8217;s pretty simple: &#8220;*ii&#8221;. Easy, right? So how bad could two be? Heh&#8230; In lambda calculus, it&#8217;s &#8220;*&lambda; s z . s (s z)*&#8221;. In SKI, it&#8217;s &#8220;(S(S(KS(KI))))&#8221; In Iota? &#8220;***i*i*i*ii***i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii*ii&#8221;.<br \/>\nIt only gets worse  with bigger numbers. Three is &#8220;***i*i*i*ii***i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii***i*i*i*ii***i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii*ii&#8221;. We&#8217;ll  stop with that.<br \/>\nTo program conditionals, we need to define true, false, and if.  The &#8220;true&#8221; value in lambda calculus is written &#8220;*&lambda; x y . x*&#8221;, and &#8220;false&#8221; is written &#8220;*&lambda; x y . y*&#8221;.  And finally, &#8220;if(cond,true,false)&#8221; is &#8220;*&lambda; c t f . (c t f)*&#8221;. So what do they look like in Lazy-K?<br \/>\n* True = &#8220;*i*i*ii&#8221;<br \/>\n* False = &#8220;**i*i*ii*ii&#8221;<br \/>\n* If = &#8220;*ii&#8221;<br \/>\nThere now, That&#8217;s not so bad, is it?<br \/>\nTo give you an idea, here&#8217;s an Iota program which generates prime numbers. It uses the Lazy-K mechanism for output.<br \/>\n*i*i*ii<br \/>\n**i*i*i*ii*ii*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii<br \/>\n**i*i*i*ii*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii<br \/>\n**i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii*i*i*i*ii**i*i*i*ii**i*i*i<br \/>\n*ii**i*i*ii*i*i*i*ii*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii<br \/>\n**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii*i<br \/>\n*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii<br \/>\n*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii<br \/>\n*i*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii*ii*ii**i*i*ii**i<br \/>\n*i*i*ii*ii**i*i*ii*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii*ii**i<br \/>\n*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i<br \/>\n*i*ii*i*i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i<br \/>\n*ii*ii**i*i*i*ii**i*i*i*ii*ii*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii<br \/>\n*i*i*i*ii*i*i*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii<br \/>\n**i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*i*ii**i*i*ii*i*i*ii*i*i*ii<br \/>\n**i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*<br \/>\nii**i*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*i*ii*i*i*i*ii*i*i<br \/>\n*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i<br \/>\n*i*ii*i*i*i*ii*i*i*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i<br \/>\n*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii*ii**i*i*i*ii**i*i<br \/>\n*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii*i*i*ii**i*i*ii*i*i*ii<br \/>\n**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii<br \/>\n**i*i*ii**i*i*i*ii*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii<br \/>\n**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii**i*i*i*ii*ii**i*i*ii*i<br \/>\n*i*ii**i*i*ii**i*i*ii**i*i*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii**i*i*i*ii*ii**i*i*i*ii*i*i*i*ii**i*i*i*ii*ii**i*i<br \/>\n*ii*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i<br \/>\n*i*ii**i*i*ii*i*i*i*ii*i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*ii<br \/>\n**i*i*ii**i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*i*ii*ii**i*i*ii*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i<br \/>\n*i*ii*ii**i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii<br \/>\n*i*i*ii*ii**i*i*i*ii**i*i*i*ii*ii*ii*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i<br \/>\n*i*ii*i*i*ii*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i<br \/>\n*ii**i*i*ii*i*i*ii**i*i*i*ii*ii*ii**i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii<br \/>\n*ii**i*i*i*ii*ii*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i<br \/>\n*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii*i*i*ii<br \/>\n**i*i*ii*ii**i*i*i*ii*i*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*<br \/>\ni*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i<br \/>\n*i*ii*ii*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i<br \/>\n*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i<br \/>\n*i*ii*i*i*ii**i*i*i*ii*ii*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i<br \/>\n*ii*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i<br \/>\n*ii**i*i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii*i*i*ii**i*i*ii*ii**i*i*i<br \/>\n*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii*ii*ii**i*i*i*ii**i*i*ii<br \/>\n**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i<br \/>\n*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii*ii*i*i*ii<br \/>\n**i*i*ii*i*i*ii**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i<br \/>\n*ii*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii*ii**i*i*ii*i*i*ii**i*i*i*ii<br \/>\n*ii**i*i*ii*i*i*ii**i*i*ii**i*i*i*ii*ii**i*i*ii*i*i*ii**i*i*i*ii<br \/>\n**i*i*i*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii*i<br \/>\n*i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii**i*i*i<br \/>\n*ii**i*i*ii*i*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii*ii*ii**i*i*ii<br \/>\n**i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*ii**i*i*ii**i*i*i*ii*ii**i*i*ii<br \/>\n**i*i*ii*ii**i*i*i*ii**i*i*ii**i*i*i*ii*ii*ii**i*i*i*ii**i*i*ii**i*i<br \/>\n*i*ii**i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii**i*i*i*ii**i*i*i*ii**i*i<br \/>\n*ii*i*i*i*ii**i*i*i*ii**i*i*ii*i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*i*ii<br \/>\n**i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii*i*i*ii**i*i*ii<br \/>\n**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii*i*i*ii**i*i*i*ii**i<br \/>\n*i*ii*i*i*ii**i*i*i*ii*ii*ii**i*i*ii**i*i*i*ii*ii**i*i*ii**i*i*ii*ii<br \/>\n**i*i*i*ii**i*i*i*ii**i*i*ii*i*i*i*ii*i*i*ii*ii**i*i*i*ii*ii*ii<br \/>\n**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*ii**i*i*i*ii**i*i*i*ii*ii**i*i*ii<br \/>\n**i*i*ii*ii*i*i*ii**i*i*i*ii*ii*ii<br \/>\nDoesn&#8217;t get more pathological than that, now does it?<br \/>\nActually, it *does*.<br \/>\nThere&#8217;s a companion to Iota, called *Jot*. Jot is a purely binary representation that is not just a two character programming language, but also a complete Godel numbering of Iota programs.<br \/>\nHere&#8217;s the combinators in Jot:<br \/>\n1. S = 11111000<br \/>\n2. K = 11100<br \/>\n3. I = 1111110001110011100<br \/>\nBasically, &#8220;0&#8221; is &iota;, and &#8220;1&#8221; is &#8220;*&#8221;. (It&#8217;s actually a tad more complex than that, but we won&#8217;t bother ourselves with the details.)<br \/>\nSo, here&#8217;s out fibonacci generator written in Jot:<br \/>\n111100111111111100011111111100000111111111000001111111000111100<br \/>\n111111000111111100011110011111000111001111111000111100111111000<br \/>\n11110011111100011110011111110001111001111110001111111000<br \/>\n11111111100000111100111111100011110011111110001111111000111100<br \/>\n111110001110011111111100000111111100011111110001111001111100011100<br \/>\n11111111000111111111000001111111110000011111110001111111000111100<br \/>\n111110001110011111111100000111001111111000111111100011110011111000<br \/>\n1111111000111100111001111111000111100111110001111111000<br \/>\n111111111000001111111110000011110011111110001111001111100011100<br \/>\n111111111000001111111000111100111111000111111100011111111100000<br \/>\n1111001111111000111100111111100011111110001111001111100011100<br \/>\n1111111110000011111111100011111110001111001111100011100<br \/>\n11111111000111111111000001111111110000011111110001111111000<br \/>\n1111001111100011100111111111000001111110001111111000111100<br \/>\n11111000111001111111100011111110001111111110000011111111100000<br \/>\n1111111110000011111110001111111000111100111110001110011111111100000<br \/>\n11100<br \/>\nIncidentally, as I&#8217;ve mentioned, there&#8217;s currently a &#8220;geek-off&#8221; competition going on at ScienceBlogs to prove who&#8217;s the biggest geek. I think that the mere *existence* of this article is more than enough to demonstrate that I am quite clearly the geekiest blogger at SB. But just to put the icing on the cake, I generated the fibonacci program above by writing a little micro-compiler from Unlambda to Iota; and then translated from Iota to Jot *by hand*. (What&#8217;s a bit scary about that is that the compiler from Unlambda to Iota is longer than the entire Iota compiler.)<br \/>\n[unlambda]: http:\/\/scienceblogs.com\/goodmath\/2006\/08\/friday_pathological_programmin_3.php<br \/>\n[lazyk]: http:\/\/esoteric.sange.fi\/essie2\/download\/lazy-k\/<br \/>\n[Iota]: http:\/\/ling.ucsd.edu\/~barker\/Iota\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For todays dose of pathological programming, we&#8217;re going to hit the worlds simplest language. A Turing-complete programming language with exactly *two* characters, no variables, and no numbers. It&#8217;s called [Iota][iota]. And rather than bothering with the rather annoying Iota compiler, we&#8217;ll just use an even more twisted language called [Lazy-K][lazyk], which can run Iota programs, [&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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[92],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-2n","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/147","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=147"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}