<?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>Luis Ziliani, a.k.a. Beta</title>
	<atom:link href="http://weblogs.manas.com.ar/lziliani/feed/" rel="self" type="application/rss+xml" />
	<link>http://weblogs.manas.com.ar/lziliani</link>
	<description>Blog of Luis Ziliani, a.k.a. Beta</description>
	<lastBuildDate>Mon, 22 Mar 2010 14:29:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>The long and winding road... to a master thesis</title>
		<link>http://weblogs.manas.com.ar/lziliani/2009/11/13/the-long-and-winding-road/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2009/11/13/the-long-and-winding-road/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 14:46:50 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>
		<category><![CDATA[Master Thesis]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=22</guid>
		<description><![CDATA[From the very start of my thesis, the key idea was to find a lambda calculus with explicit substitutions, indexes, and all the good properties (I refer the reader to all previous posts). In particular, having in mind a recent work from Delia Kesner: A Theory of Explicit Substitutions with Safe and Full Composition (well, [...]]]></description>
			<content:encoded><![CDATA[<p>From the very start of my thesis, the key idea was to find a <a href="http://weblogs.manas.com.ar/lziliani/2008/03/28/lambda-calculus/">lambda calculus</a> with <a href="http://weblogs.manas.com.ar/lziliani/2008/09/09/explicit-substitutions-or-substitutions-if-you-need-to-implement-them/">explicit substitutions</a>, <a href="http://weblogs.manas.com.ar/lziliani/2008/07/29/and-now-for-something-completely-different/">indexes</a>, and all the <a href="http://weblogs.manas.com.ar/lziliani/2008/11/13/different-properties-one-can-expect-from-any-%ce%bb-calculus/">good properties</a> (I refer the reader to all previous posts). In particular, having in mind a recent work from <a href="http://www.pps.jussieu.fr/~kesner/">Delia Kesner</a>: <a href="http://www.lmcs-online.org/ojs/viewarticle.php?id=480&amp;layout=abstract&amp;iid=19%22">A Theory of Explicit Substitutions with Safe and Full Composition</a> (well, to be honest, it was a previous one, but the ideas are the same). In this work, Kesner combines two concepts:<em>Composition of Substitutions</em> and  <em>Garbage Collection (GC)</em>. I will briefly explain these two concepts in the following sections, and conclude with some of the problem I have found trying to join these concepts with an indexed calculus.</p>
<p>But first, let's review what a substitution is: given two terms <em>t</em> and <em>u</em>, a variable <em>x</em>, the effect of substituting all the free occurrence of <em>x</em> in <em>t</em> by <em>u</em> is written as</p>
<p><em>t[x / u]</em></p>
<p>which, informally, is like a find and replace of <em>x</em> by <em>u</em>.</p>
<h3>Composition of Substitutions</h3>
<p>When having two substitutions, like in the term <em>t[x/u][y/w]</em>, some calculus, instead of make first the inner substitution and then the outer, they compose the substitutions by joining both compositions. This is necessary to achieve <strong>metaconfluence</strong>.  There are two ways for doing this:</p>
<ul>
<li>By using a list of substitutions: substitutions are a list <em>[x/u, y/w, ...]</em></li>
<li>By combining the substitutions: rules like <em>t[x/u][y/w] →t[y/w][x/u[y/w]]</em> (under certain conditions) are added to the calculus.</li>
</ul>
<p>Kesner uses the second way of composing substitutions. If no restriction is made to the rules used to compose substitutions, then it's easy to loose the property <strong>Preservation of Strong Normalization</strong>. That's when the concept of Garbage Collection came to save the day.</p>
<h3>Garbage Collection</h3>
<p>GC needs not to be confused with the usual programming concept of Garbage Collection (remember: in lambda calculus there's not such a thing as a "memory"). The idea behind this concept is simple: throw away those substitutions that have no use, i.e. do not perform any substitution, i.e. do not change the term. In particular, in the term <em>t[x/u]</em>, if <em>x</em> is not free (for instance, it does not appear) in <em>t</em>, then there is not going to be a replacement; therefore, <em>t</em> is going to remain unchanged. In that case, we said that the substitution <em>[x / u]</em> is garbage, and we throw it away.</p>
<p>When composing "garbage", one can lose the property of Preservation of Strong Normalization. By combining these two concepts, Kesner achieve a compact calculus with all the good properties. I have studied a way to perform GC in a calculus with indexes and substitutions as lists, called lambda sigma. This was particularly difficult for two reasons:</p>
<ul>
<li>When having a list of substitutions, all the variables in the list need to be checked.</li>
<li>When having indexes, the substitution is in charge of both <em>substituting</em> and <em>index updating</em>, so we need to be careful to whose substitutions we consider garbage.</li>
</ul>
<p>After obtaining the definition of garbage for lambda sigma, the next step was to define a calculus that does garbage collection, and proof all the <a href="http://weblogs.manas.com.ar/lziliani/2008/11/13/different-properties-one-can-expect-from-any-%ce%bb-calculus/">basic properties</a> for it (strong normalization of the substitution calculus, confluence, simulation). Working with an indexed calculus requires a lot of calculations, and that's how I spent a few months writing the demonstrations for all of the proofs.</p>
<p>The last part of the work was dedicated to think about the other properties: Confluence on Open Terms and Preservation of Strong Normalization. The first one was easily proved to not hold, but there might exist an extension to the calculus that do, but under certain conditions. For Preservation of Strong Normalization, I have proved that this calculus is "better" than the original lambda sigma, but it's an open question whether or not it has this property. As a matter of fact, until the last moment of the presentation of the thesis, I think I have a counterexample, but it turn out that the proof was ill-formed. That's why it's open, and if you ask me, I think it's very difficult to say if this property holds. Certainly, the proof (positive or negative) has to be very difficult.</p>
<p>Well, that's it. Now, with the invaluable help of <a href="http://www.manas.com.ar/">Manas</a>, I'm graduated, and expecting to work in my PhD at the <a href="http://www.mpi-sws.org">Max Planck Institute for Software System (MPI-SWS)</a> at Saarbruecken, Germany on January 2010.</p>
<p>This whole experience has been great, and I haven't enough word to thank all of the people here at Manas.</p>
<p>You can check-out a presentation I've perform at the MPI-SWS: <a href="http://weblogs.manas.com.ar/lziliani/files/2009/11/presentation.pdf">Download</a>.<br />
Also, you might like to see my <a href="http://weblogs.manas.com.ar/lziliani/files/2009/11/main.pdf">master thesis</a> (it's in Spanish).<br />
For any of this stuff you can ask for the <a href="http://www.latex-project.org/">Latex</a> source. Just write me at beta the-symbol-for-at ziliani dot com dot ar.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2009/11/13/the-long-and-winding-road/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a thesis</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/11/13/making-a-thesis/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/11/13/making-a-thesis/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 16:40:36 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Master Thesis]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=17</guid>
		<description><![CDATA[In all previous posts I've tried to teach the different aspects inside my thesis. But after going deeper and deeper, the concepts tend to complicate too much, and much more dedication from the reader is needed. After trying to add another technical post, full of strange symbols, I quit the idea. And then someone point [...]]]></description>
			<content:encoded><![CDATA[<p>In all previous posts I've tried to teach the different aspects inside my thesis. But after going deeper and deeper, the concepts tend to complicate too much, and much more dedication from the reader is needed. After trying to add another technical post, full of strange symbols, I quit the idea. And then someone point me out that it would be best if I just talk about what kind of problems I dealt by making my thesis. That's what I will do from now on.</p>
<p>First, I will give a brief look at the story.</p>
<p>It's the first semester of 2007, I choose three different subjects: Topics of Rewritings, Theory of Models, and Introduction to the Processing of Digital Images. Those of you who know informatics will notice that the choice is quite weird: two of the subjects are purely theoretical, and the last one is purely practical. That was my idea, see which fields of the informatics fit me best. You already know the answer.</p>
<p>The winter holidays of 2007 ended in this southern part of the world. As I was in the last part of the career, I decided to continue my studies in rewritings, so I chose to get into the course "Rewritings, Lambda Calculus, and Explicit Substitutions". At the same moment, I talked to Alejandro Ríos to be his master's student. He accepted. But I needed to end the courses and pass the exams, so I really begun the work at the beginning of 2008.</p>
<p>Then, something very uncommon happened. Since 2004 I worked in <a title="Manas" href="http://www.manas.com.ar" target="_blank">Manas</a>. But I decided that in 2008 I would put all my effort in finishing my career. The idea was to get a grant from the university, and with a few savings and my salary as teaching assistant at the university, try to survive without another job. When I was about to quit my job at Manas, my boss told me "What if we sponsor your thesis?". So that's how I end up doing my thesis in Manas.</p>
<p>In the next post I will talk what I've tried to do since I started.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/11/13/making-a-thesis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Different properties one can expect from any λ-calculus</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/11/13/different-properties-one-can-expect-from-any-%ce%bb-calculus/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/11/13/different-properties-one-can-expect-from-any-%ce%bb-calculus/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 16:38:41 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=14</guid>
		<description><![CDATA[In this post I will show two different sets of properties that any variation of λ-calculus with explicit substitutions may or must have. The must: 1) Any substitution must end, i. e. the process of change a variable by a term must always end, no matter how you do it. Put it in another way, [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will show two different sets of properties that any variation of λ-calculus with explicit substitutions may or must have.</p>
<h3>The must:</h3>
<p>1) Any substitution must end, i. e. the process of change a variable by a term must always end, no matter how you do it. Put it in another way, the calculus without the β rule must have Strong Normalization (basically, you always end up with a solution).</p>
<p>2) The calculus must be confluent. No matter which rules you apply, or in which order, you always find the same result.</p>
<p>3) Simulation of the traditional λ-calculus: There must be nothing you can do with the original λ-calculus that you can't do with the new calculus.</p>
<h3>The nice to have:</h3>
<p>1) Confluence on open terms. Basically, the idea is to see if confluence still holds if you extends your calculus with meta-variables. Meta-variables acts like holes in your formula, something you can't control. For instance, in the λx calculus shown in the previous post, this property doesn't hold. There is no way to close (converge) this divergent steps:</p>
<p>1. ((λx.t) u)[y/v] → t[x/u][y/v]</p>
<p>2. ((λx.t) u)[y/v] → (λx.t)[y/v] u[y/v] → (λx.t[y/v]) u[y/v]  → t[y/v][x/u[y/v]</p>
<p>If you asume that <em>t</em> is a classic term from the calculus, then you can find the same solution. But if it's just a hole, there's nothing you can do.</p>
<p>2) Preservation of Strong Normalization. This means that any term that always end up in a solution in the classical λ-calculus, then it will always end up in a solution in the new calculus.</p>
<p>These properties are needed, for instance, in proof assistants or HO unificators. If you don't know what I'm talking about, nevermind. The idea was just to show why the interest in these properties.</p>
<p>So, is there a calculus with explicit substitution that has all these properties? Yes, but at a price. Other wanted (but maybe less common) properties got broken.</p>
<p>I will talk about these properties in posts to come. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/11/13/different-properties-one-can-expect-from-any-%ce%bb-calculus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Explicit Substitutions, or Substitutions If You Need to Implement Them</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/09/09/explicit-substitutions-or-substitutions-if-you-need-to-implement-them/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/09/09/explicit-substitutions-or-substitutions-if-you-need-to-implement-them/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 17:02:55 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=13</guid>
		<description><![CDATA[As I told you before, performance is something desirable when programming a λ interpreter. The sustitutions we saw are made in one step. I will note the beta step as →β and a substitution step as →. For instance, (λx.x) z  →β  x[x/z]  →  z. The computations of the traditional lambda calculus are always: T [...]]]></description>
			<content:encoded><![CDATA[<p>As I told you before, performance is something desirable when programming a λ interpreter. The sustitutions we saw are made in one step.</p>
<p>I will note the beta step as →β and a substitution step as →. For instance,</p>
<p>(λx.x) z  →β  x[x/z]  →  z.</p>
<p>The computations of the traditional lambda calculus are always:</p>
<p>T →β T' → → → → until no more substitutions can be made →β T'' → → →...</p>
<p>Now, if we want to control the substitutions, one can make some computations like</p>
<p>T →β T' few steps of sustitutions →β T'' →β T''...</p>
<p>To make it clear, supose the term</p>
<p>(λx. y) ((λx. x x) z)</p>
<p>One posible reduction in the traditional λ calculus is</p>
<p>(λx. y) ((λx. x x) z)  →β  (λx. y) (x x)[x/z]  →  (λx. y) (x[x/z] x[x/z])  →  (λx. y) (z x[x/z])  →  (λx. y) (z z)  →  y[x/(z z)]  →  y</p>
<p>But a more clever path is posible, if we don't make all the substitutions:</p>
<p>(λx. y) ((λx. x x) z)  →β  (λx. y) (x x)[x/z]  →  y[x/(x x)[x/z]]  →  y</p>
<p>So a calculus with explicit substitution is a calculus that has the substitutions as another rewriting rules. For instance, λx is the simpler calculus:</p>
<table border="0">
<tbody>
<tr>
<td>(λx. M) N</td>
<td>→β</td>
<td>M[x/N]</td>
</tr>
<tr>
<td>x[x/R]</td>
<td>→</td>
<td>R</td>
</tr>
<tr>
<td>y[x/R]</td>
<td>→</td>
<td>y</td>
</tr>
<tr>
<td>(T T’)[x/R]</td>
<td>→</td>
<td>T[x/R] T’[x/R]</td>
</tr>
<tr>
<td>(λy.T)[x/R]</td>
<td>→</td>
<td>(λy.T[x/R])</td>
</tr>
</tbody>
</table>
<p>That's the idea behind explicit substitutions. It's very simple and yet has many issues I will show in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/09/09/explicit-substitutions-or-substitutions-if-you-need-to-implement-them/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>And now for something completely different</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/07/29/and-now-for-something-completely-different/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/07/29/and-now-for-something-completely-different/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 15:50:44 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=9</guid>
		<description><![CDATA[With this cite of Monthy Python, I will move into another family of calculi. What's wrong with our good ol' λ-calculus? Nearly nothing, except if you want to implement it in a real PC. In one of the firsts posts I've mentioned the α-congruence. The idea is that terms that only differs in the name [...]]]></description>
			<content:encoded><![CDATA[<p>With this cite of <a href="http://en.wikipedia.org/wiki/Monthy_python">Monthy Python</a>, I will move into another family of calculi. What's wrong with our good ol' λ-calculus? Nearly nothing, except if you want to implement it in a real PC.</p>
<p>In one of the firsts posts I've mentioned the α-congruence. The idea is that terms that only differs in the name of the variables are "the same". For instance, take</p>
<p>T1 = (λx. x)<br />
T2 = (λy. y)</p>
<p>We said T1 ≡ T2 to say that T1 and T2 are in the same class of equivalence modulo α. In other word, they are the same.</p>
<p>Suppose that we want to store a set of terms with its results. Something like a dictionary of terms used as a cache. Suppose that in that dictionary we have</p>
<p>key: (λx. x) (λx. x), value: (λx. x)</p>
<p>That is, given the identity term applied to himself, the result will be the identity term.</p>
<p>Suppose now that we are computing the result of the term</p>
<p>T = (λy. y) (λy. y) z</p>
<p>It will be a good idea to use the information in the cache, in order to make less computations. But the term in the cache differs from the term T in that the variables aren't the same. So we need to rename them in order to compare them.</p>
<p>A guy named Nicolaas Govert de Bruijn invented a way to avoid this renaming of variables. The idea is quite simple, but yet hard to grasp. Instead of naming the variables, enumerate them by the depth of that variable in the term (respect to the λ operator that bind it). So, for instance, the identity term will be</p>
<p>(λ1)</p>
<p>That is, the 1 refers to the the first λ, looking from the 1 point of view. Another example: (λx.λy. x) will be</p>
<p>(λ(λ2))</p>
<p>Another example: (λx.λy. x y) z will be</p>
<p>(λ(λ2 1)) 1</p>
<p>Note that the free variable z is called 1 in this calculus. Why? Because it can be bounded to an invisible outer λ:</p>
<p>(λ<span style="color: #c0c0c0;">z</span>.(λx.λy. x y) <span style="color: #c0c0c0;">z</span>)</p>
<p>Exercise: In the following term, which <em>index</em> (that's the new name for variables) corresponds to which lambda? I will omit some parenthesis.</p>
<p>(λλλ1 2 3 5)</p>
<p>Answer (don't look before thinking!):</p>
<p>(<span style="color: #000080;">λ</span><span style="color: #ffcc00;">λ</span><span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #000080;">3</span> <span style="color: #999999;">5</span>)</p>
<p>Another exercise:</p>
<p>λλ(1 2 3) 1</p>
<p>Answer:</p>
<p><span style="color: #ffcc00;"><span style="color: #000000;">(</span>λ</span><span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>) <span style="color: #999999;">1</span></p>
<p>Note that the gray numbers refers to the same variable in a lambda not shown (i.e. a free variable).</p>
<p>Formalizing, the terms in λDB (that's the name of λ-de Bruijn) are:</p>
<p>T ::= n | λT | T T'</p>
<p>where <em>n</em> is a natural number.</p>
<p>We now how to write λDB terms. Now we need to make them calculate something. Let's start by the β-reduction:</p>
<p>(λa) b → a{1 ← b}</p>
<p>That's "if I have a function, with the body <em>a</em>, and I execute it with the parameter <em>b</em>, I have to replace every occurrence of <em>1</em> in <em>a</em> by <em>b</em>". Why 1? Because that's our variable for the λ we are taking off.</p>
<p>Let's try to define <em>a{1 ← b}</em> by a colored example.</p>
<p>(<span style="color: #ffcc00;">λ</span><span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>) <span style="color: #999999;">1 <span style="color: #333399;">2 </span></span>→ (<span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){1 ← <span style="color: #999999;">1<span style="color: #000000;">}</span> <span style="color: #333399;">2</span></span></p>
<p>Suppose that we said:</p>
<p>(λa){1 ← b} = (λa{1 ← b})</p>
<p>we are making a big mistake: (<span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){1 ← <span style="color: #999999;">1<span style="color: #000000;">}</span> <span style="color: #000000;">=</span> </span><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){1 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span></p>
<p>Now we are changing the red 1, instead of the yellow 2! In order to avoid that, we have to increment the variable we want to replace each time we cross a λ:</p>
<p>(λa){i ← b} = (λa{i+1 ← b})</p>
<p>Let's continue with our example:</p>
<p>(<span style="color: #ff0000;">λ</span><span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){1 ← <span style="color: #999999;">1<span style="color: #000000;">}</span> <span style="color: #333399;">2 </span></span>= <span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span> <span style="color: #333399;">2</span></span></p>
<p>Now we have to distribute the replace function:</p>
<p><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #ffcc00;">2</span> <span style="color: #999999;">3</span>){2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span> <span style="color: #333399;">2 </span></span>= <span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #ffcc00;">2</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #999999;">3</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span>)<span style="color: #999999;"> <span style="color: #333399;">2</span></span></p>
<p>which gives us another rule:</p>
<p>(a b){i ← c} = a{i ← c} b{i ← c}</p>
<p>Now we reach the variables, so we have to make the replacement. Suppose that we just put the 1 when we found a 2:</p>
<p><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #ffcc00;">2</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #999999;">3</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span>)<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;"> = </span></span></span><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #999999;">1</span> <span style="color: #999999;">3</span>)<span style="color: #999999;"> <span style="color: #333399;">2</span></span></p>
<p>Something does not looks right. Take a look at the grey numbers. We know that both refers to the same variable. But why they are different? The two of them must to be changed in order to points to the first free variable. First, let's take a look at the 1. Remember that we have to cross a lambda, so now the free variable to what it refers is one lambda away. So instead of just put the term we are replacing, we have to update it to increase the variables for all the lambda we crossed. For that, I will introduce a new operator, called "U" (Update). Having fixed the 1, let's fix the 3. The three right now points to the second free variable, because it has lost one lambda. So, we have to subtract one in each free variable. So, the rules for replacing a variable are:</p>
<p>i{i ←b} = U(0, i, b)</p>
<p>i{j ←b} = i-1   if j &gt; i</p>
<p>i{j ←b} = i   if j &lt; i</p>
<p>In our example:</p>
<p><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #ffcc00;">2</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span> <span style="color: #999999;">3</span>{2 ← <span style="color: #999999;">1<span style="color: #000000;">}</span></span>)<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;"> = </span></span></span><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> U(0,2,<span style="color: #999999;">1<span style="color: #000000;">)</span></span> <span style="color: #999999;">2</span>)<span style="color: #999999;"> <span style="color: #333399;">2</span></span></p>
<p>The U operator is simple. The first parameters count the lambda it crosses, in order to take into account the bounded variables (i.e. the variables that don't need updating).</p>
<p>U(i, j, (a b)) = U(i, j, a) U(i, j, b)<br />
U(i, j, (λa)) = λU(i+1, j, a)<br />
U(i, j, n) = n + j - 1   if n &gt; i<br />
U(i, j, n) = n   if n &lt;= i</p>
<p>Continuing with our example:</p>
<p><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> U(0,2,<span style="color: #999999;">1<span style="color: #000000;">)</span></span> <span style="color: #999999;">2</span>)<span style="color: #999999;"> <span style="color: #333399;">2 <span style="color: #000000;">=</span> </span></span><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #999999;">2</span> <span style="color: #999999;">2</span>)<span style="color: #999999;"> <span style="color: #333399;">2</span></span></p>
<p>Now we can execute the beta reduction:</p>
<p><span style="color: #ff0000;">λ</span>(<span style="color: #ff0000;">1</span> <span style="color: #999999;">2</span> <span style="color: #999999;">2</span>)<span style="color: #999999;"> <span style="color: #333399;">2 </span></span>→ (<span style="color: #ff0000;">1</span> <span style="color: #999999;">2</span> <span style="color: #999999;">2</span>)<span style="color: #999999;"><span style="color: #000000;">{1 </span></span>←<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;">} = </span></span></span><span style="color: #ff0000;">1</span><span style="color: #999999;"><span style="color: #000000;">{1 </span></span>←<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;">}</span></span></span> <span style="color: #999999;">2</span><span style="color: #999999;"><span style="color: #000000;">{1 </span></span>←<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;">}</span></span></span> <span style="color: #999999;">2</span><span style="color: #999999;"><span style="color: #000000;">{1 </span></span>←<span style="color: #999999;"> <span style="color: #333399;">2<span style="color: #000000;">}</span></span></span> = U(0, 1, <span style="color: #999999;"><span style="color: #333399;">2<span style="color: #000000;">) <span style="color: #808080;">1 1</span> </span></span></span>= <span style="color: #999999;"><span style="color: #333399;">2<span style="color: #000000;"> <span style="color: #808080;">1 1</span></span></span></span></p>
<p>Note that the expression U(0, 1, x) = x for all term x.</p>
<p>Something I'm not going to show is that there is a <em>bijection</em> between the lambda calculus classic and this calculus. By bijection I mean that they computes the same things in the same way. If we define a translation between terms T (suppose that if <em>t</em> is a lambda term, then T(t) is a lambda DB term, an viceversa).</p>
<p>So, given a term <em>t</em> either in lambda or lambda DB,</p>
<p>t → ... → t'</p>
<p>implies</p>
<p>T(t) → ... → T(t')</p>
<p>Well, that's it for lambda DB. Until next post!</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/07/29/and-now-for-something-completely-different/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create &quot;recursive&quot; functions in &#955;-calculus</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/06/13/how-to-create-recursive-functions-in-calculus/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/06/13/how-to-create-recursive-functions-in-calculus/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 15:46:40 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=8</guid>
		<description><![CDATA[As you probably already now, recursive function are those that call them self. For instance, you can define the factorial function as: fact(0) = 1 fact(n) = n*fact(n-1) This doesn't look like something you can say with the small syntaxis of the λ-calculus. That is right, but I will prove that you can say something [...]]]></description>
			<content:encoded><![CDATA[<p>As you probably already now, recursive function are those that call them self. For instance, you can define the factorial function as:</p>
<p>fact(0) = 1<br />
fact(n) = n*fact(n-1)</p>
<p>This doesn't look like something you can say with the small syntaxis of the λ-calculus. That is right, but I will prove that you can say something a bit different -but with the same meaning. By doing so, I will prove that it's possible to create recursive functions in this calculus.</p>
<p>Let's try to transform the factorial function into λ-calculus sintax.<br />
First of all, we have to get rid of the different cases. That's easy:</p>
<p>fact(n) = if (n = 0) then 1 else n*fact(n-1)</p>
<p>I invite the reader to read the post "Arithmetics with λ-calculus". Because in λ-calculus there is no <strong>if</strong>, nor booleans, we have to create them. I will use the same technique for the numbers:</p>
<p>true = (λx y. x)<br />
false = (λx y. y)</p>
<p>if = (λx.x)</p>
<p><strong>true</strong> is the function that given two parameters, returns the first one. <strong>false</strong> is similar to <strong>true</strong>, but it returns the second parameter. That sounds much like the <strong>if</strong> and <strong>else</strong> part of the <strong>if</strong> structure, respectively. That's why <strong>if</strong> is just the identity function. So<br />
if condition s t → condition s t<br />
<em>and if </em>condition → ... → true<br />
<em>then</em> true s t → s</p>
<pre>(and the oposite for false)</pre>
<p>Just for fun, let's make some examples:<br />
and = (λx y. if x y false)<br />
or = (λx y. if x true y)<br />
not = (λx y z. if x z y)</p>
<p>Why does <strong>not</strong> receive more parameters than <strong>and</strong>??? Because for <strong>and</strong> we need just to return the correct boolean, and the boolean will make the "if" thing. But for the <strong>not</strong>, we've to change the order of the parameters in the "if".</p>
<p>So know we've got the booleans. Now, let's define a useful function for our factorial:</p>
<p>iszero = (λx. x alwaysfalse true)<br />
alwaysfalse = (λx.false)</p>
<p>Remember that a number <em>n</em> is the n-ary application of a function in a parameter. In this case, if the number <em>x</em> is greater than 0, then it will apply <em>x</em> times the function that always returns false. So</p>
<p>iszero 1 → ... → false</p>
<p><em>and</em></p>
<p>iszero 0 → ... → true</p>
<p>So we have almost everything for our factorial function. We have the functions <em>mult, iszero, pred, if</em>.</p>
<p>fact = (λn. if (iszero n) 1 (mult n (fact (pred n))))</p>
<p>Now, as I said before, when we use the name <em>iszero</em>, we are meaning the function written above, with all the parenthesis, λ's, etc. So, we still have something to change in our <em>fact</em> expression. Supose that we change the <em>fact</em> label in the body of the <em>fact</em> definition... it will be changed by another expression with a <em>fact</em> inside it, so we change it again... And we continue until we hang ourselves, or until we got killed by bore.</p>
<p>As the bride says: "how do we solve this dilema". And, as Bill answers "Well, It just happens I've got the solution!".</p>
<p>If we find a function (let's call it Fix) like this:</p>
<p>Fix f → ... → f (Fix f)</p>
<p>then we are done. Let's change the <em>fact</em> function so it also take a function as a parameter:</p>
<p>fact = (λf n. if (iszero n) 1 (mult n (f (pred n))))</p>
<p>So, (for simplicity, I will write <em>fact</em> instead of the term above)</p>
<p>Fix fact 3 → ... → fact (Fix fact) 3 = (λf n. if (iszero n) 1 (mult n (f (pred n)))) (Fix fact) 3</p>
<p>putting the (Fix fact) parameter inside the term:</p>
<p>→ (λn. if (iszero n) 1 (mult n ((Fix fact) (pred n)))) 3</p>
<p>putting the 3 parameter inside the term:</p>
<p>→ if (iszero 3) 1 (mult 3 ((Fix fact) (pred 3))))</p>
<p><em>iszero 3</em> is false, and pred 3 is 2, so</p>
<p>→ mult 3 ((Fix fact) 2))</p>
<p>And, again <em>Fix fact</em> is <em>fact (Fix fact)</em></p>
<p>→ mult 3 (fact (Fix fact) 2))</p>
<p>We now how the story ends: →...→  mult 3 (mult 2 (mult 1 1))) → ... → 8</p>
<p>No, just checking if you're still with me. The number is, of course, 6.<br />
Again, if you don't understand anything, try writting it down in a paper, and follow the ideas.</p>
<p>You can see the Fix function as something that feeds the original function (fact) with the next step to execute. Fix exists:</p>
<p>Fix = (λf. (λx. f (x x)) (λx. f (x x)))</p>
<p>Fix g = (λf. (λx. f (x x)) (λx. f (x x))) g → (λx. g (x x)) (λx. g (x x))</p>
<p>→ g ((λx. g (x x)) (λx. g (x x))))</p>
<p>and that exactly:</p>
<p>g (Fix g)</p>
<p>That's it for pure λ-calculus. The next step is to see different calculus that will address implementation problems that arises when trying to make a λ interpreter. 'Till next post!</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/06/13/how-to-create-recursive-functions-in-calculus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little summary of what we&#039;ve learned</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/05/16/a-little-summary-of-what-weve-learned/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/05/16/a-little-summary-of-what-weve-learned/#comments</comments>
		<pubDate>Fri, 16 May 2008 15:23:02 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=7</guid>
		<description><![CDATA[This new post is intended to summarize all what is written in this page. First of all, an errata from the previous post: I encourage the reader to define other functions, like the predecesor of a number... Well, I can't remember if I planned to be that evil, or if I was just too drunk [...]]]></description>
			<content:encoded><![CDATA[<p>This new post is intended to summarize all what is written in this page.</p>
<p>First of all, an errata from the previous post: I encourage the reader to define other functions, like the predecesor of a number... Well, I can't remember if I planned to be that evil, or if I was just too drunk or what, but the fact is that that was an open question for many years. So if you made it (without cheating), you can say out-loud "I'm a Master in lambda calculus!!!". But nobody will care, to be honest.</p>
<h4>The λ-calculus formalism</h4>
<p>I've learned how to write lambda in the posts! I will present the λ-calculus in a more formal way.  Let <strong>V</strong> be a (countable) set of variables. The terms <strong>T </strong>in the calculus are defined in a semantic way as:</p>
<p>T :== x | (T T') | (λx.T)</p>
<p>(A term is a variable, or an application, or an abstraction. Recall to the 3rd post.)</p>
<p>The β-reduction is the rule</p>
<p>(λx.T) R → T[x/R]</p>
<p>where the substitution T[x/R] is defined as:</p>
<ol>
<li>x[x/R] = R</li>
<li>y[x/R] = y</li>
<li>(T T')[x/R] = T[x/R] T'[x/R]</li>
<li>(λy.T)[x/R] = (λy.T[x/R])</li>
</ol>
<p>The idea is quite simple: we iterate through the terms until we find a variable. If the variable is what we are looking for, then we replace the variable for the new term we want in that place. This works the same as the find/replace function of any text processor. A little tricky thing is that we are assuming that the variable names are different in each abstraction. This is like what we've done in the previous post by coloring the variables in order to distinguish them. If not additional rules are needed, and a condition is required in rule 4 (do not pay too much attention to this):</p>
<p>4. (λy.T)[x/R] = (λy.T[x/R]) if <em>y</em> does not appear in R<br />
5. (λx.T)[x/R] = (λx.T)<br />
6. (λy.T)[x/R] = (λz.T[y/z][x/R]) if <em>y</em> does appears in R and <em>z</em> does not appear in any of the terms.</p>
<p>Rule 6 makes a name change to avoid a <em>variable capture</em> (we don't want the<em> y</em> variable in R to be "captured" by the new λ).</p>
<h4>Examples</h4>
<p>I was being criticized for the lack of examples. So here are a few. Maybe I add some others later. Again, I highly recommend to follow them in paper.</p>
<p>1) A function  (let's call it 'K') that given two parameters, returns the first one:</p>
<p>K = (λx.(λy.x))</p>
<p>K u v =  (λx.(λy.x)) u v → (λy.x)[x/u] v = (λy.x[x/u]) v = (λy.u) v → u[y/v] = u</p>
<p><strong>Note:</strong> I've to explain the different use of '=', and the difference with '→' in this example. The first '=' in the definition of K, is a way of saying "whenever I say 'K', I'm meaning the term <em>(λx.(λy.x))</em>)". So in 'K u v = ...' I'm just using the definition of K. Then we have the → for the β-reduction. Then we have '=' for the substitution. Why '='? Because it is an operation that have to take the first term to the subtituted term "in one step". I mean, I can write <em>(λy.x)[x/u] = (λy.u)</em>. It is an atomic operation.</p>
<p>2) A function (let's call it 'S') that given three parameters, distributes the third parameters into the other two. That is, "<em>f(x,y,z) = x(z) y(z)</em>"</p>
<p>S = (λx.(λy.(λz. (x z) (y z))))</p>
<p>S u v w = (λx.(λy.(λz. (x z) (y z)))) u v w → (λy.(λz. (x z) (y z)))[x/u] v w = ... = (λy.(λz. (u z) (y z))) v w → (λz. (u z) (y z))[y/v] w = ... = (λz. (u z) (v z)) w → ((u z) (v z))[z/w] = ... = (u w) (v w)</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/05/16/a-little-summary-of-what-weve-learned/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arithmetic with Lambda Calculus</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/05/02/arithmetic-with-lambda-calculus/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/05/02/arithmetic-with-lambda-calculus/#comments</comments>
		<pubDate>Fri, 02 May 2008 15:58:05 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=5</guid>
		<description><![CDATA[One simple way to make arithmetic expressions in lambda calculus, is just to extend the calculus with the arithmetic rules: (λx.(λy. x+y)) 2 3 → (λy. 2+y) 3 → 2+3 = 5 But that's pretty easy for us, and (as you problably have already noticed) we like to complicate what's easy. So let's try to [...]]]></description>
			<content:encoded><![CDATA[<p>One simple way to make arithmetic expressions in lambda calculus, is just to extend the calculus with the arithmetic rules:</p>
<p>(λx.(λy. x+y)) 2 3 → (λy. 2+y) 3 → 2+3 = 5</p>
<p>But that's pretty easy for us, and (as you problably have already noticed) we like to complicate what's easy. So let's try to make the sum with the base lambda calculus. Why? Because it's fun!</p>
<p>First of all, a bit of notation: let's say that we can write the expression (λx.(λy. T)) (i.e. the function that takes a parameter and returns the function that takes another parameter and returns the generalized term T) as λx y. T</p>
<p>Secondly, I highly recomend you to follow the examples in paper, trying to see why one step lead to another.</p>
<p>In the beginning there was a Beta reduction... But He (Alonso Church) says "Let there be the numerals", and the numerals appears:</p>
<p>0: (λf x.x)</p>
<p>1:  (λf x. f x)</p>
<p>2: (λf x. f (f x))</p>
<p>...</p>
<p>N: (λf x.f (... f (f x))</p>
<p>This is just a way of doing this. You can say "for me, the 0 is (λx.x), the 1 is (λx y. y), ...". Or "for me, all this stuff is pure crap. Got a life, you punk!". I choose this way for one simple reason: it is in the wikipedia, and it looks good and easy to use.</p>
<p>So the numerals are functions. Why? What's the meaning of that? Let's try to answer. The 1 is saying "given two parameters, we apply the first one to the second one". And the N says: "given two parameters, we apply N times the first one to the second one". So it's looks like a <em>for </em>loop expression in a normal programming language. In order to answer to the first question, let's show how to sum:</p>
<p>SUM: (λn1 n2 f x. n1 f (n2 f x))</p>
<p><strong>Note</strong>: because all the numerals takes two parameters, it is expected that the Sum function returns some numeral that also takes two numbers. That's why we receive the two numerals (n1 and n2) <strong>and</strong> the two parameters every numeral needs (f and x). Let's make a simple sum:</p>
<p>SUM 2 1: (λn1 n2 f x. n1 f (n2 f x)) (λf x. f (f x)) (λf x. f x) → we replace n1 by the first numeral:  (λn2 f x. (λf x. f (f x)) f (n2 f x)) (λf x. f x) → we replace n2 by the second numeral → (λf x. (λf x. f (f x)) f ((λf x. f x) f x))</p>
<p>This is a mess of f and x, so let's try to make a difference between them. I will put gay colors in it.</p>
<p>(λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">f x</span>. <span style="color: #00ff00;">f</span> (<span style="color: #00ff00;">f x</span>)) <span style="color: #ff00ff;">f</span> ((λ<span style="color: #ff9900;">f x</span>. <span style="color: #ff9900;">f x</span>)<span style="color: #ff00ff;"> f x</span>))</p>
<p>We can reduce the orange numeral with the fucsia variables:</p>
<p>(λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">f x</span>. <span style="color: #00ff00;">f</span> (<span style="color: #00ff00;">f x</span>)) <span style="color: #ff00ff;">f</span> ((λ<span style="color: #ff9900;">f x</span>. <span style="color: #ff9900;">f x</span>)<span style="color: #ff00ff;"> f x</span>)) → (λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">f x</span>. <span style="color: #00ff00;">f</span> (<span style="color: #00ff00;">f x</span>)) <span style="color: #ff00ff;">f </span>((λ<span style="color: #ff9900;">x</span>. <span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> x</span>)<span style="color: #ff00ff;"> x</span>)) → (λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">f x</span>. <span style="color: #00ff00;">f</span> (<span style="color: #00ff00;">f x</span>)) <span style="color: #ff00ff;">f</span> (<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span><span style="color: #ff00ff;">x</span>))</p>
<p>Now we can reduce the green numeral with the fucsia f (we have to change <span style="color: #00ff00;">f</span> by <span style="color: #ff00ff;">f</span>), and then we can replace the green x by the fucsia (f x) expression:</p>
<p>(λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">f x</span>. <span style="color: #00ff00;">f</span> (<span style="color: #00ff00;">f x</span>)) <span style="color: #ff00ff;">f</span> (<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span><span style="color: #ff00ff;">x</span>)) → (λ<span style="color: #ff00ff;">f x</span>. (λ<span style="color: #00ff00;">x</span>. <span style="color: #ff00ff;">f </span>(<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span><span style="color: #00ff00;">x</span>)) (<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span><span style="color: #ff00ff;">x</span>)) → (λ<span style="color: #ff00ff;">f x</span>. <span style="color: #ff00ff;">f </span>(<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span>(<span style="color: #ff00ff;">f</span><span style="color: #ff9900;"> </span><span style="color: #ff00ff;">x</span>)))</p>
<p>And now everything is girly fucsia! And what does this expression means? The numeral 3 of course!</p>
<p>If you want to play more with this arithmetic way of computations, you can try to define the other functions (multipication, predecesor, etc). Or you can take a look at</p>
<p><a href="http://en.wikipedia.org/wiki/Lambda_calculus">http://en.wikipedia.org/wiki/Lambda_calculus</a></p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/05/02/arithmetic-with-lambda-calculus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lambda Calculus</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/03/28/lambda-calculus/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/03/28/lambda-calculus/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 17:03:55 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=4</guid>
		<description><![CDATA[From the Wikipedia: "calculus can refer to any method or system of calculation", and that's not an exception for the Lambda Calculus. First of all, lets define the terms of this calculus: A Lambda Term is something with the form x where x is in V a set of variables. (u v) where u and [...]]]></description>
			<content:encoded><![CDATA[<p>From the Wikipedia: "<em>calculus</em> can refer to any method or system of calculation", and that's not an exception for the Lambda Calculus. First of all, lets define the terms of this calculus:</p>
<p>A Lambda Term is something with the form</p>
<ul>
<li><strong>x</strong> where <em>x</em> is in <strong>V</strong> a set of variables.</li>
<li><strong>(u v)</strong> where <em>u</em> and <em>v</em> are terms. We use "<em>v</em> is applied to <em>u</em>" in this case.</li>
<li><strong>(λx.u)</strong> where x is in <strong>V</strong> and u is a term. We use "an abstraction of <em>x</em> in <em>u</em>" in this case.</li>
</ul>
<p>Here is one example: (λx.(λy.z) x)</p>
<p>But we cannot compute anything with just terms, so lets show the only rule use to transform these terms into a computation. This rule is quite famous (yeah, I know... famous in the Geeks Hall of Fame...), it is the "Beta reduction":</p>
<p>(λx.u) v → u[x/v]</p>
<p>In order to avoid critics, my nick "Beta" doesn't came from this rule, ok? I will not call my dog "Albert" nor stuff like that!</p>
<p>And now, let explain the meaning of <em>u[x/v]</em>. Given terms <strong>u, v</strong>, and a variable <strong>x</strong>, <em>u[x/v]</em> means "replace each <em>free occurrence</em> of <em>x</em> in <em>u</em> with <em>v</em>". By <em>free occurrence</em> of a variable <em>x </em>in a term <em>u </em>we mean "each time <em>x</em> does not appear inside a term of the form <em>(λx. ...)</em>".</p>
<p>It is not as hard as it looks. Some examples:</p>
<ul>
<li>x[x/y] = y</li>
<li>(x y)[z/(λf.f)] = (x y)</li>
<li>(x y)[x/(λf.f)] = ((λf.f) y)</li>
</ul>
<p>And now some complete examples of lambda terms with beta reductions:</p>
<ul>
<li>x does not reduces.</li>
<li>(λx.x) does not reduces also.</li>
<li>(λx.x) y reduce to x[x/y], which turns to be equal to y. As you can see, we are applying the term <em>y</em> to the function <em>(λx.x). </em>This function is called "identity", because computes the identity function f(x) = x.</li>
<li>(λx.x x) (λx.x x) reduces to (λx.x x)[x/(λx.x x)] = (λx.x x) (λx.x x) that reduces to (λx.x x)[x/(λx.x x)] = (λx.x x) (λx.x x) and so on...</li>
</ul>
<p>Another important concept is the <strong>alpha conversion</strong>. Alpha conversion means that we will treat all the terms that differs only in the name of the <em>bounded variables</em> (variables that are not <em>free</em>) as the same term. I.e. (λx.x) and (λy.y) will be the same term for us.</p>
<p>In the next post, I will show how to use this calculus to compute the arithmetics functions, so don't miss it!</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/03/28/lambda-calculus/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Basis of Term Rewriting Systems</title>
		<link>http://weblogs.manas.com.ar/lziliani/2008/03/15/basis-of-term-rewriting-systems/</link>
		<comments>http://weblogs.manas.com.ar/lziliani/2008/03/15/basis-of-term-rewriting-systems/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 18:46:39 +0000</pubDate>
		<dc:creator>lziliani</dc:creator>
				<category><![CDATA[Lambda Calculus]]></category>

		<guid isPermaLink="false">http://weblogs.manas.com.ar/lziliani/?p=3</guid>
		<description><![CDATA[A Term Rewriting System (TRS) is a very powerful yet simple math tool used, for instance, for the creation of computational models. Given a set of function symbols S, and an (uncountable) set of variables V, I will define rewriting rule by example. Suppose we have the "constant" function (function without parameters) 0 (representing a [...]]]></description>
			<content:encoded><![CDATA[<p>A <em>Term Rewriting System</em> (TRS) is a very powerful yet simple math tool used, for instance, for the creation of computational models. Given a set of function symbols <strong>S</strong>, and an (uncountable) set of variables <strong>V</strong>, I will define <em>rewriting rule</em> by example.</p>
<p>Suppose we have the "constant" function (function without parameters) <strong>0</strong> (representing a 0 in the natural numbers), the unary function <strong>S</strong> (as the successor of a number), and the binary function <strong>+</strong> (as the add operation). Let <strong>x</strong> and <strong>y</strong> be in <strong>V</strong>.<strong> </strong>These are rewriting rules to compute the add of two numbers:</p>
<p>0 + x → x<br />
S(x) + y → x + S(y)</p>
<p>The arrow can be seen as a "rewrite as" relation. For example, S(S(0)) + S(0) rewrites by the second rule to S(0) + S(S(0)), then to 0 + S(S(S(0))), to achieve the final computation with the first rule: S(S(S(0))). And this is exacty what we expected: 2+1 = 3.  Yeah, I know that it doesn't look like a very big science discovery, but we will soon see that with more complex rules we are going to be able to compute anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://weblogs.manas.com.ar/lziliani/2008/03/15/basis-of-term-rewriting-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

