



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




This assignment is due on Thursday, June 2, 2005.
In lecture I presented five schemas for defining primitive recursive functions. They are as follows:
Zk(x 1 ,... , xk) = 0
S(x) = x + 1
P (^) ik (x 1 ,... , xk) = xi where k > 0, i ≤ k
f ◦lk [g 1... gk](x 1 ,... , xl) = f (g 1 (x 1 ,... , xl),... , gk(x 1 ,... , xl))
PRk[g, h](0, x 2 ,... , xk) = g(x 2 ,... , xk) PRk[g, h](x + 1, x 2 ,... , xk) = h(x, PRk[g, h](x, x 2 ,... , xk), x 2 ,... , xk)
In lecture we showed how to define addition by primitive recursion:
PR^2 [P 11 , S ◦^31 [P 23 ]]
Using primitive recursion define:
(a) BEQ[P] = ∃x < y.P(x) (b) BUQ[P] = ∀x < y.P(x)
Define these as functions of y. My solution uses primitive recursion on y, so the order of arguments is y first, x second. It helps to define if-then-else and “boolean” functions (I use 0 for false and 1 for true) first.
2 Lambda Calculus
Terms in the lambda calculus are either variables, lambda-abstractions, or ap- plications. Application associates to the left, that is mno is associated ((mn)o). The dot in lambda abstraction is a left parenthesis that extends as far to the right as possible. Hence, λx.λy.mno is (λx.(λy.((mn)o))). The first rule (α) states formally that variable names do not matter:
λx.M = λy.M [y/x] provided y does not occur free in M.
The second rule (β) embodies the basic mechanism for function application, in which the formal parameter is replaced by the actual parameter.
(λx.M )N = M [N/x]
Both rules rely on substitution, which is defined as follows:
z[M/x] = z if x 6 = z x[M/x] = M if x = z (λy.N )[M/x] = λz.(N [z/y][M/x]) where z is a new variable that is distinct from x and does not oc- cur in N and is not free in M. (N 1 N 2 )[M/x] = (N 1 [M/x])(N 2 [M/x])
The treatment of variable renaming prevents capture of bound variables. It is sometimes necessary to do all of the renaming suggested by the definition. Often in calculation it is useful to preserve names if they do not cause conflict.
These pairs are analyzed by providing the correct projection function. The functions satisfy the laws:
π 1 (mkpair a b) = a π 2 (mkpair a b) = b
The first projection function is:
π 1 = λp.p(λx.λy.x)
Define the second projection function (π 2 ).
FACT = λfact.λn.if n = 0 then 1 else n ∗ fact(n − 1)
3 Representability of recursive functions in lambda
calculus
In this section you will demonstrate that all primitive and partial recursive functions are definable in the lambda calculus. When answering these questions note that in many cases the function defi- nition schema has parameters that vary with the arity. It is acceptable to give a family of lambda terms to implement the schema. For example the constant function zero of arity k is given by the family of terms:
λx 1.... .λxk.λs.λz.z
My implementation of the primitive recursion schema uses some of the same techniques as the implementation of predecessor. If it helps, pick a fixed arity of PR to implement.
The function of arity k defined by minimization of a function f of arity k + 1, written μf , satisfies:
μf (x 1 ,... , xk) = the least x such that f (x, x 1 ,... , xk) 6 = 0 and for all y < x, f (y, x 1 ,... , xk) is defined and equal to 0
Show that functions defined by minimization can be defined by the lambda calculus. My implementation of the minimization schema makes essential use of the fixed point combinator used in the factorial example.