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
whileloop 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
exprin 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).
- Let be the relation of the loop body given that is true: .
- The loop execution is . This represents “running the body times.”
- 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
- State: Mapping from variables to values.
- Statements as Relations: Mapping from “State Before” to “State After”.
- Composition: Sequence of statements = mathematical composition of relations.
- While Loops: Use reflexive transitive closure () to model arbitrary iterations.
- Correctness: The set of reachable final states must be a subset of the desired postcondition.
Self-Check
- Why does relational semantics view a statement as a binary relation rather than a function?
Answer
A function takes one input state to one output state, which does not handle non-determinism (
havoc) or filtering (assume). A binary relation allows a state to be related to several successors (non-determinism) or to none at all (a blocked path). This matches Boostan’s actual behavior.
- Give the relation in words.
Answer
The pair is in iff equals the value of evaluated in , and agrees with on every other variable. Assignment changes exactly the assigned variable and leaves the rest of the state untouched.
- How is sequencing defined in relational semantics, and what does the intermediate state mean?
Answer
. The intermediate state is the state after runs and before runs; sequencing is exactly relational composition.
- Why does the semantics of
while (B) {st}use the reflexive transitive closure ?
Answer
A loop may execute its body zero, one, or arbitrarily many times before becomes false. is the smallest relation containing all finite iterations of plus the identity (zero iterations). Intersecting with keeps only those final states where the loop guard has become false, i.e., the loop actually terminated.
- What does say about partial correctness?
Answer
For every initial state satisfying , every state reachable through satisfies . It is partial because the inclusion is vacuous when has no terminating execution from : the relation simply contains no pair starting at . Total correctness would additionally require termination.
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