Semantics Liam OConnor CSE, UNSW (and data61) Term3 2019 1 - - PowerPoint PPT Presentation

semantics liam o connor
SMART_READER_LITE
LIVE PREVIEW

Semantics Liam OConnor CSE, UNSW (and data61) Term3 2019 1 - - PowerPoint PPT Presentation

Overview Operational Semantics Equivalence Proof Semantics Liam OConnor CSE, UNSW (and data61) Term3 2019 1 Overview Operational Semantics Equivalence Proof Misc The midsession exam is on at 11am, Fri 11th of October, 2019 . It should


slide-1
SLIDE 1

Overview Operational Semantics Equivalence Proof

Semantics Liam O’Connor

CSE, UNSW (and data61) Term3 2019

1

slide-2
SLIDE 2

Overview Operational Semantics Equivalence Proof

Misc

The midsession exam is on at 11am, Fri 11th of October, 2019. It should last for 50 minutes. You must be seated in your assigned location by 11:05am. The exam will start right at that time. You may bring one, single-sided a4 sheet of paper with hand-written notes. A sample midsession paper has been provided. There are two venues for the exam. You will be assigned a venue automatically, and can check which venue you have been assigned to on the course website. The venues are OMB 149 (normal lecture theatre), and CLB

  • 2. Don’t be late! Figure out where your venue is ahead of

time! Marks will be returned to you before the census date.

2

slide-3
SLIDE 3

Overview Operational Semantics Equivalence Proof

Semantics

Semantics Scopes σηµαντιχως

3

slide-4
SLIDE 4

Overview Operational Semantics Equivalence Proof

Semantics

Scopes Static Dynamic σηµαντιχως

4

slide-5
SLIDE 5

Overview Operational Semantics Equivalence Proof

Semantics

Scopes Static Dynamic Types Scopes σηµαντιχως

5

slide-6
SLIDE 6

Overview Operational Semantics Equivalence Proof

Semantics

Scopes Static Dynamic Types Scopes Behaviour Cost σηµαντιχως

6

slide-7
SLIDE 7

Overview Operational Semantics Equivalence Proof

Static Semantics

Definition The static semantics of a program is those significant aspects of the meaning of P that can be determined by the compiler (or an external lint tool) without running the program. Recall our arithmetic expression language. What properties might we derive statically about those terms?

7

slide-8
SLIDE 8

Overview Operational Semantics Equivalence Proof

Static Semantics

Definition The static semantics of a program is those significant aspects of the meaning of P that can be determined by the compiler (or an external lint tool) without running the program. Recall our arithmetic expression language. What properties might we derive statically about those terms? The only thing we can check is that the program is well-scoped (assuming FOAS).

8

slide-9
SLIDE 9

Overview Operational Semantics Equivalence Proof

Scope-Checking

(Num n) ok e1 ok e2 ok (Times e1 e2) ok e1 ok e2 ok (Plus e1 e2) ok Γ ⊢ (Var x) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

slide-10
SLIDE 10

Overview Operational Semantics Equivalence Proof

Scope-Checking

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok Γ ⊢ (Var x) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

10

slide-11
SLIDE 11

Overview Operational Semantics Equivalence Proof

Scope-Checking

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

11

slide-12
SLIDE 12

Overview Operational Semantics Equivalence Proof

Scope-Checking

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ (Let x e1 e2) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

12

slide-13
SLIDE 13

Overview Operational Semantics Equivalence Proof

Scope-Checking

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok Γ ⊢ (Let x e1 e2) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

13

slide-14
SLIDE 14

Overview Operational Semantics Equivalence Proof

Scope-Checking

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok Key Idea We keep a context Γ, a set of assumptions, on the left hand of our judgement e ok, indicating what is required in order for e to be well-scoped. This could be read as hypothetical derivations for the judgement e ok or as a binary judgement Γ ⊢ e ok; whichever you prefer.

14

slide-15
SLIDE 15

Overview Operational Semantics Equivalence Proof

Scope-Checking Example

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok

⊢ (Let "x" (N 3) (Let "y" (N 4) (Plus (V "x") (V "y"))))

15

slide-16
SLIDE 16

Overview Operational Semantics Equivalence Proof

Scope-Checking Example

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok

⊢ (N 3) ⊢ (Let "x" (N 3) (Let "y" (N 4) (Plus (V "x") (V "y"))))

16

slide-17
SLIDE 17

Overview Operational Semantics Equivalence Proof

