MENTAL
 Main Menu
 Comparisons
 MENTAL vs. Lambda Calculus, by Church


MENTAL vs. Church's Lambda Calculus
 MENTAL vs. CHURCH'S
LAMBDA CALCULUS

A theoretical model for functional expressions

"Most programming languages have their roots in the lambda calculus" (Peter Landin).



The Lambda Calculus, by Church

Fundamental concepts

The lambda calculus, created by the mathematician, logician and philosopher Alonzo Church in the 1930s, is a formal theoretical model for functional expressions, i.e., functions defined from other functions.

Lambda calculus functions are mathematical objects with the following characteristics: This distinction becomes necessary, because for example the mathematical expression x+5 does not indicate whether it is a function of the variable x or a calculation with the value of x. This problem is solved by the so-called "lambda notation". In the case of a function of one variable, the notation is λx.f(x), where: It is implemented by (λx.f(x))a = f(a) where a is the argument. For example: (λx.axb)3 = a3b

For two variables, the notation is: In general, for n variables, the notation is: The definition of a function is reminiscent of a universally quantified expression, in which λ plays a role similar to ∀ (for all).

The variable names of functional expressions is irrelevant. This is why function variables are said to be dummy or dummy. For example, λxy.x+y and λuv.u+v are equivalent.


Bound and free variables

In a lambda expression, a variable x is bound or free, depending on whether it appears as a parameter or not, respectively, in the function definition. Examples:
  1. In the functional expression (λx.xy), x is a bound variable and y is free.

  2. In the functional expression (λxy.xyx), x and y are bound variables.

Variables as functions

The variables x, y, z,... are also considered functions or self-functions, i.e. they apply to themselves and return to themselves. In this sense, the expression f(x) is usually written fx for short, since it is considered to be the application of the function f to the function x. Analogously, Therefore, a functional expression of n variables is usually written λx1 ... xn.fx1...xn.


Partial evaluation

For any lambda function of n variables, it is possible to define a "curry" version −name coming from the Haskell logic B. Curry− equivalent, in which the arguments are applied serially, one after the other. For example, the curry version of λxyz.xyz is λxyz.xyz. This process is called "currification". In both cases, the arguments must be specified in the same order and the result is the same, but the syntax is different: Therefore, in the lambda calculus, all functions of n parameters can be considered as an expression of single-parameter functions.


Substitution of variables for arguments

In the application of a function to some arguments, a substitution of each parameter by its corresponding argument is performed. To indicate this, the lambda calculus uses the notation [N/x]M, which indicates that in the expression M we want to substitute the variable x by the expression N. Examples: If in M the variable x does not appear, then M remains unchanged: [N/x]M = M. For example, [u/x]y = y.

Evidently, by the very definition of function application, it follows that It is the so-called "reduction β", "conversion β" or "axiom β" of the lambda calculus.

If the expression N appears in M as a dummy variable, it can be assigned a new name before performing the substitution. For example: It is the so-called "α conversion" or "α axiom" and is realized by means of The "η conversion" expresses the idea that two functions f and g are equal if and only if they give the same result for all possible arguments. That is, fa = ga for every argument a. If x does not appear in the body of f nor that of g, then fx = gx.


Calculations as reductions

Calculations in the lambda calculus are successive reductions, applying at each step the conversion β, until the simplest possible form is reached. An expression that can be reduced is called a "redex" (reduction expression). A redex can contain other redexes. An expression that cannot be reduced (containing no redex) is said to be in "normal form".

The Church-Rosser theorem of the lambda calculus states that the result of a calculus does not depend on the order in which reductions (substitutions β) are applied, i.e., all possible sequences of reductions progress to the same final result, which is the same as that obtained when reductions are applied concurrently.


Examples of simple functions
Higher order functions

If we have the expression of n variables λx1 ... xn.fx1 ... xn Then the higher-order functions appear.

A simple example is the composition of two functions is λgfx.g(fx). Which is equivalent to gf in traditional mathematical notation (first apply f and then apply g). For example: Some laws of function composition are:
Arithmetic

Substituting in λx.fx, x for fx, we have: λfx.f(fx)

This is the definition of a function that, acting on any function fx, produces the same function iterated twice, i.e., f(fx). This is the function identified with the symbol 2 (in bold, to differentiate it from the number 2). Analogously, Along with:
In general, a number n in the lambda calculus is a function that has as argument another function f and produces as result the n-ary composition of f. These numbers are called "Church numerals". Examples: A surprising aspect of Church's numerals is the possibility of defining the arithmetic operations of addition, multiplication, and power in terms of functions applied to numerals. Addition is based on the operation Successor (Suc), defined as follows: (Suc n) := λnfx. f(nfx) Just as the successor expression of a numeral (Suc n) is relatively simple, the Predecessor < i>Pn, i.e. n−1, is much more complex:
Logic functions

Logical functions can also be defined by lambda expressions. A logical function is a function that has as parameters the logical values V (true) or F (false) and produces a logical value as a result.

The values V and F are defined as follows: And the logical operations are defined as follows: Examples: Thanks to the above definitions of V and F as functions one can specify the logical condition If-Then-Else, by means of a lambda expression with 3 variables: b (truth value), t (branch Then) and e (branch Else):
Predicates

A predicate is defined as a function that returns a truth value. An example of a predicate is the function Z, which has a numeral as parameter and returns V if the argument is the numeral 0, and F if it is any other numeral: Where we have to take into account:
Recursive functions

