Deductive lambda calculus
Deductive lambda calculus considers what happens when lambda terms are regarded as mathematical expressions. One interpretation of the untyped lambda calculus is as a programming language where evaluation proceeds by performing reductions on an expression until it is in normal form. In this interpretation, if the expression never reduces to normal form then the program never terminates, and the value is undefined. Considered as a mathematical deductive system, each reduction would not alter the value of the expression. The expression would equal the reduction of the expression.
History
Alonzo Church invented the lambda calculus in the 1930s, originally to provide a new and simpler basis for mathematics.[1][2] However soon after inventing it major logic problems were identified with the definition of the lambda abstraction.[3]
Haskell Curry studied of illative (deductive) combinatory logic in 1941.[4] Combinatory logic is closely related to lambda calculus.
The Kleene–Rosser paradox is an implementation of Richard's paradox in combinatory logic. Combinatory logic is closely related to lambda calculus. Haskell Curry found that the key step in this paradox could be used to implement the simpler Curry's paradox. The existence of this paradox meant that the combinatory logic, and lambda calculus, could not be both consistent and complete as a deductive system.[5]
Later the lambda calculus was resurrected as a definition of a programming language.
Introduction
Lambda calculus is the model and inspiration for the development of functional programming languages. These languages implement the lambda abstraction, and use it in conjunction with application of functions, and types.
The use of lambda abstractions, which are then embedded into other mathematical systems, and used as a deductive system, leads to a number of problems, such as Curry's paradox. The problems are related to the definition of the lambda abstraction and the definition and use of functions as the basic type in lambda calculus. This article describes these problems and how they arise.
This is not a criticism of pure lambda calculus, and lambda calculus as a pure system is not the primary topic here. The problems arise with the interaction of lambda calculus with other mathematical systems. Being aware of the problems allows them to be avoided in some cases.
Terminology
For this discussion, the lambda abstraction is added as an extra operator in mathematics. The usual domains, such as Boolean and real will be available. Mathematical equality will be applied to these domains. The purpose is to see what problems arise from this definition.
Function application will be represented using the lambda calculus syntax. So multiplication will be represented by a dot. Also, for some examples, the let expression will be used.
The following table summarizes;
Name | Notation |
---|---|
Lambda abstraction. | |
Application of the function f to x | |
Multiplication of a by b | |
Let x in y | |
Mathematical equality | |
Beta reducible equality |
Interpretation of lambda calculus as mathematics
In the mathematical interpretation, lambda terms represent values. Eta and beta reductions are deductive steps that do not alter the values of expressions.
Eta reduction as mathematics
An eta-reduct is defined by,
In the mathematical interpretation,
Taking f to be a variable then,
or by letting
This definition defines to be the solution for f in the equation,
Beta reduction as mathematics
A beta reduct is,
and as,
then,
This rule is implied by the instantiation of quantified variables. If,
then is the expression y with the quantified variable x instantiated as z.
so,
As beta reduction is implied from eta reduction, there is no contradiction between the two definitions.
Logical inconsistency
From eta reduction,
This rule may be interpreted as defining to be the solution of the equation . In defining the solution to the equation in terms of x and y the definition implicitly assumes that there is one and only function f that satisfies the equation. However, for some equations there may be none or multiple solutions. The definition may be compared with defining by,
This is not a valid definition as the equation has two solutions. The proper definition is,
An expression in mathematics may represent multiple values if it has free variables. The variables may be existentially quantified. Existential quantification turns an equation into a disjunction of equations, with each variable populated with a single value in each equation.
The solution set for in is,
For the definition to be valid there must be only one solution in this solution set.
The mathematical (or extensional) definition of function equality is that two functions are equal if they perform the same mapping;
So,
The left condition is,
The next step is to chop this condition up so that the cardinality is tested for each value of , For any condition , the following result holds,
Apply this formula gives,
The inner condition only constrains where . So,
The structure of y
The condition is,
Where is not a function of , and the cardinality is 1. This leaves only the case where is a function of
The may be written,
If a condition on is to be formed then must be in the form of a function of . Call this function ,
As .
Then and are related by,
The function must use some mechanism to construct from . For this to be true for any there must be some way of extracting from . Call this function , defined by,
Then and are related by,
Plugging the results back in and simplifying gives,
No solutions
Starting with , where z is a Boolean, an equation with no solutions is formed,
Then letting and be the identity function,
As,
then it is not true that,
If we go ahead anyway,
And then,
Then is neither true or false, and as is a Boolean value then this violates the principle of bivalence.
Multiple solutions
Also it is possible to construct lambda expressions for which there are multiple values. In the real number domain, starting with,
then,
Then letting and be the identity function,
As,
then it is not true that,
If we go ahead anyway,
And then,
and,
Having an equation with multiple solutions is not an inconsistency. However the derivation demonstrated that, for all ,
Then substituting with 2 gives,
Substituting with -2 gives,
Then,
which is a contradiction, because the values 2 and -2 are defined not equal in the real domain.
Intensional versus extensional equality
Another difficulty for the interpretation of lambda calculus as a deductive system is the representation of values as lambda terms, which represent functions. The untyped lambda calculus is implemented by performing reductions on a lambda term, until the term is in normal form. The intensional interpretation[6] [7] of equality is that the reduction of a lambda term to normal form is the value of the lambda term.
This interpretation considers the identity of a lambda expression to be its structure. Two lambda terms are equal if they are alpha convertible.
One way to describe this is that extensional equality describes equality of functions, where as intensional equality describes equality of function implementations.
The mathematical (or extensional) definition of function equality is that two functions are equal if they perform the same mapping;
The extensional definition of equality is incompatible with the intensional definition. This can be seen in the example below, where applying a mathematical law changes a function to an equivalent function, yet the intensional interpretation of equality says that the two functions are not equal. This shows the untyped lambda calculus with intensional equality is inconsistent with mathematics as a deductive system.
This incompatibly is created by considering lambda terms as values. In typed lambda calculus this is not a significant problem, because built-in types may be added to carry values that are in a canonical form and have both extensional and intensional equality.
Example
In arithmetic, the distributive law implies that . Using the Church encoding of numerals the left and right hand sides may be represented as lambda terms.
So the distributive law says that the two functions,
are equal. The distributive law should apply if the church numerals provided a satisfactory implementation of numbers.
Left hand side;
Right hand side;
Comparison;
The two terms beta reduce to similar expressions. Still they are not alpha convertible, so according to intensional equality, the left hand side and the right hand side are different functions, and are not equal. But according to the distributive law the two functions are the same. If the two functions are applied to the same Church numerals they produce the same result, so in that sense the distributive law holds. But the functions themselves are not equal.
This is a significant problem because all values in the untyped lambda calculus are terms that define functions. So any mathematically correct transformation of a lambda calculus program may change the meaning of the program.
Set theoretic domain
Lambda abstractions are functions of functions. A natural step is to define a domain for the lambda abstraction as a set of all functions.
The set of all functions from a domain D to a range R is given by K in,
Then the definition of the set of all functions of functions is given by F in,
This definition is an unsolved equation for F. If there exists no function that may not be applied to itself, then there is a set F that satisfies the above definition of "all functions". This is the case with lambda calculus, as there are no restriction on the domain of parameters.
However consider the Church numerals. If the functions on Church numerals, such as plus, minus, times and divide were restricted so that they only apply to Church numerals then these are functions that may not be applied to them self. This restriction is desirable because the Church arithmetic functions do not meaningful apply to functions other than Church numerals.
However then we get a version of Russell's paradox. See also Rice's theorem, which relates to partial functions.
To show this assume g is a function that may not be applied to itself,
Firstly assume g is in F. This will be used to deduce a falsehood.
instantiate x as g.
which is false because.
Secondly assume g not in F. Again this will be used to deduce a falsehood. Starting with,
From the definition of all functions of functions, it can be shown that,
which is false because we assumed,
So g is an element of F and not an element of F.
Therefore, if there exists a function that may not be applied to itself, then there is no set F satisfying the above definition of "all functions". This result limits what can be done with the set theoretic approach to lambda calculus, while not actually ruling out the lambda calculus domain. The lambda calculus domain is OK, defined as a set, but any modification to it may cause problems. The usual approach to defining sets of functions is to build a Von Neumann universe. However, because the only type in the untyped lambda calculus is the function, it is not clear how to do this.
Domain of lambda calculus
The problems with lambda abstraction arose when a domain was imposed on it. If the lambda abstraction is allowed to define the domain, instead of imposing the domain upon the lambda abstraction, these problems no longer appear.
Lambda calculus is defined by beta reductions and eta reductions. Interpreting reduction as defining equality gives an implicit domain for the lambda calculus. The rules are,
- Every lambda abstraction has one value.
- The beta reduction of a lambda term has the same value.
- The eta reduction of a lambda term has the same value.
- Alpha convertible lambda terms are equal.
- If two lambda terms can not be shown to be equal, they are not equal.
If lambda terms may be reduced to normal form then the Church–Rosser theorem may be used to show that lambda terms are equal if their normal forms are alpha convertible.
If not then the undecidability of equivalence shows that in general there is no algorithm to determine if two lambda terms are equal. In general this makes it impossible to know what the distinct elements of the lambda calculus domain are.
Example: No solutions → one solution
For example the equation may be coded with Church encoding and using Curry's Y combinator as,
And the recursion is,
- ...
- ... (beta and then eta reduction)
Which is the first line and will recurse indefinitely. The expression never reduces to normal form. However every lambda term in the reduction represents the same value. This value is distinct from the encodings for true or false. It is not part of the Boolean domain but it exists in the lambda calculus domain.
Example: Multiple solutions → one solution
Using division and signed numbers, the Y combinator may be used to define an expression representing a whole number square root. The Church encoding may also be extended further to rational and real numbers, so that a real square root may be defined. The Church-Turing thesis implies that any computable operator (and its operands) can be represented in lambda calculus.
Using such an encoding,
Using the implementation of divide then,
represents two values in the domain of the signed numbers, if n is not equal to zero. However it is a lambda expression so has only one value in the lambda calculus domain. Beta reduction of this lambda term never reaches normal form. However it represents a value, so a single value in the lambda calculus domain represents two values in the signed number domain.
See also
References
- ↑ A. Church, "A set of postulates for the foundation of logic", Annals of Mathematics, Series 2, 33:346–366 (1932).
- ↑ For a full history, see Cardone and Hindley's "History of Lambda-calculus and Combinatory Logic" (2006).
- ↑ Kleene, S. C. & Rosser, J. B. (1935). "The inconsistency of certain formal logics". Annals of Mathematics 36 (3): 630–636. doi:10.2307/1968646.
- ↑ Curry, Haskell B. (1941). "The Paradox of Kleene and Rosser". Transactions of the American Mathematical Society 50: 454–516. doi:10.1090/S0002-9947-1941-0005275-6. MR 0005275. Retrieved 24 January 2013.
- ↑ The Inconsistency of Certain Formal Logic Haskell B. Curry The Journal of Symbolic Logic Vol. 7, No. 3 (Sep., 1942), pp. 115-117 Published by: Association for Symbolic Logic Article Stable URL: http://www.jstor.org/stable/2269292
- ↑ Selinger, Peter. "Lecture Notes on Lambda Calculus (PDF)" (PDF). p. 6.
- ↑ "Lambda calculus - intensionality". Stanford. p. 1.2 Intensionality.