Semantics of Programming Languages Preliminary Exercises
Semantics of Programming Languages Preliminary Exercises
This exercise sheet is optional. It does not count towards exam admission.
Consider the While language introduced in the lectures. We define the big-step se-
mantics of arithmetic expressions as follows.
The semantics has two kinds of configurations:
The transition relation →Aexp has the form ⟨a, s⟩ →Aexp z. The semantics is given in
Table 1.
Show that this function is well defined by proving that for each a ∈ Aexp and each
s ∈ State there is exactly one value z ∈ Z such that ⟨a, s⟩ →Aexp z.
• Then, prove that the property holds for every composite expression a1 ∼ a2 , where
∼ ∈ {+, ∗, −}, using the assumption that it holds for a1 and a2 .
Exercise 2 Extension of Boolean expressions. Semantic equivalence.
Again consider the While language introduced in the lectures. The semantics of Boolean
expressions is given by the function
B⟦true⟧s = tt
B⟦f alse⟧s = ff
tt if A⟦a1 ⟧s = A⟦a2 ⟧s
B⟦a1 = a2 ⟧s = {
ff if A⟦a1 ⟧s ≠ A⟦a2 ⟧s
tt if A⟦a1 ⟧s ≤ A⟦a2 ⟧s
B⟦a1 ≤ a2 ⟧s = {
ff if A⟦a1 ⟧s > A⟦a2 ⟧s
tt if B⟦b⟧s = ff
B⟦¬b⟧s = {
ff if B⟦b⟧s = tt
tt if B⟦b1 ⟧s = tt and B⟦b2 ⟧s = tt
B⟦b1 ∧ b2 ⟧s = {
ff if B⟦b1 ⟧s = ff or B⟦b2 ⟧s = ff
Show that for each b′ of Bexp’ there exists a Boolean expression b of Bexp such
that b′ and b are equivalent.
Exercise 3 Substitution
A⟦n⟧s = N ⟦n⟧
A⟦x⟧s = sx
A⟦a1 + a2 ⟧s = A⟦a1 ⟧s + A⟦a2 ⟧s
A⟦a1 − a2 ⟧s = A⟦a1 ⟧s − A⟦a2 ⟧s
A⟦a1 ∗ a2 ⟧s = A⟦a1 ⟧s ∗ A⟦a2 ⟧s
n[y ↦ a0 ] = n
a0 if x = y
x[y ↦ a0 ] = {
x if x ≠ y
(a1 + a2 )[y ↦ a0 ] = a1 [y ↦ a0 ] + a2 [y ↦ a0 ]
(a1 ∗ a2 )[y ↦ a0 ] = a1 [y ↦ a0 ] ∗ a2 [y ↦ a0 ]
(a1 − a2 )[y ↦ a0 ] = a1 [y ↦ a0 ] − a2 [y ↦ a0 ]
v if x = y
(s[y ↦ v])x = { where y ∈ Var, v ∈ Z.
s x if x ≠ y
[iffsos
f
] ⟨if b then S1 else S2 , s⟩ ⇒ ⟨S2 , s⟩ if B⟦b⟧s = ff
Prove that the semantics is deterministic, i.e., for all choices of S, s, γ and γ ′ we have
that if ⟨S, s⟩ ⇒ γ and ⟨S, s⟩ ⇒ γ ′ then γ = γ ′ .
• Prove that the property holds for all axioms of the inference system.
• Prove that the property holds for all rules of the inference system: For each rule
assume that the property holds for its premises. From this assumption, show that
it also holds for the conclusion of the rule provided that the conditions of the rule
are satisfied.