Algebra unifies calculi of programming Tony Hoare Feb 2012.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Models of Concurrency Manna, Pnueli.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Tracelets: a Model for the Laws of Concurrent Programming Tony Hoare OxfordFeb 2012.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Discrete Structures Lecture 29 Predicates and Programming Read Ch
Predicate Transformers
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Algebra of Concurrent Programming Tony Hoare Cambridge 2011.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
An Algebra for Program Designs Tony Hoare MoscowJuly 2011.
1 Ivan Lanese Computer Science Department University of Bologna Roberto Bruni Computer Science Department University of Pisa A mobile calculus with parametric.
Discrete Mathematics Lecture 4 Harper Langston New York University.
Logic in Computer Science Transparency No Chapter 3 Propositional Logic 3.6. Propositional Resolution.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Chapter 3 Propositional Logic
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
Proving Program Correctness The Axiomatic Approach.
Introduction to Formal Methods Based on Jeannette M. Wing. A Specifier's Introduction to Formal Methods. IEEE Computer, 23(9):8-24, September,
Charts and nets: States, Messages, and Events Tony Hoare In honour of David Harel ViennaJuly 2014.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Advanced Topics in SE Spring Process Algebra Hossein Hojjat Formal Methods Lab University of Tehran.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Laws of concurrent design Tony Hoare Microsoft ResearchCambridge FMCAD October.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Mathematical Preliminaries
Theories and Hypotheses. Assumptions of science A true physical universe exists Order through cause and effect, the connections can be discovered Knowledge.
An Axiomatic Basis for Computer Programming Robert Stewart.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Chapter 8 Asynchronous System Model by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Formally proving facts in the refinement algebra Vlad Shcherbina Ilya Maryassov Alexander Kogtenkov Alexander Myltsev Pavel Shapkin Sergey Paramonov Mentor:
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Program Analysis and Verification
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Lecture 5 Floyd-Hoare Style Verification
Lecture 2: Axiomatic semantics
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Semantics In Text: Chapter 3.
Predicate Transformers
Abstraction.
Formal Methods in software development
Program correctness Axiomatic semantics
Lecture 2: Axiomatic semantics
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Algebra unifies calculi of programming Tony Hoare Feb 2012

With Ideas from Ian Wehrman John Wickerson Stephan van Staden Peter O’Hearn Bernhard Moeller Georg Struth Rasmus Petersen …and others

and Calculi from Robin Milner Edsger Dijkstra Ralph Back Carroll Morgan Gilles Kahn, Gordon Plotkin Cliff Jones Tony Hoare

but in this talk, only four Robin Milner x Edsger Dijkstra x Ralph Back Carroll Morgan x Gilles Kahn, Gordon Plotkin Cliff Jones Tony Hoare x

Subject matter: specs variables (p, q, r) stand for computer programs, designs, contracts, specifications,… they all describe what happens inside/around a computer that executes a given program. The program itself is the most precise description – giving all the excruciating detail. The user specification is the most abstract – describing only interactions with environment. Designs come in between.

Example specs Postcondition: – execution ends with array A sorted Conditional correctness: – if execution ends, it ends with A sorted Precondition: – execution starts with x even Program: x := x+1 – the final value of x is one greater than the initial

More examples of specs Safety: – There are no buffer overflows Termination: – execution is finite (ie., always ends) Liveness: – no infinite internal activity (livelock) Fairness: – no infinite waiting Probability: – the ration of a’s to b’s tends to 1 with time

Also Security – low programs do not access high variables Separation – threads do not assign to shared variables Communication – outputs on channel c are in alphabetical order Predictability – there are no race conditions timing – interval between request and response is short

Advantages of unification Same laws for programs, designs, specs Same laws for many forms of correctness Tools based on the laws serve many purposes – and communicate by sound interfaces Scientific controversy is resolved – and engineers confidently apply the science

Operators on specs or\/disjunction and/\conjunction then;sequential composition while*concurrent composition Constants skipIterminates immediately true ⊤ does anything false ⊥ never starts

The language model a language is a set of strings of characters /\ is set intersection \/ is set union ; is pointwise concatenation of strings * is pointwise interleaving of strings I is the language with only the empty string ⊤ is set of all strings ⊥ is the empty set.

Laws \//\;* assoc yesyesyesyes comm yesyesnoyes  yesyesnono unit  T  zeroT  

Distribution axioms ; distributes through \/ (p*q) ; (p’ * q’)=>(p;p’)*(q;q’) – wherep => q = def q = p \/ q (refinement) in the language model – there are less interleavings on the left of => remember the exchange law in categories?