Scope-Checking Example

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok

⊢ (N 3) "x" ⊢ (Let "y" (N 4) (Plus (V "x") (V "y"))) ⊢ (Let "x" (N 3) (Let "y" (N 4) (Plus (V "x") (V "y"))))

17

slide-18
SLIDE 18

Overview Operational Semantics Equivalence Proof

Scope-Checking Example

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok

⊢ (N 3) "x" ⊢ (N 4) "y" , "x" ⊢ (Plus (V "x") (V "y")) "x" ⊢ (Let "y" (N 4) (Plus (V "x") (V "y"))) ⊢ (Let "x" (N 3) (Let "y" (N 4) (Plus (V "x") (V "y"))))

18

slide-19
SLIDE 19

Overview Operational Semantics Equivalence Proof

Scope-Checking Example

Γ ⊢ (Num n) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Times e1 e2) ok Γ ⊢ e1 ok Γ ⊢ e2 ok Γ ⊢ (Plus e1 e2) ok (x bound) ∈ Γ Γ ⊢ (Var x) ok Γ ⊢ e1 ok x bound, Γ ⊢ e2 ok Γ ⊢ (Let x e1 e2) ok

⊢ (N 3) "x" ⊢ (N 4) "y" , "x" ⊢ (V "x") "y" , "x" ⊢ (V "y") "y" , "x" ⊢ (Plus (V "x") (V "y")) "x" ⊢ (Let "y" (N 4) (Plus (V "x") (V "y"))) ⊢ (Let "x" (N 3) (Let "y" (N 4) (Plus (V "x") (V "y"))))

19

slide-20
SLIDE 20

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be speciified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical object for each form of syntax. COMP6752

20

slide-21
SLIDE 21

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be speciified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical object for each form of syntax. COMP6752

2

Axiomatic Semantics is the construction of a proof calculus to allow correctness of a program to be verified. COMP2111

21

slide-22
SLIDE 22

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be speciified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical object for each form of syntax. COMP6752

2

Axiomatic Semantics is the construction of a proof calculus to allow correctness of a program to be verified. COMP2111

3

Operational Semantics is the construction of a program-evaluating state machine or transition system.

22

slide-23
SLIDE 23

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be speciified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical object for each form of syntax. COMP6752

2

Axiomatic Semantics is the construction of a proof calculus to allow correctness of a program to be verified. COMP2111

3

Operational Semantics is the construction of a program-evaluating state machine or transition system. In this course We focus mostly on operational semantics. We will use axiomatic semantics (Hoare Logic) on Thursday in the imperative programming topic. Denotational semantics are mostly an extension topic, except for the very next slide.

23

slide-24
SLIDE 24

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → Num n = Var x = Plus e1 e2 = Times e1 e2 = Let x e1 e2 =

24

slide-25
SLIDE 25

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → Z Num n = n Var x = Plus e1 e2 = Times e1 e2 = Let x e1 e2 =

25

slide-26
SLIDE 26

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → (Var Z) → Z Our denotation for arithmetic expressions is functions from environments (mapping from variables to their values) to values. Num n = λE. n Var x = λE. E(x) Plus e1 e2 = λE. Times e1 e2 = λE. Let x e1 e2 = λE.

26

slide-27
SLIDE 27

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → (Var Z) → Z Our denotation for arithmetic expressions is functions from environments (mapping from variables to their values) to values. Num n = λE. n Var x = λE. E(x) Plus e1 e2 = λE. e1 e2 Times e1 e2 = λE. e1 e2 Let x e1 e2 = λE.

27

slide-28
SLIDE 28

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → (Var Z) → Z Our denotation for arithmetic expressions is functions from environments (mapping from variables to their values) to values. Num n = λE. n Var x = λE. E(x) Plus e1 e2 = λE. e1E + e2E Times e1 e2 = λE. e1E × e2E Let x e1 e2 = λE.

28

slide-29
SLIDE 29

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → (Var Z) → Z Our denotation for arithmetic expressions is functions from environments (mapping from variables to their values) to values. Num n = λE. n Var x = λE. E(x) Plus e1 e2 = λE. e1E + e2E Times e1 e2 = λE. e1E × e2E Let x e1 e2 = λE. e2 (E[x := e1E]) Where E[x := n] is a new environment just like E except the variable x now maps to n.

29

slide-30
SLIDE 30

Overview Operational Semantics Equivalence Proof

Operational Semantics

There are two main kinds of operational semantics.

