C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © 2005--2006, University of Aarhus [ ] [

Slides:



Advertisements
Similar presentations
Types and Programming Languages Lecture 4 Simon Gay Department of Computing Science University of Glasgow 2006/07.
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
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
Introduction to Computability Theory
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:
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
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 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
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,’05) O CT 13, 2005 C LAUS B RABRAND © 2005, University of Aarhus [ ] [
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 14, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
1 Semantics Q S EMANTICS (Q1,’07) Week 4 Jacob Andersen PhD student
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
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
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
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.
C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 7, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [
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,’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 [ ] [
Methods of Proof & Proof Strategies
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
CSE 755, part3 Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP: ::=skip | | | | ; | | Only integer vars; no procedures/fns; vars declared.
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
1 CS546: Machine Learning and Natural Language Discriminative vs Generative Classifiers This lecture is based on (Ng & Jordan, 02) paper and some slides.
Chapter Twenty-ThreeModern Programming Languages1 Formal Semantics.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
CS 611: Lecture 6 Rule Induction September 8, 1999 Cornell University Computer Science Department Andrew Myers.
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.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Chapter 3 Part II Describing Syntax and Semantics.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
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.
Types and Programming Languages Lecture 11 Simon Gay Department of Computing Science University of Glasgow 2006/07.
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.
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
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Lesson 10 Type Reconstruction
Operational Semantics of Scheme
Information Science and Engineering
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
Proving Properties of Recursive Functions and Data Structures
Typed Arithmetic Expressions
The Metacircular Evaluator
Program correctness Axiomatic semantics
Presentation transcript:

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C LAUS B RABRAND © , University of Aarhus [ ] [ ] S EMANTICS (Q1,’06) W EEK 4: ”STR. IND., DEFINITIONS, STATIC AND DYN. SEM.”

C LAUS B RABRAND [ 2 ] S EMANTICS (Q1,’06) S EP 21, 2006 Outline Competition Results Feedback from T.A.s Structural Induction (and Proof Structure) Comprehensive Structural Induction Example Finite vs. Infinite Stores Functional Languages (Let) Definitions (Let++) Type-Checking Definitions (Let B ++)

C LAUS B RABRAND [ 3 ] S EMANTICS (Q1,’06) S EP 21, 2006 Hand-in 2 Competition Hand-in 2 Competition:

C LAUS B RABRAND [ 4 ] S EMANTICS (Q1,’06) S EP 21, 2006 And the winner is Rikke Bendlin Emil Renner Berthing Jannick Bitsch (for introduction)

C LAUS B RABRAND [ 5 ] S EMANTICS (Q1,’06) S EP 21, 2006 Feedback from T.A.s Live exercises...(!!) Activation (both during + after lecture) Getting a fish vs. learning to fish... Exercise = Exam Training (really nice to have) Non-canonical (using your suggestions) 'Improvisation' (depending on feedback in auditorium) Otherwise: ask specific questions on the webboard... Curriculum...(?) Not unfair that lectures may actually be useful (!!) Exam questions are based on written material Notes + presentation slides + exercises

C LAUS B RABRAND [ 6 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exam Preliminary Date October 18, 2006 (Wednesday) 5 ECTS 4 hours All usual materials 13-scale And yes, there will be at least one exercise on Structural Induction.

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 S TRUCTURAL I NDUCTION A Detailed Example: Determinism of SOS for L-Expressions

C LAUS B RABRAND [ 8 ] S EMANTICS (Q1,’06) S EP 21, 2006 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

C LAUS B RABRAND [ 9 ] S EMANTICS (Q1,’06) S EP 21, 2006 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))     

C LAUS B RABRAND [ 10 ] S EMANTICS (Q1,’06) S EP 21, 2006 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: P(e) */ using the (side-effectless) small-step operational semantics Let  be given: Prove: (i.e., “prove property, P, holds for all expressions”)

C LAUS B RABRAND [ 11 ] S EMANTICS (Q1,’06) S EP 21, 2006 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)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

C LAUS B RABRAND [ 12 ] S EMANTICS (Q1,’06) S EP 21, 2006 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: [explanation]explanation P(n)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(n)   b : (false => b)  true P  Q   P  Q PQ P  Q false true falsetrue false true

C LAUS B RABRAND [ 13 ] S EMANTICS (Q1,’06) S EP 21, 2006 Proof: Base Case [v] Case [ v ]; show : Show implication “ => ” (assume [lhs], show [rhs]): assume [lhs]: and for some ,  ’ show [rhs]: could only be because ; thus,  =  (v) …and similarly: could only be because ; thus,  ’ =  (v) Thus, we have that:  =  (v) =  ’ (as required)  P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(v)  |_ v   |_ v    =  ’  |_ v  ’ |_ v  ’  |_ v   |_ v    | _ v   (v)  |_ v  ’ |_ v  ’

C LAUS B RABRAND [ 14 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 ,  ’ 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 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(e 0 )  P(e 1 ) => P(e 0 +e 1 )  | _ e 0 +e 1    | _ e 0 +e 1   ’  =  ’  | _ e 0 +e 1  

C LAUS B RABRAND [ 15 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 0 ’+e 1 = e 0 ”+e 1 =  ’ (as required)  | _ e 0 +e 1    |_ e0  e0’ |_ e0  e0’  | _ e 0 +e 1  e 0 ’+e 1 =   |_ e0  e0” |_ e0  e0”  | _ e 0 +e 1  e 0 ”+e 1 =  ’  | _ e 0 +e 1   ’   |_ e0  e0’ |_ e0  e0’  |_ e0  e0” |_ e0  e0” P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’

C LAUS B RABRAND [ 16 ] S EMANTICS (Q1,’06) S EP 21, 2006 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:  = m = n 0 +n 1 = m’ =  ’ (as required)  | _ n 0 +n 1    | _ n 0 +n 1   ’  | _ e 0 +e 1  m =   | _ e 0 +e 1  m’ =  ’ m = n 0 +n 1 m’ = n 0 +n 1   

C LAUS B RABRAND [ 17 ] S EMANTICS (Q1,’06) S EP 21, 2006 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)  ,  ’: (  | _ n     | _ n   ’ ) =>  =  ’ P(v)  ,  ’: (  | _ v     | _ v   ’ ) =>  =  ’ P(e 0 )  ,  ’: (  | _ e 0     | _ e 0   ’ ) =>  =  ’ P(e 1 )  ,  ’: (  | _ e 1     | _ e 1   ’ ) =>  =  ’ P(e 0 +e 1 )  ,  ’: (  | _ e 0 +e 1     | _ e 0 +e 1   ’ ) =>  =  ’ P(n) P(v) P(e 0 )  P(e 1 ) => P(e 0 +e 1 )

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 I NFINITE vs. F INITE S TORES

C LAUS B RABRAND [ 19 ] S EMANTICS (Q1,’06) S EP 21, 2006 Problem: Infinite Stores Problem: (Var infinite) Solution: (for V  FIN Var) Now define finite configurations:   Store = Var  Z  v  Store V = V  Z  V,E := { | Var E ( e )  V    Store V } appropriate store all vars in “V”

C LAUS B RABRAND [ 20 ] S EMANTICS (Q1,’06) S EP 21, 2006 Finite Typeable Configurations Configurations (Exp): Transitions (using “  V,E ”): Configurations (Com): Transitions (using “  V,C ”):  V.C := { | Var C ( c )  V    Store V  | _ wfc c }  V,E := { | Var E ( e )  V    Store V   : | _ e:  }  V,E [ SUM 1 ]  V,C [ SEQ 1 ]  {  |   Store V }

C LAUS B RABRAND [ 21 ] S EMANTICS (Q1,’06) S EP 21, 2006 Variable Extraction Functions Var E : Exp  P(Var) Var E ( n ) = Ø Var E ( t ) = Ø Var E ( v ) = { v } Var E ( ~ e ) = Var E ( e ) Var E ( e  e’ ) = Var E ( e )  Var E ( e’ ) Var C : Com  P(Var) Var C ( nil ) = Ø Var C ( x := e ) = { x }  Var E ( e ) Var C ( c ; c’ ) = Var C ( c )  Var C ( c’ ) Var C ( if e then c else c’ ) = Var E ( e )  Var C ( c )  Var C ( c’ ) Var C ( while e do c ) = Var E ( e )  Var C ( c ) e ::= n | v | ~ e | e  e’ c ::= nil | v := e | c ; c’ | if b then c else c’ | while b do c

C LAUS B RABRAND [ 22 ] S EMANTICS (Q1,’06) S EP 21, 2006 Finite Typeable Configurations Configurations (Exp): Transitions (using “  V,E ”): Configurations (Com): Transitions (using “  V,C ”):  V.C := { | Var C ( c )  V    Store V  | _ wfc c }  V,E := { | Var E ( e )  V    Store V   : | _ e:  }  V,E [ SUM 1 ]  V,C [ SEQ 1 ]  {  |   Store V }

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 D EFINITIONS (FUNCTIONAL LANGs)

C LAUS B RABRAND [ 24 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 '

C LAUS B RABRAND [ 25 ] S EMANTICS (Q1,’06) S EP 21, 2006 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'

C LAUS B RABRAND [ 26 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics (Trans. Sys.) Define (family of) environments: recall terminology (no side-effects) Configurations: i.e., numbers Transition relation: ; writing for  V = { |   Env V  FV( e )  V } T V = { |   Env V  z  Z }  v  Env V = V  Z Note: this is done slightly differently in the note [SOS]: through “relative transition systems” that are (implicitly) relative to an environment. V  V  VV  V  V  |- e  V e (, )  ‘  V ’

C LAUS B RABRAND [ 27 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics [n] | [x] | [e  e] Structural Operational Semantics: [ BOP 1 ] [ BOP 2 ] [ BOP 3 ] [ VAR ]  |- e 0  e 1  V e 0 ’  e 1  |- e 0  V e 0 ’  |- z 0  z 1  V z z = z 0  z 1  |- z 0  e 1  V z 0  e 1 ’  |- e 1  V e 1 ’  |- x  V z z =  (x)   Env V = V  Z

C LAUS B RABRAND [ 28 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics [ let-in ] Structural Operational Semantics: Note: the premisis works in the extended environment Live exercise: eval in env: [ LET 2 ] [ LET 3 ] [ LET 1 ]  |- let x = e 0 in e 1  V let x = e 0 ’ in e 1  |- e 0  V e 0 ’  |- let x = z in n  V n  |- let x = z in e 1  V let x = z in e 1 ’  [x  z] |- e 1  V  {x} e 1 ’ let x=y in x [y7][y7]   Env V = V  Z

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C OMPOUND D EFINITIONS

C LAUS B RABRAND [ 30 ] S EMANTICS (Q1,’06) S EP 21, 2006 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:  Val  Env {x}  Env {y} [x1][x1]  Env {x} [x1][x1][y8][y8] 4   { +, -, * } …where:

C LAUS B RABRAND [ 31 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 >

C LAUS B RABRAND [ 32 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 >

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 C OMPOUND D EFINITIONS Semantics of Let++

C LAUS B RABRAND [ 34 ] S EMANTICS (Q1,’06) S EP 21, 2006 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’ ) = Ø

C LAUS B RABRAND [ 35 ] S EMANTICS (Q1,’06) S EP 21, 2006 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 ) …

C LAUS B RABRAND [ 36 ] S EMANTICS (Q1,’06) S EP 21, 2006 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’

C LAUS B RABRAND [ 37 ] S EMANTICS (Q1,’06) S EP 21, 2006 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:  V,E = { |   Env V  FV( e )  V  |- wfe e } T V,E = { |   Env V  z  Z } only well-formed exps d ::= nil | x = e | d ; d’ | d and d’ | d in d’ |  0  V,D = { |   Env V  FV( d )  V  |- wfd d } T V,D = { |   Env V } only well-formed defs

C LAUS B RABRAND [ 38 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics: Exp Structural Operational Semantics: Note: the premisis works in the  0 - extended environment [ LET 2 ] E [ LET 3 ] E [ LET 1 ] E   Env V = V  Z  |- let d in e  V let d’ in e  |- d  V d’  |- let  0 in n  V n  |- let  0 in e  V let  0 in e’  [  0 ] |- e  V  DV(  0) e’

C LAUS B RABRAND [ 39 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [nil] | [x=e] Structural Operational Semantics: [ NIL ] D  |- nil  V [] the empty environment,  [] [ DEF 1 ] D  |- x = e  V x = e’  |- e  V e’ [ DEF 2 ] D  |- x = n  V [x  n] the environment,  [x  n]   Env V = V  Z

C LAUS B RABRAND [ 40 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [d;d’] Structural Operational Semantics: Note: the premisis 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  V d 0 ’ ; d 1  |- d 0  V d 0 ’  |-  0 ;  1  V  0 [  1 ]  |-  0 ; d 1  V  0 ; d 1 ’  [  0 ] |- d 1  V  DV(  0) d 1 ’   Env V = V  Z Live exercise: evaluate in environment: x = 2 ; x = x+y [ y = 1]

C LAUS B RABRAND [ 41 ] S EMANTICS (Q1,’06) S EP 21, 2006 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  V d 0 ’ and d 1  |- d 0  V d 0 ’  |-  0 and  1  V  0  1  |-  0 and d 1  V  0 and d 1 ’  |- d 1  V d 1 ’   Env V = V  Z 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!

C LAUS B RABRAND [ 42 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Sem.: Def [d in d’] Structural Operational Semantics: Note: the premisis 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  V d 0 ’ in d 1  |- d 0  V d 0 ’  |-  0 in  1  V  1  |-  0 in d 1  V  0 in d 1 ’  [  0 ] |- d 1  V  DV(  0) d 1 ’   Env V = V  Z

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 T YPE C HECKING D EFINITIONS

C LAUS B RABRAND [ 44 ] S EMANTICS (Q1,’06) S EP 21, 2006 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:

C LAUS B RABRAND [ 45 ] S EMANTICS (Q1,’06) S EP 21, 2006 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  )” provided “ d yields type env.  (given type env.  )” provided FV E ( e ? e’: e” ) = FV E ( e )  FV E ( e’ )  FV E ( e” ) TEnv V = V  Type  |- V e :   |- V d :  FV E ( e )  V FV D ( d )  V

C LAUS B RABRAND [ 46 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics (expressions) Expressions: [ NUM ] E  |- V n : int  |- V t : bool [ TVL ] E [ VAR ] E  |- V x :  (x) [ VAR ] E  |- V ~ e : bool  |- V e : bool [ LET ] E  |- V let d in e :   |- V d :   [  ] |- V  DV{  } e :  [ IFE ] E  |- V e 0 ? e 1 : e 2 :   |- V e 0 : bool  |- V e 1 :  1  |- V e 2 :  2  = 1 =2 = 1 =2 [ BOP ] E  |- V e 0  e 1 : type  (  0,  1 )  |- V e 0 :  0  |- V e 1 :  1

C LAUS B RABRAND [ 47 ] S EMANTICS (Q1,’06) S EP 21, 2006 Static Semantics (definitions) Definitions: [ NIL ] D  |- V nil : [] [ DEF ] D  |- V  x = e : [x  ]  |- V e :  ’  = ’ = ’ [ SEQ ] D  |- V d 0 ; d 1 :  0 [  1 ]  |- V d 0 :  0  [  0 ] |- V  DV{  0} d 1 :  1 [ AND ] D  |- V d 0 and d 1 :  0  1  |- V d 0 :  0  |- V d 1 :  1 [ IN ] D  |- V d 0 in d 1 :  1  |- V d 0 :  0  [  0 ] |- V  DV{  0} d 1 :  1 DV( d 0 )  DV( d 1 ) = Ø Note: combined environment Note: only last environment Note: disjoint environment Note: type check

C LAUS B RABRAND [ 48 ] S EMANTICS (Q1,’06) S EP 21, 2006 Dynamic Semantics: Let B ++ Type Environment (Compile-time): Type = { bool, int } Environment (Runtime): Val = B  Z, B = { tt, ff } Define type correspondence relation ‘~’: Note:  v  TEnv V = V  Type  v  Env V = V  Val  v ~  v   x  V:  v ( x ) = bool   v ( x )  B  v ( x ) = int   v ( x )  Z (  0 ~  0   1 ~  1 )   0 [  1 ] ~  0 [  1 ]

C LAUS B RABRAND [ 49 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exp. Transition System for Let B ++ Let++ Expression Configurations: Let B ++ Expression Configurations:   V  Type: Env  := i.e., “only type corresponding runtime environments”  V = { |   Env V  FV( e )  V  |- wfe e } T V = { |   Env V  z  Z } only well-formed exps   = { |   Env   FV( e )  V   :  |- V e :  } T  = { |   Env   r  B  Z } {   ( V  B  Z ) |  ~  }

C LAUS B RABRAND [ 50 ] S EMANTICS (Q1,’06) S EP 21, 2006 Def. Transition System for Let B ++ Let++ Definition Configurations: Let B ++ Definition Configurations:   V  Type: Env  := i.e., “only type corresponding runtime environments”  V = { |   Env V  FV( d )  V  |- wfd d } only well-formed defs T V = { |   Env V }   = { |   Env   FV( d )  V   :  |- V d :  } T  = { |   Env  } {   ( V  B  Z ) |  ~  }

C LAUS B RABRAND [ 51 ] S EMANTICS (Q1,’06) S EP 21, 2006 Exp. Dynamic Semantics: Let B ++ SOS of Expressions for Let B ++: E.g. [LET]: - Basically substituting  for V (from dyn. sem. of 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

C LAUS B RABRAND [ 52 ] S EMANTICS (Q1,’06) S EP 21, 2006 Def. Dynamic Semantics: Let B ++ SOS of Definitions for Let B ++: E.g [SEQ]: - Again, basically substituting  for V (from dyn. sem. of Let++) [ 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

C LAUS B RABRAND [ 53 ] S EMANTICS (Q1,’06) S EP 21, 2006 "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 Immediately

C LAUS B RABRAND S EMANTICS (Q1,’06) S EP 21, 2006 Next week (CCS): Concurrency and Communication Any Questions?