Actions & Conformance
A method is an action when its return annotation carries Action(...) or Action() inside typing.Annotated:
def withdraw(self, amount: Positive) -> Annotated[
Positive, # return type
Requires(lambda s, amount: amount <= s.balance), # guard (enabling condition)
Action(lambda s, amount: prime(s.balance) == s.balance - amount),
Ensures(lambda s, amount, result: result == amount),
Modifies("balance"),
]:
self.balance -= amount
return amountBinding Predicate Parameters#
In every method clause predicate, the first parameter binds to the state s; all remaining parameters bind by name to the method's parameters, plus result in Ensures. A predicate may omit parameters it does not use. Naming a parameter that does not exist is a static error (bad-binding).
In every predicate, s.x is the value before the step and prime(s.x) is the value after the step.
Three Forms of an Action#
| Form | Predicate | Body | Meaning |
|---|---|---|---|
| Abstract spec | Action(pred) | ... | The predicate is the transition (may be nondeterministic). |
| Code as spec | Action() | Python code | The Python body is the transition. |
| Conforming code | Action(pred) | Python code | The body is the transition AND must conform to pred in every reachable state. |
Action() with a ... body has no transition and is rejected as no-transition. A body of pass is a concrete body that changes nothing.
Automatic Frame Rule#
Unlike raw TLA⁺, you do not have to write UNCHANGED <<...>> on every action. An action changes only the variables in its frame, and every other variable stays unchanged automatically. The frame is determined in priority order:
- With
Modifies("v1", ...): exactly the variables listed. - Otherwise, with a body: the variables the body assigns or mutates (directly or through helper calls), plus any
Ghostvariables its predicate primes. - Otherwise (abstract
...body): the variables its predicate places underprime(...).
A Ghost variable the body does not touch takes its next value from the Action predicate, so implementations never need to store ghost state at runtime.
Conformance & Assertions#
When an action has a body, the checker verifies in every reachable state and for every valid argument tuple that:
- The body terminates without raising an exception (a reachable
raiseor runtime error like division by zero orIndexErrorisFAIL runtime). - Every reached
assertholds (otherwiseFAIL assertionnaming the action and line). - The resulting state satisfies the
Actionpredicate (if given), everyEnsuresclause, anyWhereon the return type, and the frame (otherwiseFAIL conformance).
Pure[T] Operators & Properties#
A method, @property, or helper function returning Pure[T] is a side-effect-free operator usable inside predicates (e.g., s.available). Writing to state inside a Pure body is rejected as bad-write.
@property
def available(self) -> Pure[NonNegative]:
return self.balance + self.credit_limitActionInvariant#
Whereas Invariant checks single states (□P), ActionInvariant checks every transition step (□[P]vars) over s.x and prime(s.x) — ideal for monotonicity or append-only history properties:
ledger_append_only=ActionInvariant(lambda s: prime(s.ledger)[: len(s.ledger)] == s.ledger)