Docsity

Mathematical Basis of Program Correctness: Inductive Proofs and Hoare Logic, Study notes of Biogenetics and Computers

Toggle sidebar
bg1
We know that any sum 25p+40m is divisible by 5.
After $140, one can get every multiple of 5.
Basis: $140 = ...
$145 = …
$150
$155
$160
Then let n be some multiple of 5 > $160. Assume that
every multiple of 5 between 140 and n is representable.
Thus n+5 = 25 + n+5-25.
n+5-25 = m*25 + p*40 by the strong induction
hypothesis.
Thus n+5 = 25 + n+5-25 = 25 = 2+ m*25+p*40 = (m+1)*25
+ p*40.
Thus the hypothesis is true for n+5.
$25 and $40 certificates
Correctness Page 1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Mathematical Basis of Program Correctness: Inductive Proofs and Hoare Logic and more Study notes Biogenetics and Computers in PDF only on Docsity!

We know that any sum 25p+40m is divisible by 5. After $140, one can get every multiple of 5. Basis: $140 = ... $145 = … $ $ $ Then let n be some multiple of 5 > $160. Assume that every multiple of 5 between 140 and n is representable. Then for n+5, n+5-25 is between 140 and n. Thus n+5 = 25 + n+5-25. n+5-25 = m25 + p40 by the strong induction hypothesis. Thus n+5 = 25 + n+5-25 = 25 = 2+ m25+p40 = (m+1)*

  • p*40. Thus the hypothesis is true for n+5. $25 and $40 certificates Docsity.com

Docsity.com

When it doesn't crash? When it answers the way we expect? When is a program "correct"? Program correctness Docsity.com

preconditions: what is true before the program starts. postconditions: what is true afterward. Every statement or program has preconditions and postconditions. p: y is a number (preconditions) S: x:=y; (statement) q: x==y (postconditions) Example x:=y The form p{S}q is called a Hoare triple. We write this as (y is a number) {x=y;} (x==y) Mathematical basis of program correctness. Docsity.com

Break large programs into smaller ones. Prove correctness of the smaller ones. Combine those proofs into a proof of correctness for the larger one. We can use a calculus of Hoare triples to The sequence rule: when is a sequence of statements correct? The if-else rule: what does an if statement do? The while rule: what does a "while" statement do? Several tools We can think of these rules as the semantics for sequence, if, and while. The calculus of Hoare triples Docsity.com

If pS 1 q and qS 2 r then p{S 1 ;S 2 }r The sequence(composition) rule: Example: T {x:=1} x==1 (def. of :=) x==1 {x:=x+1} x==2 (def. of +)


T {x:=1; x:=x+1} x== The sequence rule Docsity.com

if p→q and q{S}r then p{S}r. If p{S}q and q→r then p{S}r. Example: T { x=1 } x== x==1 → x>


T { x=1 } x> Implication Docsity.com