HO31 - Maggie Johnson CS103A Handout #31 Proving Properties...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Maggie Johnson Handout #31 CS103A Proving Properties of Loops Key Topics: * More on Induction * Validation vs. Verification * Loop Invariants * Induction to Verify Loops * Example Proofs • Induction Challenger While waiting for class to start, check out the following proof. Is it valid? If not, how would you fix it? P(n): In any convex n-gon, the longest side is shorter than the sum of the lengths of the other sides. base case: P(3), a triangle. It is a geometric fact that every side of a triangle is shorter than the sum of the other two. inductive hypothesis: Assume P(n) is true, show P(n+1), i.e., that P(n) is true for an (n+1)-gon. Proof: Take any convex (n+1)-gon P. Label the sides 1, 2, . .., n+1 in clockwise order, with side 1 being the longest. Slice off sides 2 and 3, replacing them by a single side 2’, and thus obtain a convex n-gon P’. The inductive hypothesis allows us to surmise that side 1 is shorter than the sum of the other sides of P’. If we now replace the length of side 2’ by the sum of the lengths of sides 2 and 3, the sum of the lengths of the sides other than 1 gets even greater. By the principle of mathematical induction, P(n) is true for all convex polygons. • Validation vs. Verification You validate that a program that you have written is correct by testing it with a wide range of relevant inputs. You verify a program is correct by using proof techniques to show that given any input variables that satisfy certain properties, the output variables (after execution of the program) satisfy other certain properties. This is an important distinction - both are necessary to be completely sure of a correct program. In 1967, Robert Floyd published a paper that started a whole area of research on program verification. Several researchers since that time have developed techniques for proving program correctness (Dijkstra, Gries). These researchers contend that "it is not only the programmer's task to produce a correct program, but also to demonstrate its correctness in a convincing manner." As with most techniques that are still in the process of development, methods for proving program correctness are somewhat awkward and unwieldy. Many people believe that real-world programs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
are just too complex to prove correct. Nonetheless, it is an important area of research and it also illustrates a valid computer-science application of proof techniques. One point should be made before we proceed. There is an important distinction between “proofs of
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/15/2008 for the course CS 103A taught by Professor Plummer,r during the Fall '07 term at Stanford.

Page1 / 6

HO31 - Maggie Johnson CS103A Handout #31 Proving Properties...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online