Lec05_Sample_triples_and_proof_rules

Lec05_Sample_triples_and_proof_rules - Illinois Institute...

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

View Full Document Right Arrow Icon
CS 536 Notes: Examples of Correctness Triples; Proof Rules for Correctness Triples Lecture 5, Mon Sep 27, 2010 A. Why Correctness triples are how we write a program with its speci cation. Proof rules for correctness triples will show us how to reason about programs and their speci cations. B. Outcomes After this lecture, you should Know that a program can have di erent speci cations, some more useful than others. Know why we need proof rules for correctness triples and how they connect/are di erent from validity for correctness triples. Know some of the di erent cases for reasoning about an assignment statement’s properties. Know what syntactic substitution is and how to do it. C. Quiz 1 Results Scores are shown to the right. The mean was 79.4 and the mode was 82 so we were slightly clumped toward high grades. Questions 1, 2, and 11 had the lowest average score (67%, 73%, and 13% respectively). D. Last Time: Meaning of Programs, Syntax of Correctness Triples, Partial Correctness Semantics for Correctness Triples Program are state transformers: M ( S , ! ) = { " } if running program S starting in state ! halts in state " . M ( S , ! ) = # if running program S starting in state ! leads to an in nite loop. •A Correctness Triple (a.k.a. Hoare Triple ) has a precondition predicate, a program, and a postcondition predicate 98 96 96 96 95 95 95 93 93 92 92 92 91 91 91 90 90 90 89 89 88 88 88 88 87 86 86 85 84 82 82 82 81 80 79 79 77 77 76 75 73 71 71 71 70 70 68 68 68 67 66 64 63 63 59 59 55 51 47 36 Count: 60 Mean: 79.4 Std dev: 13.9 Illinois Institute of Technology Notes for Lecture 5 CS 536: Science of Programming - 1 of 7 - © James Sasaki, 2010
Image of page 1

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

View Full Document Right Arrow Icon
Syntax : { P } S { Q } where P and Q are the pre- and post-conditions and S is the program. Note the curly braces are not part of P or Q , they’re like comment symbols or keywords. Intuitive “Partial Correctness” Semantics : { P } S { Q } holds/is satis ed/is true in state ! if (a) if P is true in ! , then (b) if running S in ! halts in some state, then (c) Q is true in that state. Equivalently, { P } S { Q } holds in state ! if P is false in ! , if S doesn’t halt in ! , or if S halts in a state in which Q is true. Notation : ! ! { P } S { Q } i (( ! ! P ) implies ( M ( S , ! ) " # implies M ( S , ! ) ! Q )). Equivalently, ! ! { P } S { Q } i ( ! " P or M ( S , ! ) = # or M ( S , ! ) ! Q ). If { P } S { Q } does not hold in a state ! that ! P then our program has a bug: P is true in ! but running S in ! halts in some state that doesn’t satisfy Q . •We want our programs to be valid (to hold in all states). Notation : ! { P } S { Q } i for all ! , ! ! { P } S { Q }. E. Some Simple Examples of Partial Correctness Triples Example 1 Is ! { x > 0 } x := x – 1 { x ! 0 }? Yes: If x > 0 then subtracting 1 makes x ! 0 . Note that in the precondition, “ x ” refers to the value of x before the assignment. In the postcondition, “ x ” refers to the value of x after the assignment. (Also note if x > 1 , we don’t care what x := x – 1 does or if we end up with x not ! 0 .) Example 2 Is ! { x ! 0 } x := x – 1 { x ! –1 }?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern