The shared rules behind every model
This page explains the small rules that the other models share. Each rule turns one kind of evidence into a yes or no answer.
The bad outcome it rules out
A refused action looks accepted, a sample sits in a state the machine does not declare, or a later success hides an earlier failure.
The cast
| Word | Meaning |
|---|---|
| attempt | One attempted change from a source state to a target state. The target can break a rule. |
| state label | The label of the state before the attempt and the label after it. |
| fact | A result from the production code, turned into an example record. |
| remembered verdict | A model-only flag that remembers an earlier failed check. It is not an application status or a database field. |
The walkthrough
Step 1: A refusal leaves the state alone
The rule reads one attempt. An accepted attempt passes without a target-state check. A refused attempt must keep the same state label. A refusal that moves the label is a bug.
| Value | This step |
|---|---|
accepted |
FALSE |
sourceState |
pending |
targetState |
pending |
verdict |
TRUE |
Model rule: RefusedActionKeepsState
RefusedActionKeepsState(attempt) ==
IF attempt.accepted
THEN TRUE
ELSE attempt.sourceState = attempt.targetState
Step 2: A sample must match its declared state
The rule compares the state that a machine declares with the state that a sample holds. A declared state that the machine does not allow returns FALSE. This stops a sample from standing for an invented state.
| Value | This step |
|---|---|
declaredState |
ending |
storedState |
ending |
allowedStates |
{pending, ending, gone, unwritten} |
verdict |
TRUE |
Model rule: SampleMatchesDeclaredState
SampleMatchesDeclaredState(declaredState, storedState, allowedStates) ==
IF declaredState \in allowedStates
THEN storedState = declaredState
ELSE FALSE
Step 3: A later success cannot erase a failure
The rule joins the earlier verdict with the current verdict. Once the result is FALSE, it stays FALSE. A bad event therefore remains visible after a later good event.
| Value | This step |
|---|---|
previousChecksPassed |
TRUE |
currentCheckPassed |
FALSE |
next value |
FALSE |
a later check |
TRUE leaves the result FALSE |
Model rule: ChecksStillPass
ChecksStillPass(previousChecksPassed, currentCheckPassed) ==
IF previousChecksPassed
THEN currentCheckPassed
ELSE FALSE
Step 4: Record the attempt and its verdict
This rule moves the model to the target label and remembers the verdict. It does not refuse an unsafe move. The safety rule of the calling model must reject that move.
| Value | This step |
|---|---|
state |
the current state label |
targetState |
the observed result label |
safe |
the remembered verdict after the step |
Model rule: AttemptedEdge
AttemptedEdge(state, targetState, verdict, safe) ==
/\ state' := targetState
/\ safe' := ChecksStillPass(safe, verdict)
\* A table of observed states is a tuple of records, one for each state. A row id
\* starts at zero, so row id 0 is tuple position 1. A caller supplies its own
\* table, its own matrix of targets, and its own laws over the rows.
Step 5: A table and its matrix must agree
A model keeps its observed states in a tuple of records. RowIds names the ids of the rows, and RowAt reads one row. TablesWellFormed checks that every row stores its own id. It also checks that each state has one target for each event, and that each target is a state id.
| Value | This step |
|---|---|
row id 0 |
tuple position 1 |
rows |
Every row stores its own id. |
targets |
One target for each state and event. |
Model rule: RowIds
RowIds(rows) == {index - 1 : index \in DOMAIN rows}
Model rule: RowAt
RowAt(rows, id) == rows[id + 1]
Model rule: TablesWellFormed
TablesWellFormed(rows, targets, events) ==
LET eventIds == {e.event : e \in events}
IN /\ Len(rows) > 0 /\ events # {} /\ Len(targets) = Len(rows)
/\ Cardinality(eventIds) = Cardinality(events)
/\ eventIds = RowIds(targets[1])
/\ \A index \in DOMAIN rows : rows[index].id = index - 1
/\ \A source \in RowIds(rows) :
/\ Len(targets[source + 1]) = Cardinality(events)
/\ \A event \in eventIds :
targets[source + 1][event + 1] \in RowIds(rows)
\* A stack of three windows a, b, and c stores one rank for each window. Rank 0
\* means that the window is absent. Ranks run from the bottom, at 1, to the top.
Step 6: A stack of three windows keeps valid ranks
A stack of windows a, b, and c stores one rank for each window. RankOf reads the rank of one window, and OpenWindows counts the windows that are open. RanksInRange requires each rank to be 0 to 3, and no rank to be above the number of open windows.
| Value | This step |
|---|---|
rank 0 |
the window is absent |
rank 1 |
the bottom window |
open windows |
The top rank is the number of windows. |
Model rule: RankOf
RankOf(s, key) ==
IF key = "a" THEN s.aRank ELSE IF key = "b" THEN s.bRank ELSE s.cRank
Model rule: OpenWindows
OpenWindows(s) == (IF s.aRank > 0 THEN 1 ELSE 0) +
(IF s.bRank > 0 THEN 1 ELSE 0) + (IF s.cRank > 0 THEN 1 ELSE 0)
Model rule: RanksInRange
RanksInRange(s) ==
\A key \in {"a", "b", "c"} :
/\ RankOf(s, key) \in {0, 1, 2, 3}
/\ RankOf(s, key) <= OpenWindows(s)
The safety claim
The helper does not claim safety by itself. It supplies the pieces that a model joins into its own safety rule.
The model checks two things:
- The first state satisfies the claim.
- Every allowed step from a state that satisfies the claim keeps it.
Together, these checks cover every finite run of the model.
What this model does not prove
- The helper has no state of its own, no start state, and no step relation.
- It makes no claim about a business lifecycle.
- Each model that uses a rule supplies its own facts and its own safety claim.
How to read the model text
| Symbol | Meaning |
|---|---|
== |
This line defines a rule. It does not assign a value. |
x' |
The value of x after the step. |
/\ |
Both conditions must hold. |
\/ |
One of the conditions must hold. |
\A |
Every supplied value must satisfy the rule. |
\E |
At least one supplied value must satisfy the rule. |
\in |
The value belongs to the set. |
=> |
If the left condition holds, the right condition must hold. |
Read the model verification guide for the method and its limits.