Deductive lambda calculus

From Wikipedia, the free encyclopedia
Jump to: navigation, search

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[edit]

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.

Interpretation of lambda calculus as mathematics[edit]

In the mathematical interpretation, lambda terms represent values. Eta and beta reductions are deductive steps that do not alter the values of expressions.

Terminology[edit]

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. \lambda v.y
Application of the function f to x f\ x
Multiplication of a by b a \cdot b
Let x in y \operatorname{let} x \operatorname{in} y
Mathematical equality m = n
Beta reducible equality m =_\beta n

Eta reduction as mathematics[edit]

An eta-reduct is defined by,

x \not \in \operatorname{FV}(f) \to \operatorname{eta-reduct}[\lambda x.(f\ x)] = f

In the mathematical interpretation,

\operatorname{eta-reduct}[X] = X

Taking f to be a variable then,

\lambda x.(f\ x) = f

or by letting f\ x = y

f\ x = y \iff f = \lambda x.y

This definition defines  \lambda x.y to be the solution for f in the equation,

f\ x = y

Beta reduction as mathematics[edit]

A beta reduct is,

\operatorname{beta-reduct}[\lambda x.b\ z] = b[x:=z]

and as,

\operatorname{beta-reduct}[X] = X

then,

\lambda x.b\ z = b[x:=z]

This rule is implied by the instantiation of quantified variables. If,

\forall x: f\ x = y

then f\ z is the expression y with the quantified variable x instantiated as z.

f\ z = y[x:=z]

so,

\lambda x.y\ z = y[x:=z]

As beta reduction is implied from eta reduction, there is no contradiction between the two definitions.

Logical inconsistency[edit]

From eta reduction,

f\ x = y \iff f = \lambda x.y

This rule may be interpreted as defining \lambda x.y to be the solution of the equation f\ x = y . 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 \sqrt{} by,

y = x^2 \iff x = \sqrt{y}

This is not a valid definition as the equation y = x^2 has two solutions. The proper definition is,

(y = x^2 \and x >= 0) \iff x = \sqrt{y}

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 f in f\ x = y is,

\{f: f\ x = y \}

For the definition (f\ x = y \iff f = \lambda x.y) 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;

f = g \iff (\forall x f\ x = g\ x)

Using this definition the cardinality condition giving a valid definition of a lambda abstraction is,

(\forall x |\{f\ x: f\ x = y \}| = 1) \to (f\ x = y \iff f = \lambda x.y)

The left hand side may often be shown to be false where x = f

No solutions[edit]

Starting with the equation,

 x = \neg x

where x is a Boolean. Defining f by \forall y, f\ y = x gives,

 \forall z, f\ z = \neg (f\ z)

or, using the definition of a let expression,

 x = (\operatorname{let} f\ z = \neg (f\ z) \operatorname{in} f\ y )

The above may be considered as the definition of the function f, which is then called with the parameter y. The purpose of the parameter to f is to pass the function f into the definition of f. This is needed for when the let expression gets converted to a lambda expression, in order to allow recursion in lambda calculus. By instantiating y with f in the call then the above is equivalent to,

 x = (\operatorname{let} f\ z = \neg (z\ z) \operatorname{in} f\ f )

To get,

 f\ z = \neg (z\ z) \iff f = \lambda z.\neg (z\ z)

the cardinality is,

|\{f\ z: f\ z = \neg (z\ z) \}|

And where z is instantiated as f.

|\{f\ f: f\ f = \neg (f\ f) \}| = 0

so it is not valid to get,

 f\ z = \neg (z\ z) \iff f = \lambda z.\neg (z\ z)

If we go ahead anyway and translate the let expression into lambda calculus,

x = (\lambda f.f\ f) (\lambda z.\neg(z\ z))

Then, by beta reduction

x = (\lambda z.\neg\ (z\ z))\ (\lambda z.\neg\ (z\ z)) = \neg\ (\lambda.z \neg\ (z\ z))\ (\lambda z.\neg\ (z\ z))

