Docsity

Fibonacci Function and Recursive Program Fixpoints, Assignments of Programming Languages

Toggle sidebar
bg1
22C:185 — Fall 2004
Homework VIII
1 (corrected). [20 points]
The Fibonacci numbers are defined by fib(0) = 0, fib(1) = 1, and fib(n) = fib(n-1) + fib(n-2)
for n≥2. Consider the recursive program over all integers Z
P: f(n) = if n=0 or n=1 then n else f(n-1) + f(n-2).
(a) Show that the Fibonacci function fib (i.e., the partial function that is undefined for
arguments less than 0) is a fixed point of the corresponding fixed point functional P,
P(g) (n) = if n=0 or n=1 then n else g(n-1) + g(n-2).
(b) Show that the total function h: Z-->Z is also a fixed point of P, where h is defined by
h(n) = fib(n) if n≥0,
h(n) = fib(-n) if n<0 and n odd,
h(n) = -fib(-n) if n<0 and n even.
2. [25 points]
Determine the least fixed point of the functional associated with the recursive function
below (over all integers Z) and justify your answer.
f(n) = if n>7 then n-5 else f(f(n+6))
3. [20 points]
Show that the following functions are continuous:
(a) or: Bool¥Bool --> Bool (i.e., logical or), where Bool and Bool¥Bool are the pointed
cpos from our text.
(b) ≥: Nat¥Nat --> Bool, where Nat, Nat¥Nat and Bool are the pointed cpos from our text.

Partial preview of the text

Download Fibonacci Function and Recursive Program Fixpoints and more Assignments Programming Languages in PDF only on Docsity!

22C:185 — Fall 2004 Homework VIII 1 (corrected). [20 points] The Fibonacci numbers are defined by fib(0) = 0, fib(1) = 1, and fib(n) = fib(n-1) + fib(n-2) for n≥2. Consider the recursive program over all integers Z P: f(n) = if n=0 or n=1 then n else f(n-1) + f(n-2). (a) Show that the Fibonacci function fib (i.e., the partial function that is undefined for arguments less than 0) is a fixed point of the corresponding fixed point functional P, P(g) (n) = if n=0 or n=1 then n else g(n-1) + g(n-2). (b) Show that the total function h: Z-->Z is also a fixed point of P, where h is defined by h(n) = fib(n) if n≥0, h(n) = fib(-n) if n<0 and n odd, h(n) = -fib(-n) if n<0 and n even.

2. [25 points] Determine the least fixed point of the functional associated with the recursive function below (over all integers Z) and justify your answer. f(n) = if n>7 then n-5 else f(f(n+6)) 3. [20 points] Show that the following functions are continuous: (a) or: Bool¥Bool --> Bool (i.e., logical or), where Bool and Bool¥Bool are the pointed cpos from our text. (b) ≥: Nat¥Nat --> Bool, where Nat, Nat¥Nat and Bool are the pointed cpos from our text.