Nielson - Semantics With Applications An Appetizer
Nielson - Semantics With Applications An Appetizer
Applications, An Appetizer
1. Numerals
2. Variables
3. Arithmetic expressions
4. Boolean expressions
5. Statements.
B. The Meta-variables - notations that will be used to range over constructs of each
category.
C. The BNF:
2. x ::= to be given somewhere (e.g. strings of letters and digits starting with a
letter).
graph TD
S_root[S] --> S_1[S]
S_root[S] --> S_root_Semi[;]
S_root[S] --> S_2[S]
graph TD
S_root[S]
S_root --> S_init[S]
S_root --> S_root_semi[;]
S_root --> S_while[S]
[Notation] We use parentheses when emphasis is put on the linear notations, e.g. SWAP:
(z := x; x := y); y := z
[Notation] To cut down the use of parentheses, the customary binding powers (a.k.a
precedences) of +, ⋆, −etc., is placed.
For demonstration purpose, we only give semantic function for numerals in binary
numerals. It is easy to define the similar results for decimal numerals.
1. N [[0]] = 0
2. N [[1]] = 1
State = Var → Z , The states. To each variable a given state will associate its current
value.
(WIP)
(WIP)
[Notation] Abbreviation
(WIP)
1. A[[n]]s = N [[n]]
2. A[[x]]s = s x
4.
5.
T = {tt, ff}
1. B[[true]]s = tt
2. B[[false]]s = ff
B[[a1 = a2 ]]s
= {
4.
5.
6.
FV : Num∣Var∣Aexp∣Bexp → 2
Var
, The free variables in an expression.
[Definition]
(WIP)
(WIP)
[y ↦ a0 ] : Num∣Var∣Aexp∣Bexp → Num∣Var∣Aexp∣Bexp
, The substitution
for a variable y in an expression by another arithmetic expression a0 .
[Definition]
[Theorem] (Exercise 1.14) (Exercise 1.15) The relationship between substitutions and
updating:
3. Axiomatic semantics -
The rest of the rules has, within each of them, a set of premises, a conclusion
and a set of conditions.
loops, otherwise.
Two statements S1 and S2 are semantically equivalent iff for all states s, s′ we
[Definition] We say that ns - the relation →on Conf - is deterministic if for all
S , s, s1 , s2
we have ⟨S , s⟩
→ s1 and ⟨S , s⟩
→ s2 implies s1
= s2 .
For each statement S the partial function Sns [[S ]]is given by
′ ′
s , if ⟨S , s⟩ → s
Sns [[S ]]s = {
undef, otherwise
The relation ⇒can be composed with itself to produce new relation ⇒i and ⇒∗
where:
γ0 ⇒
i
γi means there are isteps in the execution from γ0 to γi .
γ0 ⇒
∗
γi means there are a finite number of steps from γ0 to γi .
[Definition] We say that sos - the relation ⇒on Conf - is deterministic if for all
S , s, γ1 , γ2 we have ⟨S , s⟩
⇒ γ1 and ⟨S , s⟩
⇒ γ2 implies γ1
= γ2 .
Two statements S1 and S2 are semantically equivalent iff for all states swe have
⟨S1 , s⟩ ⇒
∗
γ ≡ ⟨S2 , s⟩ ⇒
∗
γ . (both terminates with the same
For each statement S the partial function Ssos [[S ]]is given by
′ ∗ ′
s , if ⟨S , s⟩ ⇒ s
Ssos [[S ]]s = {
undef, otherwise
[Theorem] (Theorem 2.26) For every S of While, Sns [[S ]] = Ssos [[S ]]
.
= {
g2 s, if p s = ff
[Definition] The ordering ⊑on the partial functions Dom = State ↪ State
[Theorem] (Lemma 5.25) (Dom, ⊑) is a ccpo (chain complete partially ordered
set)
graph(⨆ Y ) = ⋃{ graph(g) ∣ g ∈ Y }
[Theorem] (Proposition 5.47) The semantics function Sds defined by Table 5.1
III - Assertions and the semantics and the axiomatic inference system ⊢p
[Definition] Predicates
Pred = State → T
Predicates calculus:
1. P1 ∧ P2
2. P1 ∨ P2
3. ¬P
4. P1 ⇒ P2
5. P [x ↦ A[[a]]]
3. B[[¬b]] = ¬B[[b]]
S the statement
Glossary
descriptive constructs or
name or abstraction properties
explanation definitions
a ::=
b ::=
S ::=
the semantic
N [[_]] : Num → Z function for
numerals
to each
variable the State =
determination
A[[_]] : Aexp → State → Z
of the value of
an arithmetic
A[[a]] : State → Z Table 1.1
expressions
under a
A[[a]]s : Z
specific state
determination
B[[_]] : Bexp → State → T
of the value of
a boolean
B[[b]] : State → T Table 1.2
expressions
under a
B[[b]]s : T
specific state
Lemma 1.12
FV : Aexp∣Bexp → Var free variables $1.4, page 16
Exercise 1.13
substitutions
[y ↦ a0 ] : Aexp → Aexp
for expressions
⟨S , s⟩ → s
′
6.
ff
[whilens ]
function for
Sns [[S ]] : State ↪ State
Natural
Semantics
Sns [[S ]]s : State ∪ {⊥}
⟨S0 , s0 ⟩ ⇒ ⟨S1 , s1 ⟩ ⇒ ⋯ ⇒ sn
1.
[asssos ]
2. Lemma 2.19
- derivation
[skip ] Exercise 2.20
sos
trees
3. Exercise 2.21
- derivation
[compsos ]
1
Exercise 2.22
sequences
4.
[compsos ]
2
5.
tt
[if ]
sos
6.
ff
[ifsos ]
7.
[whilesos ]
Lemma 2.27
Ssos [[S ]] : State ↪ State
Lemma 2.28
FIX :
(State ↪ State)
Running Examples
Swap/Exchange
Factorial