CS 641 Lecture -*- Outline -*- * Operational semantics What's missing from the typed lambda calculi we've studied so far? recursion, looping, ... Definition of meaning of recursive definition can use a recursive process (operational semantics) a limit construction (fixed points) ** paradigms *** translation paradigm translate program into some other language give: definition of translation + definition of other language e.g., compiler translates program into machine language **** formalization translates into machine langauge for an abstract machine such as SECD machine (Landin) categorical abstract machine (CAM) or Turing machine **** applications to compilation study of compiler optimizations correctness proofs for compilers design of new compilers by design of new abs. machine e.g., Warren abstract machine (Prolog) graph reduction engines (functional) *** transition relation paradigm describe states and transition relation on states e.g., Plotkin's or terminal transition systems (TTS) **** Plotkin's Terminal transition systems (TTS) or SOS (structural op sem.) (Gamma, -->, T) Gamma: a set of configurations (e.g., g) --> a binary relation on Gamma T subset of terminal configurations, must be such that if g in T, then there is no g' such that g --> g'. -->+ transitive closure of --> -->* reflexive transitive closure of --> I: Programs -> Gamma the input function O: T -> Answers the output function meaning function: M[[P]] = a iff there is a g in T such that I(P) -->* g and O(g)=a **** example (while-programs) ------------------------ B ::= true | false | B and B | B or B | not B | E < E | E = E E ::= N | I | E + E | E * E | E - E | - E C ::= skip | C;C | I := E | if B then C else C fi | while B do C od ------------------------ where I is identifier, N a numeric literal States = Identifiers -> Int assume [[B]]: States -> Bool [[E]]: States -> Int Gamma (configurations) defined by: a pair (C,s) of a command C and a state s or a state s T = configurations that are just states. --------------------------------------------------------------- (skip, s) --> s (C1,s) --> (C1',s') __________________________ (C1;C2, s) --> (C1';C2, s') (C1,s) --> s' __________________________ (C1;C2, s) --> (C2, s') (I := E, s) --> s[ [[E]]s / I ] (if B then C1 else C2 fi, s) --> (C1, s) if [[B]]s = true (if B then C1 else C2 fi, s) --> (C2, s) if [[B]]s = false (while B do C od, s) --> s if [[B]]s = false (while B do C od, s) --> (C; while B do C od, s) if [[B]]s = true ------------------------------------------------------------------ ***** meaning of a command [[C]]s = s', if (C,s) ->+ s' ***** meaning of program I(C) = (C, \x.0) O(s) = s(output) M[[C]] = a iff there is a g in T such that I(C) -->* g and O(g)=a i.e., iff [[C]](\x.0) = s' and s'(output) = a -partial in general -if --> is deterministic, then M is well-defined (a function) however, not necessary that --> be deterministic only has to be Church-Rosser (confluent) ** Compositionality semantics of while not defined from subparts. compare type frames, ccc models of lambda calculus care because aesthetics would like to reason about recursion structurally do compositional interpretations of above: meaning should be partial function on states: [[skip]]s = s [[C1;C2]]s = [[C2]]([[C1]]s), etc. problem with while loop, defintion is recursive. want fixed point of associated functional (s->s) -> (s->s) F(f)(s) = s if [[B]]s = false f([[C]]s) if [[B]]s = true questions: why does such a fixed point exist? is there a cannonical choice (match to oper sem)?