<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>What&#039;s All This Brouhaha? &#187; Bare Bones</title>
	<atom:link href="https://whats.all.this.brouhaha.com/category/computing/software/software-ive-written/bare-bones/feed/" rel="self" type="application/rss+xml" />
	<link>https://whats.all.this.brouhaha.com</link>
	<description>miscellaneous musings and random rantings</description>
	<lastBuildDate>Fri, 01 Nov 2019 06:31:54 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9</generator>
	<item>
		<title>Turing Machine in Bare Bones</title>
		<link>https://whats.all.this.brouhaha.com/2008/03/03/turing-machine-in-bare-bones/</link>
		<comments>https://whats.all.this.brouhaha.com/2008/03/03/turing-machine-in-bare-bones/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 07:36:24 +0000</pubDate>
		<dc:creator><![CDATA[Eric]]></dc:creator>
				<category><![CDATA[Bare Bones]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://whats.all.this.brouhaha.com/?p=641</guid>
		<description><![CDATA[The most recent release of my Bare Bones interpreter made identifiers case-insensitive, and added an optional peephole optimizer that recognizes a common idiom: while N not 0 do; Â  decr N; Â  incr X; end; Such a loop adds N &#8230; <a href="https://whats.all.this.brouhaha.com/2008/03/03/turing-machine-in-bare-bones/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The most recent release of my Bare Bones interpreter made identifiers case-insensitive, and added an optional peephole optimizer that recognizes a common idiom:</p>
<blockquote>
<pre>while N not 0 do;
Â    decr N;
Â    incr X;
end;</pre>
</blockquote>
<p>Such a loop adds N to X, clearing N in the process.  Without the optimizer, this is has time complexity O(N).  The optimizer replaces it with a single macro that executes in O(1).  This makes the supplied example program that computes Fibonnaci numbers run much faster.</p>
<p>For the next release, I&#8217;ve added more sample programs, including an example of a Bare Bones translation of a two-symbol three-state Turing machine busy beaver program.  The Bare Bones program demonstrates that Bare Bones can perform any action that can be performed by a Turing machine, proving that Bare Bones is universal.<span id="more-641"></span></p>
<p>Brookshear states that Bare Bones is universal by comparing it to a Turing machine,  but only actually shows that it can compute two simple functions that are computable by a Turing machine.  He states that &#8220;researchers have shown that the Bare Bones programming language can be used to express algorithms for computing all the Turing-computable functions,&#8221; but unfortunately he does not give any reference to publication of such results.</p>
<p>One way to show that a machine or language is universal is to show that it can emulate a Turing machine, or that any Turing machine program can be translated into a program for the machine or language in question.  At first glance it wasn&#8217;t obvious that Bare Bones could be universal, because a Bare Bones program can only use a finite number of variables.  The key to its universality is that a Bare Bones variable can contain <em>any</em> non-negative integer.  An infinitely long one-dimensional Turing machine tape can be represented as three variables:  one contains all the symbols to the left of the head, one contains the symbol at the head, and one contains all the symbols to the right of the head.  For a turing machine with an alphabet of n symbols, to move the head position right, one must execute these assignments (in pseudo-code, not Bare Bones code):</p>
<blockquote>
<pre>LEFT := LEFT * n + HEAD;</pre>
<pre>HEAD := RIGHT mod n;</pre>
<pre>RIGHT := RIGHT / n;</pre>
</blockquote>
<p>Moving the head position left is done by the same assignments, with LEFT and RIGHT swapped.  For a two-symbol Turing machine, the Bare Bones code to move the head position to the right is:</p>
<blockquote>
<pre># LEFT := LEFT * 2;
copy LEFT to TEMP;
while TEMP not 0 do;
Â    incr LEFT;
Â    decr TEMP;
end;</pre>
<pre># LEFT := LEFT + HEAD;
while HEAD not 0 do;
Â    incr LEFT;
Â    decr HEAD;
end;</pre>
<pre># HEAD := RIGHT mod 2;
# RIGHT := RIGHT / 2;
copy RIGHT to TEMP;
clear RIGHT;
copy TEMP to HEAD;
decr TEMP;
while TEMP not 0 do;
Â    incr RIGHT;
Â    decr TEMP;
Â    copy TEMP to HEAD;
Â    decr TEMP;
end;</pre>
</blockquote>
<p>That&#8217;s the most complicated portion of the Turing machine interpreter.  I might write up an explanation of the rest at some future date.  For now, anyone interested in the details can look at the example Bare Bones source code for a simulation of a three-state Turing Machine busy beaver program:  <a href="http://svn.brouhaha.com/viewvc/barebones/trunk/examples/tm_busy_beaver_3.bb?view=co" title="tm_busy_beaver_3.bb" target="_blank">tm_busy_beaver_3.bb</a>.</p>
<p>Note that it is not currently practical to to use my Bare Bones interpreter to simulate a Turing machine with a long tape, because the division/modulus code used to shift the tape takes O(n) operations, where n is the number of bits to the right of (or left of) the head.  To make that reasonably efficient, I&#8217;ll need to extend the interpreter&#8217;s optimizer, and make the interpreter use bignum arithmetic (probably using the <a href="http://gmplib.org/" title="The GNU MP Bignum Library" target="_blank">GMP</a> library).  Once that&#8217;s done, it would be nice to try running a universal Turing machine in Bare Bones.  The smallest two-symbol UTM I&#8217;ve heard of uses 22 states.</p>
]]></content:encoded>
			<wfw:commentRss>https://whats.all.this.brouhaha.com/2008/03/03/turing-machine-in-bare-bones/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bare Bones interpreter</title>
		<link>https://whats.all.this.brouhaha.com/2008/02/11/bare-bones-interpreter/</link>
		<comments>https://whats.all.this.brouhaha.com/2008/02/11/bare-bones-interpreter/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 03:21:35 +0000</pubDate>
		<dc:creator><![CDATA[Eric]]></dc:creator>
				<category><![CDATA[Bare Bones]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://whats.all.this.brouhaha.com/?p=630</guid>
		<description><![CDATA[Over the weekend I finished the homework assignment for the &#8220;Theory of Computation&#8221; chapter of Computer Science: An Overview, Ninth Edition, by J. Glenn Brookshear. Brookshear defines a very minimal programming language called Bare Bones, in which variables may contain &#8230; <a href="https://whats.all.this.brouhaha.com/2008/02/11/bare-bones-interpreter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Over the weekend I finished the homework assignment for the &#8220;Theory of Computation&#8221; chapter of <em><a href="http://www.aw-bc.com/brookshear/" title="Computer Science: An Overview" target="_blank">Computer Science: An Overview</a></em>, Ninth Edition, by J. Glenn Brookshear.  Brookshear defines a very minimal programming language called Bare Bones, in which variables may contain arbitrarily large non-negative integers.  The only operations available are:</p>
<ul>
<li>clear var; â€” set a variable to zero</li>
<li>incr var; â€” increment a variable</li>
<li>decr var;  â€” decrement a variable, unless it is already zero</li>
<li>while var not 0 do; &lt;statement list&gt; end;  â€” loop</li>
<li>copy var1 to var2;  â€” introduced for convenience</li>
</ul>
<p>Bare Bones is universal, in that it can compute any function that can be computed by a Turing machine.  In fact, it would be universal even without the clear and copy statements, as those can be synthesized from the remaining statements.  Needless to say, writing programs in this language can be tricky.  I wasn&#8217;t confident that the programs I wrote for the homework exercises were correct, and decided to write a <a href="http://www.brouhaha.com/~eric/software/barebones/" title="Bare Bones interpreter" target="_blank">Bare Bones interpreter</a> to check them.  It&#8217;s released under the <a href="http://www.brouhaha.com/~eric/software/gpl-3.0.txt" title="General Public License, version 3" target="_blank">GPLv3</a>.</p>
<p>I wrote example Bare Bones programs to compute factorials and fibonacci numbers, and they are included with the interpreter.</p>
]]></content:encoded>
			<wfw:commentRss>https://whats.all.this.brouhaha.com/2008/02/11/bare-bones-interpreter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
