Denotational Semantics

Similar documents
Denotational Semantics

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Big-step Operational Semantics (aka Natural Semantics)

Introduction to Denotational Semantics. Brutus Is An Honorable Man. Class Likes/Dislikes Survey. Dueling Semantics

Application: Programming Language Semantics

Introduction to Denotational Semantics. Class Likes/Dislikes Survey. Dueling Semantics. Denotational Semantics Learning Goals. You re On Jeopardy!

Exercises on Semantics of Programming Languages

Formal Semantics of Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

3.7 Denotational Semantics

Formal Semantics of Programming Languages

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Introduction to Denotational Semantics (1/2)

Semantics. A. Demers Jan This material is primarily from Ch. 2 of the text. We present an imperative

Homework 6: Big- & small-step semantics for LC

The semantics of a programming language is concerned with the meaning of programs, that is, how programs behave when executed on computers.

2 Introduction to operational semantics

CS422 - Programming Language Design

Program Analysis: Lecture 02 Page 1 of 32

CS422 - Programming Language Design

Denotational Semantics. Domain Theory

CIS 500 Software Foundations. Final Exam. May 3, Answer key

Program certification with computational

Induction and Semantics in Dafny

Formal Semantics of Programming Languages

Programming Languages and Compilers (CS 421)

n <exp>::= 0 1 b<exp> <exp>a n <exp>m<exp> 11/7/ /7/17 4 n Read tokens left to right (L) n Create a rightmost derivation (R)

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

Programming Languages Third Edition

In Our Last Exciting Episode

Handout 9: Imperative Programs and State

Semantics and Verification of Software

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

PROGRAM ANALYSIS & SYNTHESIS

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

Formal Systems and their Applications

CS2104 Prog. Lang. Concepts

3.4 Denotational Semantics

Example. Programming Languages and Compilers (CS 421) Disambiguating a Grammar. Disambiguating a Grammar. Steps to Grammar Disambiguation

Semantics with Applications 3. More on Operational Semantics

Lecture 5 - Axiomatic semantics

Lectures 20, 21: Axiomatic Semantics

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

Overview. Probabilistic Programming. Dijkstra s guarded command language: Syntax. Elementary pgcl ingredients. Lecture #4: Probabilistic GCL

An Evolution of Mathematical Tools

Hoare logic. WHILE p, a language with pointers. Introduction. Syntax of WHILE p. Lecture 5: Introduction to separation logic

Foundations: Syntax, Semantics, and Graphs

Hoare logic. Lecture 5: Introduction to separation logic. Jean Pichon-Pharabod University of Cambridge. CST Part II 2017/18

An Annotated Language

CVO103: Programming Languages. Lecture 5 Design and Implementation of PLs (1) Expressions

Semantics of Programming Languages

Abstract Syntax Trees L3 24

Semantics. There is no single widely acceptable notation or formalism for describing semantics Operational Semantics

Chapter 3 (part 3) Describing Syntax and Semantics

Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018

Com S 541. Programming Languages I

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

To prove something about all Boolean expressions, we will need the following induction principle: Axiom 7.1 (Induction over Boolean expressions):

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

Operational Semantics 1 / 13

CIS 500: Software Foundations

A CRASH COURSE IN SEMANTICS

3.1 IMP: A Simple Imperative Language

Propositional Calculus: Boolean Functions and Expressions. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

Chapter 3. Describing Syntax and Semantics ISBN

Semantics of programming languages

02157 Functional Programming Interpreters for two simple languages including exercises

Sets 1. The things in a set are called the elements of it. If x is an element of the set S, we say

Introduction to Scheme

Semantics of programming languages

Semantics and Concurrence Module on Semantic of Programming Languages

A Revisionist History of Denotational Semantics

Semantics and Concurrence Module on Semantic of Programming Languages

Abstract Interpretation

Mosig M1 - PLSCD Written exam

Lecture 7. SchemeList, finish up; Universal Hashing introduction

Static Program Analysis

Now that we have keys defined for the maps, we can start talking about maps. The first of these are Total Maps. Total Maps are defined as follows:

Hoare Logic and Model Checking

CSE505, Fall 2012, Midterm Examination October 30, 2012

6. Hoare Logic and Weakest Preconditions

CSCE 314 Programming Languages. Functional Parsers

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

Introduction to Structural Operational Semantics

Introduction to Axiomatic Semantics

Last class. CS Principles of Programming Languages. Introduction. Outline

Programming Language Concepts, cs2104 Lecture 04 ( )

LECTURE 8: SETS. Software Engineering Mike Wooldridge

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

CS422 - Programming Language Design

The Programming Language Core

Lecture 5. Logic I. Statement Logic

Denotational semantics (An introduction)

CS558 Programming Languages

3.2 Big-Step Structural Operational Semantics (Big-Step SOS)

COMP 410 Lecture 1. Kyle Dewey

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Functional Parsers

Transcription:

Denotational Semantics 10 lectures for Part II CST 2011/12 Andrew Pitts Course web page: http://www.cl.cam.ac.uk/teaching/1112/denotsem/ 1

Styles of formal semantics Operational. Meanings for program phrases defined in terms of the steps of computation they can take during program execution. Axiomatic. Meanings for program phrases defined indirectly via the axioms and rules of some logic of program properties. Denotational. Concerned with giving mathematical models of programming languages. Meanings for program phrases defined abstractly as elements of some suitable mathematical structure. 6