We want to calculate, for example, the factorial of a number: The problem is that in the lambda calculus recursive functions are not allowed because the functions are anonymous and therefore cannot call themselves. However, it is possible to define them using the Y combinator (also called "fixed-point combinator" or "paradoxical combinator"), discovered by Haskell B. Curry, which is defined as follows: Applying Y to a function R we have: That is, YR is equal to the function R applied to YR. Here recursion appears, since By means of Y recursive functions can be encoded. For example, to solve the factorial problem, we define a function g (informally):

g = λf. λn.if n=1 then 1 else n*f(n−1)

g(n) returns 1 if n=1 and n*f(n−1) if n≠1.

The recursive function is g(Yg)n. For example, for n=4: The formal solution in lambda calculus consists of replacing conditional expressions and arithmetic expressions by the corresponding lambda expressions based on numerals: Therefore, the recursive expression is g(Yg)n, with
MENTAL vs. Lambda Calculus

Paradigmas

Lambda calculation. MENTAL.
Primitives

Lambda calculation. MENTAL.
Level of abstraction

Lambda calculation. MENTAL.
Expressions

Lambda calculation. MENTAL.
Bound and free variables

Lambda calculation. MENTAL.
Arithmetic

Lambda Calculus. MENTAL.
β substitution

Lambda calculation. MENTAL.
α conversion

Lambda calculation. MENTAL.
η conversion

The η conversion is not necessary, nor is any special formalism needed, because at the conceptual level it is seen that the following expressions (for example) are the same, and not only functions, but expressions in general:
Partial evaluation

Lambda calculation. MENTAL.
Recursion

Lambda calculation. MENTAL.
Parallel computing

Lambda computation. MENTAL.
Implementation

Lambda calculation. MENTAL.
Types

Lambda calculation. MENTAL.
Foundation

Lambda calculation. MENTAL.
Computational model

Lambda calculation. MENTAL.
Conclusions

Church, with the lambda calculus, made numerous contributions to the field of computation, including: However, the lambda calculus −like the Turing machine and category theory− is an example of non-compliance with Einstein's razor principle: "Everything should be made as simple as possible, but not simpler". It uses as its only concept that of functional expression, with two aspects: definition of a function and application of a function. This leads to serious expressive difficulties. Everything is a function, which causes the derived concepts (numbers, predicates, truth values, arithmetic operations, logical operations, conditions, etc.) to be expressed in a complex and unnatural way.



Addenda

Church and his contributions to science

The lambda calculus was developed in the 1930s by Alonzo Church [1941] to formalize computable functions, i.e., to define them precisely: every computable numerical function is computable by the lambda calculus, using the corresponding Church numerals instead of numbers. The lambda calculus is a theoretical model of computation, which has a computational power equivalent to that of a Turing machine.

When lambda calculus was invented, computers did not yet exist. However, it can be considered the first functional programming language in history. It has been the foundation of many functional languages, having had great influence on the design of programming languages in general.

Lisp was the first language to implement the lambda calculus [McCarthy, 1960], making it the oldest and most popular functional language. It is oriented to symbolic computation and is mainly applied to artificial intelligence topics.

Lisp was followed by, among others, Scheme, ML, Miranda and Haskell. Anyway, "pure" functional languages are only Haskell and Miranda. And hybrid languages (functional with other features, usually imperative) are Lisp, Scheme and ML.

Church's main contributions have been two:
  1. Church's thesis.
    He asserts that every effectively computable numerical function is recursive and computable by the lambda calculus. It thus replaces the informal notion of "computation".

    At the end of 1936, Turing, who had also been working on the subject of computability, published his famous paper "On computable numbers ..." in which he put forward the thesis that every computable function is computable by a theoretical device known today as a "Turing machine". Turing himself proved that both computational models were equivalent. The thesis is called the Church-Turing thesis, a thesis that connects the operational, epistemic and extrinsic aspects of arithmetic with the ontological, intrinsic and abstract aspects. This thesis also establishes the limits of computability, since all computation is limited by the primitives used (by Church or by Turing).

  2. Church's theorem.
    Church, studying "Hilbert's decision problem" (Entscheidungsproblem) led him to what is known as "Church's theorem". This theorem states that there is no algorithm or mechanical procedure capable of deciding whether the propositions of arithmetic are true or false. Therefore, that there is no general solution to the decision problem. This is equivalent to the fact that first-order predicate logic is undecidable.

    Church also used the lambda calculus to solve for the first time the problem of knowing whether or not any two functional expressions of the lambda calculus are equivalent. This problem is also undecidable: it cannot be solved by a general functional expression of the lambda calculus itself. This question was raised even before Turing's one-machine halting problem. Church and Turing were greatly influenced by Gödel's incompleteness theorem.
In 1990 a symposium was held in Church's honor at the State University of New York at Bufalo, for his seminal contributions to the foundations of the theory of computation.


Fixed-point combinators

A fixed point of a function f(x) is a value v of x such that f(v) = v. For example, 0 and 1 are fixed points of f(x) = x2, because 02 = 0 and 12 = 1. A fixed point of a higher order function f(g) is another function h such that f(h) = h. Since YR = R(YR), then YR is a fixed point of any function R.

Curry's Y fixed-point combinator is not the only one that exists in the lambda calculus. In fact, the type-free lambda calculus has infinite fixed-point combinators. In 2005, Mayer Goldberg [2005] showed that the set of fixed-point combinators of the lambda calculus is recursively numerable. In the lambda calculus with types −more restrictive at the combinatorial level− there is no fixed-point combinator.

The use of fixed-point combinators for recursion is called "anonymous recursion".


Bibliography