Small Step Small Step Big Step Big Step

30

slide-31
SLIDE 31

Overview Operational Semantics Equivalence Proof

Operational Semantics

There are two main kinds of operational semantics.

Small Step Small Step Big Step Big Step

Also called natural or evaluation semantics. One big judgement relating expressions to their values:

e ⇓ v

31

slide-32
SLIDE 32

Overview Operational Semantics Equivalence Proof

Operational Semantics

There are two main kinds of operational semantics.

Small Step Small Step Big Step Big Step

Also called natural or evaluation semantics. One big judgement relating expressions to their values:

e ⇓ v

Also called structural

  • perational

semantics (SOS). A judgement that specifies transitions between states:

e → e′

32

slide-33
SLIDE 33

Overview Operational Semantics Equivalence Proof

Big-Step Semantics

We need: A set of evaluable expressions E A set of values V A relation ⇓ ⊆ E × V Example (Arithmetic Expressions) E is the set of all closed expressions {e | e ok}. V is the set of integers Z. (Num n) ⇓ n e1 ⇓ v1 e2 ⇓ v2 (Plus e1 e2) ⇓ (v1 + v2) e1 ⇓ v1 e2 ⇓ v2 (Times e1 e2) ⇓ (v1 × v2)

To Code Let’s do it in Haskell!

slide-34
SLIDE 34

Overview Operational Semantics Equivalence Proof

Big-Step Semantics

We need: A set of evaluable expressions E A set of values V A relation ⇓ ⊆ E × V Example (Arithmetic Expressions) E is the set of all closed expressions {e | e ok}. V is the set of integers Z. (Num n) ⇓ n e1 ⇓ v1 e2 ⇓ v2 (Plus e1 e2) ⇓ (v1 + v2) e1 ⇓ v1 e2 ⇓ v2 (Times e1 e2) ⇓ (v1 × v2)

To Code Let’s do it in Haskell! 34

slide-35
SLIDE 35

Overview Operational Semantics Equivalence Proof

Big-Step Semantics

We need: A set of evaluable expressions E A set of values V A relation ⇓ ⊆ E × V Example (Arithmetic Expressions) E is the set of all closed expressions {e | e ok}. V is the set of integers Z. (Num n) ⇓ n (Let e1 (x. e2)) ⇓ e1 ⇓ v1 e2 ⇓ v2 (Plus e1 e2) ⇓ (v1 + v2) e1 ⇓ v1 e2 ⇓ v2 (Times e1 e2) ⇓ (v1 × v2)

To Code Let’s do it in Haskell! 35

slide-36
SLIDE 36

Overview Operational Semantics Equivalence Proof

Big-Step Semantics

We need: A set of evaluable expressions E A set of values V A relation ⇓ ⊆ E × V Example (Arithmetic Expressions) E is the set of all closed expressions {e | e ok}. V is the set of integers Z. (Num n) ⇓ n e1 ⇓ v1 (Let e1 (x. e2)) ⇓ e1 ⇓ v1 e2 ⇓ v2 (Plus e1 e2) ⇓ (v1 + v2) e1 ⇓ v1 e2 ⇓ v2 (Times e1 e2) ⇓ (v1 × v2)

To Code Let’s do it in Haskell! 36

slide-37
SLIDE 37

Overview Operational Semantics Equivalence Proof

Big-Step Semantics

We need: A set of evaluable expressions E A set of values V A relation ⇓ ⊆ E × V Example (Arithmetic Expressions) E is the set of all closed expressions {e | e ok}. V is the set of integers Z. (Num n) ⇓ n e1 ⇓ v1 e2[x := (Num v1)] ⇓ v2 (Let e1 (x. e2)) ⇓ v2 e1 ⇓ v1 e2 ⇓ v2 (Plus e1 e2) ⇓ (v1 + v2) e1 ⇓ v1 e2 ⇓ v2 (Times e1 e2) ⇓ (v1 × v2)

To Code Let’s do it in Haskell! 37

slide-38
SLIDE 38

Overview Operational Semantics Equivalence Proof

Evaluation Strategies

e1 ⇓ v1 e2[x := (Num v1)] ⇓ v2 (Let e1 (x. e2)) ⇓ v2 Any other ways to evaluate Let?

38

slide-39
SLIDE 39

Overview Operational Semantics Equivalence Proof

Evaluation Strategies

