Separation Logic: syntax, semantics and calculus

Size: px
Start display at page:

Download "Separation Logic: syntax, semantics and calculus"

Transcription

1 Separation Logic: syntax, semantics and calculus Syntax Semantics Calculus emp SL N/A FOL N/A = + Arithmetic N/A := ; while if then else [.] dispose(.) cons(.) State is a pair (Store,Heap) St(.) maps variables to values H p(.) maps locations to values N/A if initial state satisfies P {P}S{Q} and S terminates More Inference then S does not fault and Rules COMP 2600 Separation Logic 26 final state satisfies Q

2 Summary of Lecture I: Reasoning About Pointers State is now a pair (Store, Heap) where Store maps variables to values and Heap maps a finite subset of numbers to values (smallest heap) New Programming Language Constructs Fetch: v := [e] e.g. x := [y + 1] evaluate expression e in current state to get location l fault if location l is not in the current heap otherwise variable v is assigned the contents of location l Heap Assignment/Mutation: [e] := e 1 e.g. [y + 1] := 5 evaluate e (in the current state) as location l fault if location l is not in the current heap otherwise make the contents of location l the value of expression e 1 COMP 2600 Separation Logic 27

3 Summary of Lecture I: Reasoning About Pointers Allocation: v := cons(e 1,e 2,,e n ) e.g. p := cons(3,7) extend the heap with n consecutive new locations l,l +1,,l +n 1 put values of e 1,,e n into locations l,,l + n 1 respectively extend the store by assigning v the value l never faults Deallocation: dispose(e) evaluate e to get some number l e.g. dispose(q) fault if location l is not in the heap otherwise remove location l from the heap {P}S{Q} if initial state satisfies P and S terminates then S does not fault and final state satisfies Q (so our rules will have to guarantee no faults) COMP 2600 Separation Logic 28

4 Summary of Lecture I: Reasoning About Pointers {P}S{Q} if initial state satisfies P and S terminates then S does not fault and final state satisfies Q (so our rules will have to guarantee no faults) New: atomic formula emp s.t. (St,H p) = emp if dom(h p) = /0 (emptyset) Floyd Store Axiom for Separation Logic: replaces Hoare (Store) Axiom {x = v emp} x := e {x = e(v/x) emp} where v is an auxiliary variable which does not occur in e Hoare Logic: keep other rules (PreConStr, PostCondWeak, Seq, Cond, While), so Separation Logic is a genuine extension of Hoare Logic Reasoning: goes forwards rather than backward Need: more rules to handle the new programming language constructs and maybe new formula connectives to reason about these constructs COMP 2600 Separation Logic 29

5 COMP 2600 Separation Logic 30

6 Separation Logic: syntax, semantics and calculus Syntax Semantics Calculus emp SL N/A FOL N/A = + Arithmetic N/A := ; while if then else [.] dispose(.) cons(.) State is a pair (Store,Heap) St(.) maps variables to values H p(.) maps locations to values N/A if initial state satisfies P {P}S{Q} and S terminates More Inference then S does not fault and Rules COMP 2600 Separation Logic 31 final state satisfies Q

7 Fetch Assignment Axiom of Separation Logic {(x = v 1 ) (e v 2 )} x := [e] {(x = v 2 ) (e(v 1 /x) v 2 )} where v 1 and v 2 are auxiliary variables which do not occur in e Example: x := [y] St H p x := [y] St H p y = y = x = 1 1 e is y: so {(x = v 1 ) (y v 2 )} x := [y] {(x = v 2 ) (y(v 1 /x) v 2 )} v 2 is 1: so {(x = v 1 ) (y 1)} x := [y] {(x = 1) (y(v 1 /x) 1)} y(v 1 /x) is y: since there are no occurrences of x in y so {(x = v 1 ) (y 1)} x := [y] {(x = 1) (y 1)} COMP 2600 Separation Logic 32

8 Fetch Assignment Axiom of Separation Logic {(x = v 1 ) (e v 2 )} x := [e] {(x = v 2 ) (e(v 1 /x) v 2 )} where v 1 and v 2 are auxiliary variables which do not occur in e Example: x := [y] St H p x := [y] St H p y = y = x = 1 1 Fetch Axiom Instance: from previous slide {(x = v 1 ) (y 1)} x := [y] {(x = 1) (y 1)} New: binary formula connective to extend our syntax of formulae COMP 2600 Separation Logic 33

9 COMP 2600 Separation Logic 34

10 Separation Logic: syntax, semantics and calculus Syntax Semantics Calculus emp SL N/A FOL N/A = + Arithmetic N/A := ; while if then else [.] dispose(.) cons(.) State is a pair (Store,Heap) St(.) maps variables to values H p(.) maps locations to values N/A if initial state satisfies P {P}S{Q} and S terminates More Inference then S does not fault and Rules COMP 2600 Separation Logic 35 final state satisfies Q

