Lec04_Semantics_of_pgms_and_triples

Lec04_Semantics_of_pgms_and_triples - CS 536 Notes: Program...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 programs 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 Didnt 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 its 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 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. E.g. M ( x := random_boolean() , ! ) would = { ! [ x ! T ], ! [ x ! F ]} Notation : Well typically write M ( S , ! ) instead of M ( S , { ! })....
View Full Document

Page1 / 6

Lec04_Semantics_of_pgms_and_triples - CS 536 Notes: Program...

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