Laws of concurrent design Tony Hoare Microsoft ResearchCambridge FMCAD 2012 23 October.

Slides:



Advertisements
Similar presentations
Distributed Snapshots: Determining Global States of Distributed Systems Joshua Eberhardt Research Paper: Kanianthra Mani Chandy and Leslie Lamport.
Advertisements

Models of Concurrency Manna, Pnueli.
Types of Logic Circuits
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.
Chapter 2 Fundamentals of Logic Dept of Information management National Central University Yen-Liang Chen.
1.6 Behavioral Equivalence. 2 Two very important concepts in the study and analysis of programs –Equivalence between programs –Congruence between statements.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
1 Logic Logic in general is a subfield of philosophy and its development is credited to ancient Greeks. Symbolic or mathematical logic is used in AI. In.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Tracelets: a Model for the Laws of Concurrent Programming Tony Hoare OxfordFeb 2012.
Unifying Theories of Concurrency: CCSandCSP He Jifeng and Tony Hoare BCTCSApril 6, 2006.
Algebra unifies calculi of programming Tony Hoare Feb 2012.
Algebra of Concurrent Programming Tony Hoare Cambridge 2011.
Computability and Complexity 9-1 Computability and Complexity Andrei Bulatov Logic Reminder (Cnt’d)
A Semantic Characterization of Unbounded-Nondeterministic Abstract State Machines Andreas Glausch and Wolfgang Reisig 1.
Introduction to Computability Theory
An Algebra for Program Designs Tony Hoare MoscowJuly 2011.
CPSC 668Set 16: Distributed Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
Logic in Computer Science Transparency No Chapter 3 Propositional Logic 3.6. Propositional Resolution.
Syllabus Every Week: 2 Hourly Exams +Final - as noted on Syllabus
Modeling Software Systems Lecture 2 Book: Chapter 4.
מבנה המחשב + מבוא למחשבים ספרתיים תרגול 1#
From Chapter 4 Formal Specification using Z David Lightfoot
Chair of Software Engineering 1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan.
1 Static vs dynamic SAGAs Ivan Lanese Computer Science Department University of Bologna/INRIA Italy.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
EE1J2 – Discrete Maths Lecture 5
Introduction to Logic Logical Form: general rules
Adapted from Discrete Math
Chapter 2 – Fundamentals of Logic. Outline Basic Connectives and Truth Tables Logical Equivalence: The Laws of Logic Ligical Implication: Rules of Inference.
Boolean Algebra – I. Outline  Introduction  Digital circuits  Boolean Algebra  Two-Valued Boolean Algebra  Boolean Algebra Postulates  Precedence.
Charts and nets: States, Messages, and Events Tony Hoare In honour of David Harel ViennaJuly 2014.
Review I Rosen , 3.1 Know your definitions!
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Chap. 2 Fundamentals of Logic. Proposition Proposition (or statement): an declarative sentence that is either true or false, but not both. e.g. –Margret.
Advanced Topics in SE Spring Process Algebra Hossein Hojjat Formal Methods Lab University of Tehran.
CS6133 Software Specification and Verification
2G1516 Formal Methods2005 Mads Dam IMIT, KTH 1 CCS: Operational Semantics And Process Algebra Mads Dam Reading: Peled 8.3, 8.4, 8.6 – rest of ch. 8.
2.3Logical Implication: Rules of Inference From the notion of a valid argument, we begin a formal study of what we shall mean by an argument and when such.
Fundamentals of Logic 1. What is a valid argument or proof? 2. Study system of logic 3. In proving theorems or solving problems, creativity and insight.
Propositional Logic. Propositions Any statement that is either True (T) or False (F) is a proposition Propositional variables: a variable that can assume.
--- outputs logical functions of inputs --- new outputs appear shortly after changed inputs (propagation delay) --- no feedback loops --- no clock Sequential.
Mathematical Preliminaries
An Axiomatic Basis for Computer Programming Robert Stewart.
CSCI1600: Embedded and Real Time Software Lecture 11: Modeling IV: Concurrency Steven Reiss, Fall 2015.
Chapter 2 Fundamentals of Logic 1. What is a valid argument or proof?
Chapter 7. Propositional and Predicate Logic Fall 2013 Comp3710 Artificial Intelligence Computing Science Thompson Rivers University.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 16: Distributed Shared Memory 1.
Ordering of Events in Distributed Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 739 Distributed Systems Andrea C. Arpaci-Dusseau.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
Program Analysis and Verification
Agenda  Quick Review  Finish Introduction  Java Threads.
Discrete Math by R.S. Chang, Dept. CSIE, NDHU1 Fundamentals of Logic 1. What is a valid argument or proof? 2. Study system of logic 3. In proving theorems.
CSE 461. Binary Logic Binary logic consists of binary variables and logical operations. Variables are designated by letters such as A, B, C, x, y, z etc.
CHAPTER 2 Boolean algebra and Logic gates
Chapter 1 Logic and proofs
CENG 424-Logic for CS Introduction Based on the Lecture Notes of Konstantin Korovin, Valentin Goranko, Russel and Norvig, and Michael Genesereth.
Chapter 7. Propositional and Predicate Logic
2. The Logic of Compound Statements Summary
Introduction to Logic for Artificial Intelligence Lecture 2
Propositional Calculus: Boolean Algebra and Simplification
Elementary Metamathematics
Information Technology Department
Chap 3. The simplex method
Lecture 2: Distributed Programs and their Correctness
Computer Security: Art and Science, 2nd Edition
Chapter 7. Propositional and Predicate Logic
COMP 1380 Discrete Structures I Thompson Rivers University
Program correctness Axiomatic semantics
Presentation transcript:

Laws of concurrent design Tony Hoare Microsoft ResearchCambridge FMCAD October

Summary What are they? Are they useful? Are they true? Are they beautiful?

1. Laws

Subject matter (traces of) execution of a program – recording a set of events, – occurring inside and near a computer – while it is executing a program specifications/designs/programs – describing sets of traces – that are desired/planned/actual – when the program is executed the same laws will apply to both.

Three operators then;sequential composition with||concurrent composition skip I does nothing

Five Axioms assocp;(q;r) = (p;q);r(also ||) commp||q = q||p unitp|| I = p = I ||p(also ;)

Reversibility assocp;(q;r) = (p;q);r(also ||) commp||q = q||p unit p|| I = p = I ||p (also ;) swapping the order of operands of ; (or of ||) translates each axiom into itself.

Duality Metatheorem: (theorems for free) When a theorem is translated by reversing the operands of all ;s (or of all ||s), the result is also a theorem. Many laws of physics are also reversible in the direction of time

Comparison: p => q Example: refinement – every trace described by p is also described by q Example: definement(Scott ⊑) – if the trace p is defined it is equal to the trace q

Axiom => is a partial order – reflexivep => p – transitiveif p => q & q => r then p => r swapping the operands of => translates each axiom into itself justifies duality by order reversal

Monotonicity Definition: an operator  is monotonic if – p => q implies p  r => q  r & r  p => r  q Axiom: ; and || are monotonic justifies replacement of any component of a term by one that is more refined/defined

Monotonicity Metatheorem : Let F be a formula containing p. Let F’ be a translation of F that replaces an occurrence of p by q Let p => q be a theorem Then F(p) => F’(q) is also a theorem

Exchange Axiom (p||q) ; (p’||q’)=>(p;p’) || (q;q’) Theorem (frame): (p||q) ; q’ => p||(q;q’) – Proof: substitute  for p’ in exchange axiom Theorem: p;q => p*q This axiom is self-dual by time-reversal

2. Applications

The laws are useful for proof of correctness of programs/designs – by means of Hoare logic – extended by concurrent separation logic. for design/proof of implementations – using Milner transitions – extended by sequential composition.

The Hoare triple Definition: {p} q {r} = p;q => r – If p describes what has happened so far – and q is then executed to completion, – the overall result will satisfy r.

The rule of composition Definition: {p} q {r} = p;q => r Theorem: {p} q {s} {s} q’ {r} {p} q;q’ {r}

Proof Definition: {p} q {r} = p;q => r expanding the definition: p;q => s s;q’ => r p;q;q’ => r because ; is monotonic and associative

Modularity rule for || in concurrent separation logic {p} q {r} {p’} q’ {r’} {p||p’} q||q’ {r||r’} – permits modular proof of concurrent programs. it is equivalent to the exchange law

Modularity rule implies Exchange law By reflexivity: p;q => p;q and p’;q’ => p’;q’ Exchange is the conclusion of modularity rule (p||p’) ; (q||q’) =>(p;q) || (p’;q’)

Exchange law implies modularity Assume:p;q => r and p’;q’ => r’ monotonicity of || gives (p;q) || (p’;q’) =>r|| r’ the Exchange law says (p||p’) ; (q||q’) =>(p;q) || (p’;q’) by transitivity: (p||p’) ; (q||q’)=>r||r’ which is the conclusion of the modularity rule

Frame Rules {p} q {r} {p||f} q {r||f} – adapts a triple to a concurrent environment f – proof: from frame theorem {p} q {r}__ {f;p} q {f;r} – proof: mon, assoc of ;

The Milner triple: r - q -> p defined as q;p => r – the time reversal of {p} q {r} – r may be executed by first executing q – with p as continuation for later execution. maybe there are other ways of executing r Tautology: (q ; p) – q -> p Proof: from reflexivity: q;p => q;p

Technical Objection Originally, Hoare restricted q to be a program, and p, r to be state descriptions Originally, Milner restricted p and r to be programs, and q to be an atomic action. These restrictions are useful in application. And so is their removal (provided that the axioms are still consistent).

Sequential composition {p} q {s} {s} q’ {r} {p} q;q’ {r} r –q-> ss –q’-> p r –(q;q’)-> p Proof: by reversal of the Hoare rule

Concurrency in CCS r –p-> qr’ -p’-> q’ (r||r’) -(p||p’)-> (q||q’) – provided p||p’ = τ – where τ is the unobserved atomic transition, which occurs (in CCS) when p and p’ are an input and an output on the same channel. Proof: by reversal of the modularity rule

