Docsity

Homework IX: Recursive Functions and Monotone Functions in Pointed Complete Partial Orders, Assignments of Programming Languages

Toggle sidebar
bg1
22C:185 — Fall 2004
Homework IX
1. [15 points]
Consider the recursive program over all integers Z
P: f(x,y) = if x>10 then x-1 else f(x+2, f(x,y+1)).
Determine the least fixed point of the functional P (i.e., the recursive function defined
using lazy evaluation) and justify your answer.
2. [20 points]
(a) Show that if X is a pointed cpo, C is a chain of X, and f: X ‡ X is a monotone
function whose domain includes C, then f(C) = {f(x) | xŒC} is also a chain.
(b) Suppose we define a function mp: Nat¥Nat ‡ Nat, where Nat, and Nat¥Nat are the
pointed cpos from our text, by
mp(^Nat,^Nat) = ^Nat,
mp(0,^Nat) = 0,
mp(^Nat,0) = 0, and
mp(m,n) = m*n for m,nŒ{0,1,2, … }.
Determine whether or not mp is monotone and continuous (justify your answer).
3. [25 points]
Let p be the Wren program fragment
if A=B or A=-B
then if A>B then C:= A else C:= B-A+1 end if
else if A*B>0 then C:= A*B else C:= 1-A*B end if
end if
Assuming a store, sto, where sto(A) and sto(B) denote (positive, negative, or zero)
integer values, use the denotational semantics of Wren to argue that if execute[p] sto =
sto', then sto'(C)=int(c) with c> 0.

Partial preview of the text

Download Homework IX: Recursive Functions and Monotone Functions in Pointed Complete Partial Orders and more Assignments Programming Languages in PDF only on Docsity!

22C:185 — Fall 2004 Homework IX

1. [15 points] Consider the recursive program over all integers Z P: f(x,y) = if x>10 then x-1 else f(x+2, f(x,y+1)). Determine the least fixed point of the functional P (i.e., the recursive function defined using lazy evaluation) and justify your answer. 2. [20 points] (a) Show that if X is a pointed cpo, C is a chain of X, and f: X ‡ X is a monotone

function whose domain includes C, then f(C) = {f(x) | xŒC} is also a chain.

(b) Suppose we define a function mp: Nat¥Nat ‡ Nat, where Nat, and Nat¥Nat are the pointed cpos from our text, by mp(^Nat,^Nat) = ^Nat, mp(0,^Nat) = 0, mp(^Nat,0) = 0, and mp(m,n) = m*n for m,nŒ{0,1,2, … }. Determine whether or not mp is monotone and continuous (justify your answer).

3. [25 points] Let p be the Wren program fragment if A=B or A=-B then if A>B then C:= A else C:= B-A+1 end if else if AB>0 then C:= AB else C:= 1-A*B end if end if Assuming a store, sto, where sto(A) and sto(B) denote (positive, negative, or zero) integer values, use the denotational semantics of Wren to argue that if execute[p] sto = sto', then sto'(C)=int(c) with c> 0.