Denotational Semantics

Similar documents
Denotational Semantics

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.

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

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

Big-step Operational Semantics (aka Natural Semantics)

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

3.7 Denotational Semantics

Formal Semantics of Programming Languages

Application: Programming Language Semantics

Formal Semantics of Programming Languages

Introduction to Denotational Semantics (1/2)

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

Exercises on Semantics of Programming Languages

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

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

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

Semantics and Verification of Software

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

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

PROGRAM ANALYSIS & SYNTHESIS

CS422 - Programming Language Design

Program Analysis: Lecture 02 Page 1 of 32

Denotational Semantics. Domain Theory

Programming Languages Third Edition

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

Handout 9: Imperative Programs and State

CS422 - Programming Language Design

Lecture 5 - Axiomatic semantics

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

Induction and Semantics in Dafny

An Annotated Language

3.4 Denotational Semantics

Formal Semantics of Programming Languages

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Design

CS2104 Prog. Lang. Concepts

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)

Chapter 3. Describing Syntax and Semantics ISBN

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

In Our Last Exciting Episode

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

Chapter 3 (part 3) Describing Syntax and Semantics

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

Semantics with Applications 3. More on Operational Semantics

Lectures 20, 21: Axiomatic Semantics

The Programming Language Core

Formal Systems and their Applications

Compiler Construction

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

Module 3. Requirements Analysis and Specification. Version 2 CSE IIT, Kharagpur

A CRASH COURSE IN SEMANTICS

Compiler Construction

Hoare Logic and Model Checking

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

Proving Properties on Programs From the Coq Tutorial at ITP 2015

Compiler Construction

3.1 IMP: A Simple Imperative Language

Com S 541. Programming Languages I

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

Introduction to Axiomatic Semantics

An Evolution of Mathematical Tools

6. Hoare Logic and Weakest Preconditions

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

Static Program Analysis

Compiler Construction

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

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS522 Programming Language Semantics

Compiler Construction

CONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics

Operational Semantics 1 / 13

Lecture 5. Logic I. Statement Logic

COMP 410 Lecture 1. Kyle Dewey

Abstract Syntax Trees L3 24

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

Program certification with computational

Semantics of programming languages

A Revisionist History of Denotational Semantics

Introduction to Scheme

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

Abstract Interpretation

02157 Functional Programming Interpreters for two simple languages including exercises

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

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Compiler Construction

A Hoare Logic Contract Theory: An Exercise in Denotational Semantics

Compiler Construction

CSE505, Fall 2012, Midterm Examination October 30, 2012

Foundations: Syntax, Semantics, and Graphs

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

Static Program Analysis

Introduction to Axiomatic Semantics (1/2)

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

Introduction to Structural Operational Semantics

Programming Language Concepts, cs2104 Lecture 04 ( )

Introduction to Axiomatic Semantics (1/2)

Contents. Chapter 1 SPECIFYING SYNTAX 1

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

A Partial Correctness Proof for Programs with Decided Specifications

Denotational semantics (An introduction)

Transcription:

Denotational Semantics 8 12 lectures for Part II CST 2010/11 Marcelo Fiore Course web page: http://www.cl.cam.ac.uk/teaching/1011/denotsem/ 1

Lecture 1 Introduction 2

What is this course about? General area. Formal methods: Mathematical techniques for the specification, development, and verification of software and hardware systems. Specific area. Formal semantics: Mathematical theories for ascribing meanings to computer languages. 3

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

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

Basic idea of denotational semantics Syntax [[ ]] Semantics Recursive program Partial recursive function Concerns: Boolean circuit Boolean function P [P ] 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

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 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 then C else C 9

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

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) ) where eq(a, a ) = { true if a = a false if a 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 x if b = true if b = 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 composition C; 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

Fixed point property of [while B do C ] [while B do C ] = f [[B]],[[C]] ([while B do C ]) where, for each b : State {true,false} and c : State State, we define as f b,c : (State State) (State State) f b,c = λw (State State). λs State.if ( b(s), w(c(s)), s ). Why does w = 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

Approximating [while B do C ] f [[B]],[[C]] n ( ) = λs State. [C ] k (s) if 0 k < n. [B]([C ] k (s)) = false and 0 i < k. [B]([C ] i (s)) = true if 0 i < n. [B]([C ] i (s)) = true 18

D def = (State State) Partial order on D: w w iff for all s State, if w is defined at s then so is w and moreover w(s) = w (s). iff the graph of w is included in the graph of w. Least element D w.r.t. : = totally undefined partial function = partial function with empty graph (satisfies w, for all w D). 19