Docsity

Problems on Recursive Functions and Lambda Calculus | CS 581, Assignments of Computer Science

Toggle sidebar
bg1
Theory of Computation Assignment 7
May 24, 2005
This assignment is due on Thursday, June 2, 2005.
1 Primitive Recursive Functions
In lecture I presented five schemas for defining primitive recursive functions.
They are as follows:
1. [Zero] There is a constant function zero of every arity.
Zk(x1, . . . , xk) = 0
2. [Successor] There is a successor function of arity 1.
S(x) = x+ 1
3. [Projection] There are projection functions for every argument position of
every arity.
Pk
i(x1, . . . , xk) = xiwhere k > 0, i≤k
4. [Composition (also called substitution)] The composition of the function
fof arity kwith functions g1, . . . gk, each of arity l, defines a f◦l
k[g1. . . gk]
of arity lsatisfying:
f◦l
k[g1. . . gk](x1, . . . , xl) = f(g1(x1, . . . , xl), . . . , gk(x1, . . . , xl))
5. [Primitive Recursion] The arity kfunction defined by primitive recursion
from a function gof arity k−1 and a function hof arity k+1 is indicated
PRk[g, h]. It satisfies:
PRk[g, h](0, x2, . . . , xk) = g(x2, . . . , xk)
PRk[g, h](x+ 1, x2, . . . , xk) = h(x, PRk[g, h](x, x2, . . . , xk), x2, . . . , xk)
In lecture we showed how to define addition by primitive recursion:
PR2[P1
1, S ◦3
1[P3
2]]
1
pf3
pf4
pf5

Partial preview of the text

Download Problems on Recursive Functions and Lambda Calculus | CS 581 and more Assignments Computer Science in PDF only on Docsity!

Theory of Computation Assignment 7

May 24, 2005

This assignment is due on Thursday, June 2, 2005.

1 Primitive Recursive Functions

In lecture I presented five schemas for defining primitive recursive functions. They are as follows:

  1. [Zero] There is a constant function zero of every arity.

Zk(x 1 ,... , xk) = 0

  1. [Successor] There is a successor function of arity 1.

S(x) = x + 1

  1. [Projection] There are projection functions for every argument position of every arity.

P (^) ik (x 1 ,... , xk) = xi where k > 0, i ≤ k

  1. [Composition (also called substitution)] The composition of the function f of arity k with functions g 1 ,... gk, each of arity l, defines a f ◦lk [g 1... gk] of arity l satisfying:

f ◦lk [g 1... gk](x 1 ,... , xl) = f (g 1 (x 1 ,... , xl),... , gk(x 1 ,... , xl))

  1. [Primitive Recursion] The arity k function defined by primitive recursion from a function g of arity k − 1 and a function h of arity k + 1 is indicated PRk[g, h]. It satisfies:

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

1.1 Exercises

Using primitive recursion define:

  1. Multiplication
  2. Bounded quantification Define the bounded existential and universal quantifiers

(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

2.1 Syntax

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 ).

  1. Define a function that maps 0 to the representation of the pair (0, 0), and maps every other natural number n to (n, n − 1). Use this function to define the predecessor function.
  2. Define the monus function, which returns the difference of two numbers if the difference is non-negative. If the difference is negative monus should return zero. [Hint: use the predecessor function.]
  3. Define an integer equality function.
  4. Argue convincingly that the factorial function below is definable in the lambda calculus:

FACT = λfact.λn.if n = 0 then 1 else n ∗ fact(n − 1)

  1. Illustrate a fragment of the computation of (Y FACT )(λs.λz.s(sz)). (Re- call that Y = λf (λx.f (xx))(λx.f (xx)))

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

3.1 Exercies

  1. Show that all primitive recurisve functions are definable in the lambda calculus by giving lambda terms for every schema. You may assume any of the results of the previous problem, even if you didn’t solve it.

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.

  1. Illustrate your construction by showing the translation of the addition function given in the first exercise.
  2. Recall the minimization schema:

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.