11 Semantics of Separation Logic Store : Var Val Heap : Num f in Val State = Store Heap St(e) value of an expression in a store as explained earlier (St,H p) = emp if dom(h p) = /0 New: binary connective e 1 e 2 which relates two expressions Semantics: (St,H p) = e 1 e 2 if dom(h p)={st(e 1 )} and H p(st(e 1 )) = St(e 2 ) i.e. a state (St,H p) makes the formula e 1 e 2 true if the heap is of size one and maps the location St(e 1 ) to the value St(e 2 ) COMP 2600 Separation Logic 36

12 Fetch Assignment Axiom of Separation Logic {(x = v 1 ) (e v 2 )} x := [e] {(x = v 2 ) (e(v 1 /x) v 2 )} where v 1 and v 2 are auxiliary variables which do not occur in e Example: x := [y] St H p x := [y] St H p y = y = x = 1 1 Fetch Axiom Instance: from previous slide {(x = v 1 ) (y 1)} x := [y] {(x = 1) (y 1)} Example: (St,H p) = y 1 if dom(h p) = {St(y)} and H p(st(y)) = St(1) i.e.: (St,H p) = y 1 if dom(h p) = {20} and H p(20) = 1 COMP 2600 Separation Logic 37

13 Fetch Assignment Axiom of Separation Logic {(x = v 1 ) (e v 2 )} x := [e] {(x = v 2 ) (e(v 1 /x) v 2 )} where v 1 and v 2 are auxiliary variables which do not occur in e St H p x := [e] St H p e St(e) e St(e) x = v 1 v 2 x = v 2 v 2 Fetch: x := [e] evaluate expression e in current state to get location l fault if location l is not in the current heap otherwise variable x is assigned the contents of location l (e v 2 ) in precondition demands heap contains location l so fetch instruction will not fault if it is executed from such a prestate Smallness: the heap is as small as possible i.e. of size one COMP 2600 Separation Logic 38

14 Heap Assignment Axiom of Separation Logic Heap Assignment Axiom {e } [e] := e 1 {e e 1 } where (e ) abbreviates ( z. e z) and z does not occur in e St H p [y] := 5 St H p y St(y) y St(y) 5 Heap Assignment Axiom Instance {y } [y] := 5 {y 5} where (y ) abbreviates ( z. y z) and z does not occur in y Heap Assignment Semantics: put value of e 1 into contents of location e evaluate e (in the current state) as location l i.e. St(e) fault if location l i.e. St(e) is not in the current heap i.e. H p otherwise make contents of location l the value of e 1 i.e St(e 1 ) COMP 2600 Separation Logic 39

15 Heap Assignment Axiom of Separation Logic Heap Assignment Axiom {e } [e] := e 1 {e e 1 } where (e ) abbreviates ( z. e z) St H p [e] := e 1 St H p e St(e) e St(e) c St(e 1 ) Semantics of e e 1 is (St,H p) = e e 1 if dom(h p)={st(e)} and H p(st(e)) = St(e 1 ) i.e. H p is a single location St(e) containing St(e 1 ) Semantics of e is (St,H p) = z.e z if for some value c we have dom(h p)={st(e)} and H p(st(e)) = c i.e. H p is a single location St(e) containing c So Heap Assignment Axiom means: if H p is a single location St(e) containing c then [e] := e 1 gives a single location St(e) containing St(e 1 ) COMP 2600 Separation Logic 40

16 Heap Assignment Axiom of Separation Logic Heap Assignment Axiom {e } [e] := e 1 {e e 1 } where (e ) abbreviates ( z. e z) St H p [e] := e 1 St H p e St(e) e St(e) c St(e 1 ) So Heap Assignment Axiom means: if H p is a single location St(e) containing c then [e] := e 1 gives a single location St(e) containing St(e 1 ) Heap Assignment Semantics: put value of e 1 into contents of location e evaluate e (in the current state) as location l i.e. St(e) fault if location l i.e. St(e) is not in the current heap i.e. H p otherwise make the contents of location l i.e. H p(st(e)) the value of expression e 1 i.e St(e 1 ) COMP 2600 Separation Logic 41

17 Heap Assignment Axiom of Separation Logic Heap Assignment Axiom {e } [e] := e 1 {e e 1 } where (e ) abbreviates ( z. e z) St H p [e] := e 1 St H p e St(e) e St(e) c St(e 1 ) Heap Assignment Axiom means: if H p is a single location St(e) containing some value then [e] := e 1 gives a single location St(e) containing St(e 1 ) Faults?: The assignment statement faults if location St(e) is not in the heap But: the precondition (e ) tells us that heap does contains location St(e) Hence: heap assignment will not fault if it is executed from such a prestate Smallness: the heap is as small as possible i.e. of size one COMP 2600 Separation Logic 42

