The inc/footer.default.html now has a common Copyright and CC BY-SA 4.0 License section for all generated HTML files. All markdown files have a similar Copyright and CC at the bottom in the form of an HTML comment.
604 lines
60 KiB
HTML
604 lines
60 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
<!-- START: two lines up starts content from: inc/top.default.html -->
|
||
<!-- -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- -->
|
||
<!-- END: this line ends content from: inc/top.default.html -->
|
||
<!-- -->
|
||
<!-- This web page was formed via the tool: bin/readme2index.sh -->
|
||
<!-- -->
|
||
<!-- The content of main section of this web page came from: 2012/tromp/README.md -->
|
||
<!-- -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2012/tromp/README.md -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2012/tromp/README.md -->
|
||
<!-- !!! Do not modify this web page, instead modify the file: 2012/tromp/README.md -->
|
||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||
<!-- -->
|
||
<!-- Markdown content was converted into HTML via the tool: bin/md2html.sh -->
|
||
<!-- -->
|
||
<!-- START: this line starts content from: inc/head.default.html -->
|
||
|
||
<head>
|
||
<link rel="stylesheet" href="../../ioccc.css">
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
<title>2012/tromp - Most functional</title>
|
||
<meta name="description" content="2012 IOCCC entry tromp - Most functional">
|
||
<meta name="keywords" content="IOCCC, 2012, IOCCC 2012, IOCCC entry, tromp, Most functional">
|
||
</head>
|
||
|
||
<!-- END: this line ends content from: inc/head.default.html -->
|
||
<!-- START: this line starts content from: inc/body.default.html -->
|
||
|
||
<body>
|
||
|
||
<!-- END: this line ends content from: inc/body.default.html -->
|
||
<!-- START: this line starts content from: inc/header.default.html -->
|
||
|
||
<div class="header">
|
||
<img src="../../png/ioccc.png" alt="IOCCC image by Matt Zucker" width=300 height=110>
|
||
<h1>The International Obfuscated C Code Contest</h1>
|
||
<h2>2012/tromp - Most functional</h2>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/header.default.html -->
|
||
<!-- START: this line starts content from: inc/topnav.mid.html -->
|
||
|
||
<div class="topnav">
|
||
<a class="Left" href="../omoikane/index.html">← omoikane</a>
|
||
<a class="Left" href="../index.html">↑ 2012 ↑</a>
|
||
<a class="Left" href="../vik/index.html">vik →</a>
|
||
<a class="Right" href="https://github.com/ioccc-src/temp-test-ioccc/2012/tromp/tromp.c">C code</a>
|
||
<a class="Right" href="https://github.com/ioccc-src/temp-test-ioccc/2012/tromp/Makefile">Makefile</a>
|
||
<a class="Right" href="#inventory">Inventory</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/topnav.mid.html -->
|
||
<!-- START: this line starts content from: inc/begin-row.default.html -->
|
||
|
||
<div class="row">
|
||
|
||
<!-- END: this line ends content from: inc/begin-row.default.html -->
|
||
<!-- START: this line starts content from: inc/begin-leftcolumn.default.html -->
|
||
|
||
<div class="leftcolumn">
|
||
|
||
<!-- END: this line ends content from: inc/begin-leftcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/sidenav.default.html -->
|
||
|
||
<div class="sidenav">
|
||
<a href="#content">Jump to contents</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../index.html">IOCCC Home</a>
|
||
<a href="../../years.html">Winning Entries</a>
|
||
<a href="../../authors.html">People who have won</a>
|
||
<a href="../../location.html">Location of authors</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../news.html">IOCCC News</a>
|
||
<a href="../../status.html">Contest status</a>
|
||
<a href="../../faq.html#submit">How to enter the IOCCC</a>
|
||
<a href="../../faq.html">FAQ</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../bugs.html">Bugs & (mis)features</a>
|
||
<a href="../../faq.html#fix_an_entry">Fixing IOCCC entries</a>
|
||
<a href="../../faq.html#fix_web_site">Fixing the web site</a>
|
||
<a href="../../faq.html#fix_author">Fixing author info</a>
|
||
<a href="../../thanks-for-help.html">Thanks for the help</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="../../judges.html">The IOCCC Judges</a>
|
||
<a href="../../contact.html">Contacting the IOCCC</a>
|
||
</div>
|
||
<hr>
|
||
<div class="sidenav">
|
||
<a href="#top">Jump to top</a>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/sidenav.default.html -->
|
||
<!-- START: this line starts content from: inc/end-leftcolumn.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-leftcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/begin-rightcolumn.default.html -->
|
||
|
||
<div class="rightcolumn">
|
||
|
||
<!-- END: this line ends content from: inc/begin-rightcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/before-content.default.html -->
|
||
|
||
<a name="content"></a>
|
||
|
||
<!-- END: this line ends content from: inc/before-content.default.html -->
|
||
<!-- START: this line starts content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-author.sh -->
|
||
|
||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||
<ul>
|
||
<li>Name: <a href="../../authors.html#John_Tromp">John Tromp</a><br>
|
||
Location: <a href="../../location.html#US">US</a> - <em>United States of America</em> (<em>United States</em>)
|
||
<br><br></li>
|
||
</ul>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
|
||
<h2 id="to-build">To build:</h2>
|
||
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> all <span class="co"># On a 64-bit machine (default)</span></span>
|
||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> tromp32 <span class="co"># On a 32-bit machine</span></span></code></pre></div>
|
||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||
<p>The current status of this entry is:</p>
|
||
<pre><code>STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||
<p>For more detailed information see <a href="../../bugs.html#2012_tromp">2012 tromp bugs</a>.</p>
|
||
<h2 id="to-use">To use:</h2>
|
||
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./tromp</span> <span class="pp">[-</span><span class="ss">b</span><span class="pp">]</span></span></code></pre></div>
|
||
<p>Use <code>./tromp32</code> as you would <code>./tromp</code> if on a 32-bit machine.</p>
|
||
<h2 id="to-use-1">To use:</h2>
|
||
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> ascii-prog.blc data <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span></span>
|
||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> binary-prog.Blc data <span class="kw">|</span> <span class="ex">./tromp</span></span></code></pre></div>
|
||
<h2 id="try">Try:</h2>
|
||
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./try.sh</span></span></code></pre></div>
|
||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||
<p>The judges dare to say that the data files this entry is processing
|
||
are more obfuscated than the entry itself.</p>
|
||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||
<p>This program celebrates the close connection between obfuscation and conciseness,
|
||
by implementing the most concise language known, <a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">Binary Lambda Calculus
|
||
(BLC)</a>.</p>
|
||
<p><a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">BLC</a> was developed to
|
||
make <a href="https://en.wikipedia.org/wiki/Algorithmic_information_theory">Algorithmic Information
|
||
Theory</a>, the
|
||
theory of smallest programs, more concrete. It starts with the simplest model of
|
||
computation, the <a href="https://en.wikipedia.org/wiki/Lambda_calculus">lambda
|
||
calculus</a>, and adds the minimum
|
||
amount of machinery to enable binary input and output.</p>
|
||
<p>More specifically, it defines a universal machine, which, from an input stream
|
||
of bits, parses the binary encoding of a <a href="https://en.wikipedia.org/wiki/Lambda_calculus">lambda
|
||
calculus</a> term, applies that to
|
||
the remainder of input (translated to a lazy list of
|
||
<a href="https://en.wikipedia.org/wiki/Boolean_algebra">booleans</a>, which have a standard
|
||
representation in lambda calculus), and translates the evaluated result back
|
||
into a stream of bits to be output.</p>
|
||
<p>Lambda is encoded as 00, application as 01, and the variable bound by the <code>n</code>th
|
||
enclosing lambda (denoted <code>n</code> in so-called <a href="https://en.wikipedia.org/wiki/De_Bruijn_notation">De Bruijn
|
||
notation</a>) as <code>1^{n}0</code>.
|
||
That’s all there is to
|
||
<a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">BLC</a>!</p>
|
||
<p>For example the encoding of lambda term <code>S = \x \y \z (x z) (y z)</code>,
|
||
with <a href="https://en.wikipedia.org/wiki/De_Bruijn_notation">De Bruijn notation</a> <code>\ \ \ (3 1) (2 1)</code>, is <code>00 00 00 01 01 1110 10 01 110 10</code>.</p>
|
||
<p>In the closely related
|
||
<a href="https://tromp.github.io/cl/Binary_lambda_calculus.html#BLC8:_byte_sized_I.2FO">BLC8</a>
|
||
language, I/O is byte oriented, translating between a stream of bytes and a list
|
||
of length-8 lists of <a href="https://en.wikipedia.org/wiki/Boolean_algebra">booleans</a>.</p>
|
||
<p>The submission implements the universal machine in the most concise manner conceivable.
|
||
It lacks <code>#define</code>s and <code>#include</code>s, and compiles to a (stripped) executable of
|
||
under 6K in size.</p>
|
||
<p>Without arguments, it runs in byte mode, using standard input and output.
|
||
With one (arbitrary) argument, it runs in bit mode, using only the least significant
|
||
bit of input, and using characters <code>0</code> and <code>1</code> for output.</p>
|
||
<p>The program uses the following exit codes:</p>
|
||
<pre><code>0: OK; result is a finite list
|
||
5: Out of term space
|
||
6: Out of memory
|
||
1,2,3,4,8,9: result not in list form</code></pre>
|
||
<p>The size of the term space is fixed at compile time with <code>-DA</code>.</p>
|
||
<h3 id="a-half-byte-cat">A half byte <code>cat</code></h3>
|
||
<p>The shortest (closed) lambda calculus term is <code>\x x (\ 1</code> in <a href="https://en.wikipedia.org/wiki/De_Bruijn_notation">De Bruijn
|
||
notation</a>) which is the
|
||
identity function. When its encoding <code>0010</code> is fed into the universal machine,
|
||
it will simply copy the input to the output (well, not that simply, since each
|
||
byte is smashed to bits and rebuilt from scratch). Voila: a half byte cat:</p>
|
||
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> echo <span class="st">" Hello, world"</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Hello,</span> world</span></code></pre></div>
|
||
<p>Since the least significant 4 bits of the first byte are just arbitrary padding
|
||
that is ignored by the program, any character from ASCII 32 (space) through 47
|
||
(<code>/</code>) will do, e.g.:</p>
|
||
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> echo <span class="st">"*Hello, world"</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Hello,</span> world</span></code></pre></div>
|
||
<h3 id="bad-programs">Bad programs</h3>
|
||
<p>If the input doesn’t start with a valid program, that is,
|
||
if the interpreter reaches end-of-file during program parsing,
|
||
it will crash in some way. E.g. the following might dump core:</p>
|
||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="at">-n</span> <span class="st">"U"</span> <span class="kw">|</span> <span class="ex">./tromp</span></span></code></pre></div>
|
||
<p>Furthermore, the interpreter requires the initial encoded lambda term to be
|
||
closed, that is, variable <code>n</code> can only appear within at least <code>n</code> enclosing
|
||
lambdas. For instance, here the term <code>\ 5</code> is not closed, causing the
|
||
interpreter to crash when looking into a null-pointer environment:</p>
|
||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">">Hello, world"</span> <span class="kw">|</span> <span class="ex">./tromp</span></span></code></pre></div>
|
||
<p>will likely dump core.</p>
|
||
<p>Since these properties can be checked when creating
|
||
<a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">BLC</a> programs,
|
||
the interpreter doesn’t bother checking for it.</p>
|
||
<h3 id="a-self-interpreter">A Self Interpreter</h3>
|
||
<p>The <a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">BLC</a> universal
|
||
machine may be small at 650 bytes of C (952 bytes including layout), but written
|
||
as a self interpreter in BLC it is downright minuscule at 232 bits (29 bytes):</p>
|
||
<pre><code> 01010001
|
||
10100000
|
||
00010101
|
||
10000000
|
||
00011110
|
||
00010111
|
||
11100111
|
||
10000101
|
||
11001111
|
||
000000111
|
||
10000101101
|
||
1011100111110
|
||
000111110000101
|
||
11101001 11010010
|
||
11001110 00011011
|
||
00001011 11100001
|
||
11110000 11100110
|
||
11110111 11001111
|
||
01110110 00011001
|
||
00011010 00011010</code></pre>
|
||
<p>The byte oriented BLC8 version weighs in at 43 bytes (shown in hexadecimal).</p>
|
||
<pre><code> 19468
|
||
05580
|
||
05f00
|
||
bfe5f
|
||
85f3f
|
||
03c2d
|
||
b9fc3f8
|
||
5e9d65e5f
|
||
0decb f0fc3
|
||
9befe 185f7
|
||
0b7fb 00cf6
|
||
7bb03 91a1a
|
||
</code></pre>
|
||
<div class="sourceCode" id="cb13"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> <span class="er">(</span><span class="fu">cat</span> uni8.Blc<span class="kw">;</span> <span class="bu">echo</span> <span class="st">" Ni hao"</span><span class="kw">)</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Ni</span> hao</span></code></pre></div>
|
||
<h3 id="a-prime-number-sieve">A prime number sieve</h3>
|
||
<p>Even shorter than the self-interpreter is this prime number sieve in 167 bits
|
||
(under 21 bytes):</p>
|
||
<pre><code> 000100011001100101000110100
|
||
000000101100000100100010101
|
||
11110111 101001000
|
||
11010000 111001101
|
||
000000000010110111001110011
|
||
11111011110000000011111001
|
||
10111000
|
||
00010110
|
||
0000110110
|
||
</code></pre>
|
||
<p>The <code>n</code>th bit in the output indicates whether n is prime:</p>
|
||
<div class="sourceCode" id="cb15"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 70</span>
|
||
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="ex">0011010100010100010100010000010100000100010100010000010000010100000100</span></span></code></pre></div>
|
||
<p>For those who prefer to digest their primes in decimal, there is <code>oddindices.Blc</code>,
|
||
which will print the indices of all odd characters (with
|
||
<a href="https://en.wikipedia.org/wiki/Bit_numbering">LSB</a> = 1)
|
||
separated by a given character:</p>
|
||
<pre><code>$ (cat oddindices.Blc; echo -n " "; cat primes.blc | ./tromp -b) | ./tromp | head -c 70
|
||
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97</code></pre>
|
||
<h3 id="a-space-filling-program">A Space filling program</h3>
|
||
<p>The program <code>hilbert.Blc</code>, at 143 bytes, is a very twisty “one-liner” (shown in hexadecimal):</p>
|
||
<pre><code> 1818181 8111154 6806041 55ff041
|
||
9d f9 de 16 ff fe 5f 3f
|
||
ef f615ff9 46 84 058117e 05
|
||
cb fe bc bf
|
||
ee86cb9 4681600 5c0bfac bfbf71a
|
||
85 e0 5c f4
|
||
14d5fe0 8180b048d0800e078 016445f
|
||
fe 5f
|
||
f7 ffffe5fff2fc 02f7ad97f5bf ff
|
||
ff bf ff ca af ff
|
||
7817ffa df76695 4680601 57f7e16
|
||
05 c1
|
||
3fe80b2 2c18581 bfe5c10 42ff805
|
||
de ec 06 c2 c0 c0
|
||
60 8191a00167fb cbcfdf65f7c0 a20</code></pre>
|
||
<p>It expects <code>n</code> arbitrary characters of input, and draws a space filling <a href="https://en.wikipedia.org/wiki/Hilbert_curve">Hilbert
|
||
curve</a> of order <code>n</code>:</p>
|
||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> <span class="er">(</span><span class="fu">cat</span> hilbert.Blc<span class="kw">;</span> <span class="bu">echo</span> <span class="at">-n</span> <span class="st">"1"</span><span class="kw">)</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span></span>
|
||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> <span class="er">(</span><span class="fu">cat</span> hilbert.Blc<span class="kw">;</span> <span class="bu">echo</span> <span class="at">-n</span> <span class="st">"12"</span><span class="kw">)</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> _</span>
|
||
<span id="cb18-7"><a href="#cb18-7" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-8"><a href="#cb18-8" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span></span>
|
||
<span id="cb18-9"><a href="#cb18-9" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span></span>
|
||
<span id="cb18-10"><a href="#cb18-10" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb18-11"><a href="#cb18-11" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> <span class="er">(</span><span class="fu">cat</span> hilbert.Blc<span class="kw">;</span> <span class="bu">echo</span> <span class="at">-n</span> <span class="st">"123"</span><span class="kw">)</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb18-12"><a href="#cb18-12" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> _ _ _</span>
|
||
<span id="cb18-13"><a href="#cb18-13" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-14"><a href="#cb18-14" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span></span>
|
||
<span id="cb18-15"><a href="#cb18-15" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_____</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span></span>
|
||
<span id="cb18-16"><a href="#cb18-16" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">___</span> ___ <span class="kw">|</span></span>
|
||
<span id="cb18-17"><a href="#cb18-17" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span></span>
|
||
<span id="cb18-18"><a href="#cb18-18" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span></span>
|
||
<span id="cb18-19"><a href="#cb18-19" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-20"><a href="#cb18-20" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb18-21"><a href="#cb18-21" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> <span class="er">(</span><span class="fu">cat</span> hilbert.Blc<span class="kw">;</span> <span class="bu">echo</span> <span class="at">-n</span> <span class="st">"1234"</span><span class="kw">)</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb18-22"><a href="#cb18-22" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> _ _ _ _ _ _ _</span>
|
||
<span id="cb18-23"><a href="#cb18-23" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-24"><a href="#cb18-24" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span></span>
|
||
<span id="cb18-25"><a href="#cb18-25" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_____</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="kw">|</span><span class="ex">_____</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span></span>
|
||
<span id="cb18-26"><a href="#cb18-26" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">___</span> ___ <span class="kw">|</span> <span class="kw">|</span> <span class="ex">___</span> ___ <span class="kw">|</span></span>
|
||
<span id="cb18-27"><a href="#cb18-27" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span></span>
|
||
<span id="cb18-28"><a href="#cb18-28" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span> _ <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span></span>
|
||
<span id="cb18-29"><a href="#cb18-29" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-30"><a href="#cb18-30" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span> ___ ___ ___ ___ _<span class="kw">|</span></span>
|
||
<span id="cb18-31"><a href="#cb18-31" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span></span>
|
||
<span id="cb18-32"><a href="#cb18-32" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span></span>
|
||
<span id="cb18-33"><a href="#cb18-33" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span></span>
|
||
<span id="cb18-34"><a href="#cb18-34" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span> _ <span class="kw">|</span> <span class="ex">___</span> ___ <span class="kw">|</span> <span class="ex">_</span> _</span>
|
||
<span id="cb18-35"><a href="#cb18-35" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span></span>
|
||
<span id="cb18-36"><a href="#cb18-36" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span> <span class="ex">_</span> <span class="kw">|</span><span class="ex">_</span> _<span class="kw">|</span></span>
|
||
<span id="cb18-37"><a href="#cb18-37" aria-hidden="true" tabindex="-1"></a> <span class="ex">_</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">___</span><span class="kw">|</span> <span class="kw">|</span><span class="ex">_</span></span></code></pre></div>
|
||
<h3 id="a-brainfuck-interpreter">A <a href="https://en.wikipedia.org/wiki/Brainfuck">Brainfuck</a> interpreter</h3>
|
||
<p>The smallest known BF interpreter is written in… you guessed it,
|
||
<a href="https://tromp.github.io/cl/Binary_lambda_calculus.html">BLC</a>,
|
||
coming in at 112 bytes (including 3 bits of padding):</p>
|
||
<pre><code>$ od -t x4 bf.Blc
|
||
0000000 01a15144 02d55584 223070b7 00f032ff
|
||
0000020 7f85f9bf 956fe15e c0ee7d7f 006854e5
|
||
0000040 fbfd5558 fd5745e0 b6f0fbeb 07d62ff0
|
||
0000060 d7736fe1 c0bc14f1 1f2eff0b 17666fa1
|
||
0000100 2fef5be8 ff13ffcf 2034cae1 0bd0c80a
|
||
0000120 e51fee99 6a5a7fff ff0fff1f d0049d87
|
||
0000140 db0500ab 3bb74023 b0c0cc28 10740e6c
|
||
0000160</code></pre>
|
||
<p>It expects its input to consist of a
|
||
<a href="https://en.wikipedia.org/wiki/Brainfuck">Brainfuck</a> program
|
||
(looking only at bits <code>0</code>, <code>1</code> and <code>4</code> to distinguish among <code>,-.+<>][</code>)
|
||
followed by a <code>]</code>, followed by the input for the Brainfuck program.</p>
|
||
<pre><code>$ more hw.bf
|
||
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.]
|
||
$ cat bf.Blc hw.bf | ./tromp
|
||
Hello World!</code></pre>
|
||
<p>Curiously, the interpreter <code>bf.Blc</code> is the exact same size as <code>hw.bf</code>.</p>
|
||
<h3 id="a-blc-assembler">A BLC assembler</h3>
|
||
<p>Writing BLC programs can be made slightly less painful with this parser that
|
||
translates single-letter-variable lambda calculus into BLC:</p>
|
||
<div class="sourceCode" id="cb21"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> echo <span class="st">"\f\x f (f (f x))"</span> <span class="op">></span> three</span>
|
||
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat parse.Blc three <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a><span class="ex">000001110011100111010</span></span></code></pre></div>
|
||
<h3 id="converting-between-bits-and-bytes">Converting between bits and bytes</h3>
|
||
<p>The program <code>inflate.Blc</code> and its inverse <code>deflate.Blc</code> allow us to translate between
|
||
BLC and BLC8. If you assemble a byte oriented program, you’ll need to compact it
|
||
into BLC8:</p>
|
||
<p>So we could assemble an input reversing program as</p>
|
||
<div class="sourceCode" id="cb22"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">"\a a ((\b b b) (\b \c \d \e d (b b) (\f f c e))) (\b \c c)"</span> <span class="op">></span> reverse</span>
|
||
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> parse.Blc reverse <span class="kw">|</span> <span class="ex">./tromp</span> <span class="op">></span> reverse.blc</span></code></pre></div>
|
||
<p>and change it to BLC8 with</p>
|
||
<div class="sourceCode" id="cb23"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat deflate.Blc reverse.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="op">></span> rev.Blc</span>
|
||
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> wc rev.Blc</span>
|
||
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">0</span> 1 9 rev.Blc</span></code></pre></div>
|
||
<p>and then try it out with:</p>
|
||
<div class="sourceCode" id="cb24"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat rev.Blc <span class="at">-</span> <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Hello,</span> world!</span>
|
||
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a><span class="ex">^D</span></span>
|
||
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a><span class="ex">!dlrow</span> ,olleH</span></code></pre></div>
|
||
<h3 id="symbolic-lambda-calculus-reduction">Symbolic Lambda Calculus reduction</h3>
|
||
<p>BLC8 program <code>symbolic.Blc</code> shows individual reduction steps on symbolic lambda terms.
|
||
Here it is used to show the calculation of 2^3 in Church numerals:</p>
|
||
<div class="sourceCode" id="cb25"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> echo <span class="st">"(\f\x f (f (f x))) (\f\x f (f x))"</span> <span class="op">></span> threetwo</span>
|
||
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat parse.Blc threetwo <span class="kw">|</span> <span class="ex">./tromp</span> <span class="op">></span> threetwo.blc</span>
|
||
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat symbolic.Blc threetwo.blc <span class="kw">|</span> <span class="ex">./tromp</span></span>
|
||
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a><span class="kw">(</span><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> b<span class="kw">)))</span> <span class="kw">(</span><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> b<span class="kw">))</span></span>
|
||
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="er">(</span><span class="ex">\b</span> <span class="dt">\c</span> b <span class="er">(</span><span class="ex">b</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\b</span> <span class="dt">\c</span> b <span class="er">(</span><span class="ex">b</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\b</span> <span class="dt">\c</span> b <span class="er">(</span><span class="ex">b</span> c<span class="kw">))</span> <span class="ex">a</span><span class="kw">))</span></span>
|
||
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> <span class="er">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">)</span></span>
|
||
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> <span class="er">(</span><span class="ex">\c</span> <span class="er">(</span><span class="ex">\d</span> <span class="dt">\e</span> d <span class="er">(</span><span class="ex">d</span> e<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\d</span> <span class="dt">\e</span> d <span class="er">(</span><span class="ex">d</span> e<span class="kw">))</span> <span class="ex">a</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">)</span></span>
|
||
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> <span class="er">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">))</span></span>
|
||
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> <span class="er">(</span><span class="ex">\c</span> a <span class="er">(</span><span class="ex">a</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">))</span></span>
|
||
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">)))</span></span>
|
||
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> a <span class="er">(</span><span class="ex">a</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">)))</span></span>
|
||
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span><span class="kw">)</span> <span class="ex">b</span><span class="kw">))))</span></span>
|
||
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="er">(</span><span class="ex">\d</span> <span class="dt">\e</span> d <span class="er">(</span><span class="ex">d</span> e<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\d</span> <span class="dt">\e</span> d <span class="er">(</span><span class="ex">d</span> e<span class="kw">))</span> <span class="ex">a</span> c<span class="kw">))</span> <span class="ex">b</span><span class="kw">))))</span></span>
|
||
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> b<span class="kw">)))))</span></span>
|
||
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> a <span class="er">(</span><span class="ex">a</span> c<span class="kw">))</span> <span class="kw">((</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> b<span class="kw">)))))</span></span>
|
||
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> c <span class="er">(</span><span class="ex">c</span> d<span class="kw">))</span> <span class="ex">a</span> b<span class="kw">))))))</span></span>
|
||
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> a <span class="er">(</span><span class="ex">a</span> c<span class="kw">))</span> <span class="ex">b</span><span class="kw">))))))</span></span>
|
||
<span id="cb25-18"><a href="#cb25-18" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="dt">\b</span> a <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> <span class="er">(</span><span class="ex">a</span> b<span class="kw">)))))))</span></span></code></pre></div>
|
||
<p>As expected, the resulting normal form is <a href="https://en.wikipedia.org/wiki/Church_encoding">Church
|
||
numeral</a> 8.</p>
|
||
<p>Taking only the first line of output gives us a sort of BLC disassembler, an
|
||
exact inverse of the above assembler. The prime number sieve disassembles as
|
||
follows:</p>
|
||
<div class="sourceCode" id="cb26"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat symbolic.Blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-1</span></span>
|
||
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="ex">\a</span> <span class="er">(</span><span class="ex">\b</span> b <span class="er">(</span><span class="ex">b</span> <span class="er">(</span><span class="kw">(</span><span class="ex">\c</span> c c<span class="kw">)</span> <span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> <span class="dt">\e</span> e <span class="er">(</span><span class="ex">\f</span> <span class="dt">\g</span> g<span class="kw">)</span> <span class="kw">((</span><span class="ex">\f</span> c c f <span class="er">(</span><span class="kw">(</span><span class="ex">\g</span> g g<span class="kw">)</span> <span class="kw">(</span><span class="ex">\g</span> f <span class="er">(</span><span class="ex">g</span> g<span class="kw">))))</span> <span class="kw">(</span><span class="ex">\f</span> <span class="dt">\g</span> <span class="dt">\h</span> <span class="dt">\i</span> i g <span class="er">(</span><span class="ex">h</span> <span class="er">(</span><span class="ex">d</span> f<span class="kw">)))))</span> <span class="kw">(</span><span class="ex">\c</span> <span class="dt">\d</span> <span class="dt">\e</span> b <span class="er">(</span><span class="ex">e</span> c<span class="kw">)))))</span> <span class="kw">(</span><span class="ex">\b</span> <span class="dt">\c</span> c <span class="er">(</span><span class="ex">\d</span> <span class="dt">\e</span> d<span class="kw">)</span> <span class="ex">b</span><span class="kw">)</span></span></code></pre></div>
|
||
<p>Hardly any less obfuscated…</p>
|
||
<p>The last line of</p>
|
||
<div class="sourceCode" id="cb27"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> symbolic.Blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-16</span></span></code></pre></div>
|
||
<p>starts out as</p>
|
||
<pre><code>\a \b b (\c \d c) (\c c (\d \e d) (\d d (\e \f f) (\e e (\f \g g) ((\f (\g \h \i</code></pre>
|
||
<p>The <code>\a</code> is for ignoring the rest of the input (to which the universal machine
|
||
applies the decoded lambda term). The <code>\b b (..) (...)</code> is the list constructor,
|
||
usually called <code>cons</code>, applied to a head (a list element) and a tail (another list).
|
||
In this case the element is <code>(\c \d c)</code>, which represents the boolean true, and
|
||
which we use to represent a 0 bit. This is the bit that says 0 is not prime.
|
||
The next list element (following another <code>cons</code>) is <code>(\d \e d)</code>. Another 0 bit,
|
||
this time saying that 1 is not prime. The third list element is <code>(\e \f f)</code>,
|
||
a 1 bit, confirming our suspicion that 2 is prime. As is the next number,
|
||
according to <code>(\f \g g)</code>. We can see that the tail after the first 4 elements
|
||
is still subject to further reduction. The bit for number 4 will show up
|
||
for the first time in line 30, as <code>(\g \h g)</code>, or 0, as the result of zeroing
|
||
out all multiples of the first prime, 2.</p>
|
||
<p>Since my computer reaches swap hell before line 40, we can’t see the next bit arriving,
|
||
at least not in this symbolic reduction.</p>
|
||
<h3 id="performance">Performance</h3>
|
||
<p>Performance is quite decent, and amazingly good for such a tiny implementation,
|
||
being roughly 50% slower than a Haskell implementation of the universal machine
|
||
using so-called <a href="https://en.wikipedia.org/wiki/Higher-order_abstract_syntax">Higher Order Abstract
|
||
Syntax</a> which relies on the highly optimized
|
||
Haskell runtime system for evaluation. Of course individual BLC programs running
|
||
under the interpreter perform much worse than that same program written in Haskell.</p>
|
||
<p>Our interpreter copes well with extra levels of interpretation:</p>
|
||
<div class="sourceCode" id="cb29"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> time cat primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 210 <span class="op">></span> /dev/null</span>
|
||
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a><span class="ex">real</span> 0m0.043s</span>
|
||
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> time cat uni.blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 210 <span class="op">></span> /dev/null</span>
|
||
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a><span class="ex">real</span> 0m0.191s</span>
|
||
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> time cat uni.blc uni.blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 210 <span class="op">></span> /dev/null</span>
|
||
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a><span class="ex">real</span> 0m1.919s</span>
|
||
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> time cat uni.blc uni.blc uni.blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 210 <span class="op">></span> /dev/null</span>
|
||
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a><span class="ex">real</span> 0m23.514s</span>
|
||
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> time cat uni.blc uni.blc uni.blc uni.blc primes.blc <span class="kw">|</span> <span class="ex">./tromp</span> <span class="at">-b</span> <span class="kw">|</span> <span class="fu">head</span> <span class="at">-c</span> 210 <span class="op">></span> /dev/null</span>
|
||
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a><span class="ex">real</span> 4m52.700s</span></code></pre></div>
|
||
<h3 id="obfuscation">Obfuscation</h3>
|
||
<p>Obfuscation is due entirely to conciseness. Some questions to ponder:</p>
|
||
<p>Which of the term space codes <code>0</code>, <code>1</code>, <code>2</code>, <code>3</code> serve multiple purposes?</p>
|
||
<p>Why is the environment pointer pointing into the term space?</p>
|
||
<p>What does the test <code>u+m&1?</code> do?</p>
|
||
<p>How does the program reach exit code 0?</p>
|
||
<p>And how do any of those BLC programs work?</p>
|
||
<h3 id="portability">Portability</h3>
|
||
<p>The program freely (without casting) converts between <code>int</code> and <code>int *</code>, causing
|
||
many warnings;</p>
|
||
<pre><code> note: expected 'int *' but argument is of type 'int'
|
||
warning: assignment from incompatible pointer type
|
||
warning: assignment makes integer from pointer without a cast
|
||
warning: assignment makes pointer from integer without a cast
|
||
warning: incompatible implicit declaration of built-in function 'calloc'
|
||
warning: incompatible implicit declaration of built-in function 'exit'
|
||
warning: passing argument 1 of 'd' makes pointer from integer without a cast
|
||
warning: passing argument 1 of 'p' makes pointer from integer without a cast
|
||
warning: pointer/integer type mismatch in conditional expression</code></pre>
|
||
<p>Avoiding these would make the program substantially longer,
|
||
and detract from its single minded focus on conciseness.</p>
|
||
<p>It implicitly declares functions <code>read(2)</code>, <code>write(2)</code>, <code>exit(3)</code> and
|
||
<code>calloc(3)</code>, the latter two incompatibly. 32 bit and 64 bit executables are
|
||
separate <a href="Makefile">Makefile</a> targets, involving a change from <code>int</code> to <code>long</code>
|
||
and from a hardcoded sizeof of 4 to 8.</p>
|
||
<p>The program has been tested to work correctly on Linux/Solaris/MacOSX both in 32
|
||
and 64 bits.</p>
|
||
<h3 id="how-the-program-works">How the program works</h3>
|
||
<p>See the file <a href="how.html">how.html</a>.</p>
|
||
<h3 id="acknowledgements">Acknowledgements</h3>
|
||
<p>Christopher Hendrie, Bertram Felgenhauer, Alex Stangl, Seong-hoon Kang,
|
||
and <a href="../../authors.html#Yusuke_Endoh">Yusuke Endoh</a> have contributed ideas and
|
||
suggestions for improvement.</p>
|
||
<h3 id="references">References</h3>
|
||
<p>Binary Lambda Calculus -
|
||
<a href="https://tromp.github.io/cl/Binary_lambda_calculus.html" class="uri">https://tromp.github.io/cl/Binary_lambda_calculus.html</a></p>
|
||
<p>G J Chaitin, Algorithmic information theory, Volume I,
|
||
Cambridge Tracts in Theoretical Computer Science, Cambridge University Press, October 1987.
|
||
<a href="https://web.archive.org/web/20121125233450/https://www.cs.auckland.ac.nz/~chaitin/cup.html" class="uri">https://web.archive.org/web/20121125233450/https://www.cs.auckland.ac.nz/~chaitin/cup.html</a></p>
|
||
<p>Jean-Louis Krivine. 2007.
|
||
A call-by-name lambda-calculus machine
|
||
Higher Order Symbol. Comput. 20, 3 (September 2007), 199-207.
|
||
<a href="http://www.pps.univ-paris-diderot.fr/~krivine/articles/lazymach.pdf" class="uri">http://www.pps.univ-paris-diderot.fr/~krivine/articles/lazymach.pdf</a></p>
|
||
<!--
|
||
|
||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
|
||
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
|
||
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<h1 id="inventory-for-2012tromp"><a name="inventory"></a>Inventory for 2012/tromp</h1>
|
||
<p><a href="#top">Jump to top</a></p>
|
||
<h2 id="primary-files">Primary files</h2>
|
||
<ul>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/tromp.c">tromp.c</a> - entry source</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/Makefile">Makefile</a> - entry Makefile</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/tromp.orig.c">tromp.orig.c</a> - original source</li>
|
||
<li><a href="how.html">how.html</a> - author supplied spoiler</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/primes.pl">primes.pl</a> - post process tromp output to print primes</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/try.sh">try.sh</a> - how to run</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/hw.bf">hw.bf</a> - bf source code</li>
|
||
<li><a href="2012_tromp.tar.bz2">2012_tromp.tar.bz2</a> - download entry source</li>
|
||
</ul>
|
||
<h2 id="secondary-files">Secondary files</h2>
|
||
<ul>
|
||
<li><a href="index.html">index.html</a> - entry home page</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/README.md">README.md</a> - markdown source for index.html</li>
|
||
<li><a href="bf.Blc">bf.Blc</a> - sample input</li>
|
||
<li><a href="deflate.Blc">deflate.Blc</a> - sample input</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/.entry.json">.entry.json</a> - description of entry in JSON</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/.gitignore">.gitignore</a> - list of files that should not be committed under git</li>
|
||
<li><a href="hilbert.Blc">hilbert.Blc</a> - sample input</li>
|
||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2012/tromp/how.md">how.md</a> - markdown source for how.html</li>
|
||
<li><a href="inflate.Blc">inflate.Blc</a> - sample input</li>
|
||
<li><a href="oddindices.Blc">oddindices.Blc</a> - sample input</li>
|
||
<li><a href="parse.Blc">parse.Blc</a> - sample input</li>
|
||
<li><a href=".path">.path</a> - directory path from top directory</li>
|
||
<li><a href="primes.blc">primes.blc</a> - sample input</li>
|
||
<li><a href="symbolic.Blc">symbolic.Blc</a> - sample input</li>
|
||
<li><a href="uni8.Blc">uni8.Blc</a> - sample input</li>
|
||
<li><a href="uni.blc">uni.blc</a> - sample input</li>
|
||
</ul>
|
||
|
||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||
|
||
<!-- END: this line ends content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
|
||
<!-- START: this line starts content from: inc/after-content.default.html -->
|
||
|
||
<!-- END: this line ends content from: inc/after-content.default.html -->
|
||
<!-- START: this line starts content from: inc/end-rightcolumn.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-rightcolumn.default.html -->
|
||
<!-- START: this line starts content from: inc/end-row.default.html -->
|
||
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/end-row.default.html -->
|
||
<!-- START: this line starts content from: inc/footer.default.html -->
|
||
|
||
<!--
|
||
|
||
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
|
||
|
||
You are free to share and adapt this file under the terms of this license:
|
||
|
||
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
|
||
|
||
For more information, see:
|
||
|
||
https://creativecommons.org/licenses/by-sa/4.0/
|
||
|
||
-->
|
||
|
||
<div class="footer">
|
||
<h2>Copyright and CC BY-SA 4.0 License</h2>
|
||
<p>This file and web page is:</p>
|
||
<blockquote><b>Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.</b></p></blockquote>
|
||
<p>You are free to share and adapt this file under the terms of this license:</p>
|
||
<blockquote><b>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</b></blockquote>
|
||
<p>For more information, see:</p>
|
||
<blockquote><a
|
||
href="https://creativecommons.org/licenses/by-sa/4.0/">https://creativecommons.org/licenses/by-sa/4.0/</a></blockquote>
|
||
<h2>Coda</h2>
|
||
<p><a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2012%2Ftromp%2Findex.html">Nu HTML check this web page</a></p>
|
||
<p><a href="#top">Jump to top</a> <a href="#content">Jump to Content</a> <a href="#inventory">Jump to Inventory</a></p>
|
||
</div>
|
||
|
||
<!-- END: this line ends content from: inc/footer.default.html -->
|
||
<!-- START: this line starts content from: inc/bottom.default.html -->
|
||
|
||
</body>
|
||
</html>
|
||
|
||
<!-- END: this line ends content from: inc/bottom.default.html -->
|