e1 ⇓ v1 e2[x := (Num v1)] ⇓ v2 (Let e1 (x. e2)) ⇓ v2 Any other ways to evaluate Let? The above is called call-by-value or strict evaluation. Below we have call-by-name: e2[x := e1] ⇓ v2 (Let e1 (x. e2)) ⇓ v2

39

slide-40
SLIDE 40

Overview Operational Semantics Equivalence Proof

Evaluation Strategies

e1 ⇓ v1 e2[x := (Num v1)] ⇓ v2 (Let e1 (x. e2)) ⇓ v2 Any other ways to evaluate Let? The above is called call-by-value or strict evaluation. Below we have call-by-name: e2[x := e1] ⇓ v2 (Let e1 (x. e2)) ⇓ v2 This can be computationally very expensive, for example: let x = very expensive computation in x + x + x + x Haskell uses call-by-need or lazy evaluation, which optimises cases like this.

40

slide-41
SLIDE 41

Overview Operational Semantics Equivalence Proof

Small Step Semantics

For small step semantics, we need: A set of states Σ A set of initial states I ⊆ Σ A set of final states F ⊆ Σ A relation → ⊆ Σ × Σ, which specifies only “one step” of the execution. An execution or trace σ1 → σ2 → σ3 → · · · → σn is called maximal if there exists no σn+1 such that σn → σn+1; and is called complete if it is maximal and σn ∈ F.

41

slide-42
SLIDE 42

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) →

To Code Let’s do it in Haskell! 42

slide-43
SLIDE 43

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

To Code Let’s do it in Haskell! 43

slide-44
SLIDE 44

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

(Plus (Num n) e2) → (Plus (Num n) (Num m)) →

To Code Let’s do it in Haskell! 44

slide-45
SLIDE 45

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) →

To Code Let’s do it in Haskell! 45

slide-46
SLIDE 46

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m))

To Code Let’s do it in Haskell! 46

slide-47
SLIDE 47

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m)) (Similarly for Times)

To Code Let’s do it in Haskell! 47

slide-48
SLIDE 48

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m)) (Similarly for Times) (Let e1 (x. e2)) →

To Code Let’s do it in Haskell! 48

slide-49
SLIDE 49

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m)) (Similarly for Times) e1 → e′

1

(Let e1 (x. e2)) → (Let e′

1 (x. e2))

To Code Let’s do it in Haskell! 49

slide-50
SLIDE 50

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m)) (Similarly for Times) e1 → e′

1

(Let e1 (x. e2)) → (Let e′

1 (x. e2))

(Let (Num n) (x. e2)) →

To Code Let’s do it in Haskell! 50

slide-51
SLIDE 51

Overview Operational Semantics Equivalence Proof

Example

Example (Arithmetic Expressions) Σ and I are the set of all closed expressions {e | e ok}, F is the set of evaluated expressions {(Num n) | n ∈ Z}.

e1 → e′

1

(Plus e1 e2) → (Plus e′

1 e2)

e2 → e′

2

(Plus (Num n) e2) → (Plus (Num n) e′

2)

(Plus (Num n) (Num m)) → (Num (n + m)) (Similarly for Times) e1 → e′

1

(Let e1 (x. e2)) → (Let e′

1 (x. e2))

(Let (Num n) (x. e2)) → e2[x := Num n]

To Code Let’s do it in Haskell! 51

slide-52
SLIDE 52

Overview Operational Semantics Equivalence Proof

Equivalence

Comparing small step and big step Small step semantics are lower-level, they clearly specify the order

  • f evaluation. Big step semantics give us a result without telling us

explicitly how it was computed. Having specified the dynamic semantics in these two ways, it becomes desirable to show they are equivalent, that is: If there exists a trace e → · · · → (Num n), then e ⇓ n, and vice versa. We will need to define some notation to remove those blasted magic dots.

52

slide-53
SLIDE 53

Overview Operational Semantics Equivalence Proof

Notation

Let

→ be the reflexive, transitive closure of →. e

→ e e1 → e2 e2

→ en e1

→ en We can now state our property formally as: e

→ (Num n) ⇐ ⇒ e ⇓ n

53

slide-54
SLIDE 54

Overview Operational Semantics Equivalence Proof

Doing the Proof

The proof will be done on the iPad, with typeset versions being uploaded as usual. The big-step to small-step direction can be proven by reasonably straightforward rule induction: e ⇓ n e

→ n The other direction requires the lemma: e → e′ e′ ⇓ n e ⇓ n Which is a painful case distinction, that, depending on time and my mood, I may skip presenting in the lecture.

54