Automated Reasoning
Petros Papapanagiotou October 4, 2013
1 / 26
Automated Reasoning Petros Papapanagiotou October 4, 2013 1 / 26 - - PowerPoint PPT Presentation
Automated Reasoning Petros Papapanagiotou October 4, 2013 1 / 26 Extra Lecture Program verification using Hoare Logic 1 Petros Papapanagiotou 1 Partially adapted from Mike Gordons slides on Hoare Logic:
1 / 26
1Partially adapted from Mike Gordon’s slides on Hoare Logic:
2 / 26
3 / 26
◮ Safety-critical systems (e.g. medical equipment software,
◮ Core system components (e.g. device drivers) ◮ Security (eg. ATM software, cryptographic algorithms) ◮ Hardware verification (e.g. processors)
◮ Design by Contract (DBC) and the Eiffel programming
◮ Java assert. ◮ DBC for Java with JML and ESC/Java 2. ◮ Why tool: Krakatoa and Jessie (Java and C). ◮ Why3 tool: WhyML (Correct-by-construction OCaml
4 / 26
5 / 26
6 / 26
◮ {P} C {T} ◮ {F} C {Q}
◮ Specification for the maximum of two variables:
◮ C could be:
◮ But C could also be:
◮ Or even:
◮ What we really wanted is:
◮ Variables x and y are “auxiliary” (ie. not program variables). 7 / 26
◮ Conditions P and Q are described using FOL. ◮ VCs = What needs to be proven so that {P} C {Q} is true?
◮ VCs are presented as proof obligations or simply proof
8 / 26
◮ Assignment ◮ Sequence ◮ Skip ◮ Conditional ◮ While
◮ Precondition strengthening ◮ Postcondition weakening 9 / 26
10 / 26
11 / 26
12 / 26
13 / 26
14 / 26
15 / 26
16 / 26
17 / 26
18 / 26
18 / 26
◮ Say what has been done so far together with what remains to
◮ Hold at each iteration of the loop. ◮ Give the desired result when the loop terminates. 19 / 26
◮ {P ∧ Z = X} Z := Z + 1 ; Y := Y × Z {P} ◮ Y = 1 ∧ Z = 0 −
◮ P ∧ ¬(Z = X) −
20 / 26
◮ Therefore: {Y = Z! ∧ Z = X} Z := Z + 1 ; Y := Y × Z {Y = Z!}
◮ Y = 1 ∧ Z = 0 −
◮ Y = Z! ∧ ¬(Z = X) −
21 / 26
22 / 26
23 / 26
◮ ... sound? - Yes! Based on programming language semantics
◮ ... decidable? - No! {T} C {F} is the halting problem! ◮ ... complete? - Relatively. Only for simple languages.
24 / 26
◮ Preconditions P ◮ Program C ◮ Postconditions Q
◮ One for each program construct. ◮ Precondition strenghtening. ◮ Postcondition weakening.
◮ Properties that hold during while loops. ◮ Loop invariant generation is generally undecidable.
25 / 26
26 / 26