Acce Notes 0 2
Acce Notes 0 2
Table of Contents
Σ = {“x ” 7→ Z, “y ” 7→ Z} :
i = {“x ” 7→ 10, “y ” 7→ 5} : Σ
o = {“x ” 7→ 6, “y ” 7→ 5} : Σ
is a behaviour.
(c) Theodore Norvell, adapted by Reza Shahidi
Advanced Computing Concepts for Engineering, 2024. Slide Set 0-2 Imperative Programming
Transformational Imperative Programming Programming Constructs
Table of Contents
Syntax (Form)
skipΣ†Σ Skip
V :=Σ†Σ E Assignment
V0 , V1 , ..., Vk :=Σ†Σ E0 , E1 , ..., Ek Parallel asignment
fΣ†Σ ; gΣ†Σ Sequential composition
if B then fΣ†Σ else gΣ†Σ Alternation
while B do fΣ†Σ Iteration
(fΣ†Σ ) Grouping
where
V and each Vi is a variable name mapped in Σ
E is an expression of type Σ(V)
each Ei is an expression of type Σ(Vi )
B is an expression of type B.
fΣ†Σ and gΣ†Σ are specifications
(c) Theodore Norvell, adapted by Reza Shahidi
Advanced Computing Concepts for Engineering, 2024. Slide Set 0-2 Imperative Programming
Transformational Imperative Programming Programming Constructs
Syntax (Form)
Semantics (Meaning)
Semantics (Meaning)
Semantics (Meaning)
Semantics (Meaning)
Semantics (Meaning)
Example
Suppose that Σ maps names “x ”, “y ”, and “z ”.
x := x − 1; y := 2 × x
= “definition of assignment”
⟨ 0 ⟩
x = x − 1 ∧ y 0 = y ∧ z0 = z ;
⟨ 0 ⟩
x = x ∧ y 0 = 2 × x ∧ z0 = z
= “definition of sequential composition”
⟨ (x 0 = x − 1 ∧ y 0 = y ∧ z 0 = z ) ⟩
[x 0 , y 0 , z 0 : ẋ , ẏ , ż ]
∃ẋ , ẏ , ż ·
∧ (x = x ∧ y = 2 × x ∧ z 0 = z )
0 0
[x , y , z : ẋ , ẏ , ż ]
= “making the substitutions”
⟨ ( )⟩
(ẋ = x − 1 ∧ ẏ = y ∧ ż = z )
∃ẋ , ẏ , ż ·
∧ (x 0 = ẋ ∧ y 0 = 2 × ẋ ∧ z 0 = ż )
(c) Theodore Norvell, adapted by Reza Shahidi
Advanced Computing Concepts for Engineering, 2024. Slide Set 0-2 Imperative Programming
Transformational Imperative Programming Programming Constructs
Semantics (Meaning)
= “one-point law”
⟨ 0 ⟩
x = x − 1 ∧ y 0 = 2 × (x − 1) ∧ z 0 = z
Semantics (Meaning)
Semantics (Meaning)
to be
(hAi ∧ f ) ∨ (¬ hAi ∧ g )
Exercise. Show that
Semantics (Meaning)
Example
Semantics (Meaning)
= “Distributivity”
⟨( ) ⟩
(y < x ∧ x 0 = y 0 = y ) 0
∧z =z
∨ (y ≥ x ∧ x 0 = y 0 = x )
= “Definition of min ”
⟨ 0 ⟩
x = y 0 = min(x , y ) ∧ z 0 = z
Semantics (Meaning)