Actions & Conformance

A method is an action when its return annotation carries Action(...) or Action() inside typing.Annotated:

python
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 amount

Binding 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#

FormPredicateBodyMeaning
Abstract specAction(pred)...The predicate is the transition (may be nondeterministic).
Code as specAction()Python codeThe Python body is the transition.
Conforming codeAction(pred)Python codeThe 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:

  1. With Modifies("v1", ...): exactly the variables listed.
  2. Otherwise, with a body: the variables the body assigns or mutates (directly or through helper calls), plus any Ghost variables its predicate primes.
  3. Otherwise (abstract ... body): the variables its predicate places under prime(...).

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 raise or runtime error like division by zero or IndexError is FAIL runtime).
  • Every reached assert holds (otherwise FAIL assertion naming the action and line).
  • The resulting state satisfies the Action predicate (if given), every Ensures clause, any Where on the return type, and the frame (otherwise FAIL 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.

python
@property
def available(self) -> Pure[NonNegative]:
    return self.balance + self.credit_limit

ActionInvariant#

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:

python
ledger_append_only=ActionInvariant(lambda s: prime(s.ledger)[: len(s.ledger)] == s.ledger)