1 Semantics Q1 2007 S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student

Slides:



Advertisements
Similar presentations
Completeness and Expressiveness
Advertisements

Substitution & Evaluation Order cos 441 David Walker.
Jacob Andersen PhD student
- Vasvi Kakkad.  Formal -  Tool for mathematical analysis of language  Method for precisely designing language  Well formed model for describing and.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Semantics Q S EMANTICS (Q1,’07) Week 1 Jacob Andersen PhD student
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 8, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
Induction Sections 41. and 4.2 of Rosen Fall 2008 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Discussion #12 1/22 Discussion #12 Deduction, Proofs and Proof Techniques.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Induction Sections 4.1 and 4.2 of Rosen Fall 2010
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 8, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
1 Semantics Q S EMANTICS (Q1,’07) Week 2 Jacob Andersen PhD student
1 Semantics Q S EMANTICS (Q1,’07) Week 3 Jacob Andersen PhD student
C LAUS B RABRAND © S EMANTICS (Q1,’06) A UG 31, 2006 C LAUS B RABRAND © 2005–2006, University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 14, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Proof by Deduction. Deductions and Formal Proofs A deduction is a sequence of logic statements, each of which is known or assumed to be true A formal.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’05) S EP 22, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
C LAUS B RABRAND © S EMANTICS (Q1,’05) S EP 1, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
What it is? Why is it a legitimate proof method? How to use it?
Methods of Proof & Proof Strategies
Lecture 9. Arithmetic and geometric series and mathematical induction
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
Methods of Proof Lecture 3: Sep 9. This Lecture Now we have learnt the basics in logic. We are going to apply the logical rules in proving mathematical.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Formal Semantics of Programming Languages 虞慧群 Topic 3: Principles of Induction.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Example to Type Check object World { var z : Boolean var u : Int def f(y : Boolean) : Int { z = y if (u > 0) { u = u – 1 var z : Int z = f(!y) + 3 z+z.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Chapter 3 Part II Describing Syntax and Semantics.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Course 2D1453, Some material from B. Pierce: TAPL + some from.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Compiler Principles Fall Compiler Principles Lecture 7: Lowering Correctness Roman Manevich Ben-Gurion University of the Negev.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Soundness of Types Ensuring that a type system is not broken.
CMSC 330: Organization of Programming Languages Operational Semantics.
Types and Programming Languages Lecture 3 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Process Algebra (2IF45) Basic Process Algebra Dr. Suzana Andova.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Arrays Using array as an expression, on the right-hand side Assigning to an array.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Lesson 10 Type Reconstruction
Operational Semantics of Scheme
CSCE 355 Foundations of Computation
Advanced Algorithms Analysis and Design
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Corky Cartwright January 18, 2017
Disjunctive Normal Form
Mathematical Induction Recursion
CSCE 355 Foundations of Computation
Proving Properties of Recursive Functions and Data Structures
Typed Arithmetic Expressions
Simplification of Boolean Expressions
Logic Logic is a discipline that studies the principles and methods used to construct valid arguments. An argument is a related sequence of statements.
Mathematical Induction
Program correctness Axiomatic semantics
Presentation transcript:

1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student

2 Semantics Q News…

3 Semantics Q Outline (Structural) Induction Finite vs. Infinite Stores Functional Languages (Let) Compound Definitions (Let++) Type-Checking Definitions (Let B ++)

4 Semantics Q (S TRUCTURAL ) I NDUCTION

5 Semantics Q Principle of Mathematical Induction Let P be a predicate (i.e. a boolean function): then we have that: Intuitive: ? P: N  { true, false }  n  N : P(n) P(0)  induction stepbase case Principle of mathematical induction: P(n)  P(n+1)  P(3) P(0)P(0) => P(1)P(1) => P(2)P(2) => P(3) 

6 Semantics Q Mathematical Induction example Prove the following theorem: All non-empty subsets of ℕ have a smallest element. or by contraposition: Live exercise… [Think 3 mins; then interactively on the whiteboard] ∀ A ⊆ ℕ : A ≠ ∅  (∃ l ∈ A : ∀ a ∈ A : l ≤ a ) ∀ A ⊆ ℕ : (∀ l ∈ A : ∃ a ∈ A : l>a )  A = ∅ Let A ⊆ ℕ be given. Assume: ∀ l ∈ A : ∃ a ∈ A : l>a Prove: A = ∅

7 Semantics Q Mathematical Induction example What about: Will work ??? Instead this will work: ∀ A ⊆ ℕ : (∀ l ∈ A : ∃ a ∈ A : l>a )  A = ∅ Let A ⊆ ℕ be given. Assume: ∀ l ∈ A : ∃ a ∈ A : l>a Prove: A = ∅ P(n) ≝ n ∉ A P(n)  P(n+1) NO ! P(n) ≝ ∀ m ∈ ℕ : m ≤ n  m ∉ A  n  ℕ : P(n) P(0) P(n)  P(n+1)    ∀ n, m ∈ ℕ : m ≤ n  m ∉ A or:  ∀ m ∈ ℕ : m ∉ A  A ∩ ℕ = ∅ (Since A ⊆ ℕ )   A = ∅ 

8 Semantics Q Structural Induction (for Exp) Given: Arithmetic Expressions ( e  Exp) – e ::= n | v | e 0 +e 1  e  Exp : P(e) P(n)  composite (inductive) case base cases Principle of structural induction: P(e 0 )  P(e 1 )  P(e 0 +e 1 )  P(v) and

9 Semantics Q Intuition: Induction vs. Str’ Induction Induction: Holds for ? Structural Induction: Holds for ? P(0)P(0) => P(1)P(1) => P(2)P(2) => P(3)  P(3) P(7+(x+y)) P(7) P(x) P(y) P(x+y) P(7+(x+y))     

10 Semantics Q Structural Induction Examples Given: Arithmetic Expressions ( e  Exp) – Determinism of SOS* for L-expressions : “One-step evaluation of expressions is deterministic” e ::= n | v | e 0 +e 1 P(e)   e’,e’’:[(  | _ e  e’   | _ e  e’’) => e’= e’’]  e: P(e) */ using the (side-effectless) small-step operational semantics Let  be given: Prove: (i.e., “prove property, P, holds for all expressions”)

11 Semantics Q Proof Structure (according to SI) Base cases: –Case [ n ]; show : –Case [ v ]; show : Inductive case: –Case [ e 0 +e 1 ]; show : –assume induction hypothesis [lhs]: P(e 0 )  P(e 1 ) –show inductive step [rhs]: P(e 0 +e 1 ) P(n)   e’,e’’:(  | _ n  e’   | _ n  e’’) => e’=e’’ P(v)   e’,e’’:(  | _ v  e’   | _ v  e’’) => e’=e’’ P(e 0 )   e’,e’’:(  | _ e 0  e’   | _ e 0  e’’) => e’=e’’ P(e 1 )   e’,e’’:(  | _ e 1  e’   | _ e 1  e’’) => e’=e’’ P(e 0 +e 1 )   e’,e’’:(  | _ e 0 +e 1  e’   | _ e 0 +e 1  e’’) => e’=e’’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

12 Semantics Q Proof: Base Case [n] –Case [ n ]; show : –Show implication “ => ” (assume [lhs], show [rhs]): However, since [lhs] is trivially false (no rules for constants), the whole thing is trivially true (aka. “vacuously true”) »Recall that: P(n)   e’,e’’:(  | _ n  e’   | _ n  e’’ ) => e’ = e’’ P(n)   b : (false => b)  true P  Q   P  Q PQ P  Q false true falsetrue false true

13 Semantics Q Proof: Base Case [v] –Case [ v ]; show : –Show implication “ => ” (assume [lhs], show [rhs]): assume [lhs]: and for some e’,e’’ show [rhs]: – could only be because ; thus, e’ =  (v) …and similarly: – could only be because ; thus, e’’ =  (v) –Thus, we have that: e’ =  (v) = e’’ (as required)  P(v)   e’,e’’:(  | _ v  e’   | _ v  e’’) => e’=e’’ P(v)  | _ v  e’ e’ = e’’  | _ v  e’’  | _ v  e’  | _ v   (v)  | _ v  e’’  | _ v   (v)

14 Semantics Q Proof: Inductive Case [e 0 +e 1 ] –Case [ e 0 +e 1 ]; show : –assume induction hypothesis: P(e 0 )  P(e 1 ) –show inductive step: P(e 0 +e 1 ) –Show implication “ => ” (assume [lhs], show [rhs]): Assume [lhs]: and for some e’,e’’ Show [rhs]: When could we have that: (?) –Case Analysis (on e 0 +e 1 ) »Three possibilities ( [SUM 1 ], [SUM 2 ], and [SUM 3 ] )… P(e 0 )   e’,e’’:(  | _ e 0  e’   | _ e 0  e’’) => e’=e’’ P(e 1 )   e’,e’’:(  | _ e 1  e’   | _ e 1  e’’) => e’=e’’ P(e 0 +e 1 )   e’,e’’:(  | _ e 0 +e 1  e’   | _ e 0 +e 1  e’’) => e’=e’’ P(e 0 )  P(e 1 ) => P(e 0 +e 1 )  | _ e 0 +e 1  e’  | _ e 0 +e 1  e’’ e’ = e’’  | _ e 0 +e 1  e

15 Semantics Q Proof: Case Analysis (on e 0 +e 1 ) –Case Analysis (on e 0 +e 1 ): Case [SUM 1 (e 0  Z)]: – could only be because –But from our induction hypothesis, P(e 0 ) ; i.e. … : … we get that: » and implies that: e 0 ’ = e 0 ” »Thus we have that: e’ = e 0 ’+e 1 = e 0 ”+e 1 = e’’ (as required)  | _ e 0 +e 1  e’  |_ e0  e0’ |_ e0  e0’  | _ e 0 +e 1  e 0 ’+e 1 = e’  |_ e0  e0” |_ e0  e0”  | _ e 0 +e 1  e 0 ”+e 1 = e’’  | _ e 0 +e 1  e’’   |_ e0  e0’ |_ e0  e0’  |_ e0  e0” |_ e0  e0” P(e 0 )   e’,e’’:(  | _ e 0  e’   | _ e 0  e’’) => e’=e’’

16 Semantics Q Proof: Case Analysis (on e 0 +e 1 ) Case [SUM 2 (e 0  Z, e 1  Z)]: – (analoguous) Case [SUM 3 (e 0  Z, e 1  Z)]: – could only be because –Thus, we have that: e’ = m = n 0 +n 1 = m’ = e’’ (as required) Q.E.D.  | _ n 0 +n 1  e’  | _ n 0 +n 1  e’’  | _ n 0 +n 1  m = e’  | _ n 0 +n 1  m’ = e’’ m = n 0 +n 1 m’ = n 0 +n 1   

17 Semantics Q What did we do: Proof Structure Base cases: –Case [ n ]; showed : –Case [ v ]; showed : Inductive case: –Case [ e 0 +e 1 ]; showed : –assumed induction hypothesis [lhs]: P(e 0 )  P(e 1 ) –showed inductive step [rhs] via case analysis: P(e 0 +e 1 ) P(n)   e’,e’’:(  | _ n  e’   | _ n  e’’) => e’=e’’ P(v)   e’,e’’:(  | _ v  e’   | _ v  e’’) => e’=e’’ P(e 0 )   e’,e’’:(  | _ e 0  e’   | _ e 0  e’’) => e’=e’’ P(e 1 )   e’,e’’:(  | _ e 1  e’   | _ e 1  e’’) => e’=e’’ P(e 0 +e 1 )   e’,e’’:(  | _ e 0 +e 1  e’   | _ e 0 +e 1  e’’) => e’=e’’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

18 Semantics Q I NFINITE vs. F INITE S TORES

19 Semantics Q Problem: Infinite Stores At this point Plotkin starts using stores with no upper bound. Problem: (Var infinite) –Solution: (for V  FIN Var) –Now define finite configurations: We shall not worry about this (like TM vs. DFA)   Store = Var  Z  v  Store V = V  Z  V,E := { | Var E ( e )  V    Store V } appropriate store all vars in “V”

20 Semantics Q D EFINITIONS (FUNCTIONAL LANGs)

21 Semantics Q Introducing Binding Constructs Consider the language ”Let”: Expressions ( e  Exp): –Example Let program: –Note: the actual identifier names are irrellevant (only the use-def links are significant) e ::= n | x | e  e’ | let x = e in e’   { +, -, * } …where: x + let x = 5 in x + let x = 1 + x in x * x Definition (def) Usage (use): Free use Bound use use-def link Terminology definition scope for ' x '

22 Semantics Q Free Variables Determine the free variables? FV: Exp  P(Var) –FV( n ) = Ø –FV( x ) = { x } –FV( e  e’ ) = FV( e )  FV( e’ ) –FV( let x=e in e’ ) = FV( e )  ( FV( e’ ) \ { x } ) e ::= n | x | e  e’ | let x = e in e'

23 Semantics Q Dynamic Semantics (Trans. Sys.) Define environments: recall terminology (no side-effects) Configurations: i.e., numbers Transition relation: ; writing for  = { } T = { | z  Z }   Env = Var  Z Note: this is done differently in the note [SOS]: through “relative transition systems” that are (implicitly) relative to an environment.           |- e  e (, )  ‘  ’

24 Semantics Q Dynamic Semantics [n] | [x] | [e  e] Structural Operational Semantics: [ BOP 1 ] [ BOP 2 ] [ BOP 3 ] [ VAR ]  |- e 0  e 1  e 0 ’  e 1  |- e 0  e 0 ’  |- z 0  z 1  z z = z 0  z 1  |- z 0  e 1  z 0  e 1 ’  |- e 1  e 1 ’  |- x  z z =  (x)

25 Semantics Q Dynamic Semantics [ let-in ] Structural Operational Semantics: »Note: the premises work in the extended environment Live exercise: eval in env: [ LET 2 ] [ LET 3 ] [ LET 1 ]  |- let x = e 0 in e 1  let x = e 0 ’ in e 1  |- e 0  e 0 ’  |- let x = z in n  n  |- let x = z in e 1  let x = z in e 1 ’  [x  z] |- e 1  e 1 ’ let x=y in x [y7][y7]

26 Semantics Q C OMPOUND D EFINITIONS

27 Semantics Q Compound Definitions Consider language Let++: –Expressions ( e  Exp): –Definitions (d  Def): e ::= n | x | e  e’ | let d in e d ::= nil | x = e | d ; d’ | d and d’ | d in d’ x + 3y = x+7 Graphically:  Z Z  Env [x1][x1] [x1][x1][y8][y8] 4   { +, -, * } …where:

28 Semantics Q Graphically: [x = e] | [d ; d’] Definition block: –E.g.: Sequential definition: –E.g.: let d in e d 0 ; d 1 let x=a ; y=b in b * c + y a b c x y b c >

29 Semantics Q Graphically: [d and d’] | [d in d’] Simultaneous definition: –E.g.: Private definition: –E.g.: d 0 and d 1 d 0 in d 1 >

30 Semantics Q C OMPOUND D EFINITIONS Semantics of Let++

31 Semantics Q Static Semantics: Let++ Problem: I.e. non-disjoint simultaneous definitions! Solution: static semantics def / exp “well-formedness relations”: ‘|- wfd ’ / ‘|- wfe ’: let x = 1 and x = 2 in x | _ wfe e | _ wfe e’ | _ wfe e  e’ Exp well-formedness: | _ wfe n | _ wfe x | _ wfd d | _ wfe e | _ wfe let d in e  Definition well-formedness: | _ wfd nil | _ wfe e | _ wfd x = e | _ wfd d | _ wfd d’ | _ wfd d ; d’ | _ wfd d | _ wfd d’ | _ wfd d and d’ | _ wfd d | _ wfd d’ | _ wfd d in d’ DV( d )  DV( d’ ) = Ø

32 Semantics Q Recall: Free Variables for Let Let: –FV( n ) = Ø –FV( x ) = { x } –FV( e  e’ ) = FV( e )  FV( e’ ) –FV( let x=e in e’ ) = FV( e )  ( FV( e’ ) \ { x } ) Let++: –FV( let d in e’ ) = FV( d )  ( FV( e’ ) \ DV( d ) ) –So we need FV( d ) and DV( d ) …

33 Semantics Q Defining Variables and Free Variables DV: Def  P(Var) –DV( nil ) = Ø –DV( x = e )= { x } –DV( d ; d’ ) = DV( d )  DV( d’ ) –DV( d and d’ )= DV( d )  DV( d’ ) –DV( d in d’ )= DV( d’ ) FV: Def  P(Var) –FV( nil ) = Ø –FV( x = e )= FV( e ) –FV( d ; d’ ) = FV( d )  ( FV( d’ ) \ DV( d ) ) –FV( d and d’ )= FV( d )  FV( d’ ) –FV( d in d’ )= FV( d )  ( FV( d’ ) \ DV( d ) ) + should be disjoint union d ::= nil | x = e | d ; d’ | d and d’ | d in d’

34 Semantics Q Dynamic Semantics Expression Configurations: –Problem: what should definitions evaluate to? Environments (like expressions evaluate to numbers) –Solution: “environments as results” (add intermediate syntax): Definition Configurations:  E = { | |- wfe e } T E = { | z  Z } only well-formed exps d ::= nil | x = e | d ; d’ | d and d’ | d in d’ |  0  D = { | |- wfd d } T D = { } only well-formed defs Question: Why not (just) define:  D = { } ∪ Env T D = Env ??? Note: This is a static property!

35 Semantics Q Dynamic Semantics: Exp Structural Operational Semantics: »Note: the premisis works in the  0 - extended environment [ LET 2 ] E [ LET 3 ] E [ LET 1 ] E  |- let d in e  let d’ in e  |- d  d’  |- let  0 in n  n  |- let  0 in e  let  0 in e’  [  0 ] |- e  e’

36 Semantics Q Structural Operational Semantics: [ NIL ] D  |- nil  [] [ DEF 1 ] D  |- x = e  x = e’  |- e  e’ [ DEF 2 ] D  |- x = n  [x  n] Dynamic Sem.: Def [nil] | [x=e]

37 Semantics Q Dynamic Sem.: Def [d;d’] Structural Operational Semantics: »Note: the premises works in the  0 - extended environment »Note: the result is the combined environment,  0 [  1 ] [ SEQ 2 ] D [ SEQ 3 ] D [ SEQ 1 ] D  |- d 0 ; d 1  d 0 ’ ; d 1  |- d 0  d 0 ’  |-  0 ;  1   0 [  1 ]  |-  0 ; d 1   0 ; d 1 ’  [  0 ] |- d 1  d 1 ’ Live exercise: evaluate in environment: x = 2 ; x = x+y [ y = 1]

38 Semantics Q Dynamic Sem.: Def [d and d’] Structural Operational Semantics: »Notice the independence of the two operands ( d 0 & d 1 ) »Note: the result is the disj. combined environment,  0  1 [ AND 2 ] D [ AND 3 ] D [ AND 1 ] D  |- d 0 and d 1  d 0 ’ and d 1  |- d 0  d 0 ’  |-  0 and  1   0  1  |-  0 and d 1   0 and d 1 ’  |- d 1  d 1 ’ Q: what happens if operands do not contain disjoint definitions (e.g. "x=1 and x=2") A: trans. sys. was only def'd for well-formed exps/defs! Hence, no such runtime errors!

39 Semantics Q Dynamic Sem.: Def [d in d’] Structural Operational Semantics: »Note: the premises works in the  0 - extended environment »Note: the result is only the last environment,  1 [ IN 2 ] D [ IN 3 ] D [ IN 1 ] D  |- d 0 in d 1  d 0 ’ in d 1  |- d 0  d 0 ’  |-  0 in  1   1  |-  0 in d 1   0 in d 1 ’  [  0 ] |- d 1  d 1 ’

40 Semantics Q T YPE C HECKING D EFINITIONS

41 Semantics Q Adding Boolean Variables: Let B ++ Consider language Let B ++: –Mixed Expressions ( e  Exp): –Definitions (d  Def): –Note: The type of a var is now context dependent I.e. a context-free (grammar) approach will not suffice –Examples: ? ? … e ::= n | t | x | ~ e | e  e’ | e ? e’ : e” | let d in e d ::= nil |  x = e | d ; d’ | d and d’ | d in d’   { +, -, *, =, or } …where: x or tt x * x type definition (annotation)   { bool, int } …where:

42 Semantics Q Static Semantics: Let B ++ FV E, DV D and FV D as before …adding: We now need type environments: Type = { bool, int } Define static semantics (type checking rel’s): “ e has type  (given type environment  )” “ d yields type env.  (given type env.  )” FV E ( e ? e’: e” ) = FV E ( e )  FV E ( e’ )  FV E ( e” ) TEnv V = Var  Type  |- e :   |- d : 

43 Semantics Q Static Semantics (expressions) Expressions: [ NUM ] E  |- n : int  |- t : bool [ TVL ] E [ VAR ] E  |- x :  (x) [ VAR ] E  |- ~ e : bool  |- e : bool [ LET ] E  |- let d in e :   |- d :   [  ] |- e :  [ IFE ] E  |- e 0 ? e 1 : e 2 :   |- e 0 : bool  |- e 1 :  1  |- e 2 :  2  = 1 =2 = 1 =2 [ BOP ] E  |- e 0  e 1 : type  (  0,  1 )  |- e 0 :  0  |- e 1 :  1

44 Semantics Q Static Semantics (definitions) Definitions: [ NIL ] D  |- nil : [] [ DEF ] D  |-  x = e : [x  ]  |- e :  ’  = ’ = ’ [ SEQ ] D  |- d 0 ; d 1 :  0 [  1 ]  |- d 0 :  0  [  0 ] |- d 1 :  1 [ AND ] D  |- d 0 and d 1 :  0  1  |- d 0 :  0  |- d 1 :  1 [ IN ] D  |- d 0 in d 1 :  1  |- d 0 :  0  [  0 ] |- d 1 :  1 DV( d 0 )  DV( d 1 ) = Ø Note: combined environment Note: only last environment Note: disjoint environment Note: type check

45 Semantics Q Dynamic Semantics: Let B ++ Type Environment (Compile-time): Type = { bool, int } Environment (Runtime): Val = B  Z, B = { tt, ff } –Define type correspondence relation ‘~’: –Note:   TEnv = Var  Type   Env = Var  Val  ~    x  V:  ( x ) = bool   ( x )  B  ( x ) = int   ( x )  Z (  0 ~  0   1 ~  1 )   0 [  1 ] ~  0 [  1 ]

46 Semantics Q Exp. Transition System for Let B ++ Let++ Expression Configurations: Let B ++ Expression Configurations: –   Var  Type: Env  := »i.e., “only type corresponding runtime environments”  = { | |- wfe e } T = { | z  Z } only well-formed exps   = { |   Env    :  |- e :  } T  = { |   Env   r  B  Z } {   ( Var  B  Z ) |  ~  }

47 Semantics Q Def. Transition System for Let B ++ Let++ Definition Configurations: Let B ++ Definition Configurations: –   Var  Type: Env  := »i.e., “only type corresponding runtime environments”  V = { | |- wfd d } only well-formed defs T V = { }   = { |   Env    :  |- V d :  } T  = { |   Env  } {   ( Var  B  Z ) |  ~  }

48 Semantics Q Exp. Dynamic Semantics: Let B ++ SOS of Expressions for Let B ++: –E.g. [LET]: [ LET 2 ] [ LET 3 ] [ LET 1 ]   Env   |- let d in e   let d’ in e  |- d   d’  |- let  0 in r   r  |- let  0 in e   let  0 in e’  [  0 ] |- e   [  0] e’ 0 ~ 00 ~ 0

49 Semantics Q Def. Dynamic Semantics: Let B ++ SOS of Definitions for Let B ++: –E.g [SEQ]: [ SEQ 2 ] [ SEQ 3 ] [ SEQ 1 ]  |- d 0 ; d 1   d 0 ’ ; d 1  |- d 0   d 0 ’  |-  0 ;  1    0 [  1 ]  |-  0 ; d 1    0 ; d 1 ’  [  0 ] |- d 1   [  0] d 1 ’   Env  0 ~ 00 ~ 0

50 Semantics Q "Three minutes paper" Please spend three minutes writing down the most important things that you have learned today (now). After 1 day After 1 week After 3 weeks After 2 weeks Right away

51 Semantics Q Next week (CCS): Concurrency and Communication Any Questions?