There is no solution to the equation, and the value does not exist in the Boolean domain. Then,

(\lambda z.\neg\ (z\ z))\ (\lambda z.\neg\ (z\ z)) = \operatorname{true} \implies \operatorname{true} = \neg \operatorname{true}

and,

(\lambda z.\neg\ (z\ z))\ (\lambda z.\neg\ (z\ z)) = \operatorname{false} \implies \operatorname{false} = \neg \operatorname{false}

So,

(\lambda z.\neg\ (z\ z))\ (\lambda z.\neg\ (z\ z)) \not \in \{\operatorname{true}, \operatorname{false}\}

which violates the principle of bivalence.

Multiple solutions[edit]

Also it is possible to construct lambda expressions for which there are multiple values. For example, in the real number domain,

x^2 = 4

gives,

x = 4/x

Defining f by \forall y, f\ y = x gives,

 \forall z, f\ z = \frac{4}{f\ z}

or, using the definition of a let expression,

 x = (\operatorname{let} f\ z = \frac{4}{f\ z} \operatorname{in} f\ y )

By instantiating y with f in the call then the above is equivalent to,

 x = (\operatorname{let} f\ z = \frac{4}{z\ z} \operatorname{in} f\ f )

To get,

 f\ z = \frac{4}{z\ z} \iff f = \lambda z.\frac{4}{z\ z}

the cardinality is,

|\{f\ z: f\ z = \frac{4}{z\ z} \}|

And where z is instantiated as f.

|\{f\ f: f\ f = \frac{4}{f\ f} \}| = |\{f\ f: (f\ f)^2 = 4 \}| = 2

so it is not valid to get,

 f\ z = \frac{4}{z\ z} \iff f = \lambda z.\frac{4}{z\ z}

If we go ahead anyway and translate the let expression into lambda calculus,

x = (\lambda f.f\ f) (\lambda z.\frac{4}{z\ z})

Beta reduction then gives,

x = (\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z}) = \frac{4}{(\lambda.z \frac{4}{z\ z}\ (\lambda z.\frac{4}{z\ z})}

so,

((\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z}))^2 = 4

Having an equation with multiple solutions is not an inconsistency. However the derivation demonstrated that, for all y,

y^2 = 4 \implies y = (\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z})

Then substituting y with 2 gives,

\operatorname{true} \implies (\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z}) = 2

Substituting y with -2 gives,

\operatorname{true} \implies (\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z}) = -2

Then,

(\lambda z.\frac{4}{z\ z})\ (\lambda z.\frac{4}{z\ z}) = 2 = -2

which is a contradiction, because the values 2 and -2 are defined not equal in the real domain.

Intensional versus extensional equality[edit]

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 identify 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;

f = g \iff (\forall x f\ x = g\ x)

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[edit]

In arithmetic, the distributive law implies that 2 * (r + s) = 2*r + 2*s. Using the Church encoding of numerals the left and right hand sides may be represented as lambda terms.

Left hand side;

\lambda r.\lambda s.\operatorname{mult}\ 2\ (\operatorname{plus}\ r\ s)
\lambda r.\lambda s.(\lambda m.\lambda n.\lambda f. m\ (n\ f))\ (\lambda f.\lambda x.f\ (f\ x))\ ((\lambda m.\lambda n.\lambda f.\lambda x. m\ f\ (n\ f\ x))\ r\ s)
\lambda r.\lambda s.\lambda f.\lambda x.r\ f\ (s\ f\ (r\ f\ (s\ f\ x)))

Right hand side;

