## CS4123 Theory of Computation. B97

### Prof. Carolina Ruiz

Department of Computer Science

Worcester Polytechnic Institute

# Homework 2

Due on Monday, Nov. 17 at 2:30 pm

- (Taken from Lewis and Papadimitriou '98)
Show that the following functions are primitive
recursive:
- factorial(n) = n!
- gcd(m,n), the greatest common divisor of m and n.
- the function prime(n) defined as follows:
if n is a prime number then prime(n) = 1, otherwise prime(n) = 0.
- p(n), the n_th prime number, where p(0) = 2, p(1) = 3, and so on.
- the function F: N -> N defined by:
F(n) = f(f(f(... f(n) ...))), where
there are n function compositions and the function f: N -> N
is primitive recursive.

- Show that the language L = {a^n.b^n.c^n | n >= 0} is decidable.

(Note: "a^n" denotes "a" repeated n times, and "." denotes concatenation.
That is, a^n.b^n.c^n denotes the string that consists of
n repetitions of "a" followed by
n repetitions of "b" followed by
n repetitions of "c".)