Big-step semantics for While
Mechanizing mathematical theory of programming
languages: Operational semantics of WHILE in COQ
Lecture 2 on 05.06.2013
Compositional definition (1)
The syntactic category is specified by an abstract syntax giving
• the basis elements, and
• the composite elements.
The composite elements have a unique decomposition into
their immediate constituents.
Compositional definition (2)
The semantics is defined by compositional definitions of a
function:
There is a semantic clause for
• each of the basis elements of the syntactic category, and
• each of the methods for constructing composite elements.
The clauses for composite elements are defined in terms of the
semantics of the immediate constituents of the elements.
Free variables
Properties of expressions
The free variables of an arithmetic expression a, FV(a), is the
set of variables occurring in it.
FV(a) is defined by structural induction over a.
FV(n)
FV(x)
FV(a1 + a2 )
FV(a1 ∗ a2 )
FV(a1 − a2 )
=
=
=
=
=
∅
{x}
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
The definition is compositional.
E.g., FV(x + 1) =?, FV(x + y ∗ x) =?.
Structural induction
1. Prove that the property holds for all the basis elements of
the syntactic category.
2. Prove that the property holds for all the composite
elements of the syntactic category:
• Assume that the property holds for all the immediate
constituents of the element (induction hypothesis).
• Prove that the property holds for the element itself.
Property of free variables
The value of an expression a only depends on the values of
variables in FV(a).
Lemma
For any a and σ, σ 0 such that, for all x ∈ FV(a), σ x = σ 0 x, we
have that AJaKσ = AJaKσ 0 .
Proof. By structural induction over a.
(On the black board.)
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true) = ∅
FV(false) = ∅
FV(a1 = a2 ) =
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true) = ∅
FV(false) = ∅
FV(a1 = a2 ) = FV(a1 ) ∪ FV(a2 )
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
= ∅
= ∅
= FV(a1 ) ∪ FV(a2 )
=
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
FV(¬b)
=
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
FV(¬b)
=
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
FV(b)
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
FV(¬b)
FV(b1 ∧ b2 )
=
=
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
FV(b)
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
FV(¬b)
FV(b1 ∧ b2 )
=
=
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
FV(b)
FV(b1 ) ∪ FV(b2 )
Free variables of boolean expressions
Similarly, the free variables of a boolean expression b, FV(b) is
defined by structural induction over b.
FV(true)
FV(false)
FV(a1 = a2 )
FV(a1 ≤ a2 )
FV(¬b)
FV(b1 ∧ b2 )
=
=
=
=
=
=
∅
∅
FV(a1 ) ∪ FV(a2 )
FV(a1 ) ∪ FV(a2 )
FV(b)
FV(b1 ) ∪ FV(b2 )
Lemma
For any b and σ, σ 0 such that, for all x ∈ FV(b), σ x = σ 0 x, we
have BJbKσ = BJbKσ 0 .
Substitutions
Substitution of an arithmetic expression a at a variable y by an
arithmetic expression a0 , a[y 7→ a0 ], replaces every occurrence
of y in a by a0 .
a[y 7→ a0 ] is defined by structural induction over a.
n[y 7→ a0 ] = n
a0
x[y 7→ a0 ] =
x
(a1 + a2 )[y 7→ a0 ] = (a1 [y
(a1 ∗ a2 )[y 7→ a0 ] = (a1 [y
(a1 − a2 )[y 7→ a0 ] = (a1 [y
if x = y
if x 6= y
7→ a0 ]) + (a2 [y 7→ a0 ])
7→ a0 ]) ∗ (a2 [y 7→ a0 ])
7→ a0 ]) − (a2 [y 7→ a0 ])
E.g., (x + 1)[x 7→ 3] =?, (x + y ∗ x)[x 7→ y − 5] =?.
Property of substitution
We define update of a state σ by a value v at y , σ[y 7→ v ] by
v
if x = y
(σ[y 7→ v ]) x =
σ x if x 6= y
Property of substitution
We define update of a state σ by a value v at y , σ[y 7→ v ] by
v
if x = y
(σ[y 7→ v ]) x =
σ x if x 6= y
Lemma
For any a, y , a0 and σ, AJa[y 7→ a0 ]Kσ = AJaK(σ[y 7→ AJa0 Kσ]).
Proof. By structural induction over a.
(On the black board.)
Operational semantics
We look at two approaches to operational semantics.
• Natural semantics (or big-step semantics), describing how
the overall results of executions are obtained.
• Structural operational semantics (or small-step semantics),
describing how the individual steps of the computations
take place.
Operational semantics
We look at two approaches to operational semantics.
• Natural semantics (or big-step semantics), describing how
the overall results of executions are obtained.
• Structural operational semantics (or small-step semantics),
describing how the individual steps of the computations
take place.
Both kinds of operational semantics are specified by a
transition system, with two configurations:
• hS, σi, representing that the statement S is to be executed
from the state σ, and
• σ, representing a terminal state.
Natural semantics
The judgment hS, σi → σ 0 states that running the statement S
from the initial state σ terminates in the final state σ 0 .
Natural semantics for While
hx := a, σi → σ[x 7→ AJaKσ] (N-ass)
hskip, σi → σ (N-skip)
hS1 , σi → σ 0 hS2 , σ 0 i → σ 00
(N-seq)
hS1 ; S2 , σi → σ 00
BJbKσ = true hS1 , σi → σ 0
(N-if-tt)
hif b then S1 else S2 , σi → σ 0
BJbKσ = false hS2 , σi → σ 0
(N-if-ff)
hif b then S1 else S2 , σi → σ 0
BJbKσ = true hS, σi → σ 0 hwhile b do S, σ 0 i → σ 00
(N-while-tt)
hwhile b do S, σi → σ 00
BJbKσ = false
(N-while-ff)
hwhile b do S, σi → σ
Examples
h(z := x; x := y); y := z, σi → σ[x 7→ 7, y 7→ 5, z 7→ 5]
where σ x = 5 and σ y = 7.
Examples
h(z := x; x := y); y := z, σi → σ[x 7→ 7, y 7→ 5, z 7→ 5]
where σ x = 5 and σ y = 7.
hy := 1; while ¬(x = 1) do (y := y ∗ x; x := x − 1), σi → ?
where σ x = 3.
(over to Coq)
Induction on natural numbers
Review
Let P(n) be a proposition involving a natural number n.
We want to show ∀n. P(n) by induction on n.
We do so by
1. show that P(0) holds;
2. show that, for any n0 , if P(n0 ) holds then so does P(S n0 ).
This concludes that P(n) holds for all n.
© Copyright 2026 Paperzz