Docsity

Theory of Computation Assignment 7: Primitive Recursive Functions and Lambda Calculus - Pr, Assignments of Computer Science

Toggle sidebar
bg1
Theory of Computation Assignment 7
November 16, 2005
This assignment is due on Tuesday, November 22, 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

Partial preview of the text

Download Theory of Computation Assignment 7: Primitive Recursive Functions and Lambda Calculus - Pr and more Assignments Computer Science in PDF only on Docsity!

Theory of Computation Assignment 7

November 16, 2005

This assignment is due on Tuesday, November 22, 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. If-then-else (e.g. ITE(1, x, y) = x, ITE(0, x, y) = y)
  3. Or
  4. And
  5. 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.