\lambda r.\lambda s.\operatorname{plus}\ (\operatorname{mult}\ 2\ r)\ (\operatorname{mult}\ 2\ s)
\lambda r.\lambda s.(\lambda m.\lambda n.\lambda f.\lambda x. m\ f\ (n\ f\ x))\ ((\lambda m.\lambda n.\lambda f. m\ (n\ f))\ (\lambda f.\lambda x.f\ (f\ x))\ r)\ ((\lambda m.\lambda n.\lambda f. m\ (n\ f))\ (\lambda f.\lambda x.f\ (f\ x))\ s)
\lambda r.\lambda s.\lambda f.\lambda x.r\ f\ (r\ f\ (s\ f\ (s\ f\ x)))

Comparison;

\lambda r.\lambda s.\lambda f.\lambda x.r\ f\ (s\ f\ (r\ f\ (s\ f\ x)))
\lambda r.\lambda s.\lambda f.\lambda x.r\ f\ (r\ f\ (s\ f\ (s\ f\ x)))

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. 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 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[edit]

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,

f \in K \iff (\forall  x : x \in D \implies f\ x \in R)

Then the definition of the set of all functions of functions is given by F in,

f \in F \iff (\forall x : x \in F \implies f\ x \in F)

This definition is an unsolved equation for F. So is there a solution for F?

Consider a version of Russell's paradox. Suppose there is a function g that is defined on all functions other than itself.

g\ g \not \in F
x \ne g \implies g\ x \in F

Firstly assume g is in F. This will be used to deduce a falsehood.

g \in F \iff (\forall x : x \in F \implies g\ x \in F)

instantiate x as g.

 \implies (g \in F \implies g\ g\in F)
 \implies g\ g \in F

which is false because.

g\ g \not \in F

Secondly assume g not in F. Again this will be used to deduce a falsehood. Starting with,

g \not \in F

From the definition of all functions of functions, it can be shown that,

 (\forall x : x \in F \implies g\ x \in F) \implies g \in F
 (\forall x : x \in F \implies g \ne x \implies g\ x \in F) \implies g \in F
 (\forall x : x \in F \implies \operatorname{true}) \implies g \in F
 \operatorname{true} \implies g \in F
 g \in F

which is false because we assumed,

g \not \in F

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 leads us to question the set theoretic approach to lambda calculus. 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[edit]

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.

Example: No solutions -> one solution[edit]

For example the equation x = \neg x may be coded with Church encoding and using Curry's Y combinator as,

\operatorname{not}_1 = \lambda p.\lambda a.\lambda b.p\ b\ a
(\lambda f.(\lambda x.f\ (x\ x))\ (\lambda x.f\ (x\ x))) (\lambda p.\lambda a.\lambda b.p\ b\ a)

And the recursion is,

(\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))\ (\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))
(\lambda p.\lambda a.\lambda b.p\ b\ a)\ ((\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))\ (\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x)))
\lambda a.\lambda b.((\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))\ (\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x)))\ b\ a
...
\lambda a.\lambda b.(\lambda a.\lambda b.((\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))\ (\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x)))\ b\ a)\ b\ a
... (beta and then eta reduction)
(\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))\ (\lambda x.(\lambda p.\lambda a.\lambda b.p\ b\ a)\ (x\ x))

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[edit]

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,

 x^2 = n \Rightarrow x = \frac{n}{x} \Rightarrow f\ x = \frac{n}{x} \and Y\ f = x

Using the implementation of divide then,

 Y (\operatorname{divide} n)

represents two values in the domain of the signed numbers. 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[edit]

References[edit]

  1. ^ A. Church, "A set of postulates for the foundation of logic", Annals of Mathematics, Series 2, 33:346–366 (1932).
  2. ^ For a full history, see Cardone and Hindley's "History of Lambda-calculus and Combinatory Logic" (2006).
  3. ^ Kleene, S. C. & Rosser, J. B. (1935). "The inconsistency of certain formal logics". Annals of Mathematics 36 (3): 630–636. doi:10.2307/1968646. 
  4. ^ 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. 
  5. ^ 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
  6. ^ Selinger, Peter. "Lecture Notes on Lambda Calculus (PDF)". p. 6. 
  7. ^ "Lambda calculus - intensionality". Stanford. p. 1.2 Intensionality.