

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Dr. Ferucio Laurent¸iu T¸ IPLEA Visiting Professor School of Computer Science University of Central Florida CSB # Orlando, FL 32816- Tel: (407) 823- E-mail: [email protected]
COP 5021 (Program Analysis) Spring 2006
Let (S, 1) be the recursive program
F 1 (x) ⇐ if x = 0 then 0 else F 2 (x − 1) F 2 (x) ⇐ if x = 0 then 1 else F 1 (x − 1)
under the standard interpretation on N⊥ (i.e., D⊥ = N⊥). The λ-terms associated to the program are
T 1 = [λF 1 , F 2 .[λx.if x = 0 then 0 else F 2 (x − 1)]]
and T 2 = [λF 1 , F 2 .[λx.if x = 0 then 1 else F 1 (x − 1)]].
Their types are
τ 1 = τ 2 = ((nat→nat), (nat→nat)→(nat→nat)),
and the corresponding domains are
Dτ 1 = Dτ 2 = [[N⊥→N⊥] × [N⊥→N⊥]→[N⊥→N⊥]].
The semantic function of the program is
φI (S, 1) = (I(T 1 )(γ), I(T 2 )(γ)),
where γ is an arbitrary but fixed assignment. The lest fixed point of the semantic function is the supremum of the following chain: L = {φI (S, 1)n(⊥(N⊥→N⊥), ⊥(N⊥ →N⊥ ))|n ≥ 0 },
where ⊥(N⊥ →N⊥ ) is the least element of [N⊥→N⊥], that is, the function which maps each x ∈ N⊥ to ⊥. Denote:
We have: f 1 (k) = I(T 1 )(γ)(f 0 , g 0 )(k) = I(T 1 )(γ[F 1 /f 0 ][F 2 /g 0 ][x/k]) = if k = 0 then 0 else g 0 (k − 1) = if k = 0 then 0 else ⊥
g 1 (k) = I(T 2 )(γ)(f 0 , g 0 )(k) = I(T 2 )(γ[F 1 /f 0 ][F 2 /g 0 ][x/k]) = if k = 0 then 1 else f 0 (k − 1) = if k = 0 then 1 else ⊥
f 2 (k) = I(T 1 )(γ)(f 1 , g 1 )(k) = I(T 1 )(γ[F 1 /f 1 ][F 2 /g 1 ][x/k]) = if k = 0 then 0 else g 1 (k − 1) = if k = 0 then 0 else if k − 1 = 0 then 1 else ⊥ = if k = 0 then 0 else if k = 1 then 1 else ⊥
g 2 (k) = I(T 2 )(γ)(f 1 , g 1 )(k) = I(T 2 )(γ[F 1 /f 1 ][F 2 /g 1 ][x/k]) = if k = 0 then 1 else f 1 (k − 1) = if k = 0 then 1 else if k − 1 = 0 then 0 else ⊥ = if k = 0 then 1 else if k = 1 then 0 else ⊥
f 3 (k) = I(T 1 )(γ)(f 2 , g 2 )(k) = I(T 1 )(γ[F 1 /f 2 ][F 2 /g 2 ][x/k]) = if k = 0 then 0 else g 2 (k − 1) = if k = 0 then 0 else if k − 1 = 0 then 1 else if k − 1 = 1 then 0 else ⊥ = if k = 0 then 0 else if k = 1 then 1 else if k = 2 then 0 else ⊥
g 3 (k) = I(T 2 )(γ)(f 2 , g 2 )(k) = I(T 2 )(γ[F 1 /f 2 ][F 2 /g 2 ][x/k]) = if k = 0 then 1 else f 2 (k − 1) = if k = 0 then 1 else if k − 1 = 0 then 0 else if k − 1 = 1 then 1 else ⊥ = if k = 0 then 1 else if k = 1 then 0 else if k = 2 then 1 else ⊥
for any k ∈ N⊥. By mathematical induction we can easily show that
fn(k) =
0 , if k < n is even 1 , if k < n is odd ⊥, otherwise