Big Step Semantics Dr. Mattox Beckman, based in part on slides by - - PowerPoint PPT Presentation

big step semantics
SMART_READER_LITE
LIVE PREVIEW

Big Step Semantics Dr. Mattox Beckman, based in part on slides by - - PowerPoint PPT Presentation

Introduction The Rules Proof Trees Conclusion Big Step Semantics Dr. Mattox Beckman, based in part on slides by Elsa Gunter. University of Illinois at Urbana-Champaign Department of Computer Science Introduction The Rules Proof Trees


slide-1
SLIDE 1

Introduction The Rules Proof Trees Conclusion

Big Step Semantics

  • Dr. Mattox Beckman, based in part on slides by Elsa Gunter.

University of Illinois at Urbana-Champaign Department of Computer Science

slide-2
SLIDE 2

Introduction The Rules Proof Trees Conclusion

Objectives

◮ Describe the components of a big-step semantic rule. ◮ Know how to build a proof tree for an expression. ◮ Explain the correspondence between big step semantics and small

step semantics.

slide-3
SLIDE 3

Introduction The Rules Proof Trees Conclusion

Grammar for Simple Imperative Programming Language

The Language

S ::= skip | u := A | S1; S2 | if B then S1 else S2 fi | while B do S1 od B ::= E ∼ E | true | false E ::= u | int | E ⊕ E

◮ Let u be a possibly subscripted variable. ◮ E represents arithmetic expressions, ⊕ is an arithmetic operator. ◮ B represents boolean expressions, ∼ represents relationals.

slide-4
SLIDE 4

Introduction The Rules Proof Trees Conclusion

The Downarrow Notation

◮ In small step semantics we use the → to represent one step of

computations.

◮ In big step semantics we use ⇓ to represent an entire evaluation.

Statements < S, σ >⇓ σ′ Expressions < E, σ >⇓e v Booleans < B, σ >⇓b b

slide-5
SLIDE 5

Introduction The Rules Proof Trees Conclusion

Expressions

Integers

< i, σ >⇓e i if i is an integer.

Variables

< u, σ >⇓e v if u := v ∈ σ.

Operations

< e1, σ >⇓e v1 < e2, σ >⇓e v2 < e1 ⊕ e2, σ >⇓e v1 ⊕ v2 Here ⊕ represents typical binary operations like +, −, ×, etc.

slide-6
SLIDE 6

Introduction The Rules Proof Trees Conclusion

Booleans

Booleans

< true , σ >⇓b true < false , σ >⇓b false

Variables

< u, σ >⇓b v if u := v ∈ σ.

Relational Operations

< e1, σ >⇓e v1 < e2, σ >⇓e v2 < e1 ∼ e2, σ >⇓b v1 ∼ v2 Here ∼ represents the typical comparison operations like <, ≤, =, =, >, ≥, etc.

slide-7
SLIDE 7

Introduction The Rules Proof Trees Conclusion

Skip and Assignment

skip < skip , σ >⇓ σ assignment < e, σ >⇓e v < x := e, σ >⇓ σ[x := v]

slide-8
SLIDE 8

Introduction The Rules Proof Trees Conclusion

Skip and Assignment

skip < skip , σ >⇓ σ assignment < e, σ >⇓e v < x := e, σ >⇓ σ[x := v] Next is sequencing. See if you can guess what the rule looks like.

slide-9
SLIDE 9

Introduction The Rules Proof Trees Conclusion

Sequencing

< S1, σ >⇓ σ′ < S2, σ′ >⇓ σ′′ < S1; S2, σ >⇓ σ′′

◮ Compare this to the small step version...

< S1, σ >→< S2, σ′ > < S1; S, σ >→< S2; S, σ′ >

slide-10
SLIDE 10

Introduction The Rules Proof Trees Conclusion

Sequencing

< S1, σ >⇓ σ′ < S2, σ′ >⇓ σ′′ < S1; S2, σ >⇓ σ′′

◮ Compare this to the small step version...

< S1, σ >→< S2, σ′ > < S1; S, σ >→< S2; S, σ′ > Next is if . There are two rules for this. See if you can guess what the rules looks like.

slide-11
SLIDE 11

Introduction The Rules Proof Trees Conclusion

If Statements

< B, σ >⇓b true < S1, σ >⇓ σ′ < if B then S1 else S2 fi , σ >⇓ σ′ < B, σ >⇓b false < S2, σ >⇓ σ′ < if B then S1 else S2 fi , σ >⇓ σ′

slide-12
SLIDE 12

Introduction The Rules Proof Trees Conclusion

If Statements

< B, σ >⇓b true < S1, σ >⇓ σ′ < if B then S1 else S2 fi , σ >⇓ σ′ < B, σ >⇓b false < S2, σ >⇓ σ′ < if B then S1 else S2 fi , σ >⇓ σ′ Next is while . There are two rules for this. See if you can guess what the rules looks like. The second one uses induction!

slide-13
SLIDE 13

Introduction The Rules Proof Trees Conclusion

While statements

< B, σ >⇓b false < while B do S od , σ >⇓ σ

slide-14
SLIDE 14

Introduction The Rules Proof Trees Conclusion

While statements

< B, σ >⇓b false < while B do S od , σ >⇓ σ < B, σ >⇓b true < while B do S od , σ′ >⇓ σ′′ < S, σ >⇓ σ′ < while B do S od , σ >⇓ σ′′

slide-15
SLIDE 15

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

Here is what we want to evaluate. What kind of expression is this? < 2 × y + 9 × x, σ >⇓e???

slide-16
SLIDE 16

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

Move up the two subexpressions. < 2 × y, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-17
SLIDE 17

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e??? < y, σ >⇓e??? < 2 × y, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-18
SLIDE 18

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e??? < 2 × y, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-19
SLIDE 19

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-20
SLIDE 20

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-21
SLIDE 21

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9, σ >⇓e??? < x, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-22
SLIDE 22

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9, σ >⇓e 9 < x, σ >⇓e??? < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-23
SLIDE 23

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9, σ >⇓e 9 < x, σ >⇓e 3 < 9 × x, σ >⇓e??? < 2 × y + 9 × x, σ >⇓e???

slide-24
SLIDE 24

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9, σ >⇓e 9 < x, σ >⇓e 3 < 9 × x, σ >⇓e 27 < 2 × y + 9 × x, σ >⇓e???

slide-25
SLIDE 25

Introduction The Rules Proof Trees Conclusion

Proof Trees

◮ To show the effect of a program, we need to build proof trees. ◮ What is 2 × y + 9 × x? ◮ Let σ = {x := 3, y := 4}.

< 2, σ >⇓e 2 < y, σ >⇓e 4 < 2 × y, σ >⇓e 8 < 9, σ >⇓e 9 < x, σ >⇓e 3 < 9 × x, σ >⇓e 27 < 2 × y + 9 × x, σ >⇓e 35

slide-26
SLIDE 26

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Here is an example that will use all three versions of ⇓. < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-27
SLIDE 27

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

This is an if statement, so... < x > y, σ >⇓b??? ??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-28
SLIDE 28

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Deconstructing x > y. < x, σ >⇓e??? < y, σ >⇓e??? < x > y, σ >⇓b??? ??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-29
SLIDE 29

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Evaluate x and y. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b??? ??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-30
SLIDE 30

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Falsehood! Go with S2. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < m := 2 × x, σ >⇓??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-31
SLIDE 31

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Evaluate 2 × x. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < 2 × x >⇓e??? < m := 2 × x, σ >⇓??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-32
SLIDE 32

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Evaluate 2 and x. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < 2, σ >⇓e 2 < x, σ >⇓e 10 < 2 × x >⇓e??? < m := 2 × x, σ >⇓??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-33
SLIDE 33

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Multiply. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < 2, σ >⇓e 2 < x, σ >⇓e 10 < 2 × x >⇓e 20 < m := 2 × x, σ >⇓??? < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-34
SLIDE 34

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Assign. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < 2, σ >⇓e 2 < x, σ >⇓e 10 < 2 × x >⇓e 20 < m := 2 × x, σ >⇓ σ′ < if x > y then m := x else m := 2 × x fi , σ >⇓???

slide-35
SLIDE 35

Introduction The Rules Proof Trees Conclusion

Statement Proof Tree

◮ Let σ = {x := 10, y := 20}. ◮ Let σ′ = {x := 10, y := 20, m := 20}

Propagate. < x, σ >⇓e 10 < y, σ >⇓e 20 < x > y, σ >⇓b false < 2, σ >⇓e 2 < x, σ >⇓e 10 < 2 × x >⇓e 20 < m := 2 × x, σ >⇓ σ′ < if x > y then m := x else m := 2 × x fi , σ >⇓ σ′

slide-36
SLIDE 36

Introduction The Rules Proof Trees Conclusion

In Class

◮ The ⇓ is really just eval that you already know and love. ◮ The σ is just the env parameter. ◮ In class: we’ll write out the big step and small step semantics for

λ-calculus.