# Weakest pre-conditions and towards machine consistency Saima Zareen.

## Presentation on theme: "Weakest pre-conditions and towards machine consistency Saima Zareen."— Presentation transcript:

Weakest pre-conditions and towards machine consistency Saima Zareen

Outline State Space Multiple assignment statements Post Condition Skip statement Conditional statement CASE statement Proof Obligations

State Space

Multiple Assignment statements

Post Condition A particular statement which is required to be true after executing S. Notation S [P] Exercise

skip The empty statement which has no effect at all on any part of the state. It is always guaranteed to terminate successfully and the state on termination will be the same as the state before it was executed. Predicate will remain same before and after skip executes [skip]P=P

Conditional Statement Programming languages provide conditional statements which allow branching depending on a particular value on the state. The most common of this is If then else IF E THEN S ELSE T END It is used in two circumstances When the post condition is of P can be guaranteed. Either E is true in which S will be executed Otherwise then T will execute

Conditional Statement contd..

Conditional Statement alternative interpretation

Case Statement Allows the flow of control of the assignment to depend on the value of a particular expression. It lists a number of alternative values. A case statement is written as follows

Case Statement contd.. E describes expression which is to be evaluated. If it evaluates to e1,then T1 is executed If it evaluates to e2 then T2 is executed. If does not evaluate to any of the list of alternatives then ELSE clause is executed. It is an optional clause. For example The set DIRECTION={north, south, east, west} Variable dir must evaluate to some element of DIRECTION, then the following CASE statement finds the opposite direction for dir

Case Statement contd..

Only finite cases are included. If there are infinitely many possibilities then the remaining ones will have to be covered by the ELSE clause or left with no associate statement. For example The following CASE statement assigns a percentage discount rate depending on the size of the order

Case Statement contd.. For a CASE statement to guarantee to establish a post condition P, we require that any branch OR e THEN T must have that T establishes P whenever the expression E evaluates to the value e on that branch. If E =e then [T]P must hold. If none f the values is matched, then the ELSE clause must establish P. This leads to the following rule

CASE statement Exercise

Begin and End

Consistency of INVARIANT

Proof Obligations A proof obligation is a mathematical formula to be proven, in order to ensure that a B component is correct.

Proof Obligation for Initialization

[T]I

Proof Obligation for Operations

B is a method for specifying, designing, and coding software systems.  Jean-Raymond Abrial

Inconsistency An operation whose proof obligation is not true, highlights a confusion between the machine invariant and the operation. It needs to be resolved. Number of ways to resolve a machine inconsistency. By Strengthening the precondition. May be Body of the operation might not be correct. May be Invariant may be too loose that allowed some states that should not be permitted. Invariant may be wrong.

Summary We have studied the concept of state space and weakest pre- conditions that result in valid final states. Multiple assignment statements can also be used to show parallel execution of statements. Evaluation of pre conditions using conditional and case statements. Proof obligations of initialization and Operations

Download ppt "Weakest pre-conditions and towards machine consistency Saima Zareen."

Similar presentations