Lec04_Semantics_of_pgms_and_triples

Lec04_Semantics_of_pgms_and_triples - Illinois Institute of...

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

View Full Document Right Arrow Icon
CS 536 Notes: Program Semantics; Correctness Triples Lecture 4, Mon Sep 20, 2010 A. Why The meaning of a program is that it transforms states. To specify a program’s correctness, we need to know its precondition (what must be true before executing it) and its postcondition (what should be true after it). B. Outcomes After this lecture, you should Know the semantics of our programs at intuitive and formal levels. Know the syntax of correctness triples (a.k.a. Hoare triples) as { P } S { Q } and that its precondition and postcondition are P and Q respectively. (Note: Not { P } and { Q }.) Know what it means for a program to satisfy its speci cation ( ! ! { P } S { Q }). Understand what it means for a correctness triple to be valid ( ! { P } S { Q }). C. Quiz 1, then lecture 30 minutes, covering Lectures 1 and 2 and Homeworks 1 and 2. D. Last Time: Satisfaction of Predicates; Syntax of Programs/Statements Satisfaction and validity of predicates is about the semantic truth of predicates. •State ! satis es predicate P (written ! ! P ) means P is true in state ! . ! ! ¬ P if ! " P Didn’t mention last time : If Σ is a set of states, then Σ ! P means that every state in Σ satis es P . Vacuous case: " ! P because Σ = " implies (does not exist ! # Σ ) implies (does not exist ! # Σ such that ! " P ) implies (for every ! # Σ , ! ! P ) implies Σ ! P . P is valid (is a tautology ) if it is true in all states. ! P if and only if for every ! , we have ! ! P . P is a contradiction if its negation is a tautology: ! ¬ P . P is a contingency if it’s true sometimes and false sometimes. For some state ! , we have ! ! P ; for some state ! " , we have ! " ! ¬ P . Our programming language Do nothing: skip Assignment: v := e Array element assignment: b[ e # ] := e $ Illinois Institute of Technology Notes for Lecture 4 CS 536: Science of Programming - 1 of 6 - © 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
Sequence: S # ; S $ Conditional: if B then S # else S $ fi if B then S # fi (“ else skip ” is understood) Loop: while B do S # od Informally, the meaning of a program or statement is that it is a state transformer. E. Formal Meaning of Programs as State Transformers •De nition: M ( S , Σ ) is the meaning of statement S in the set of states Σ . M ( S , Σ ) = {state $ | If we execute S in a state ! # Σ , we end up in state $ }. •For our simple programs, either M ( S , { ! }) = { $ } for some $ , or M ( S , { ! }) = " because of an in nite loop. If we add random or nondeterministic choices, we could end up with M ( S , Σ ) having size > 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