Theorems => is a partial order All the operators are monotonic (p*q);q’ => p*(q;q’) – Proof: substitute  for p’ in exchange (p/\q);(p’/\q’) =>(p;p’)/\(q;q’) – Proof: lhs => p;p’by monotonicity of ; lhs => q;q’similarly. The result follows from Boolean algebra.

Hoare triple: {p} q {r} defined as p;q => r – starting in the final state of any execution of p, q ends in the final state of some execution of r – (p and r may be arbitrary specs). example: {..x+1 ≤ n} x:= x + 1 {..x ≤ n} where..b (finally b) describes all executions that end in a state satisfying a single-state predicate b.

Milner triple: r - p -> q defined as p;q => r (same as Hoare!) – r may be executed by first executing p and then executing q. – p is usually restricted to atomic actions. example: ( ;q) – -> q where is an atomic action – r -> p = def. p => r an execution step may reduce non-determinism

Theorems Using these definitions, the rules of the Hoare calculus and of the Milner calculus are derivable by simple algebraic proofs from the laws of the algebra.

Rule of consequence p => p’ {p’} q {r’}r’ => r {p} q {r} r -> r’r’ –q-> p’p’ -> p r –q-> p Proof: ; is monotonic, => is transitive. These two rules are not only similar, they are the same!

Sequential composition {p} q {s} {s} q’ {r} {p} q;q’ {r} r –q-> ss –q’-> p r –q;q’-> p – Proof: associativity of ;

Small-step rule p – -> r (r;q’) – ->(q;q’) {p} q {r}. {p} q;q’ {r;q’} Proof: monotonicity of ;

Choice {p} q {r}{p} q’ {r} {p} (q \/ q’) {r} – both choices must be correct r –q-> p (r \/ r’) –q-> p – so the execution may make either choice

Frame Law {p} q {r} {p*f} q {r*f} – adapts a rule to a wider environment f r –q-> p (r*f) –q-> (p*f) – a step that is possible for a single thread is still possible in a wider environment f

Concurrency (and Conjunction) {p} q {r} {p’} q’ {r’} {p*p’} (q * q’) {r*r’} – permits modular proof of concurrent programs. {p} q {r} {p’} q’ {r’} {p/\p’} (q /\ q’) {r/\r’} – in Floyd’s rule of conjunction, q = q’.

Concurrency r –p-> qr’ -p’-> q’ (r*r) -(p*p’)-> (q*q’) – provided p*p’ = τ – where τ is the unobserved transition, (which occurs (in CCS) when p and p’ are an input and an output on the same channel).

Dijkstra triple: p => q\r usually written:p => wlp(q,r) ‘defined’ by:p;q => r(again) wp(q,r) = wlp(q, r/\ terminates) q\r specifies the weakest program which can be executed before q to achieve the overall effect of r.

Morgan triple: q => r/p ‘defined’ by:p;q => r(again) r/p is the weakest program which can be executed after p to achieve r.

Theorems q\(r /\ r’)=(q\r) /\ (q\r’) (r /\ r’)/p=(r/p) /\ (r’/p) (q \/ q’)\r=(q\r) /\ (q’\r) r/(p \/ p’)=(r/p) /\ (r/p’)

Theorems (q;q’)\r=q\(q’\r) r/(p;p’)=(r/p)/p’ (q\r)*(q’\r’)=>(q*q’)\(r*r’) exchange law

Unification is the goal of every branch of pure science, because it increases conviction in theory Specialisation is needed for each application, e.g., Hoare logic: proofs of correctness, Milner: implementation, Dijkstra: program analysis, Morgan: programs from specifications …

Algebra is modular, incremental, comprehensible, abstract and beautiful. An algebraic law can say as little as you like – using any other concepts that you need. – new properties can be added by new laws. The definition of a concept is allowed only once – so it must describe all the needed properties, – using only previously defined concepts. Inductive clauses restrict incrementality Algebra is good for unification

Summary: p;q => r is written p {q} r {p} q {r} r –p-> q p => wlp(q,r) q => [p, r] by Hoare(triple) Wirth(triple) Milner (transition) Dijkstra (weakest precondition) Morgan (specification statement) Milner restricts p to atomic actions (small-step version). The others restrict p and r to descriptions of single states.

Conclusions All the calculi are derived from the same algebra of programming. The algebra is simpler than each of the calculi, and stronger than all of them combined.

Isaac Newton Communication with Richard Gregory (1694) “Our specious algebra [of fluxions] is fit enough to find out, but entirely unfit to consign to writing and commit to posterity.”