Docsity

Denotational Semantics of While Programs: A COP 5021 Example at UCF, 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 while programs
Let Sbe the while program
y:= 1; while ¬(x= 1) do (y:= y∗x;x:= x−1)
under the interpretation D=Nand I0(∗) = ∗,I0(−) = −and I0(n) = n, for
all n≥0).
Let γ6=⊥. Then,
φI(S)(γ) = φI(while ¬(x= 1) do (y:= y∗x;x:= x−1))(φI(y:= 1)(γ))
=φI(while ¬(x= 1) do (y:= y∗x;x:= x−1))(γ[y /I0(1)])
=φI(while ¬(x= 1) do (y:= y∗x;x:= x−1))(γ[y /1])
=µ(F)(γ[y/1]),
where F(f)(γ′) is given by
•F(f)(γ′) = f(φI(y:= y∗x;x:= x−1)(γ′)), if I(¬(x= 1))(γ′) = 1 and
γ′6=⊥;
•F(f)(γ′) = γ′, if I(¬(x= 1))(γ′) = 0 and γ′6=⊥;
•F(f)(γ′) = ⊥, if γ′=⊥,
for any f∈[Γ⊥→Γ⊥] and γ′∈Γ⊥.
Then,
•F(f)(γ′) = f(γ′[y/γ′(y)∗γ′(x)][x/(γ′[y/γ′(y)∗γ′(x)](x)−1)]), if γ′(x)6= 1
and γ′6=⊥;
•F(f)(γ′) = γ′, if γ′(x) = 1 and γ′6=⊥;
•F(f)(γ′) = ⊥, if γ′=⊥.
Let f0=⊥(Γ⊥→Γ⊥)be the least element of [Γ⊥→Γ⊥], i.e., the function given
by f0(γ′) = ⊥, for all γ′∈Γ⊥.
1
pf2

Partial preview of the text

Download Denotational Semantics of While Programs: A COP 5021 Example at UCF 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 while programs

Let S be the while program

y := 1; while ¬(x = 1) do (y := y ∗ x; x := x − 1)

under the interpretation D = N and I 0 (∗) = ∗, I 0 (−) = − and I 0 (n) = n, for all n ≥ 0). Let γ 6 = ⊥. Then,

φI (S)(γ) = φI (while ¬(x = 1) do (y := y ∗ x; x := x − 1))(φI (y := 1)(γ)) = φI (while ¬(x = 1) do (y := y ∗ x; x := x − 1))(γ[y/I 0 (1)]) = φI (while ¬(x = 1) do (y := y ∗ x; x := x − 1))(γ[y/1]) = μ(F )(γ[y/1]),

where F (f )(γ′) is given by

  • F (f )(γ′) = f (φI (y := y ∗ x; x := x − 1)(γ′)), if I(¬(x = 1))(γ′) = 1 and γ′^6 = ⊥;
  • F (f )(γ′) = γ′, if I(¬(x = 1))(γ′) = 0 and γ′^6 = ⊥;
  • F (f )(γ′) = ⊥, if γ′^ = ⊥,

for any f ∈ [Γ⊥→Γ⊥] and γ′^ ∈ Γ⊥. Then,

  • F (f )(γ′) = f (γ′[y/γ′(y)∗γ′(x)][x/(γ′y/γ′(y)∗γ′(x)−1)]), if γ′(x) 6 = 1 and γ′^6 = ⊥;
  • F (f )(γ′) = γ′, if γ′(x) = 1 and γ′^6 = ⊥;
  • F (f )(γ′) = ⊥, if γ′^ = ⊥.

Let f 0 = ⊥(Γ⊥→Γ⊥) be the least element of [Γ⊥→Γ⊥], i.e., the function given by f 0 (γ′) = ⊥, for all γ′^ ∈ Γ⊥.

We know that μ(F ) = sup({F n(f 0 )|n ≥ 0 }). We compute the elements of this chain:

F (f 0 )(γ′) =

⊥, if γ′(x) 6 = 1 γ′, if γ′(x) = 1

F 2 (f 0 )(γ′) =

⊥, if γ′(x) 6 = 1 and γ′(x) 6 = 2 γ′[y/γ′(y) ∗ 2][x/1], if γ′(x) = 2 γ′, if γ′(x) = 1

=

⊥, if γ′(x) 6 = 1 and γ′(x) 6 = 2 γ′[y/γ′(y) ∗ 2][x/1], if γ′(x) = 2 γ′[y/γ′(y) ∗ 1][x/1], if γ′(x) = 1

for any γ′. By mathematical induction we get:

F n(f 0 )(γ′) =

⊥, if γ′(x) < 1 or γ′(x) > n γ′[y/γ′(y) ∗ j ∗ · · · ∗ 2 ∗ 1][x/1], if γ′(x) = j and 1 ≤ j ≤ n,

for any γ′^ and n ≥ 1. Then,

μ(F )(γ′) =

⊥, if γ′(x) < 1 γ′[y/γ′(y) ∗ n ∗ · · · ∗ 2 ∗ 1][x/1], if γ′(x) = n ≥ 1 ,

for any γ′. Substituting γ′^ by γ[y/1] we get

μ(F )(γ[y/1]) =

⊥, if γ(x) < 1 γ[y/ 1 ∗ n ∗ · · · ∗ 2 ∗ 1][x/1], if γ(x) = n ≥ 1 ,

for any γ 6 = ⊥. Then, the semantics is:

M(S)(γ) =

γ[y/ 1 ∗ n ∗ · · · ∗ 2 ∗ 1][x/1], if γ(x) = n ≥ 1 undefined, if γ(x) < 1 ,

for any γ. For instance, if γ(x) = 5, then M(S)(γ) = 1 ∗ 5 ∗ 4 ∗ 3 ∗ 2 ∗ 1.