{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec06_Subst_and_Pf_Rules

# Lec06_Subst_and_Pf_Rules - Illinois Institute of Technology...

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

CS 536 Notes: Syntactic Substitution; More Proof Rules Lecture 6, Mon Oct 4, 2010 A. Why To reason about assignments, we need to understand syntactic substitution. To reason about programs more generally, we need inference rules for the remaining statements (sequencing, conditional, and iterative). B. Outcomes After this lecture, you should Know what syntactic substitution is and how and why to do it. Know the two basic assignment axioms. Know the rules of inference for sequencing, conditional, and iterative statements. C. Last Time We looked at examples of correctness triples (most of them valid). Looked at why we need rules to reason about correctness triples. (Basically, because we can’t just sit down and verify arbitrary correctness triples). •Looked at the axiom for skip : { P } skip { P } •Worked our way up to developing a “forward” axiom for assignment . The key is to use a symbolic constant for the value of the variable before the assignment. (Below, v is the variable and c is the named constant.) It’s a “logical” constant — it can only appear in the conditions, not the program itself. Assignment axiom 1 (Forward) : { P v = c } v := e { P [ c / v ] v = e [ c / v ]}. (It’s the “forward” rule because we take the precondition and fi gure out the postcondition.) The notations P [ c / v ] and e [ c / v ] stand for the predicate P or expression e where occurrences of v are replaced by c . Example: ( x>0 x ² –(x+1)<y )[ c / x ] is c>0 c ² –(c+1)<y . Special case : { P } v := e { P v = e } if v is fresh (appears in neither P or e ). The special case is just the general case where the conjunct v = c in the precondition is dropped because c doesn’t appear in P or e . Illinois Institute of Technology Notes for Lecture 6 CS 536: Science of Programming - 1 of 8 - © James Sasaki, 2010

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

View Full Document
D. Backward Assignment Rule •For the “backward” assignment rule , we are given the postcondition and fi gure out the precondition. We use it in goal-directed situations. Assignment axiom 2 (Backward) : { P [ e / v ]} v := e { P }. Example 1 : { x–1>0 } x:=x–1 { x>0 } If you want to know that x is positive after you decrement it, you need to know that x–1 is positive before the decrement. Example 2 : { SortedUp(b,k+1) } k:=k+1 { SortedUp(b,k) } Here SortedUp(b,k) means that b[0..k–1] is sorted . E.g., SortedUp(b,k) ⇔ ∀ j.0 j<k–1 b[j] b[j+1] . If you want to know that the fi rst k elements of b are sorted upward after you say k:=k+1 , you need to know that the fi rst k+1 elements of b are sorted upward beforehand. E. Back to Syntactic Substitution For both assignment axioms, we need syntactic substitution. Say we want to substitute into an expression, as in e [ e / v ] or a predicate, as in P [ e / v ]. “Precedence” of substitution Sometimes we’ll have expressions or predicates that mix substituted and unsubstituted items. Let’s take substitution to have extremely high “precedence”.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern