big step semantics
play

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


  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

  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.

  3. skip Introduction The Rules Proof Trees Conclusion Grammar for Simple Imperative Programming Language The Language S ::= u := A | S 1 ; S 2 | if B then S 1 else S 2 fi | while B do S 1 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.

  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

  5. Introduction The Rules Proof Trees Conclusion Expressions Integers Variables if u := v ∈ σ . if i is an integer. < u , σ > ⇓ e v < i , σ > ⇓ e i Operations < e 1 , σ > ⇓ e v 1 < e 2 , σ > ⇓ e v 2 < e 1 ⊕ e 2 , σ > ⇓ e v 1 ⊕ v 2 Here ⊕ represents typical binary operations like + , − , × , etc.

  6. Introduction The Rules Proof Trees Conclusion Booleans Booleans Variables < true , σ > ⇓ b true if u := v ∈ σ . < u , σ > ⇓ b v < false , σ > ⇓ b false Relational Operations < e 1 , σ > ⇓ e v 1 < e 2 , σ > ⇓ e v 2 < e 1 ∼ e 2 , σ > ⇓ b v 1 ∼ v 2 Here ∼ represents the typical comparison operations like <, ≤ , = , � = , >, ≥ , etc.

  7. skip Introduction The Rules Proof Trees Conclusion Skip and Assignment < skip , σ > ⇓ σ assignment < e , σ > ⇓ e v < x := e , σ > ⇓ σ [ x := v ]

  8. skip Introduction The Rules Proof Trees Conclusion Skip and Assignment < skip , σ > ⇓ σ assignment < e , σ > ⇓ e v < x := e , σ > ⇓ σ [ x := v ] Next is sequencing. See if you can guess what the rule looks like.

  9. Introduction The Rules Proof Trees Conclusion Sequencing < S 2 , σ ′ > ⇓ σ ′′ < S 1 , σ > ⇓ σ ′ < S 1 ; S 2 , σ > ⇓ σ ′′ ◮ Compare this to the small step version... < S 1 , σ > → < S 2 , σ ′ > < S 1 ; S , σ > → < S 2 ; S , σ ′ >

  10. Introduction The Rules Proof Trees Conclusion Sequencing < S 2 , σ ′ > ⇓ σ ′′ < S 1 , σ > ⇓ σ ′ < S 1 ; S 2 , σ > ⇓ σ ′′ ◮ Compare this to the small step version... < S 1 , σ > → < S 2 , σ ′ > < S 1 ; S , σ > → < S 2 ; S , σ ′ > Next is if . There are two rules for this. See if you can guess what the rules looks like.

  11. Introduction The Rules Proof Trees Conclusion If Statements < B , σ > ⇓ b true < S 1 , σ > ⇓ σ ′ < if B then S 1 else S 2 fi , σ > ⇓ σ ′ < B , σ > ⇓ b false < S 2 , σ > ⇓ σ ′ < if B then S 1 else S 2 fi , σ > ⇓ σ ′

  12. Introduction The Rules Proof Trees Conclusion If Statements < B , σ > ⇓ b true < S 1 , σ > ⇓ σ ′ < if B then S 1 else S 2 fi , σ > ⇓ σ ′ < B , σ > ⇓ b false < S 2 , σ > ⇓ σ ′ < if B then S 1 else S 2 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!

  13. Introduction The Rules Proof Trees Conclusion While statements < B , σ > ⇓ b false < while B do S od , σ > ⇓ σ

  14. Introduction The Rules Proof Trees Conclusion While statements < B , σ > ⇓ b false < while B do S od , σ > ⇓ σ < while B do S od , σ ′ > ⇓ σ ′′ < B , σ > ⇓ b true < S , σ > ⇓ σ ′ < while B do S od , σ > ⇓ σ ′′

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

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

  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 } . < y , σ > ⇓ e ??? < 2 , σ > ⇓ e ??? < 2 × y , σ > ⇓ e ??? < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e ??? < 2 , σ > ⇓ e 2 < 2 × y , σ > ⇓ e ??? < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < 2 , σ > ⇓ e 2 < 2 × y , σ > ⇓ e ??? < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < 2 , σ > ⇓ e 2 < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < x , σ > ⇓ e ??? < 2 , σ > ⇓ e 2 < 9 , σ > ⇓ e ??? < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < x , σ > ⇓ e ??? < 2 , σ > ⇓ e 2 < 9 , σ > ⇓ e 9 < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < x , σ > ⇓ e 3 < 2 , σ > ⇓ e 2 < 9 , σ > ⇓ e 9 < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e ??? < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < x , σ > ⇓ e 3 < 2 , σ > ⇓ e 2 < 9 , σ > ⇓ e 9 < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e 27 < 2 × y + 9 × x , σ > ⇓ e ???

  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 } . < y , σ > ⇓ e 4 < x , σ > ⇓ e 3 < 2 , σ > ⇓ e 2 < 9 , σ > ⇓ e 9 < 2 × y , σ > ⇓ e 8 < 9 × x , σ > ⇓ e 27 < 2 × y + 9 × x , σ > ⇓ e 35

  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 , σ > ⇓ ???

  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 , σ > ⇓ ???

  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 , σ > ⇓ ???

  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 , σ > ⇓ ???

Recommend


More recommend