Clauses & Decorators

Class-level clauses attach via @spec(name=Clause(...)); method-level clauses live in the method's Annotated[...] return type.

Class Decorators#

@spec(**clauses: _ClassClause)#

Attaches named class clauses (Assume, Init, Invariant, ActionInvariant, Property, Fairness) to a class without modifying its attributes or type. Must sit above @dataclass(slots=True).

python
@spec(init=Init(lambda s: s.x == 0), small=Invariant(lambda s: s.x < 5))
class Counter:
    x: State[int]

clauses_of(cls: type) -> Mapping[str, _ClassClause]#

Returns the read-only mapping of clauses attached directly to cls by @spec (inherited clauses belong to their defining base classes).

Class Clauses#

Assume(predicate, description=None)#

Level 0TLA⁺: ASSUME P

Assumes predicate(s) over constants before state exploration.

Init(predicate, description=None)#

Level 1TLA⁺: Init == P

Constrains the initial state(s). Multiple Init clauses and field defaults are conjoined.

Invariant(predicate, description=None)#

Level 1TLA⁺: []P

Claims predicate(s) holds in every reachable state.

ActionInvariant(predicate, description=None)#

Level 2TLA⁺: [][P]_vars

Claims predicate(s) (using s.x and prime(s.x)) holds on every transition step.

Property(predicate, description=None)#

Level 3TLA⁺: PROPERTY P

Claims a temporal formula (using always, eventually, leads_to) holds of every behaviour.

Fairness(predicate, description=None)#

Level 3TLA⁺: Spec == Init /\ [][Next]_vars /\ Fair

Adds scheduler fairness assumptions built from weak_fairness and strong_fairness to Spec.

Method & Contract Clauses#

Action(predicate=None, description=None)#

Level 2TLA⁺: Action

Declares a method as an action. With a predicate and ... body, the predicate is the transition; with Action() and a body, the body is the transition; with both, the body must conform to the predicate.

Requires(predicate, description=None)#

Level 1

Action enabling guard or function contract precondition. Multiple Requires clauses are conjoined.

Ensures(predicate, description=None)#

Level 2

Postcondition over s.x, prime(s.x), parameters, and result.

Modifies(*variables: str)#

FrameTLA⁺: UNCHANGED <<others>>

Explicit action frame: the action may modify only the named state/ghost variables; all others remain unchanged.

class Refines(Generic[T]): Refines(**mapping)#

TLA⁺: INSTANCE Abstract WITH v <- e

Return type and runtime mapping for a refinement method def m(self) -> Refines[Abstract]. Claims C!Spec ⇒ Abstract!Spec under the mapping.

python
def refines_queue(self) -> Refines[BoundedQueue[T]]:
    return Refines(capacity=self.capacity, items=tuple(...))