Why do we care? Rigour.... specification of programming languages... justification of program transformations Insight.... generalisations of notions computability... higher-order functions... data structures 4

Feedback into language design.... continuations... monads Reasoning principles.... Scott induction... Logical relations... Co-induction 5

Basic idea of denotational semantics Syntax [[ ]] Semantics P [P] 7

Basic idea of denotational semantics Syntax Recursive program Boolean circuit P [[ ]] Semantics Partial recursive function Boolean function [P] 7

Characteristic features of a denotational semantics Each phrase (= part of a program),p, is given a denotation, [P] a mathematical object representing the contribution of P to the meaning of any complete program in which it occurs. The denotation of a phrase is determined just by the denotations of its subphrases (one says that the semantics is compositional). 8

Basic idea of denotational semantics Syntax Recursive program Boolean circuit P [[ ]] Semantics Partial recursive function Boolean function [P] Concerns: Abstract models (i.e. implementation/machine independent). Lectures 2, 3 and 4. Compositionality. Lectures 5 and 6. Relationship to computation (e.g. operational semantics). Lectures 7 and 8. 7

Basic example of denotational semantics (I) IMP syntax Arithmetic expressions A Aexp ::= n L A+A... where n ranges over integers and L over a specified set of locations L Boolean expressions B Bexp ::= true false A = A... B... Commands C Comm ::= skip L := A C;C if B thenc elsec 9

Basic example of denotational semantics (II) Semantic functions A : Aexp (State Z) where Z = {..., 1,0,1,...} State = (L Z) 10

Basic example of denotational semantics (II) Semantic functions A : Aexp (State Z) B : Bexp (State B) where Z = {..., 1,0,1,...} B = {true,false} State = (L Z) 10

Basic example of denotational semantics (II) Semantic functions A : Aexp (State Z) B : Bexp (State B) C : Comm (State State) where Z = {..., 1,0,1,...} B = {true,false} State = (L Z) 10

Partial functions Computation Theory, L 2 29/171 ordered pairs {(x, y) x X y Y} i.e. for all x X there is at most one y Y with (x, y) f Definition. A partial function from a set X to a set Y is specified by any subset f X Y satisfying (x, y) f (x, y ) f y = y for all x X and y, y Y.

Basic example of denotational semantics (III) Semantic function A A[n] = λs State.n A[L] = λs State.s(L) A[A 1 +A 2 ] = λs State.A[A 1 ](s)+a[a 2 ](s) 11

Basic example of denotational semantics (IV) Semantic function B B[true] = λs State.true B[false] = λs State.false B[A 1 = A 2 ] = λs State.eq ( A[A 1 ](s),a[a 2 ](s) ) whereeq(a,a ) = { true ifa = a false ifa a 12

Basic example of denotational semantics (V) Semantic function C [skip] = λs State.s NB: From now on the names of semantic functions are omitted! 13

A simple example of compositionality Given partial functions [C], [C ] : State State and a function [B] : State {true,false}, we can define [if B then C else C ] = λs State.if ( [B](s), [C](s), [C ](s) ) where if(b,x,x ) = { x ifb = true x ifb = false 14

Basic example of denotational semantics (VI) Semantic function C [L := A] = λs State.λl L.if ( l = L, [A](s),s(l) ) 15

Denotational semantics of sequential composition Denotation of sequential compositionc;c of two commands [C;C ] = [C ] [C] = λs State. [C ] ( [C](s) ) given by composition of the partial functions from states to states [C], [C ] : State State which are the denotations of the commands. 16

Denotational semantics of sequential composition Denotation of sequential compositionc;c of two commands [C;C ] = [C ] [C] = λs State. [C ] ( [C](s) ) given by composition of the partial functions from states to states [C], [C ] : State State which are the denotations of the commands. 16

Denotational semantics of sequential composition Denotation of sequential compositionc;c of two commands [C;C ] = [C ] [C] = λs State. [C ] ( [C](s) ) given by composition of the partial functions from states to states [C], [C ] : State State which are the denotations of the commands. Cf. operational semantics of sequential composition: C,s s C,s s C;C,s s. 16

[while B do C] 17

[while B do C] 17

Fixed point property of [while B do C] [while B do C] = f [[B]],[[C]] ([while B do C]) where, for eachb : State {true,false} and c : State State, we define f b,c : (State State) (State State) as f b,c = λw (State State).λs State. if ( b(s),w(c(s)),s ). 17

Fixed point property of [while B do C] [while B do C] = f [[B]],[[C]] ([while B do C]) where, for eachb : State {true,false} and c : State State, we define f b,c : (State State) (State State) as f b,c = λw (State State).λs State. if ( b(s),w(c(s)),s ). Why doesw = f [[B]],[[C]] (w) have a solution? What if it has several solutions which one do we take to be [while B do C]? 17

[while X > 0 do (Y :=X Y ;X := X 1)] Let State def = (L Z) integer assignments to locations D def = (State State) partial functions on states For [while X > 0 do Y :=X Y ;X := X 1] D we seek a minimal solution tow = f(w), wheref : D D is defined by: f(w) ( [X x,y y] ) = { [X x,y y] ifx 0 w ( [X x 1,Y x y] ) ifx > 0. 19

Partial order ond: D def = (State State) w w iff for alls State, ifw is defined atsthen so isw and moreoverw(s) = w (s). iff the graph ofw is included in the graph ofw. Least element D w.r.t. : = totally undefined partial function = partial function with empty graph (satisfies w, for allw D). 19