Frame Rules r –q-> p (r||f) –q-> (p||f) – a step q possible for a single thread r is still possible when r is executed concurrently with f r –q-> p (r;f) –q->(p;f) – operational definition of ;

The internal step r -> p = def. p => r – (the order dual of refinement) – the implementation may make a refinement step – reducing the range of subsequent behaviours

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 and associative, – => is transitive. Each rule is the dual of the other – by order reversal and time reversal

Additional operators p \/ qdescribes all traces of p and all of q – describes options in design – choice (non-determinism) in execution p /\ q describes all traces of both p and q – conjunction of requirements (aspects) in design – lock-step concurrency in execution

Axioms /\ is the disjunction and \/ is the conjunction of a Boolean Algebra (even with negation). Axiom: ; and || distribute through \/ – which validates reasoning by cases – and implementation by non-deterministic selection

Choice {p} q {r}{p} q’ {r} {p} (q \/ q’) {r} – both choices must be correct – proof: distribution of ; through \/ ___r –q-> p____ (r \/ r’) –q-> p – only one of the alternatives is executed – proof: r => r \/ r’

Axioms proved from calculi from Hoare p ; (q\/r) => p;q \/ p;r p;r \/ q;r => (p\/q) ; r from Milner (p\/q) ; r => (p;r) \/ (q;r) p;q \/ p;r => p ; (q\/r) from both p ; (q;r) => (p;q) ; r (p;q) ; r => p ; (q;r) exchange law

Message Both the Hoare and Milner rules are derived from the same algebra of programming. The algebra is simpler than each of the calculi, and stronger than both of them combined. They are mutually consistent, provided the laws are true

3. The laws are true

The laws are true of… specifications, designs, implementations of – programs – hardware – networks – hybrid systems – the real world of events occurring in space and time

Happens before (  ) Let e, f, g є Ev (a set of event occurrences). Let e  f mean (your choice of) : – ‘the occurrence e was/will be an immediate and necessary cause of the occurrence f ’ – ‘the occurrence f directly depends (depended) on the occurrence e ’ – ‘e happens before f ’‘f happens after e ’

Example: hardware a rising edge  next falling edge on same wire a rising edge  rising edge on another wire

Example: Petri nets e  f, f’  g e f g f’

Message sequence charts sqlappnet

Examples: software n th output  n th input(on reliable channel) n th V  n th P (on an exclusion semaphore) n th assignment  read of n th value (of a variable in memory) read of n th value  (n + 1) st assignment (in strong memory)

Precedes Define < as (  )* – the reflexive transitive closure Define >as<  – the converse of < Examples: – allocation of a resource <any use of it – disposal of a resource >any use of it

Interpretations e < f& f < e means – e and f are (part of) the same atomic action – or there is deadlock not e < f & not f < e means – e and f are independent of each other – their executions may overlap in time, – or one may complete before the other starts

Cartesian product Let p, q, r  Ev – traces of execution Define p × q = {(e,f) | e  p & f  q } – cartesian product Theorem: p × (q  r) = p×q  p×r (q  r) × p = q×p  r×p

Composition Let p, q, r  Ev (traces of execution) Let seq  Ev × Ev (arbitrary relation) Define p;q = p  qif p × q  seq & p, q are defined – and is undefined otherwise Theorem: ; is monotonic – with respect to definement ordering

Theorem:(p ; q) ; r = p ; (q ; r) Proof: when they are both defined, each side is equal to ( p  q  r ). LHS is defined  (by definition of ;) p × q  seq & (p  q) × r  seq (by × distrib  )  p × q  seq & p × r  seq & q × r  seq  p × (q  r)  seq & q × r  seq  RHS is defined

Sequential composition Define seq = < Then p;q is strong sequential composition means that p must finish before q starts – all events in p precede all events in q Example: Ev is NN – {1, 7, 19} ; {21, 32} = {1, 7, 19, 21, 32} – {1, 7, 19} ; {19, 32} is undefined

Sequential composition Define seq = not > Then p;q is weak sequential composition means that p may finish before q begins – note that q may start before p finishes – with events that are independent of p – just as in your computer today

Concurrent Composition Define par = seq  seq  Note:seq  par = par  Define p||q = p  q if p × q  par and p, q defined Theorem: || is associative and commutative. Strong || is interleaving. Weak || avoids deadlocks

Proof: when LHS is defined, it equals RHS LHS defined  q × q’  par & r × r’  par & (q  q’) × (r  r’)  seq  q × q’  r × r’  par & q’ × r’  q × r  q’ × r  q × r’  seq  q’ × r’  seq & q × r  seq & (q  r) × (q’  r’)  par  RHS defined. (q || q’) ; (r || r’)=> (q ; r ) || (q’ ; r’)

Interleaving Strong. {1, 7, 9}||{3, 12} = {1, 3, 7, 9, 12}

4. Conclusion The laws are useful The laws are true

The Laws The laws are useful – they shorten formulae, theorems, proofs – they prove consistency of proof rules – with the implementation The laws are true – of specifications, designs, products – hardware/software/the real world The laws are beautiful