Semantics Dr. Liam OConnor University of Edinburgh LFCS UNSW, Term - - PowerPoint PPT Presentation

semantics dr liam o connor
SMART_READER_LITE
LIVE PREVIEW

Semantics Dr. Liam OConnor University of Edinburgh LFCS UNSW, Term - - PowerPoint PPT Presentation

Overview Operational Semantics Equivalence Proof Semantics Dr. Liam OConnor University of Edinburgh LFCS UNSW, Term 3 2020 1 Overview Operational Semantics Equivalence Proof Semantics Semantics Scopes Scopes 2


slide-1
SLIDE 1

Overview Operational Semantics Equivalence Proof

Semantics

  • Dr. Liam O’Connor

University of Edinburgh LFCS UNSW, Term 3 2020

1

slide-2
SLIDE 2

Overview Operational Semantics Equivalence Proof

Semantics

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

2

slide-3
SLIDE 3

Overview Operational Semantics Equivalence Proof

Semantics

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

3

slide-4
SLIDE 4

Overview Operational Semantics Equivalence Proof

Semantics

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

4

slide-5
SLIDE 5

Overview Operational Semantics Equivalence Proof

Semantics

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

5

slide-6
SLIDE 6

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?

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? The only thing we can check is that the program is well-scoped (assuming FOAS).

7

slide-8
SLIDE 8

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-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.

9

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 (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.

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 Γ ⊢ (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.

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 Γ ⊢ 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.

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 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.

13

slide-14
SLIDE 14

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"))))

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

⊢ (N 3) ⊢ (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) "x" ⊢ (Let "y" (N 4) (Plus (V "x") (V "y"))) ⊢ (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" ⊢ (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"))))

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" ⊢ (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"))))

18

slide-19
SLIDE 19

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be specified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical

  • bject for each form of syntax. COMP6752 (briefly)

19

slide-20
SLIDE 20

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be specified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical

  • bject for each form of syntax. COMP6752 (briefly)

2

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

20

slide-21
SLIDE 21

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be specified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical

  • bject for each form of syntax. COMP6752 (briefly)

2

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

3

Operational Semantics is the construction of a program-evaluating state machine

  • r transition system.

21

slide-22
SLIDE 22

Overview Operational Semantics Equivalence Proof

Dynamic Semantics

Dynamic Semantics can be specified in many ways:

1

Denotational Semantics is the compositional construction of a mathematical

  • bject for each form of syntax. COMP6752 (briefly)

2

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

3

Operational Semantics is the construction of a program-evaluating state machine

  • r 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.

22

slide-23
SLIDE 23

Overview Operational Semantics Equivalence Proof

Denotational Semantics

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

23

slide-24
SLIDE 24

Overview Operational Semantics Equivalence Proof

Denotational Semantics

· : AST → Z Num n = 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 → (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.

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. e1 e2 Times e1 e2 = λE. e1 e2 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. e1E + e2E Times e1 e2 = λE. e1E × e2E 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. e2 (E[x := e1E]) Where E[x := n] is a new environment just like E except the variable x now maps to n.

28

slide-29
SLIDE 29

Overview Operational Semantics Equivalence Proof

Operational Semantics

There are two main kinds of operational semantics.

Small Step Small Step Big Step Big Step

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

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

e ⇓ v

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

Also called structural

  • perational

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

e → e′

31

slide-32
SLIDE 32

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-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! 33

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 (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! 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 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! 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 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! 36

slide-37
SLIDE 37

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?

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? 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

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 This can be computationally very expensive, for example: let x = very expensive computation in x + x + x + x In confluent languages like this or λ-calculus, this only matters for performance. In

  • ther languages, this is not so. Why?

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 In confluent languages like this or λ-calculus, this only matters for performance. In

  • ther languages, this is not so. Why?

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 of 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 The abridged proof is presented in this lecture, with all cases left for the course website.

54