






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







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)*
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