Professional Documents
Culture Documents
J. Carette
McMaster University
Fall 2023
“In modern languages, the type system is often taken as the foundation
of the language’s design, and the organizing principle, in light of which
every other aspect of the design is considered.” (Pierce, 2002)
⟨digit⟩ ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
.........................................................................
Here, we have two rules. The top level rule, <Integer>, and a
sub-rule, <digit>.
“|” denotes a set of options. For example, <digit> can be any of the
numbers indicated, but no others.
“[]” denote something which is optional. For example, the negative
sign denoting a negative integer may be absent.
“{}” denote zero or more repetitions of the contents. For example, zero
or more digits may follow the first.
.........................................................................
⟨t⟩ ::= true
| false
| if ⟨t⟩ then ⟨t⟩ else ⟨t⟩
| 0
| succ ⟨t⟩
| pred ⟨t⟩
| iszero ⟨t⟩
.........................................................................
t is a metavariable.
EBNF is a metalanguage (a language which describes languages), and
t is a variable of that language.
t∈T
succ t ∈ T pred t ∈ T iszero t ∈ T
t1 ∈ T t2 ∈ T t3 ∈ T
if t1 then t2 else t3 ∈ T
S0 = ∅
Si+1 = {true, false, 0}
∪ {t ∈ Si | succ t, pred t, iszero t}
∪ {t1 , t2 , t3 ∈ Si |if t1 then t2 else t3 }
And let
[
S= Si
i
With these new definitions, we can now introduce three exciting new forms
of induction!
[Induction on Size] [Induction on depth]
If, for s ∈ T If, for s ∈ T
▶ Given P(r ) for all r such that ▶ Given P(r ) for all r such that
size(r ) < size(s) depth(r ) < depth(s)
▶ we can show P(s) ▶ we can show P(s)
We may conclude ∀s ∈ T | P(s) We may conclude ∀s ∈ T | P(s)
These two forms of induction are derived from Complete Induction over N
1
By you! During an assignment!
J. Carette (McMaster University) Towards the Lambda Calculus Fall 2023 17 / 36
Operational Semantics
Big Step
Small Step
A single transition within the abstract
For each state, gives either the results
of a single simplification, or indicates machine evaluates the term to its final
the machine has halted. result.
Sometimes, we will use two different operational semantics for the same
language. For example:
One might be abstract, on the terms of the language as used by the
programmer.
Another might represent the structures used by the compiler/interpreter.
In the above case, proving correspondance between these two machines is
proving the correctness of an implementation of the language, i.e., proving
the correctness of the compiler itself.
if true then (if false then false else false) else true (4)
Let’s set t to the inner if expression so the derivation tree fits on the page:
if (if true then false else true) then true else false (6)
THEOREM :
[Determinacy of One-Step Evaluation]
t → t ′ ∧ t → t ′′ =⇒ t ′ = t ′′ (8)
That is to say, if a term t evaluates to t ′ , and the same term evaluates to t ′′ ,
t ′ and t ′′ must be the same term.
By induction on the derivation of t → t ′ .
But what about the the halting problem ? Rough answer: it’s easy to use
types to keep it at bay.
t → t ′ =⇒ t →∗ t ′ (10)
∀t ∈ T | t →∗ t (11)
t →∗ t ′ ∧ t ′ →∗ t ′′ =⇒ t →∗ t ′′ (12)
t →∗ u ∧ t →∗ u ′ =⇒ u = u ′ (13)
Proof idea:
single-step is unique
can’t have multiple normal forms in a path of →∗ (by definition, normal
forms don’t evaluate).
∀t ∈ T ∃t ′ ∈ N |t →∗ t ′ (14)
Where N is the set of normal forms of T .
Useful: LEMMA :
E-IsZero!
We can’t use E-IsZeroSucc, because succ pred succ 0 is not a value.
If E-IsZeroSucc did not require a numeric value, the rule would also
apply to evaluatable succ terms.
This would cause a rather nasty ambiguity, destroying our language’s
determinacy! Basically...
t → t ′ ∧ t → t ′′ no longer implies t ′ = t ′′ (16)
This is bad language design, even if multi-step semantics might still turn out
fine.