An Axiomatic Basis for Computer Programming Tony Hoare, 1969 - - PowerPoint PPT Presentation

an axiomatic basis for computer programming
SMART_READER_LITE
LIVE PREVIEW

An Axiomatic Basis for Computer Programming Tony Hoare, 1969 - - PowerPoint PPT Presentation

An Axiomatic Basis for Computer Programming Tony Hoare, 1969 Presented by Alexa VanHattum, Great Works in PL Spring 2019 Mentor Jonathan DiLorenzo software bugs are bad manual testing is not enough formal reasoning is better Motivation


slide-1
SLIDE 1

An Axiomatic Basis for Computer Programming

Tony Hoare, 1969

Presented by Alexa VanHattum, Great Works in PL Spring 2019 Mentor Jonathan DiLorenzo

slide-2
SLIDE 2

software bugs are bad

manual testing is not enough

formal reasoning is better

slide-3
SLIDE 3

Motivation

“Computer programming is an exact science in that all the properties of a program and all the consequences of executing it in any given environment can, in principle, be found out from the text of the program itself by means of purely deductive reasoning.”

slide-4
SLIDE 4

Historical Context

“Assigning Meaning to Programs” Robert Floyd, 1967

slide-5
SLIDE 5

Historical Context

“Assigning Meaning to Programs” Robert Floyd, 1967

“If the initial values of the program variables satisfy the relation R1, the final values on completion will satisfy the relation R2”

slide-6
SLIDE 6

Axioms

Deductive Rules

Theorems bricks? cement?

bra.org economictimes.indiatimes.com rebelwalls.com

The Strategy

slide-7
SLIDE 7

Hoare’s contribution

slide-8
SLIDE 8

Precondition Program Postcondition

If P holds and Q executes and terminates, then R holds

slide-9
SLIDE 9

true {x := 1} x = 1 x = 0 {x := x + 1} x = 1

✅ ✅

Valid Hoare Triples?

false {x := 1} x = 0

x > 0 {while x > 1 do x := x + 1} x < 1

✅ ❌

x = n {x := x * 2} x = 2n

x > 0 {while x > 1 do x := x + 1} x = 1

slide-10
SLIDE 10

Hoare’s Axioms

Integer arithmetic Overflow?

That depends!

  • 1. Strict interpretation
  • 2. Firm boundary
  • 3. Modulo arithmetic

Assume 1 or 2 for now

slide-11
SLIDE 11

how do we apply this reasoning to programs?

axiom schemas!

slide-12
SLIDE 12

Assignment

slide-13
SLIDE 13

Assignment

x = 0 {x := 1} (x = 0)[1/x] x = 0 {x := 1} 1 = 0

x = 0 {x := 1} ?

slide-14
SLIDE 14

Assignment

(x = 1)[1/x] {x := 1} x = 1 1 = 1 {x := 1} x = 1 ? {x := 1} x = 1

✅ ✅

true {x := 1} x = 1

slide-15
SLIDE 15

Assignment

slide-16
SLIDE 16

Consequence

slide-17
SLIDE 17

Composition

slide-18
SLIDE 18

Iteration

slide-19
SLIDE 19

Iteration

x > 0 {while x > 1 do x := x + 1} x = 1

slide-20
SLIDE 20

Iteration

x > 0 {while x > 1 do x := x + 1} ¬(x > 1) ∧ x > 0

x > 0 {while x > 1 do x := x + 1} x = 1

consequence rule ¬(x > 1) ∧ x > 0 ⇒ x = 1

slide-21
SLIDE 21

Iteration

x > 0 {while x > 1 do x := x + 1} ¬(x > 1) ∧ x > 0

x > 0 ∧ x > 1 {x := x + 1} x > 0

x > 0 {while x > 1 do x := x + 1} x = 1

iteration rule

slide-22
SLIDE 22

x + 1 > 0 {x := x + 1} x > 0

Iteration

x > 0 {while x > 1 do x := x + 1} ¬(x > 1) ∧ x > 0

x > 0 ∧ x > 1 {x := x + 1} x > 0

x > 0 {while x > 1 do x := x + 1} x = 1

consequence rule x > 0 ∧ x > 1 ⇒ x + 1 > 0

slide-23
SLIDE 23

Iteration

x > 0 {while x > 1 do x := x + 1} ¬(x > 1) ∧ x > 0

x > 0 ∧ x > 1 {x := x + 1} x > 0

x > 0 {while x > 1 do x := x + 1} x = 1

assignment rule

x + 1 > 0 {x := x + 1} x > 0

slide-24
SLIDE 24

Iteration

How do we find P? Can we automate it?

slide-25
SLIDE 25

Extension to Hoare Logic: Separation Logic

  • Extends Hoare logic to

include reasoning over shared data

  • Separation conjunction *:

P * Q asserts P and Q hold for separate regions of memory

The frame rule (when c does not modify the free variables of r)

slide-26
SLIDE 26

Application of Hoare Logic

www.microsoft.com

slide-27
SLIDE 27

Conclusion

  • Relate deductive reasoning to

programs via Hoare triples

  • Formalize/automate axiomatic

reasoning via rules

  • Enable pen-and-paper proofs

and automated reasoning tools

  • Axioms can leave aspects of the

language undefined

slide-28
SLIDE 28

“The practice of supplying proofs for nontrivial programs will not become widespread until considerably more powerful proof techniques become available, and even then will not be

  • easy. But the practical advantages of program proving will

eventually outweigh the difficulties, in view of the increasing costs of programming errors.”

Conclusion

slide-29
SLIDE 29

30 years later…

slide-30
SLIDE 30

“Researchers into formal methods […] predicted that the programming world would embrace with gratitude every assistance promised by formalization to solve the problems of reliability that arise when programs get large and more safety-critical […] It has turned out that the world just does not suffer significantly from the kind of problem that our research was originally intended to solve.”

  • Tony Hoare, 1996