<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6265039086215303226</id><updated>2011-07-31T00:51:30.365-07:00</updated><title type='text'>A Different Kind of Uselessness</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://fmota91.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6265039086215303226.post-6026382996607295238</id><published>2007-11-11T19:26:00.001-08:00</published><updated>2007-11-11T21:00:09.396-08:00</updated><title type='text'>Small shots of lambda calculus, part III</title><content type='html'>&lt;p&gt;&lt;a href="http://fmota91.blogspot.com/2007/09/small-shots-of-lambda-calculus-part-ii.html"&gt;Last time&lt;/a&gt;, we talked about pairs and more complex arithmetic, and we &lt;a href="http://fmota91.blogspot.com/2007/09/small-shots-of-lambda-calculus-part-i.html"&gt;previously&lt;/a&gt; discussed the basics of lambda calculus and simple arithmetic.&lt;/p&gt;&lt;p&gt;This time we&amp;#8217;re going to talk about lists.&lt;/p&gt;&lt;p&gt;There are several different ways to define lists in lambda calculus. One way is as a more complicated pair. We use &lt;code&gt;cons&lt;/code&gt; and &lt;code&gt;nil&lt;/code&gt; to construct lists:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; cons h t f x = f h t&lt;br /&gt;&amp;gt; nil      f x = x&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And we use &lt;code&gt;head&lt;/code&gt; and &lt;code&gt;tail&lt;/code&gt; to get the first item and all but the first items, respectively:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; head_ x l = l (\h t -&amp;gt; h)&lt;br /&gt;&amp;gt; head = head_ 0&lt;br /&gt;&amp;gt; tail_ x l = l (\h t -&amp;gt; t)&lt;br /&gt;&amp;gt; tail = tail_ nil&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here are a few examples of using them in our imaginary lambda calculus interpreter:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; cons 1 nil&lt;br /&gt;cons 1 nil&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; head (cons 1 nil)&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail (cons 1 nil)&lt;br /&gt;nil&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; head nil&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail nil&lt;br /&gt;nil&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is all well and good, but it&amp;#8217;s kind of boring. These lists are basically no different from pairs and, in order to do anything useful such as mappings and folds, we have to go jump through hoops of complexity.&lt;/p&gt;&lt;p&gt;Perhaps this is best, for otherwise we might&amp;#8217;ve been content with this representation for lists and not have found the other viable representation, which I consider to be the most elegant.&lt;/p&gt;&lt;p&gt;An empty list is &lt;code&gt;nil&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; nil f x = x&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that nil is unchanged, and that nil has the same definition as 0.&lt;/p&gt;&lt;p&gt;To construct the list we use cons:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; cons h t f x = f h (t f x)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is very similar to the &lt;code&gt;succ&lt;/code&gt; function we defined in Part 1. To understand how it works, we should look at some sample lists. (Note our list shorthand: comma separated list of values encased in square brackets.)&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; [] f x&lt;br /&gt;x&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; [1] f x&lt;br /&gt;f 1 x&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; [1,2] f x&lt;br /&gt;f 1 (f 2 x)&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; [1,2,3] f x&lt;br /&gt;f 1 (f 2 (f 3 x))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Compare this to the way numbers are defined:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; 0 f x&lt;br /&gt;x&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; 1 f x&lt;br /&gt;f x&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; 2 f x&lt;br /&gt;f (f x)&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; 3 f x&lt;br /&gt;f (f (f x))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It&amp;#8217;s hard to argue that there&amp;#8217;s a more natural way of expressing lists in lambda calculus.*&lt;/p&gt;&lt;p&gt;It&amp;#8217;s easy to get the head value:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; head_ x l = l (\h v -&amp;gt; h) x&lt;br /&gt;&amp;gt; head = head_ 0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; head []&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; head [1]&lt;br /&gt;1&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; head [1,2]&lt;br /&gt;1&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;But getting the tail is &lt;strong&gt;hard&lt;/strong&gt;, like getting the predecessor of a number:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; tail_ x l = 1st (l (\h p -&amp;gt; pair (2nd p) (cons h (2nd p))) (pair x nil))&lt;br /&gt;&amp;gt; tail = tail_ nil&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail []&lt;br /&gt;[]&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail [1]&lt;br /&gt;[]&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail [1,2]&lt;br /&gt;[2]&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; tail [1,2,3]&lt;br /&gt;[2,3]&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Actually &lt;code&gt;tail&lt;/code&gt; works just like &lt;code&gt;pred&lt;/code&gt;, but instead of doing &lt;code&gt;succ&lt;/code&gt; each iteration, it does &lt;code&gt;cons h&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Some properties and predicates:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; length l = l (\h n -&amp;gt; succ n) 0&lt;br /&gt;&amp;gt; nil?   l = l (\h b -&amp;gt; false) true&lt;br /&gt;&amp;gt; sum    l = l add 0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; length []&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; length [1,2,3,4]&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; nil? []&lt;br /&gt;true&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; nil? [1,2,3,4]&lt;br /&gt;false&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; sum []&lt;br /&gt;0&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; sum [1,2,3,4]&lt;br /&gt;10&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We should also define &lt;code&gt;map&lt;/code&gt; (which passes a function through all items of a list):&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;gt; map f l = l (\h v -&amp;gt; cons (f h) v) nil&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; map (add 5) []&lt;br /&gt;[]&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; map (add 5) [3]&lt;br /&gt;[8]&lt;br /&gt;&lt;br /&gt;&amp;gt;&amp;gt;&amp;gt; map (\x -&amp;gt; mul x x) [1,2,3,4,5]&lt;br /&gt;[1,4,9,16,25]&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That&amp;#8217;s it for today. Tell me what else you&amp;#8217;d like to know about Lambda Calculus (in the comments on &lt;a href="http://programming.reddit.com/info/60ddz/comments/"&gt;reddit&lt;/a&gt;).&lt;/p&gt;&lt;h4&gt;Footnotes&lt;/h4&gt;&lt;p&gt;* - By the way, this list representation corresponds to Haskell&amp;#8217;s &lt;code&gt;foldr&lt;/code&gt;.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6265039086215303226-6026382996607295238?l=fmota91.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6026382996607295238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6026382996607295238'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/2007/11/small-shots-of-lambda-calculus-part-iii.html' title='Small shots of lambda calculus, part III'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6265039086215303226.post-6376399887596509697</id><published>2007-09-20T15:22:00.000-07:00</published><updated>2007-11-04T23:01:23.849-08:00</updated><title type='text'>Small Shots of Lambda Calculus, Part II</title><content type='html'>&lt;a href="http://fmota91.blogspot.com/2007/09/small-shots-of-lambda-calculus-part-i.html"&gt;Last time&lt;/a&gt;, we talked about simple arithmetic in lambda calculus. Let's expand on that.&lt;br /&gt;&lt;br /&gt;We have a successor function, but we don't have a predecessor function. To define it we need a different abstraction though: the pair!&lt;br /&gt;&lt;pre&gt;&lt;code&gt;pair a b f = f a b&lt;br /&gt;1st p = p true&lt;br /&gt;2nd p = p false&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;[We're using Haskell-like syntax now. This means that (bla a = b) is the same as (bla = (\ a -&gt; b)). Oh, and we're using \ at the beginning of lambda expressions, too.]&lt;br /&gt;&lt;br /&gt;&lt;code&gt;pair&lt;/code&gt; works because you usually only supply 2 arguments -- and when you want to use them, pass a function to them. You can also extract the 1st and 2nd elements using &lt;code&gt;1st&lt;/code&gt; and &lt;code&gt;2nd&lt;/code&gt;, which use &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; to select the correct element, respectively.&lt;br /&gt;&lt;br /&gt;A few examples of using pair (in our imaginary lambda calculus interpreter):&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&gt; 1st (pair 42 13)&lt;br /&gt;42&lt;br /&gt;&gt; 2nd (pair 42 13)&lt;br /&gt;13&lt;br /&gt;&gt; pair 42 13 add&lt;br /&gt;55&lt;br /&gt;&gt; pair 10 (pair 20 30) (\a b -&gt; pair (pair a (1st b)) (2nd b))&lt;br /&gt;pair (pair 10 20) 30&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We can now use pair to create our predecessor function:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;pred n = 1st (n (\p -&gt; pair (2nd p) (suc (2nd p))) (pair 0 0))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This is complicated, so I'll go through this with you. You start with &lt;code&gt;(pair 0 0)&lt;/code&gt;, and apply &lt;code&gt;(\p -&gt; pair (2nd p) (suc (2nd p)))&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt; times. What each of those applications does is, in effect, it transforms the pair (a, b) into the pair (b, b+1). So, by the time you've applied it n times to the pair (0, 0), you get the pair (n - 1, n). Then all you have to do is get the 1st element using &lt;code&gt;1st&lt;/code&gt;. That's it!&lt;br /&gt;&lt;br /&gt;If you do &lt;code&gt;(pred 0)&lt;/code&gt;, it returns &lt;code&gt;0&lt;/code&gt;, but we can make an alternate version of &lt;code&gt;pred&lt;/code&gt; that takes care of this:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;pred_ x n = 1st (n (\p -&gt; pair (2nd p) (succ (2nd p))) (pair x 0))&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Another way to define &lt;code&gt;pred&lt;/code&gt; now is:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;pred = pred_ 0&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We can now do subtraction:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;sub a b = a pred b&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;or&lt;br /&gt;&lt;pre&gt;&lt;code&gt;sub_ x a b = a (pred_ x) b&lt;br /&gt;sub = sub_ 0&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;For division we need a predicate. Predicates are functions that return either true or false:&lt;br /&gt;&lt;pre&gt;&lt;code&gt;not b = b false true&lt;br /&gt;is0? n = n (\x -&gt; false) true&lt;br /&gt;ge? a b = is0? (sub b a)&lt;br /&gt;lt? a b = not (ge? a b)&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;code&gt;not&lt;/code&gt; inverts a boolean, &lt;code&gt;is0?&lt;/code&gt; asks whether or not a number is &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;ge?&lt;/code&gt; asks if one number is greater than or equal to the other, and &lt;code&gt;le?&lt;/code&gt; asks if a number is less than another. We can now do division and modulo (remainder):&lt;br /&gt;&lt;pre&gt;&lt;code&gt;div a b = lt? a b 0 (suc (div (sub a b) b))&lt;br /&gt;mod a b = lt? a b a (mod (sub a b) b)&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You learned about pairs, predecessors, predicates, and powerful arithmetic, today. Tomorrow: Lists! Can't wait! :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6265039086215303226-6376399887596509697?l=fmota91.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6376399887596509697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6376399887596509697'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/2007/09/small-shots-of-lambda-calculus-part-ii.html' title='Small Shots of Lambda Calculus, Part II'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6265039086215303226.post-6654337501002816085</id><published>2007-09-19T00:08:00.000-07:00</published><updated>2007-09-19T00:28:08.975-07:00</updated><title type='text'>Small Shots of Lambda Calculus, Part I</title><content type='html'>Lambda calculus was invented by Alonzo Church.&lt;br /&gt;&lt;br /&gt;Lambda calculus revolves around the application of anonymous functions -- lambda expressions.&lt;br /&gt;&lt;br /&gt;[For the sake of clarity, I'll be using the syntax &lt;code&gt;(a -&gt; b)&lt;/code&gt; over &lt;code&gt;(lambda a. b)&lt;/code&gt;.]&lt;br /&gt;&lt;br /&gt;It's best to explain by example.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;(a -&gt; b) x&lt;/code&gt; becomes &lt;code&gt;b&lt;/code&gt;&lt;br /&gt;&lt;code&gt;(a -&gt; a) x&lt;/code&gt; becomes &lt;code&gt;x&lt;/code&gt;&lt;br /&gt;&lt;code&gt;(a b -&gt; b a) x y&lt;/code&gt; becomes &lt;code&gt;y x&lt;/code&gt;&lt;br /&gt;&lt;code&gt;(a b -&gt; b a) (a -&gt; b) (a -&gt; a)&lt;/code&gt; becomes &lt;code&gt;(a -&gt; a) (a -&gt; b)&lt;/code&gt; becomes &lt;code&gt;(a -&gt; b)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Everything is a function in this extremely minimal lambda calculus. I'll introduce you to some of the most important ones:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;I = (x -&gt; x)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;I&lt;/code&gt; doesn't do much -- it just returns its argument.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;true = (a b -&gt; a)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;false = (a b -&gt; b)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;true&lt;/code&gt; returns its first argument while &lt;code&gt;false&lt;/code&gt; returns its second argument. They're the archetypal Boolean values of lambda calculus.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;0 = (f x -&gt; x)&lt;br /&gt;1 = (f x -&gt; f x)&lt;br /&gt;2 = (f x -&gt; f (f x))&lt;br /&gt;3 = (f x -&gt; f (f (f x)))&lt;br /&gt;...&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;These are called the Church numerals, and they're used to apply a function to an argument a variable number of times. Note the similarity (in fact, equivalence) between 0 and false.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;succ = (n f x -&gt; f (n f x))&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;We can use succ to go from one Church numeral to the next. It is now trivial to do arithmetic on Church numerals.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;add = (a b -&gt; a succ b)&lt;/code&gt;&lt;br /&gt;&lt;code&gt;mul = (a b -&gt; a (add b) 0)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;G'night. Tomorrow: More lambda calculus.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6265039086215303226-6654337501002816085?l=fmota91.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6654337501002816085'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/6654337501002816085'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/2007/09/small-shots-of-lambda-calculus-part-i.html' title='Small Shots of Lambda Calculus, Part I'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6265039086215303226.post-2887518474363717733</id><published>2007-09-13T16:55:00.000-07:00</published><updated>2007-09-19T20:54:35.933-07:00</updated><title type='text'>So, is 0 zero?</title><content type='html'>&lt;strong&gt;Is 0 zero?&lt;/strong&gt;&lt;br /&gt;Um, yes...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is 0.0 zero?&lt;/strong&gt;&lt;br /&gt;Yes...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is 0.00 zero?&lt;/strong&gt;&lt;br /&gt;Yes. I don't know where you're going with this, but it better be entertaining.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Hang on and it will be.&lt;/strong&gt;&lt;br /&gt;It better.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Is 0.000 zero?&lt;/strong&gt;&lt;br /&gt;Yes. Get on with it!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Okay. If I keep placing 0 at the end of the number, is it still zero?&lt;/strong&gt;&lt;br /&gt;Yes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;So 0.00000... is zero, then?&lt;/strong&gt;&lt;br /&gt;Assuming you're using only the digit 0, then yes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Ah! What happens if we take that assumption away?&lt;/strong&gt;&lt;br /&gt;Then I don't know if the number is zero or not. You could have some digit other than 0 in there.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Yes. Let's play a game.&lt;/strong&gt;&lt;br /&gt;Okay. What are the rules?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;I think of a digit after the decimal point. You can choose between asking me for the digit, or declaring whether or not the number is zero. If you ask for a digit, I get to think of another digit and the process starts again.&lt;/strong&gt;&lt;br /&gt;And if I declare whether or not the number is zero&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;I reveal my digit. If you're right, you win. Otherwise I do.&lt;/strong&gt;&lt;br /&gt;Heh. Seems like you can win every time.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Whatever, let's play. I've thought of my first digit.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3, go.&lt;/strong&gt;&lt;br /&gt;That's easy! The number is not zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Right you are, my next digit was 3.&lt;/strong&gt;&lt;br /&gt;You let me win.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Yes. Let's play again. Go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;...we're not going anywhere are we? I guess the number is zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Bzzzzt! My next digit was 8.&lt;/strong&gt;&lt;br /&gt;You only say that because I guessed it was zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Right you are. Let's modify the rules a little bit. I have to write my digit down on this piece of paper, and show it to you every time you ask [etches something on the paper with a blunt pencil].&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[Reveals a "0.0", then etches some more onto the paper.] Go.&lt;/strong&gt;&lt;br /&gt;I guess the number is zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[Reveals "0.00".] You win!&lt;/strong&gt;&lt;br /&gt;That was easier. It seems to me like the only viable thing for you to do is to always write down a zero, or I might ask for it and reveal the obvious truth. I should always guess that it's a zero, at random times.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;But what if I write a 1 just when you're about to guess?&lt;/strong&gt;&lt;br /&gt;You'd win, but there's a pretty slim chance of getting it right.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;True.&lt;/strong&gt;&lt;br /&gt;On the other hand, if I keep asking, you might slip and give me something other than a 0.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;But if I don't?&lt;/strong&gt;&lt;br /&gt;We'd be getting nowhere, and I'd be inclined to guess zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;And so I'd be inclined to put something other than a 0 the longer it goes on, right?&lt;/strong&gt;&lt;br /&gt;Right... but that means I can just keep asking and I'll win...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Good, you completely grok the game.&lt;/strong&gt;&lt;br /&gt;It's weird and pointless. Can I go now?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Nope. So, what did you learn? How do the two games compare?&lt;/strong&gt;&lt;br /&gt;Well, I always lose on the first game, and I usually win on the second game.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;But why?&lt;/strong&gt;&lt;br /&gt;Because you can't change your mind in the second game?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Exactly. Let's try a simple variation on the second game now.&lt;/strong&gt;&lt;br /&gt;Oh, not again...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;I decide what the number is up-front and write it down, or an equation representing it. You can ask for digits, etc...&lt;/strong&gt;&lt;br /&gt;Okay.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[Pauses for a moment, then scribbles something down.] Go!&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1, go.&lt;/strong&gt;&lt;br /&gt;Not zero. Why did you let me win?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;To prove a point. Let's play again. [Scribbles something else down.]&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;...we're at this again. I guess the number is zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[Reveals 0.0001]. Oops! I win! Maybe you could have played better?&lt;/strong&gt;&lt;br /&gt;You mean I just had to keep asking?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Apparently. Wanna try again? [Scribbles some more.] Go!&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Ask.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;0, go.&lt;/strong&gt;&lt;br /&gt;Oh, whatever... I'm guessing not zero.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[Smiles, and reveals a nice round 0.] Geez, I thought you'd have learnt not to trust me by now.&lt;/strong&gt;&lt;br /&gt;Hey, that hurts! So... how can I tell if it's a 0?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;...you can't! That's my point. You can't tell if it's a zero just by asking digits.&lt;/strong&gt;&lt;br /&gt;So basically we can both win this game. I can win through perseverance, you can win through cunning. Should I go now?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Wait! We haven't even reflected on this.&lt;/strong&gt;&lt;br /&gt;It's getting dark outside...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Calm down, nothing bad is going to happen if you learn a little bit more.&lt;/strong&gt;&lt;br /&gt;Just get on with it.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Kids these days, so hasty... Anyway, you can't tell whether or not my number is a 0 just from looking at the digits individually. What if I tell you what all the digits are?&lt;/strong&gt;&lt;br /&gt;Sounds simple enough.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Oh really? Here: the nth digit is 0, for all n.&lt;/strong&gt;&lt;br /&gt;Well, that's obviously 0...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Okay. Try: the nth digit is the same as the n minus one -th digit.&lt;/strong&gt;&lt;br /&gt;Depends on the first digit. You aren't giving me all the information here.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Fair enough. Suppose I did give you all the information. Would you always be able to tell me whether or not the number is zero?&lt;/strong&gt;&lt;br /&gt;Of course! If I know every digit of the number, I know what the number is!&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Really? I wanna see that. What about this: the nth digit is 0 if n converges to the 1-4-2-1 cycle of the Collatz conjecture, and otherwise is 1.&lt;/strong&gt;&lt;br /&gt;...oh, I don't know that!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;... I haven't figured out a good way to end this yet.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6265039086215303226-2887518474363717733?l=fmota91.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/2887518474363717733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/2887518474363717733'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/2007/09/is-0-zero-um-yes.html' title='So, is 0 zero?'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6265039086215303226.post-7668179289932864094</id><published>2007-09-11T21:39:00.000-07:00</published><updated>2007-09-12T12:45:12.405-07:00</updated><title type='text'>Introducing... sectorForth!</title><content type='html'>&lt;span style="font-family:verdana;"&gt;sectorForth is extreme, and I mean extreme. I believe it qualifies as esoteric too.&lt;br /&gt;&lt;br /&gt;Each sectorForth program consists of up to 128 lines each with at most 5 words (a word being a sequence of characters delimited by whitespace). This means that even the most complicated sectorForth program is, at most, 640 words long.&lt;br /&gt;&lt;br /&gt;If a line starts with a word (no whitespace preceding it), then it's a definition. Otherwise, it's a continuation and is only allowed to be 4 words long. I'll give you a little example:&lt;br /&gt;&lt;pre&gt;fact    0? drop 1&lt;br /&gt;        dup 1- fact *&lt;/pre&gt;&lt;br /&gt;That's a little factorial function. The word &lt;code&gt;0?&lt;/code&gt; checks to see if the top item (on the stack) is 0. If it is, it continues execution on that line. Otherwise it goes to the next line and executes that. In plain old forth, this means&lt;br /&gt;&lt;br /&gt;&lt;code&gt;: fact (n -- n!) recursive dup 0 = if drop 1 else dup 1- fact * then ;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Needless to say, I prefer sectorForth's way.&lt;br /&gt;&lt;br /&gt;sectorForth has up to 128 predefined words. Among these you have:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 32 64 128 256 512 1024 4096 65536 -7 -6 -5 -4 -3 -2 -1&lt;/code&gt;&lt;br /&gt;&lt;code&gt;+ - * / 1- 1+ | &amp;amp; ^ &gt;&gt; &amp;lt;&amp;lt; 8&amp;lt;&amp;lt;| neg &lt;/code&gt;&lt;br /&gt;&lt;code&gt;? 0? _? = != &gt; &amp;lt; &gt;= &amp;lt;= &gt;? &amp;lt;?&lt;/code&gt;&lt;br /&gt;&lt;code&gt;dup swap over rot -rot drop { }&lt;/code&gt;&lt;br /&gt;&lt;code&gt;emit . open close in out :in :out&lt;/code&gt;&lt;br /&gt;&lt;code&gt;@ ! A B :A :B A@ A! B@ B! A@+ A!+ B@+ B!+ @@ !! A@@ A!! B@@ B!!  A@@+ A!!+ B@@+ B!!+ word* new free&lt;/code&gt;&lt;br /&gt;&lt;code&gt;call cur+&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Nifty, but... why?!&lt;/h4&gt;The point of sectorForth is to fit one program into 512 bytes (the size of a sector on most disks). This is done by restricting the number of words you can define (up to 128) and the length of each word (up to 4 calls per word). Since you can define 128 words, and you have 128 predefined words... you can have up to 256 distinct calls.&lt;br /&gt;&lt;br /&gt;This means you only need one byte to represent a single call. Since a word is 4 calls, you need 32bits (an int by todays standards) for a word. And 128 * 4 = 512. :)&lt;br /&gt;&lt;br /&gt;Actual practical uses? Very few. Maybe in an esoteric OS. Hmm...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6265039086215303226-7668179289932864094?l=fmota91.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/7668179289932864094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6265039086215303226/posts/default/7668179289932864094'/><link rel='alternate' type='text/html' href='http://fmota91.blogspot.com/2007/09/introducing-sectorforth.html' title='Introducing... sectorForth!'/><author><name>FMota</name><uri>http://www.blogger.com/profile/14394936561912046612</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>
