Docsity

Example: Denotational Semantics of Recursive Programs | COP 5021, Study notes of Computer Science

Toggle sidebar
bg1
Dr. Ferucio Laurent¸iu T¸ IPLEA
Visiting Professor
School of Computer Science
University of Central Florida
CSB #205
Orlando, FL 32816-2362
Tel: (407) 823-1593
COP 5021 (Program Analysis)
Spring 2006
Example: denotational semantics of recursive programs
Let (S, 1) be the recursive program
(S, 1) F1(x)⇐if x = 0 then 0else F2(x−1)
F2(x)⇐if x = 0 then 1else F1(x−1)
under the standard interpretation on N⊥(i.e., D⊥=N⊥).
The λ-terms associated to the program are
T1= [λF1, F2.[λx.if x = 0 then 0else F2(x−1)]]
and
T2= [λF1, F2.[λx.if x = 0 then 1else F1(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(T1)(γ),I(T2)(γ)),
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:
•f0is the function ⊥(N⊥→N⊥);
1
pf3

Partial preview of the text

Download Example: Denotational Semantics of Recursive Programs | COP 5021 and more Study notes Computer Science in PDF only on Docsity!

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

Example: denotational semantics of recursive programs

Let (S, 1) be the recursive program

(S, 1)

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:

  • f 0 is the function ⊥(N⊥ →N⊥);
  • φI (S, 1)n(f 0 , g 0 ) = (fn, gn), for any n ≥ 0, where g 0 = f 0. Moreover, fn = I(T 1 )(γ)(fn− 1 , gn− 1 ) and gn = I(T 2 )(γ)(fn− 1 , gn− 1 ), for any n ≥ 1.

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