18 Allocation Assignment Axiom of Separation Logic Allocation Assignment Axiom {x = v emp} x := cons(e 1,e 2,,e n ) {x e 1 (v/x),e 2 (v/x),,e n (v/x)} where v is an auxiliary variable different from x and not appearing in e 1,e 2,,e n Allocation Assignment Axiom means: if St(x) = v and H p is empty then x := cons(e 1,e 2,,e n ) makes x e 1 (v/x),e 2 (v/x),,e n (v/x) true Allocation Assignment Statement: means the following by definition St x := cons(e 1,e 2,,e n ) St H p x = l l l + 1 l + n 1 St(e 1 (v/x)) St(e 2 (v/x)) St(e n (v/x)) Never faults by definition COMP 2600 Separation Logic 43

19 Allocation Assignment Axiom of Separation Logic Allocation Assignment Axiom {x = v emp} x := cons(e 1,e 2,,e n ) {x e 1 (v/x),e 2 (v/x),,e n (v/x)} where v is an auxiliary variable different from x and not appearing in e 1,e 2,,e n St x := cons(e 1,e 2,,e n ) St H p x = l l l + 1 l + n 1 St(e 1 (v/x)) St(e 2 (v/x)) St(e n (v/x)) Semantics of x e 1 (v/x),e 2 (v/x),,e n (v/x) must say H p consists of n distinct locations such that picture holds Let: x e 1 (v/x),e 2 (v/x),,e n (v/x) abbreviate x e 1 (v/x) (x + 1) e 2 (v/x) (x + n 1) e n (v/x) COMP 2600 Separation Logic 44

20 Semantics of Separation Logic Store : Var Val Heap : Num f in Val State = Store Heap St(e) value of an expression in a store as explained earlier (St,H p) = emp if H p = /0 (St,H p) = e 1 e 2 if dom(h p)={st(e 1 )} and H p(st(e 1 )) = St(e 2 ) New: binary connective relating two formulae Semantics: (St,H p) = A B if H p can be partitioned into two disjoint heaps H p 1 and H p 2 and (St,H p 1 ) = A and (St,H p 2 ) = B Implies: (St,H p) = A 1 A 2 A n if H p can be partitioned into n distinct heaps H p 1,H p 2,,H p n and (St,H p 1 ) = A 1 and (St,H p 2 ) = A 2 and and (St,H p n ) = A n COMP 2600 Separation Logic 45

21 Allocation Assignment Axiom of Separation Logic Allocation Assignment Axiom {x = v emp} x := cons(e 1,e 2,,e n ) {x e 1 (v/x),e 2 (v/x),,e n (v/x)} where v is an auxiliary variable different from x and not appearing in e 1,e 2,,e n St x := cons(e 1,e 2,,e n ) St H p x = v x St(x) St(x) + 1 St(x) + n 1 St(e 1 (v/x)) St(e 2 (v/x)) St(e n (v/x)) So: x e 1 (v/x),e 2 (v/x),,e n (v/x) abbreviates x e 1 (v/x) (x + 1) e 2 (v/x) (x + n 1) e n (v/x) Allocation Assignment Axiom means: if St(x) = v and the heap is empty then executing x := cons(e 1,e 2,,e n ) gives a heap consisting of n new consecutive locations, where location St(x)+i contains St(e i+1 (v/x)) COMP 2600 Separation Logic 46

22 Allocation Assignment Axiom of Separation Logic Allocation Assignment Axiom {x = v emp} x := cons(e 1,e 2,,e n ) {x e 1 (v/x),e 2 (v/x),,e n (v/x)} where v is an auxiliary variable different from x and not appearing in e 1,e 2,,e n So: x e 1 (v/x),e 2 (v/x),,e n (v/x) abbreviates x e 1 (v/x) (x + 1) e 2 (v/x) (x + n 1) e n (v/x) Allocation Assignment Axiom means: if St(x) = v and the heap is empty then executing x := cons(e 1,e 2,,e n ) gives a heap consisting of n new consecutive locations, where location St(x)+i contains St(e i+1 (v/x)) Faults?: never by definition of allocation Smallness: the initial heap is as small as possible i.e. empty and the final heap is no larger than needed COMP 2600 Separation Logic 47

