Back to Program Verification Index | Previous: (y-06) Boogie and Boostan | Next: (y-08) Hoare Proof System

Mental Model for Relational Semantics

  • Programs as Relations: In verification, we don’t just “run” code; we view a statement as a Binary Relation between the state before and the state after.
  • State: A mapping from every program variable to a value (e.g., ).
  • Composition: Running two statements in a row is mathematically represented as the Relational Composition of their individual relations.
  • Loops: A while loop is represented as the Reflexive Transitive Closure () of its body, filtered by the exit condition.

What is a Program State?

A Program State is a function that assigns a value to every variable in the program.

  • If we have variables , a state might be .
  • We use FOL formulas to describe sets of states. For example, the formula represents all possible states where is positive and is zero.

Relational Semantics of Boostan

We define the meaning (semantics) of each Boostan statement as a relation .

1. Assignment: x := expr

The relation consists of pairs where:

  • The new value of (in ) is the result of evaluating expr in the old state .
  • All other variables remain unchanged ().

Formal Definition:

2. Composition: st1; st2

Running st1 followed by st2 is the relational composition: .

  • is in the relation if there exists an intermediate state that links them.

Formal Definition:

3. If-Then-Else: if (B) {st1} else {st2}

The relation follows one of two branches based on the Boolean condition .

Formal Definition:


Semantics of Loops: while (B) {st}

Loops are the most complex part of relational semantics. We use the Reflexive Transitive Closure () to model an arbitrary number of iterations (0 or more).

  1. Let be the relation of the loop body given that is true: .
  2. The loop execution is . This represents “running the body times.”
  3. The final state must satisfy (the loop must have terminated).

Formal Definition: Equivalently:


Precondition-Postcondition Pairs

We say a program is correct with respect to a precondition and a postcondition if the set of all possible final states is contained within the postcondition.

Formal Definition: Where .


Summary

  1. State: Mapping from variables to values.
  2. Statements as Relations: Mapping from “State Before” to “State After”.
  3. Composition: Sequence of statements = mathematical composition of relations.
  4. While Loops: Use reflexive transitive closure () to model arbitrary iterations.
  5. Correctness: The set of reachable final states must be a subset of the desired postcondition.

Self-Check

  1. Why does relational semantics view a statement as a binary relation rather than a function?
  1. Give the relation in words.
  1. How is sequencing defined in relational semantics, and what does the intermediate state mean?
  1. Why does the semantics of while (B) {st} use the reflexive transitive closure ?
  1. What does say about partial correctness?

Back to Program Verification Index | Previous: (y-06) Boogie and Boostan | Next: (y-08) Hoare Proof System | (y) Return to Notes | (y) Return to Home