A lambda expression is given by the syntax (where the represent variable names):
It satisfies the three elements that all programming languages have:
with Variables, Applications, and Abstractions, respectively.
An upright word is to be interpreted as a single symbol. Function application is notated with a space.
The Church encoding is denoted with a subscript while the Scott encoding is denoted with a subscript .
We present an explicit universal turing machine implementation in the Lambda Calculus, thus showing that Lambda Calculus is at least as powerful as Turing Machines.
The implementation is the function which takes a machine and a string and computes running on input .
The result is for accept, for reject and infinite recursion for non-halting.
The machine has a set of states and a symbol set . The machine is assumed to be given as , where is the start state, is a function that returns if the input is an accept state and otherwise, is a function that returns if the input is an reject state and otherwise, is the blank symbol, and is the transition function from the current state and read tape character to the next state, the written tape character, and the head movement (Left or Right).
The input string is assumed to be in the form of a linked list in the Scott encoding (where the list [1,2]
is represented as
).
This lambda expression takes as input the machine and the string and returns if accepts, returns if rejects, and never normalizes if doesn’t halt.
Here is an analogous implementation in Haskell
U = \ m s -> case m of
(q0, qa, qr, b, d) -> f q0 [] s
where f q ta tb =
if qa q then True else
if qr q then False else
let u = \ ta tb q g h -> case h of
Left -> case ta of
[] -> f q [] (g:tb)
g':ta -> f q ta (g':g:tb)
Right -> f q (g:ta) tb
in
case tb of
[] -> case d (q, b) of
(q, g, h) -> u ta tb q g h
g:tb -> case d (q, g) of
(q, g, h) -> u ta tb q g h