{"id":348,"date":"2007-03-16T15:39:33","date_gmt":"2007-03-16T15:39:33","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/03\/16\/simple-programming-in-binary-binary-combinatory-logic\/"},"modified":"2007-03-16T15:39:33","modified_gmt":"2007-03-16T15:39:33","slug":"simple-programming-in-binary-binary-combinatory-logic","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/03\/16\/simple-programming-in-binary-binary-combinatory-logic\/","title":{"rendered":"Simple Programming in Binary: Binary Combinatory Logic"},"content":{"rendered":"<p> For reasons that I&#8217;ll explain in another post, I don&#8217;t have a lot of time for writing a long pathological programming post, so I&#8217;m going to hit you with something short, sweet, and beautiful: <a href=\"http:\/\/www.esolangs.org\/wiki\/Binary_combinatory_logic\">binary combinatory logic.<\/a><\/p>\n<p> I&#8217;ve written in the past about lambda calculus, and it&#8217;s equivalent variable-free form, the SKI combinator calculus. I&#8217;ve ever written about other combinator calculus based languages, like <a href=\"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/08\/friday-pathological-programming-unlambda-or-programming-without-variables\">Unlambda<\/a> and <a href=\"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/09\/pathological-programming-the-worlds-smallest-programming-language\">Iota<\/a>.<\/p>\n<p> Binary combinatory logic, aka BCL, is a language based on SKI calculus &#8211; except that it encodes the entire thing into binary. Two characters, plus two rewrite rules, and that&#8217;s it &#8211; a complete<br \/>\ncombinator calculus based programming language.<\/p>\n<p> SKI combinator calculus is a simple variable-free calculus with three constructs: S, K, and I; and I isn&#8217;t really primitive, but can be defined in terms of S and K.<\/p>\n<ol>\n<li> S=&lambda;x y z.x z (y z)<\/li>\n<li> K=&lambda;x.(&lambda;y.x)<\/li>\n<li> I=&lambda;x.x=SKK<\/li>\n<\/ol>\n<p> So, in BCL, S is written &#8220;01&#8221;; K is written &#8220;00&#8221;. And there are two rewrite rules, which basically define &#8220;1&#8221; without a zero prefix as a a paren-like grouping construct:<\/p>\n<ol>\n<li> &#8220;1100xy&#8221;, where &#8220;x&#8221; and &#8220;y&#8221; are valid BCL terms (that is, complete syntactic units),<br \/>\ngets rewritten to be &#8220;x&#8221;. If you follow that through, that means that it reduces to ((Kx)y).<\/li>\n<li> &#8220;11101xzy&#8221; gets rewritten to &#8220;11xz1yz&#8221;. Again, following it through, and that<br \/>\nreduces out to &#8220;(((Sx)y)z)&#8221;.<\/li>\n<\/ol>\n<p> So, following on unlambda&#8217;s method of handling IO, &#8220;hello world&#8221; in BCL is:<\/p>\n<pre>\n010001101000010000010110000000000101101111\n000010110111110011111111011110000010011010\n<\/pre>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"bcl.gif\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_149.gif?resize=64%2C68\" width=\"64\" height=\"68\" class=\"inset right\" \/><\/p>\n<p> And here&#8217;s the really neat thing. Write an interpreter for BCL in BCL. Take the bit string that results, and convert it to a bitmap. That&#8217;s what&#8217;s over the right here. So, for example, the first line is &#8220;1111100000111001&#8221;; keep going, and you&#8217;ll find the entire BCL interpreter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For reasons that I&#8217;ll explain in another post, I don&#8217;t have a lot of time for writing a long pathological programming post, so I&#8217;m going to hit you with something short, sweet, and beautiful: binary combinatory logic. I&#8217;ve written in the past about lambda calculus, and it&#8217;s equivalent variable-free form, the SKI combinator calculus. I&#8217;ve [&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-348","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-5C","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/348","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=348"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/348\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=348"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}