Reading preferences
Optional display controls need JavaScript. All reading content and navigation work without it.
Source file content/lambda-calculus/lambda-definability/lambda-definability.tex
Editorial
This chapter is experimental. It needs more explanation, and the material should be structured better into definitions and propositions with proofs, and more examples.
Source file content/lambda-calculus/lambda-definability/introduction.tex
Introduction
At first glance, the lambda calculus is just a very abstract calculus of expressions that represent functions and applications of them to others. Nothing in the syntax of the lambda calculus suggests that these are functions of particular kinds of objects, in particular, the syntax includes no mention of natural numbers. Its basic operations---application and lambda abstractions---are operations that apply to any function, not just functions on natural numbers.
Nevertheless, with some ingenuity, it is possible to define arithmetical functions, i.e., functions on the natural numbers, in the lambda calculus. To do this, we define, for each natural number source, a special source-term source, the Church numeral for source. (Church numerals are named for Alonzo Church.)
Definition of Church numerals
If source, the corresponding Church numeral source represents source:
Here, source stands for the result of applying source to source source times. For example, source is source, and source is source.
The Church numeral source is encoded as a lambda term which represents a function accepting two arguments source and source, and returns source. Church numerals are evidently in normal form.
A representation of natural numbers in the lambda calculus is only useful, of course, if we can compute with them. Computing with Church numerals in the lambda calculus means applying a source-term source to such a Church numeral, and reducing the combined term source to a normal form. If it always reduces to a normal form, and the normal form is always a Church numeral source, we can think of the output of the computation as being the number source. We can then think of source as defining a function source, namely the function such that source iff source. Because of the Church--Rosser property, normal forms are unique if they exist. So if source, there can be no other term in normal form, in particular no other Church numeral, that source reduces to.
Conversely, given a function source, we can ask if there is a term source that defines source in this way. In that case we say that source lambda-defines source, and that source is lambda-definable. We can generalize this to many-place and partial functions.
Definition of lambda definability for a partial function
Suppose source. We say that a lambda term source lambda-defines source if for all source, dots, source,
if source is defined, and source has no normal form otherwise.
A very simple example are the constant functions. The term source lambda-defines the function source such that source. For source for any source. The identity function is lambda-defined by source. More complex functions are of course harder to define, and often require a lot of ingenuity. So it is perhaps surprising that every computable function is lambda-definable. The converse is also true: if a function is lambda-definable, it is computable.
Source file content/lambda-calculus/lambda-definability/arithmetical-functions.tex
lambda definable Arithmetical Functions
Successor is lambda definable
The successor function source is lambda-definable.
Proof
A term that lambda-defines the successor function is
i.e., source.
Example computing the successor of zero
Let's look at what happens when we apply source to source, i.e., source. We'll spell the terms out in full:
Exercise on an alternative successor term
The term
lambda-defines the successor function. Explain why.
Addition is lambda definable
The addition function source is lambda-definable.
Proof
Addition is lambda-defined by the terms
And since source lambda-defines the successor function, and the successor function applied source times to source gives source, this in turn reduces to source.
Multiplication is lambda definable
Multiplication is lambda-definable by the term
Proof
To see how this works, suppose we apply source to Church numerals source and source: source reduces to source. The term source defines a function which applies source to its argument source times. Consequently, source applies the function “apply source source times” itself source times to source. In other words, we apply source to source, source times. But the resulting normal term is just the Church numeral source.
Editorial
We can actually simplify this term further by source-reduction:
But then we first have to explain source-reduction.
Exercise on an alternative multiplication term
Multiplication can be lambda-defined by the term
Explain why this works.
The definition of exponentiation as a source-term is surprisingly simple:
The first argument source is the base and the second source is the exponent. Intuitively, source is source by our encoding of numbers. If you find it hard to understand, we can still define exponentiation also by iterated multiplication:
Predecessor and subtraction on Church numeral is not as simple as we might think: it requires encoding of pairs.
Source file content/lambda-calculus/lambda-definability/pairs.tex
Pairs and Predecessor
Definition of an encoded pair
The pair of source and source (written source) is defined as follows:
Intuitively it is a function that accepts a function, and applies that function to the two elements of the pair. Following this idea we have this constructor, which takes two terms and returns the pair containing them:
Given a pair, we also want to recover its elements. For this we need two access functions, which accept a pair as argument and return the first or second elements in it:
Exercise on pair access functions
Now with pairs we can lambda-define the predecessor function:
Remember that source reduces to source; in this case source is a function that accepts a pair source and returns a new pair containing the second component of source and the successor of the second component; source is the pair source. Thus, the result is source for source, and source otherwise. source then returns the first component of the result.
Subtraction can be defined as source applied to source, source times:
Source file content/lambda-calculus/lambda-definability/truth-values.tex
Truth Values and Relations
We can encode truth values in the pure lambda calculus as follows:
Truth values are represented as selectors, i.e., functions that accept two arguments and returning one of them. The truth value source selects its first argument, and source its second. For example, source always reduces to source, while source always reduces to source.
Definition of a lambda-definable relation
We call a relation source lambda-definable if there is a term source such that
otherwise.
For instance, the relation source which holds of source and source only, is lambda-definable by
How does it work? Since Church numerals are defined as iterators (functions which apply their first argument source times to the second), we set the initial value to be source, and for every step of iteration, we return source regardless of the result of the last iteration. This step will be applied to the initial value source times, and the result will be source if and only if the step is not applied at all, i.e., when source.
On the basis of this representation of truth values, we can further define some truth functions. Here are two, the representations of negation and conjunction:
The function “source” accepts one argument, and returns source if the argument is source, and source if the argument is source. The function “source” accepts two truth values as arguments, and should return source iff both arguments are source. Truth values are represented as selectors (described above), so when source is a truth value and is applied to two arguments, the result will be the first argument if source is source and the second argument otherwise. Now source takes its two arguments source and source, and in return passes source and source to its first argument source. Assuming source is a truth value, the result will evaluate to source if source is source, and to source if source is source, which is just what is desired.
Note that we assume here that only truth values are used as arguments to source. If it is passed other terms, the result (i.e., the normal form, if it exists) may well not be a truth value.
Exercise defining disjunction and exclusive disjunction
Define the functions source and source representing the truth functions of inclusive and exclusive disjunction using the encoding of truth values as source-terms.
Source file content/lambda-calculus/lambda-definability/primitive-recursive-functions.tex
Primitive Recursive Functions are lambda definable
Recall that the primitive recursive functions are those that can be defined from the basic functions source, source, and source by composition and primitive recursion.
Basic primitive recursive functions are lambda definable
The basic primitive recursive functions source, source, and projections source are lambda-definable.
Proof
They are lambda-defined by the following terms:
Closure of lambda-definable total functions under composition
Suppose the source-ary function source, and source-ary functions source, are lambda-definable by terms source, source, dots, source, and source is defined from them by composition. Then source is lambda-definable.
Proof
source can be lambda-defined by the term
We leave verification of this fact as an exercise.
Exercise verifying the composition term
Complete the proof of the lemma on closure under composition by showing that source.
Note that the lemma on closure under composition did not require that source and source, dots, source are primitive recursive; it is only required that they are total and lambda-definable.
Closure under primitive recursion
Suppose source is an source-ary function and source is an source-ary function, they are lambda-definable by terms source and source, and the function source is defined from source and source by primitive recursion. Then source is also lambda-definable.
Proof
Recall that source is defined by
Informally speaking, the primitive recursive definition iterates the application of the function source source times and applies it to source. This is reminiscent of the definition of Church numerals, which is also defined as a iterator.
For simplicity, we give the definition and proof for a single additional argument source. The function source is lambda-defined by:
The iteration state we maintain is a pair, the first of which is the current source and the second is the corresponding value of source. For every step of iteration we create a pair of new values of source and source; after the iteration is done we return the second part of the pair and that's the final source value. We now prove this is indeed a representation of primitive recursion.
We want to prove that for any source and source, source. To do this we first show that if source, then source We proceed by induction on source.
If source, we want source. But source just is source. Since source lambda-defines source, this reduces to source, and since source, this is source
Now suppose that source. We want to show that source.
Since source, we are done.
Finally, consider
Every primitive recursive function is lambda definable
Every primitive recursive function is lambda-definable.
Proof
By the lemma on lambda definability of the basic functions, all basic functions are lambda-definable, and by the lemma on closure under composition and the lemma on closure under primitive recursion, the lambda-definable functions are closed under composition and primitive recursion.
Source file content/lambda-calculus/lambda-definability/fixpoints.tex
Fixpoints
Suppose we wanted to define the factorial function by recursion as a term source with the following property:
That is, the factorial of source is source if source, and source times the factorial of source otherwise. Of course, we cannot define the term source this way since source itself occurs in the right-hand side. Such recursive definitions involving self-reference are not part of the lambda calculus. Defining a term, e.g., by
only involves previously defined terms in the right-hand side, such as source. We can always remove source by replacing it with its defining term. This would give the term source as a pure lambda term; if source itself involved defined terms (as, e.g., source does), we could continue this process and finally arrive at a pure lambda term.
However this is not true in the case of recursive definitions like the one of source above. If we replace the occurrence of source on the right-hand side with the definition of source itself, we get:
and we still haven't gotten rid of source on the right-hand side. Clearly, if we repeat this process, the definition keeps growing longer and the process never results in a pure lambda term. Thus this way of defining factorial (or more generally recursive functions) is not feasible.
The recursive definition does tell us something, though: If source were a term representing the factorial function, then the term
applied to the term source, i.e., source, also represents the factorial function. That is, if we regard source as a function accepting a function and returning a function, the value of source is just source, provided source is the factorial. A function source with the property that source is called a fixpoint of source. So, the factorial is a fixpoint of source.
There are terms in the lambda calculus that compute the fixpoints of a given term, and these terms can then be used to turn a term like source into the definition of the factorial.
Definition of Turing's fixpoint combinator
The Y-combinator is the term:
Turing combinator produces a fixpoint
source has the property that source for any term source. Thus, source is always a fixpoint of source.
Proof
Let's abbreviate source by source, so that source. Then
Since source and source both reduce to source, source, so source is a fixpoint of source.
Of course, since source is a redex, the reduction can continue indefinitely:
So we can think of source as source applied to itself infinitely many times. If we apply source to it one additional time, we---so to speak---aren't doing anything extra; source applied to source applied infinitely many times to source is still source applied to source infinitely many times.
Note that the above sequence of source-reduction steps starting with source is infinite. So if we apply source to some term, i.e., consider source, that term will also reduce to infinitely many different terms, namely source, source, dots. It is nevertheless possible that some other sequence of reduction steps does terminate in a normal form.
Take the factorial for instance. Define source as source (i.e., a fixpoint of source). Then:
What goes for source goes for any recursive definition. Suppose we have a recursive equation
The source combinator of the definition of Turing's fixpoint combinator is due to Alan Turing. Alonzo Church had proposed a different version which we'll call source:
Church's combinator is a bit weaker than Turing's in that source but not source. Let source be the term source, so that source. Then
In other words, source and source reduce to a common term source; so source. This is often enough for applications.
Source file content/lambda-calculus/lambda-definability/minimization.tex
Minimization
The general recursive functions are those that can be obtained from the basic functions source, source, source by composition, primitive recursion, and regular minimization. To show that all general recursive functions are lambda-definable we have to show that any function defined by regular minimization from a lambda definable function is itself lambda-definable.
Closure under regular minimization
If source is regular and lambda-definable, then source defined by
is also lambda-definable.
Proof
Suppose the lambda term source source-defines the regular function source. To lambda-define source we use a search function and a fixpoint combinator:
where source is any fixpoint combinator. Informally speaking, source is a self-referencing function: starting with source, test whether source is zero: if so, return source, otherwise call itself with source. Thus source returns the least source for which source.
Specifically, observe that
Every general recursive function is lambda definable
Every general recursive function is lambda-definable.
Proof
By the lemma on lambda definability of the basic functions, all basic functions are lambda-definable, and by the lemma on closure under composition, the lemma on closure under primitive recursion, and the lemma on closure under regular minimization, the lambda-definable functions are closed under composition, primitive recursion, and regular minimization.
Source file content/lambda-calculus/lambda-definability/partial-recursive-functions.tex
Partial Recursive Functions are lambda definable
Partial recursive functions are those obtained from the basic functions by composition, primitive recursion, and unbounded minimization. They differ from general recursive function in that the functions used in unbounded search are not required to be regular. Not requiring regularity means that functions defined by minimization may sometimes not be defined.
At first glance it might seem that the same methods used to show that the (total) general recursive functions are all lambda-definable can be used to prove that all partial recursive functions are lambda-definable. For instance, the composition of source with source is lambda-defined by source if source and source are lambda-defined by terms source and source, respectively. However, when the functions are partial, this is problematic. When source is undefined, meaning source has no normal form. In most cases this means that source has no normal forms either, which is what we want. But consider when source is source, in which case source does have a normal form (source).
This problem is not insurmountable, and there are ways to lambda-define all partial recursive functions in such a way that undefined values are represented by terms without a normal form. These ways are, however, somewhat more complicated and less intuitive than the approach we have taken for general recursive functions. We record the theorem here without proof:
Partial recursive functions are lambda definable
All partial recursive functions are lambda-definable.
Source file content/lambda-calculus/lambda-definability/lambda-definable-recursive.tex
lambda definable Functions are Recursive
Not only are all partial recursive functions lambda-definable, the converse is true, too. That is, all lambda-definable functions are partial recursive.
Lambda-definable partial functions are partial recursive
If a partial function source is lambda-definable, it is partial recursive.
Proof
We only sketch the proof. First, we arithmetize source-terms, i.e., systematially assign Gödel numbers to source-terms, using the usual power-of-primes coding of sequences. Then we define a partial recursive function source operating on the Gödel number source of a lambda term as argument, and which returns the Gödel number of the normal form if it has one, or is undefined otherwise. Then define two partial recursive functions source and source that maps natural numbers to and from the Gödel numbers of the corresponding Church numeral.
Using these recursive functions, we can define the function source as a partial recursive function. There is a source-term source that lambda-defines source. To compute source, first obtain the Gödel numbers of the corresponding Church numerals using source, append these to source to obtain the Gödel number of the term source. Now use source on this Gödel number. If source is defined, source has a normal form (which must be a Church numeral), and otherwise it has no normal form (and so
is undefined). Finally, use source on the Gödel number of the normalized term.
Source disclosures
- TR045-SAR-001: Source caveat. The constant function is introduced as c subscript k, but its following value equation drops that subscript and prints c of n equals k. Both source notations are retained. source
- TR045-SAR-002: Source caveat. The source prints a one-step arrow from a Church numeral applied to f and x to the iterated body. Under the displayed nested lambda convention, supplying both arguments requires separate beta contractions. The one-step arrow is preserved as printed, not silently changed to a general reduction arrow. source
- TR045-SAR-003: Source caveat. Several addition steps are printed with one-step arrows even though their abbreviated terms require multiple beta contractions. The displayed arrows are preserved as written, with no new proof inserted. source
- TR045-SAR-004: Source caveat. The alternative multiplication exercise binds a and b, but its body uses a twice and never uses b. Consequently the printed term cannot depend on its second input as general multiplication does. The exercise and term remain unchanged and unsolved. source
- TR045-SAR-005: Source caveat. At the Church-zero exponent, this short exponentiation term beta reduces to an identity abstraction, rather than to the Church-one numeral defined earlier. They are related by eta conversion, but that is not the same as the stated reduction to the exact Church numeral. The printed definition is retained without silently adding a conversion convention or a special case. source
- TR045-SAR-006: Source caveat. The predecessor explanation prints ordinary zeros in its initial pair, whereas the displayed lambda term uses Church-zero numerals. The text's unbarred zeros and the formula's Church numerals are kept distinct rather than silently changing the source notation. source
- TR045-SAR-007: Source caveat. This relation definition states arity n but indexes its displayed arguments through k. It also reuses capital R for the relation and its representing lambda term. These source conventions are preserved; no argument count is silently substituted. source
- TR045-SAR-008: Source caveat. The composition lemma lists component functions through subscript k minus one, but representing terms through capital G subscript k. Its conclusion names capital H rather than h. The following proof gives a term capital H using components only through k minus one. The mismatched names and endpoints are preserved and disclosed. source
- TR045-SAR-009: Source caveat. The second recursion equation prints h as its outer right-hand function, and the following prose says to iterate h. The surrounding lemma and the later step term use g for the recursion step. The source equation therefore has an arity mismatch as written. Its h symbols remain unchanged; the later g symbols are also retained. source
- TR045-SAR-014: Source caveat. The first right-hand side omits outer parentheses around the lambda abstraction before the two Church-numeral arguments. Under the earlier convention that a lambda takes the widest available scope, those arguments remain inside its body, rather than being applied to the whole abstraction. The written expression is preserved; the later reduction cannot silently supply the missing parentheses. source
- TR045-SAR-010: Source caveat. This illustrative multiplication term again binds b without using it, and prints plain zero instead of the Church-zero numeral. Its purpose here is to contrast prior definitions with self-reference, but it is not silently repaired into a correct multiplication term. source
- TR045-SAR-015: Source caveat. The first reduction's right-hand side omits parentheses around the lambda abstraction before its following factor. The source's widest-scope rule therefore places that factor inside the innermost lambda body. The next row does parenthesize the abstraction. Both printed groupings and the claimed identity are preserved, without silently inserting parentheses into the earlier row. source
- TR045-SAR-012: Source caveat. Although this sentence discusses Church's combinator, it prints capital Y without the capital C subscript in both claims. The surrounding definition and ensuing calculation use capital Y subscript capital C. The missing subscripts are disclosed but not silently restored in the quoted formulas. source
- TR045-SAR-013: Source caveat. The lemma calls the minimized function g, while the proof calls it h and its representing term capital H. More importantly, Search's recursive branch applies g to the vector x arguments and Successor of y without passing f again. The branch also has an unmatched opening parenthesis. These source defects remain disclosed; the later claimed reduction is not treated as a repaired algorithm. source