Reading preferences
Optional display controls need JavaScript. All reading content and navigation work without it.
Source file content/lambda-calculus/syntax/syntax.tex
Source file content/lambda-calculus/syntax/terms.tex
Terms
The terms of the lambda calculus are built up inductively from an infinite supply of variables source, source, dots, the symbol “source”, and parentheses. We will use source, source, source, dots to designate variables, and source, source, source, dots to desginate terms.
Definition of lambda terms
[Terms] The set of terms of the lambda calculus is defined inductively by:
If a term source is formed according to the abstraction formation clause we say it is the result of an abstraction, and the source in source is called a parameter. A term source formed according to the application formation clause is the result of an application.
The terms defined above are fully parenthesized. This can get rather cumbersome, as the term source demnostrates. We will introduce conventions for avoiding parentheses. However, the official definition makes it easy to determine how a term is constructed according to the definition of lambda terms. For example, the last step of forming the term source must be abstraction where the parameter is source. It results by abstraction from the term source, which is an application of two terms. Each of these two terms is the result of an abstraction, and so on.
Exercise on formation of a nested lambda term
Describe the formation of source.
Source file content/lambda-calculus/syntax/unique-readability.tex
Unique Readability
We may wonder if for each term there is a unique way of forming it, and there is. For each lambda term there is only one way to construct and interpret it. In the following discussion, a formation is the procedure of constructing a term using the formation rules (one or several times) of the definition of lambda terms.
Lemma on the first symbol of a term
A term starts with either a variable or a parenthesis.
Proof
Something counts as a term only if it is constructed according to the definition of lambda terms. If it is the result of the variable formation clause, it must be a variable. If it is the result of the abstraction formation clause or the application formation clause, it starts with a parenthesis.
Lemma on the first symbols of an application
The result of an application starts with either two parentheses or a parenthesis and a variable.
Proof
If source is the result of an application, it is of the form source, so it begins with a parenthesis. Since source is a term, by the lemma on the first symbol of a term, it begins either with a parenthesis or a variable.
Lemma on proper initial parts
No proper initial part of a term is itself a term.
Exercise proving the initial part lemma
Prove the lemma that no proper initial part is a term by induction on the length of terms.
Unique readability proposition
[Unique Readability] There is a unique formation for each term. In other words, if a term source is formed by a formation, then it is the only formation that can form this term.
Proof
We prove this by induction on the formation of terms.
source is of the form source, where source is some variable. Since the results of abstractions and applications always start with parentheses, they cannot have been used to construct source; Thus, the formation of source must be a single step of the definition of lambda termsthe variable formation clause.
source is of the form source, where source is some variable and source is a term. It could not have been constructed according to the definition of lambda termsthe variable formation clause, because it is not a single variable. It is not the result of an application, by the lemma on the first symbols of an application. Thus source can only be the result of an abstraction on source. By inductive hypothesis we know that formation of source is itself unique.
source is of the form source, where source and source are terms. Since it starts with a parentheses, it cannot also be constructed by the definition of lambda termsthe variable formation clause. By the lemma on the first symbol of a term, source cannot begin with source, so source cannot be the result of an abstraction. Now suppose there were another way of constructing source by application, e.g., it is also of the form source. Then source is a proper initial segment of source (or vice versa), and this is impossible by the lemma that no proper initial part is a term. So source and source are uniquely determined, and by inductive hypothesis we know that formations of source and source is unique.
A more readable paraphrase of the above proposition is as follows:
Three uniquely determined forms of a term
A term source can only be one of the following forms:
Source file content/lambda-calculus/syntax/abbreviated-syntax.tex
Abbreviated Syntax
Terms as defined in the definition of lambda terms are sometimes cumbersome to write, so it is useful to introduce a more concise syntax. We must of course be careful to make sure that the terms in the concise notation also are uniquely readable. One widely used version called abbreviated terms is as follows.
When parentheses are left out, application takes place from left to right. For example, if source, source, source, and source are terms, then source abbreviates source.
Again, when parentheses are left out, lambda abstraction is given the widest scope possible. From example, source is read as source.
A lambda can be used to abstract multiple variables. For example, source is short for source.
For example,
abbreviates
Exercise expanding abbreviated syntax
Expand the abbreviated term source.
Source file content/lambda-calculus/syntax/free-variables.tex
Free Variables
Lambda calculus is about functions, and lambda abstraction is how functions arise. Intuitively, source is the function with values given by source when the argument to the function is assigned to source. But not every occurrence of source in source is relevant: if source contains another abstract source then the occurrences of source in source are relevant to source but not to source. So, a lambda abstract source inside source binds those occurrences of source in source that are not already bound by another lambda abstract---the free occurrences of source in source.
Definition of scope as printed
[Scope] If source occurs inside a term source, then the corresponding occurrence of source is the scope of the source.
Definition of free and bound occurrence
[Free and bound occurrence] An occurrence of variable source in a term source is free if it is not in the scope of a source, and bound otherwise. An occurrence of a variable source in source is bound by the initial source iff the occurrence of source in source is free.
Examples distinguishing nested binders
In source, both source and source are in the scope of source, so source is bound by source. Since source is not in the scope of any source, it is free. In source, both occurrences of source are bound by source, since both are free in source. In source, the last occurrence of source is free, since it is not in the scope of a source. In source, the scope of the first source is source and the scope of the second source is the second-to-last occurrence of source. In source, the last occurrence of source is free, and the second-to-last is bound. Thus, the second-to-last occurrence of source in source is bound by the second source, and the last occurrence by the first source.
For a term source, we can check all variable occurrences in it and get a set of free variables. This set is denoted by source with a natural definition as follows:
Recursive definition of free variables
[Free variables of a term] The set of free variables of a term is defined inductively by:
Exercises identifying scopes and free variables
Explain
A free variable is like a reference to the outside world (the environment), and a term containing free variables can be seen as a partially specified term, since its behaviour depends on how we set up the environment. For example, in the term source, which accepts an argument source and returns source of that argument, the variable source is free. This value of the term is dependent on the environment it is in, in particular the value of source in that environment.
If we apply abstraction to this term, we get source. This term is no longer dependent on the environment variable source, because it now designates a function that accepts two arguments and returns the result of applying the first to the second. Changing source in the environment won't have any effect on the behavior of this term, as the term will only use whatever is passed as an argument, and not the value of source in the environment.
Definition of closed term and combinator
[Closed term, combinator] A term with no free variables is called a closed term, or a combinator.
Free variable membership lemma
Proof
Exercise.
Exercise proving free variable membership
Source file content/lambda-calculus/syntax/substitution.tex
Substitution
Explain
Free variables are references to environment variables, thus it makes sense to actually use a specific value in the place of a free variable. For example, we may want to replace source in source with a specific term, like the identity function source. This results in source. The process of replacing free variables with lambda terms is called substitution.
Definition of partial substitution on terms
[Substitution] The substitution of a term source for a variable source in a term source, source, is defined inductively by:
Explain
In the definition of partial substitutionthe substitution definition's abstraction clause, we require source because we don't want to replace bound occurrences of the variable source in source by source. For example, if we compute the substitution source, the result should not be source but simply source.
When substituting source for source in source, we also require that source. For example, we cannot substitute source for source in source, i.e., source, because it would result in source, a term that stands for the function that accepts an argument and returns it directly. But the term source stands for a function that always returns the term source (or whatever source refers to). So the result we actually want is a function that accepts an argument, drop it, and returns the environment variable source. To do this properly, we would first have to “rename” the bound variable source.
Exercises evaluating partial substitutions
What is the result of the following substitutions?
Free variables after substitution for a variable not free
Proof
By induction on the formation of source.
Exercise completing the nonfree substitution proof
Complete the proof of the substitution theorem for a variable not free in the term.
Free variables after substitution for a free variable
Proof
By induction on the formation of source.
source is a variable: exercise.
source is of the form source: Since source is defined, it has to be source with both substitution defined. Also, since source, either source or source or both. The rest is left as an exercise.
source is of the form source. Since source is defined, it has to be source, with source defined, source and source; also, since source, we have source too. Now:
Exercise completing the free substitution proof
Complete the proof of the substitution theorem for a variable free in the term.
Theorem on removal of a free variable
Proof
Exercise.
Exercise proving removal of a free variable
Prove the theorem on removal of a free variable by substitution.
Theorem on inverse variable substitution
Proof
By induction on the formation of source.
Exercise completing the inverse substitution proof
Complete the proof of the inverse substitution theorem.
Source file content/lambda-calculus/syntax/alpha.tex
source-Conversion
What is the relation between source and source? They both represent the identity function. They are, of course, syntactically different terms. They differ only in the name of the bound variable, and one is the result of “renaming” the bound variable in the other. This is called source-conversion.
Local definition of change of bound variable
[Change of bound variable, source] If a term source contains an occurrence of source, source, and source is defined, then replacing this occurrence by
resulting in source is called a change of bound variable, written as source.
Definition of compatible relation
[Compatibility of relation] A relation source on terms is said to be compatible if it satisfies following conditions:
Thus let's rephrase the definition:
Compatible closure definition of bound variable change
[Change of bound variable, source] Change of bound variable (source) is the smallest compatible relation on terms satisfying following condition:
“Smallest” here means the relation contains only pairs that are required by compatibility and the additional condition, and nothing else. Thus this relation can also be defined as follows:
Inductive definition of one alpha change
[Change of bound variable, source] Change of bound variable (source) is inductively defined as follows:
The definitions are equivalent, but we leave the proof as an exercise. From now on we will use the inductive definition.
Reflexive transitive closure definition of alpha conversion
[source-conversion, source] source-conversion (source) is the smallest reflexitive and transitive relation on terms containing source.
As above, “smallest” means the relation only contains pairs required by transitivity, and source, which leads to the following equivalent definition:
Inductive definition of alpha conversion
[source-conversion, source] source-conversion (source) is inductively defined as follows:
Examples of alpha conversion and free names
source source-converts to source, and conversely. Informally speaking, they are both functions that accept an argument and return source of that argument, refering to the environment variable source.
source does not source-convert to source. Informally speaking, they refer to the environment variables source and source respectively, and this makes them different functions: they behave differently in environments where source and source are different.
Exercise deciding alpha convertibility
Are the following pairs of terms source-convertible?
Lemma that one alpha change preserves free variables
Proof
By induction on the derivation of source.
Exercise completing preservation of free variables
Complete the proof of the lemma that one alpha change preserves free variables.
Lemma reversing one alpha change
Proof
Induction on the derivation of source.
If the last rule is the bound variable renaming clause, then source is of the form source and source of the form source, where source, source and source defined. First, we have source by the theorem on removal of a free variable by substitution. By the inverse substitution theorem we have that source is not only defined, but also equal to source. Then by the bound variable renaming clause, we have source.
Exercise completing reversibility of alpha change
Complete the proof of the lemma reversing one change of bound variable
Theorem that alpha conversion is an equivalence relation
source-Conversion is an equivalence relation on terms, i.e., it is reflexive, symmetric, and transitive.
Proof
For each term source, source can be changed to source by zero changes of bound variables.
If source is source-converts to source by a series of changes of bound variables, then from source we can just inverse these changes (by the lemma reversing one change of bound variable) in opposite order to obtain source.
If source source-converts to source by a series of changes of bound variables, and source to source by another series, then we can change source to source by first applying the first series and then the second series.
From now on we say that source and source are source-equivalent, source, iff source source-converts to source (which, as we've just shown, is the case iff source source-converts to source).
Alpha equivalence preserves free variables
Proof
Immediate from the lemma that one alpha change preserves free variables.
Lemma on an alpha equivalent replacement term
If source and source is defined, then source is defined and source-equivalent to source.
Proof
Exercise.
Exercise on an alpha equivalent replacement term
Prove the substitution lemma for alpha equivalent replacement terms.
Recall that in the section Substitution, substitution is undefined in some cases; however, using source-conversion on terms, we can make substitution always defined by renaming bound variables. The result preserves source-equivalence, as shown in this theorem:
Theorem making substitution defined by alpha conversion
For any source, source, and source, there exists source such that source and source is defined. Moreover, if there is another pair source and source where source is defined and source, then source.
Proof
By induction on the formation of source:
Suppose source is of the form source. Select a variable source other than source and source and such that source and source. By inductive hypothesis, we there is source such that source and source is defined. Then source too, by the inductive definition of one change of bound variableits abstraction compatibility clause. Now source by the inductive definition of one change of bound variablethe bound variable renaming clause. We can do this because source, source and source is defined. Finally, source is defined, because source and source.
Moreover, if there is another source and source satisfying the same conditions,
Exercise completing alpha representative substitution
Complete the proof of the theorem choosing alpha equivalent representatives for defined substitution.
Printed corollary on pairs of representatives
For any source, source, and source, there exists a pair of source and source such that source, source and source is defined. Moreover, if there is another pair source and source with source defined, then source.
Proof
Immediate from the theorem choosing alpha equivalent representatives for defined substitution.
Source file content/lambda-calculus/syntax/de-bruijn.tex
The De Bruijn Index
source-Equivalence is very natural, as terms that are source-equivalent “mean the same.” In fact, it is possible to give a syntax for lambda terms which does not distinguish terms that can be source-converted to each other. The best known replaces variables by their De Bruijn index.
When we write source, we explicitly state that source is the parameter of the function, so that we can use source in source to refer to this parameter. In the de Bruijn index, however, parameters have no name and reference to them in the function body is denoted by a number denoting the levels of abstraction between them. For example, consider the example of source: the outer abstraction is on binds the variable source; the inner abstraction binds the variable is source; the sub-term source lies in the scope of the inner abstraction: there is no abstraction between source and its abstract source, but one abstract between source and its abstract source. Thus we write source for source, and source for the entire term.
Definition of de Bruijn terms
De Bruijn terms are inductively defines as follows:
A formalized translation from ordinary lambda terms to De Bruijn indexed terms is as follows:
Translation from named terms to de Bruijn terms
where source is a list of variables indexed from zero, and source denotes the position of the variable source in source. For example, if source is source, then source is source and source is source.
source denotes the list resulted from pushing source to the head of source; for instance, continuing the source in last example, source is source.
Recovering a standard lambda term from a de Bruijn term is done as follows:
Recovery of named terms from de Bruijn terms
where source is again a list of variables indexed from zero, and source denotes the variable in position source. For example, if source is source, then source is source.
The variable source in last equation is chosen to be any variable that not in source.
Here we give some results without proving them:
De Bruijn translation is unchanged by alpha change
If source, and source is any list containing source, then source.
Source file content/lambda-calculus/syntax/term-revisited.tex
Terms as source-Equivalence Classes
From now on, we will consider terms up to source-equivalence. That means when we write a term, we mean its source-equivalance class it is in. For example, we write source for the set of all terms source-equivalent to it, such as source, source, etc.
Also, while in previous sections letters such as source are used to denote a term, from now on we use them to denote a class, and it is these classes instead of terms that will be our subjects of study in what follows. Letters such as source continues to denote a variable.
We also adopt the notation source to denote an arbitrary element of the class source, and source if we need more than one.
We reuse the notations from terms to simplify our wording. We have following definition on classes:
Abstraction and application on alpha equivalence classes
It is not hard to see that they are well defined, because source-conversion is compatible.
Free variables of an alpha equivalence class
The free variables of an source-equivalence class source, or source, is defined to be source.
This is well defined since source, as shown in the theorem that alpha equivalence preserves free variables.
We also reuse the notation for substition into classes:
Substitution on alpha equivalence classes
The substitution of source for source in source, or source, is defined to be source, for any source and source making the substition defined.
This is also well defined as shown in the corollary on substitution using pairs of representatives.
Note how this definition significantly simplifies our reasoning. For example:
the first labelled equation, substitution into the identity abstraction on x is undefined if we still regard it as substitution on terms; but as mentioned earlier, we now consider it a substitution on classes, which is why the second labelled equation, substitution into the identity abstraction on z can happen: we can replace source with source because they belong to the same class.
For the same reason, from now on we will assume that the representatives we choose always satisfy the conditions needed for substitution. For example, when we see source, we will assume the representative source is chosen so that source and source.
Since it is a bit strange to call source a “class”, let's call them source-terms (or simply “terms” in the rest of the part) from now on, to distinguish them from source-terms that we are familiar with.
Editorial
We cannot say goodbye to terms yet: the whole definition of source-terms is based on source-terms, and we haven't provided a method to define functions on source-terms, which means all such functions have to be first defined on source-terms, and then “projected” to source-terms, as we did for substitutions. However we assume the reader can intuitively understand how we can define functions on source-terms.
Source file content/lambda-calculus/syntax/beta.tex
source-reduction
When we see source, it is natural to conjecture that it has some connection with source, namely the second term should be the result of “simplifying” the first. The notion of source-reduction captures this intuition formally.
Definition of beta contraction
[source-contraction, source] The source-contraction (source) is the smallest compatible relation on terms satisfying the following condition:
We say source is source-contracted to source if source. A term of the form source is called a redex.
Exercise giving inductive beta contraction rules
Spell out the equivalent inductive definitions of source-contraction as we did for change of bound variable in the inductive definition of one change of bound variable.
Definition of beta reduction
[source-reduction, source] source-reduction (source) is the smallest reflexive, transitive relation on terms containing source. We say source is source-reduced to source if source.
We will write source instead of source, and source instead of source when context is clear.
Informally speaking, source if and only if source can be changed to source by zero or several steps of source-contraction.
Definition of beta normal term
[source-normal] A term that cannot be source-contracted any further is said to be source-normal.
If source and source is source-normal, then we say source is a normal form of source. One may ask if the normal form of a term is unique, and the answer is yes, as we will see later.
Let us consider some examples.
We have
“Simplifying” a term can actually make it more complex:
It can also leave a term unchanged:
Also, some terms can be reduced in more than one way; for example,
by contracting the outermost application; and
by contracting the innermost one. Note, in this case, however, that both terms further reduce to the same term, source.
The final outcome in the last example is not a coincidence, but rather illustrates a deep and important property of the lambda calculus, known as the Church--Rosser property.
Digress
In general, there is more than one way to source-reduce a term, thus many reduction strategies have been invented, among which the most common is the natural strategy. The natural strategy always contracts the left-most redex, where the position of a redex is defined as its starting point in the term. The natural strategy has the useful property that a term can be reduced to a normal form by some strategy iff it can be reduced to normal form using the natural strategy. In what follows we will use the natural stratuegy unless otherwise specified.
Inductive definition of beta equivalence
[source-equivalence, source] source-Equivalence (source) is the relation inductively defined as follows:
The first three rules make the relation an equivalence relation; the next three make it compatible; the last ensures that it contains source-contraction.
Informally speaking, two terms are source-equivalent if and only if one of them can be changed to the other in zero or more steps of source-contraction, or “inverse” of source-contraction. The inverse of source-contraction is defined so that source inverse-source-contracts to source iff source source-contracts to source.
Besides the above rules, we will extend the relation with more rules, and denote the extended equivalence relation as source, where source is the extending rule.
Source file content/lambda-calculus/syntax/eta.tex
source-conversion
There is another relation on source terms. In the section Free Variables we used the example source, which accepts an argument and applies source to it. In other words, it is the same function as source: source and source both reduce to source. We use source-reduction (and source-extension) to capture this idea.
Definition of eta contraction
[source-contraction, source] source-contraction (source) is the smallest compatible relation on terms satisfying the following condition:
Definition of beta eta reduction
[source-reduction, source] source-reduction (source) is the smallest reflexive, transitive relation on terms containing source and source, i.e., the rules of reflexivity and transitive plus the following two rules:
Extending equivalence by eta conversion
We extend the equivalence relation source with the source-conversion rule:
and denote the extended relation as source.
source-equivalence is important because it is related to extensionality of lambda terms:
Extensionality rule
[Extensionality] We extend the equivalence relation source with the (ext) rule:
and denote the extended relation as source.
Roughly speaking, the rule states that two terms, viewed as functions, should be considered equal if they behave the same for the same argument.
We now prove that the source rule provides exactly the extensionality, and nothing else.
Equivalence of eta and extensionality extensions
Proof
First we prove that source is closed under the extensionality rule. That is, source rule doesn't add anything to source. We then have source contains source, and if source, then source.
To prove source is closed under ext, note that for any source derived by the ext rule, we have source as premise. Then we have source by a rule of source, applying source on both side gives us source.
Similarly we prove that the source rule is contained in source. For any source and source with source, we have that source, giving us source by the ext rule.
Source disclosures
- TR043-SAR-001: Source note. The definition calls the surrounding term capital N the scope. The examples instead use the abstraction body as its scope. The conflicting wording is retained, not silently repaired. source
- TR043-SAR-002: Source note. This explanation says substituting into the identity abstraction should return that abstraction. The preceding definition makes substitution under a binder on the replaced variable undefined. The later section on alpha equivalence classes explains how a renamed representative can be used. Both stages are preserved. source
- TR043-SAR-003: Source note. In this abstraction case the source suddenly mentions capital Q, although the body is capital P. This variable mismatch is retained. source
- TR043-SAR-004: Source note. The antecedent ends with an unmatched closing parenthesis after the free variable set. The formula is preserved, with that punctuation identified in speech. source
- TR043-SAR-005: Source note. The printed proof changes the substitution variable from x to y in the application case, interchanges x and y in the abstraction premise, and gives a set calculation with an unmatched parenthesis and inconsistent removed variables. In particular it cites x not free in capital N although the definition required y not free there. The original calculation is retained; no corrected proof is claimed. source
- TR043-SAR-006: Source note. This first definition of a change of bound variable does not require x to differ from y. Both following definitions explicitly require that inequality. Their claimed equivalence is preserved with this qualification. source
- TR043-SAR-007: Source note. The second and third exercise pairs are identical in the original. Both are retained, and no answers are added. source
- TR043-SAR-008: Source note. One row types the letters F and V literally rather than using the free variable macro. It is spoken as the free variable operation indicated by the surrounding calculation; the original notation remains available. source
- TR043-SAR-009: Source note. The reversal proof claims that y is not free after substituting y for x. Its cited theorem supports removal of x, not removal of the replacement variable y. The printed variable is retained and the proof is not silently repaired. source
- TR043-SAR-010: Source note. This supplied proof does not establish all the needed inner substitution definedness conditions. Its comparison chain also writes literal equalities where the cited replacement lemma establishes alpha equivalence. The printed argument and relations are preserved, without claiming the gap has been repaired. source
- TR043-SAR-011: Source note. The moreover clause repeats the first pair in its definedness condition, and does not state that the second replacement is alpha equivalent to the first. The conclusion about the second pair therefore lacks hypotheses as printed. The statement is retained rather than silently strengthened. source
- TR043-SAR-012: Source note. This displayed eta equation uses the free variable f and does not repeat a freshness premise. The earlier general eta contraction rule explicitly requires x not free in its function term. That condition must not be dropped when reading a general eta rule into this example. source