23 Dispose Axiom of Separation Logic Dispose Axiom {e } dispose(e) {emp} where (e ) abbreviates ( z. e z) and z does not occur in e St H p dispose(e) St e St(e) c Dispose Axiom means: if the heap is a single location St(e) containing some value c then executing dispose(e) gives the empty heap Deallocation: dispose(e) evaluate e to get some number l i.e. St(e) e.g. dispose(q) fault if location l is not in the heap otherwise remove location l from the heap COMP 2600 Separation Logic 48

24 Dispose Axiom of Separation Logic Dispose Axiom {e } dispose(e) {emp} where (e ) abbreviates ( z. e z) and z does not occur in e St H p dispose(e) St e St(e) c Dispose Axiom means: if the heap is a single location St(e) containing some value c then executing dispose(e) gives the empty heap Faults?: running dispose(e) from a prestate satisfying e means that the location St(e) is in the H p so it will not fault Smallness: initial heap is smallest possible heap from which we can dispose something i.e. singleton COMP 2600 Separation Logic 49

Separation Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré. Australian National University Semester 2, 2016

Separation Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré. Australian National University Semester 2, 2016 Separation Logic COMP2600 Formal Methods for Software Engineering Rajeev Goré Australian National University Semester 2, 2016 COMP 2600 Separation Logic 1 Motivation: Reasoning About Pointers Recall this

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Pointers Pointers and

More information

The Rule of Constancy(Derived Frame Rule)

The Rule of Constancy(Derived Frame Rule) The Rule of Constancy(Derived Frame Rule) The following derived rule is used on the next slide The rule of constancy {P } C {Q} {P R} C {Q R} where no variable assigned to in C occurs in R Outline of derivation

More information

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

Hoare logic. WHILE p, a language with pointers. Introduction. Syntax of WHILE p. Lecture 5: Introduction to separation logic Introduction Hoare logic Lecture 5: Introduction to separation logic In the previous lectures, we have considered a language, WHILE, where mutability only concerned program variables. Jean Pichon-Pharabod

More information

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

Hoare logic. Lecture 5: Introduction to separation logic. Jean Pichon-Pharabod University of Cambridge. CST Part II 2017/18 Hoare logic Lecture 5: Introduction to separation logic Jean Pichon-Pharabod University of Cambridge CST Part II 2017/18 Introduction In the previous lectures, we have considered a language, WHILE, where

More information

Hoare triples. Floyd-Hoare Logic, Separation Logic

Hoare triples. Floyd-Hoare Logic, Separation Logic Hoare triples Floyd-Hoare Logic, Separation Logic 1. Floyd-Hoare Logic 1969 Reasoning about control Hoare triples {A} p {B} a Hoare triple partial correctness: if the initial state satisfies assertion

More information

Compilation and Program Analysis (#11) : Hoare triples and shape analysis

Compilation and Program Analysis (#11) : Hoare triples and shape analysis Compilation and Program Analysis (#11) : Hoare triples and shape analysis Laure Gonnord http://laure.gonnord.org/pro/teaching/capm1.html Laure.Gonnord@ens-lyon.fr Master 1, ENS de Lyon dec 2017 Inspiration

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the

More information

Hoare Logic and Model Checking. A proof system for Separation logic. Introduction. Separation Logic

Hoare Logic and Model Checking. A proof system for Separation logic. Introduction. Separation Logic Introduction Hoare Logic and Model Checking In the previous lecture we saw the informal concepts that Separation Logic is based on. Kasper Svendsen University of Cambridge CST Part II 2016/17 This lecture

More information

An Annotated Language

An Annotated Language Hoare Logic An Annotated Language State and Semantics Expressions are interpreted as functions from states to the corresponding domain of interpretation Operators have the obvious interpretation Free of

More information

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré

Hoare Logic. COMP2600 Formal Methods for Software Engineering. Rajeev Goré Hoare Logic COMP2600 Formal Methods for Software Engineering Rajeev Goré Australian National University Semester 2, 2016 (Slides courtesy of Ranald Clouston) COMP 2600 Hoare Logic 1 Australian Capital

More information

Hoare logic. A proof system for separation logic. Introduction. Separation logic

Hoare logic. A proof system for separation logic. Introduction. Separation logic Introduction Hoare logic Lecture 6: Examples in separation logic In the previous lecture, we saw how reasoning about pointers in Hoare logic was problematic, which motivated introducing separation logic.

More information

Chapter 3: Propositional Languages

Chapter 3: Propositional Languages Chapter 3: Propositional Languages We define here a general notion of a propositional language. We show how to obtain, as specific cases, various languages for propositional classical logic and some non-classical

More information

BI as an Assertion Language for Mutable Data Structures

BI as an Assertion Language for Mutable Data Structures BI as an Assertion Language for Mutable Data Structures Samin Ishtiaq Peter W. O Hearn Queen Mary & Westfield College, London ABSTRACT Reynolds has developed a logic for reasoning about mutable data structures

More information

Lecture 5 - Axiomatic semantics

Lecture 5 - Axiomatic semantics Program Verification March 2014 Lecture 5 - Axiomatic semantics Lecturer: Noam Rinetzky Scribes by: Nir Hemed 1.1 Axiomatic semantics The development of the theory is contributed to Robert Floyd, C.A.R

More information

COMP Logic for Computer Scientists. Lecture 17

COMP Logic for Computer Scientists. Lecture 17 COMP 1002 Logic for Computer Scientists Lecture 17 5 2 J Puzzle: the barber In a certain village, there is a (male) barber who shaves all and only those men of the village who do not shave themselves.

More information

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 19 Tuesday, April 3, 2018 1 Introduction to axiomatic semantics The idea in axiomatic semantics is to give specifications

More information

Reminder of the last lecture. Aliasing Issues: Call by reference, Pointer programs. Introducing Aliasing Issues. Home Work from previous lecture

Reminder of the last lecture. Aliasing Issues: Call by reference, Pointer programs. Introducing Aliasing Issues. Home Work from previous lecture Reminder of the last lecture Aliasing Issues: Call by reference, Pointer programs Claude Marché Cours MPRI 2-36-1 Preuve de Programme 18 janvier 2017 Additional features of the specification language Abstract

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,

More information

Induction and Semantics in Dafny

Induction and Semantics in Dafny 15-414 Lecture 11 1 Instructor: Matt Fredrikson Induction and Semantics in Dafny TA: Ryan Wagner Encoding the syntax of Imp Recall the abstract syntax of Imp: a AExp ::= n Z x Var a 1 + a 2 b BExp ::=

More information

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 27, 2017 Goal: write programs in a high-level (ML-style) language, prove them correct interactively,

More information

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

Typed Lambda Calculus

Typed Lambda Calculus Department of Linguistics Ohio State University Sept. 8, 2016 The Two Sides of A typed lambda calculus (TLC) can be viewed in two complementary ways: model-theoretically, as a system of notation for functions

More information

Working with recursion

Working with recursion Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

Merge Sort Goodrich, Tamassia Merge Sort 1

Merge Sort Goodrich, Tamassia Merge Sort 1 Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 2004 Goodrich, Tamassia Merge Sort 1 Review of Sorting Selection-sort: Search: search through remaining unsorted elements for min Remove: remove

More information

Proving the Correctness of Distributed Algorithms using TLA

Proving the Correctness of Distributed Algorithms using TLA Proving the Correctness of Distributed Algorithms using TLA Khushboo Kanjani, khush@cs.tamu.edu, Texas A & M University 11 May 2007 Abstract This work is a summary of the Temporal Logic of Actions(TLA)

More information

More on Operational Semantics

More on Operational Semantics More on Operational Semantics (Slides modified from those created by Xinyu Feng) 1 / 23 Outline Various formulations Extensions Going wrong Local variable declaration Heap Big-step operational semantics

More information

Reasoning About Imperative Programs. COS 441 Slides 10

Reasoning About Imperative Programs. COS 441 Slides 10 Reasoning About Imperative Programs COS 441 Slides 10 The last few weeks Agenda reasoning about functional programming It s very simple and very uniform: substitution of equal expressions for equal expressions

More information

Module 8: Binary trees

Module 8: Binary trees Module 8: Binary trees Readings: HtDP, Section 14 We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Formal Specification: Z Notation. CITS5501 Software Testing and Quality Assurance

Formal Specification: Z Notation. CITS5501 Software Testing and Quality Assurance Formal Specification: Z Notation CITS5501 Software Testing and Quality Assurance The Zed Notation, J.M.Spivey. Semester 1, 2017 A Formal Specification Notation A Syntax - often based on set theory and

More information

Comp 311: Sample Midterm Examination

Comp 311: Sample Midterm Examination Comp 311: Sample Midterm Examination October 29, 2007 Name: Id #: Instructions 1. The examination is closed book. If you forget the name for a Scheme operation, make up a name for it and write a brief

More information

Reasoning About Programs Panagiotis Manolios

Reasoning About Programs Panagiotis Manolios Reasoning About Programs Panagiotis Manolios Northeastern University March 22, 2012 Version: 58 Copyright c 2012 by Panagiotis Manolios All rights reserved. We hereby grant permission for this publication

More information

Module 9: Binary trees

Module 9: Binary trees Module 9: Binary trees Readings: HtDP, Section 14 We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week 16: Review Zhiyuan Li Department of Computer Science Purdue University, USA This has been quite a journey Congratulation to all students who have worked hard in honest

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Lecture 20 : Trees DRAFT

Lecture 20 : Trees DRAFT CS/Math 240: Introduction to Discrete Mathematics 4/12/2011 Lecture 20 : Trees Instructor: Dieter van Melkebeek Scribe: Dalibor Zelený DRAFT Last time we discussed graphs. Today we continue this discussion,

More information

More Examples. Lecture 24: More Scala. Higher-Order Functions. Control Structures

More Examples. Lecture 24: More Scala. Higher-Order Functions. Control Structures More Examples Lecture 24: More Scala CSC 131 Fall, 2014 Kim Bruce MyList, MyArrayList, SinglyLinkedList - Val vs var - Can create Array[T] (unlike Java), though need implicit ClassManifest - foreach(f)

More information

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory Logic as a framework for NL semantics Semantic Theory Type Theory Manfred Pinkal Stefan Thater Summer 2007 Approximate NL meaning as truth conditions. Logic supports precise, consistent and controlled

More information

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

CS321 Languages and Compiler Design I Winter 2012 Lecture 13 STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how

More information

Computer Algorithms-2 Prof. Dr. Shashank K. Mehta Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Computer Algorithms-2 Prof. Dr. Shashank K. Mehta Department of Computer Science and Engineering Indian Institute of Technology, Kanpur Computer Algorithms-2 Prof. Dr. Shashank K. Mehta Department of Computer Science and Engineering Indian Institute of Technology, Kanpur Lecture - 6 Minimum Spanning Tree Hello. Today, we will discuss an

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6 - Defining a Programming Language Bottom Up Collaboration and Management - Elements of Programming Dana Fisman 1 What we accomplished

More information

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University

Static Program Analysis Part 9 pointer analysis. Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Static Program Analysis Part 9 pointer analysis Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Agenda Introduction to points-to analysis Andersen s analysis Steensgaards s

More information

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur Module 6 Knowledge Representation and Logic (First Order Logic) 6.1 Instructional Objective Students should understand the advantages of first order logic as a knowledge representation language Students

More information

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 Goals of this tutorial You should be able to... understand

More information

Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017

Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017 Integrated Introduction to Computer Science Hughes Lecture 27: (PROVISIONAL) Insertion Sort, Selection Sort, and Merge Sort 10:00 AM, Nov 8, 2017 Contents 1 Program Structure and Data Structure 1 2 Sorting

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

A Small Interpreted Language

A Small Interpreted Language A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that

More information

Software Verification : Introduction

Software Verification : Introduction Software Verification : Introduction Ranjit Jhala, UC San Diego April 4, 2013 What is Algorithmic Verification? Algorithms, Techniques and Tools to ensure that Programs Don t Have Bugs (What does that

More information

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 37 Resolution Rules Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras Lecture - 37 Resolution Rules If some literals can be unified, the same algorithm should be able

More information

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs?

Part II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs? Part II. Hoare Logic and Program Verification Part II. Hoare Logic and Program Verification Dilian Gurov Props: Models: Specs: Method: Tool: safety of data manipulation source code logic assertions Hoare

More information

Software Quality Assurance

Software Quality Assurance Software Quality Assurance Every week we see new examples of: computer systems error/failure Here are some examples, taken from different industries Airport chaos after computer crash By Vanessa Allen,

More information

Chapter 3 (part 3) Describing Syntax and Semantics

Chapter 3 (part 3) Describing Syntax and Semantics Chapter 3 (part 3) Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Typed Lambda Calculus for Syntacticians

Typed Lambda Calculus for Syntacticians Department of Linguistics Ohio State University January 12, 2012 The Two Sides of Typed Lambda Calculus A typed lambda calculus (TLC) can be viewed in two complementary ways: model-theoretically, as a

More information

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

Functional Programming in Embedded System Design

Functional Programming in Embedded System Design Functional Programming in Embedded System Design Al Strelzoff CTO, E-TrolZ Lawrence, Mass. al.strelzoff@e-trolz.com 1/19/2006 Copyright E-TrolZ, Inc. 1 of 20 Hard Real Time Embedded Systems MUST: Be highly

More information

Integrating Arrays into the Heap-Hop program prover

Integrating Arrays into the Heap-Hop program prover Integrating Arrays into the Heap-Hop program prover Ioana Cristescu under the supervision of Jules Villard Queen Mary University of London 7 September 2011 1 / 29 Program verification using Heap-Hop Program

More information

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Lecture 14 No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions? Friday, February 11 CS 215 Fundamentals of Programming II - Lecture 14 1 Outline Static

More information

Inferring Invariants in Separation Logic for Imperative List-processing Programs

Inferring Invariants in Separation Logic for Imperative List-processing Programs Inferring Invariants in Separation Logic for Imperative List-processing Programs Stephen Magill Carnegie Mellon University smagill@cs.cmu.edu Aleksandar Nanevski Harvard University aleks@eecs.harvard.edu

More information

Introduction to Axiomatic Semantics (1/2)

Introduction to Axiomatic Semantics (1/2) #1 Introduction to Axiomatic Semantics (1/2) How s The Homework Going? Remember: just do the counterexample guided abstraction refinement part of DPLL(T). If you notice any other errors, those are good

More information

Lecture 4. First order logic is a formal notation for mathematics which involves:

Lecture 4. First order logic is a formal notation for mathematics which involves: 0368.4435 Automatic Software Verification April 14, 2015 Lecture 4 Lecturer: Mooly Sagiv Scribe: Nimrod Busany, Yotam Frank Lesson Plan 1. First order logic recap. 2. The SMT decision problem. 3. Basic

More information

Mathematical Programming Formulations, Constraint Programming

Mathematical Programming Formulations, Constraint Programming Outline DM87 SCHEDULING, TIMETABLING AND ROUTING Lecture 3 Mathematical Programming Formulations, Constraint Programming 1. Special Purpose Algorithms 2. Constraint Programming Marco Chiarandini DM87 Scheduling,

More information

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction Topics Chapter 3 Semantics Introduction Static Semantics Attribute Grammars Dynamic Semantics Operational Semantics Axiomatic Semantics Denotational Semantics 2 Introduction Introduction Language implementors

More information

Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008

Softwaretechnik. Lecture 03: Types and Type Soundness. Peter Thiemann. University of Freiburg, Germany SS 2008 Softwaretechnik Lecture 03: Types and Type Soundness Peter Thiemann University of Freiburg, Germany SS 2008 Peter Thiemann (Univ. Freiburg) Softwaretechnik SWT 1 / 35 Table of Contents Types and Type correctness

More information

A semantics for concurrent separation logic

A semantics for concurrent separation logic A semantics for concurrent separation logic Stephen Brookes Carnegie Mellon University Department of Computer Science Abstract. We present a denotational semantics based on action traces, for parallel

More information

Formal Syntax and Semantics of Programming Languages

Formal Syntax and Semantics of Programming Languages Formal Syntax and Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html The While

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

Pointers. Memory. void foo() { }//return

Pointers. Memory. void foo() { }//return Pointers Pointers Every location in memory has a unique number assigned to it called it s address A pointer is a variable that holds a memory address A pointer can be used to store an object or variable

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the

More information

Introduction to Axiomatic Semantics (1/2)

Introduction to Axiomatic Semantics (1/2) #1 Introduction to Axiomatic Semantics (1/2) How s The Homework Going? Remember that you can t just define a meaning function in terms of itself you must use some fixed point machinery. #2 #3 Observations

More information

A verified runtime for a verified theorem prover

A verified runtime for a verified theorem prover A verified runtime for a verified theorem prover Magnus Myreen 1 and Jared Davis 2 1 University of Cambridge, UK 2 Centaur Technology, USA Two projects meet My theorem prover is written in Lisp. Can I

More information

Planning: STRIPS and POP planners

Planning: STRIPS and POP planners S 57 Introduction to I Lecture 8 Planning: STRIPS and POP planners Milos Hauskrecht milos@cs.pitt.edu 5329 Sennott Square Representation of actions, situations, events Propositional and first order logic

More information

A Proposal for Weak-Memory Local Reasoning

A Proposal for Weak-Memory Local Reasoning A Proposal for Weak-Memory Local Reasoning Ian Wehrman and Josh Berdine Abstract Program logics are formal systems for specifying and reasoning about software programs. Most program logics make the strong

More information

On the C11 Memory Model and a Program Logic for C11 Concurrency

On the C11 Memory Model and a Program Logic for C11 Concurrency On the C11 Memory Model and a Program Logic for C11 Concurrency Manuel Penschuck Aktuelle Themen der Softwaretechnologie Software Engineering & Programmiersprachen FB 12 Goethe Universität - Frankfurt

More information

Deductive Methods, Bounded Model Checking

Deductive Methods, Bounded Model Checking Deductive Methods, Bounded Model Checking http://d3s.mff.cuni.cz Pavel Parízek CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Deductive methods Pavel Parízek Deductive Methods, Bounded

More information

Principles of Program Analysis. Lecture 1 Harry Xu Spring 2013

Principles of Program Analysis. Lecture 1 Harry Xu Spring 2013 Principles of Program Analysis Lecture 1 Harry Xu Spring 2013 An Imperfect World Software has bugs The northeast blackout of 2003, affected 10 million people in Ontario and 45 million in eight U.S. states

More information

λ calculus is inconsistent

λ calculus is inconsistent Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles

More information

Lectures 20, 21: Axiomatic Semantics

Lectures 20, 21: Axiomatic Semantics Lectures 20, 21: Axiomatic Semantics Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Based on slides by George Necula Pratikakis (CSD) Axiomatic Semantics

More information

Program Analysis: Lecture 02 Page 1 of 32

Program Analysis: Lecture 02 Page 1 of 32 Program Analysis: Lecture 02 Page 1 of 32 Program Analysis/ Mooly Sagiv Lecture 1, 31/10/2012 Operational Semantics Notes by: Kalev Alpernas As background to the subject of Program Analysis, we will first

More information

Conceptual modeling of entities and relationships using Alloy

Conceptual modeling of entities and relationships using Alloy Conceptual modeling of entities and relationships using Alloy K. V. Raghavan Indian Institute of Science, Bangalore Conceptual modeling What is it? Capture requirements, other essential aspects of software

More information

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic. Overview CS389L: Automated Logical Reasoning Lecture 6: First Order Logic Syntax and Semantics Işıl Dillig So far: Automated reasoning in propositional logic. Propositional logic is simple and easy to

More information

User-defined Functions. Conditional Expressions in Scheme

User-defined Functions. Conditional Expressions in Scheme User-defined Functions The list (lambda (args (body s to a function with (args as its argument list and (body as the function body. No quotes are needed for (args or (body. (lambda (x (+ x 1 s to the increment

More information

Recency Types for Dynamically-Typed, Object-Based Languages

Recency Types for Dynamically-Typed, Object-Based Languages Recency Types for Dynamically-Typed, Object-Based Languages Phillip Heidegger, Peter Thiemann Albert-Ludwigs-Universität Freiburg 15.10.2008 Task: Maintenance Finding bugs in JavaScript programs Understanding

More information

Axiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof

Axiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof Lecture 18: Axiomatic Semantics & Type Safety CSCI 131 Fall, 2011 Kim Bruce Axiomatic Rules Assignment axiom: - {P [expression / id]} id := expression {P} - Ex: {a+47 > 0} x := a+47 {x > 0} - {x > 1} x

More information

Introduction to Programming in C Department of Computer Science and Engineering

Introduction to Programming in C Department of Computer Science and Engineering Introduction to Programming in C Department of Computer Science and Engineering Once we know structures and pointers to structures, we can introduce some very important data structure called link list.

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

n Takes abstract syntax trees as input n In simple cases could be just strings n One procedure for each syntactic category

n Takes abstract syntax trees as input n In simple cases could be just strings n One procedure for each syntactic category Interpreter Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul

More information

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics ISBN Chapter 3 Describing Syntax and Semantics ISBN 0-321-49362-1 Chapter 3 Topics Describing the Meanings of Programs: Dynamic Semantics Copyright 2015 Pearson. All rights reserved. 2 Semantics There is no

More information

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018 Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters Corky Cartwright January 26, 2018 Denotational Semantics The primary alternative to syntactic semantics is denotational semantics.

More information

Exercise 1: Graph coloring (10 points)

Exercise 1: Graph coloring (10 points) Exercise 1: Graph coloring (10 points) Graph coloring is the problem of assigning colors to vertices in a non-directed graph, so that no two adjacent nodes have the same color. In other words, if two vertices

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 16: Functional Programming Zheng (Eddy Zhang Rutgers University April 2, 2018 Review: Computation Paradigms Functional: Composition of operations on data.

More information

Chapter 7 Sorting. Terminology. Selection Sort

Chapter 7 Sorting. Terminology. Selection Sort Chapter 7 Sorting Terminology Internal done totally in main memory. External uses auxiliary storage (disk). Stable retains original order if keys are the same. Oblivious performs the same amount of work

More information

EDAA40 At home exercises 1

EDAA40 At home exercises 1 EDAA40 At home exercises 1 1. Given, with as always the natural numbers starting at 1, let us define the following sets (with iff ): Give the number of elements in these sets as follows: 1. 23 2. 6 3.

More information

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once. Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation Lecture 15 COP 3014 Fall 2017 November 6, 2017 Allocating memory There are two ways that memory gets allocated for data storage: 1. Compile Time (or static) Allocation Memory

More information

Merge Sort fi fi fi 4 9. Merge Sort Goodrich, Tamassia

Merge Sort fi fi fi 4 9. Merge Sort Goodrich, Tamassia Merge Sort 7 9 4 fi 4 7 9 7 fi 7 9 4 fi 4 9 7 fi 7 fi 9 fi 9 4 fi 4 Merge Sort 1 Divide-and-Conquer ( 10.1.1) Divide-and conquer is a general algorithm design paradigm: Divide: divide the input data S

More information