Models, Domains & Symmetry
A Model is the Python equivalent of a TLC .cfg file: it binds constants and gives finite domains to the types a specification or contract quantifies over.
from temporal_typing import Model, Symmetry
PROCS = frozenset({Proc("p1"), Proc("p2"), Proc("p3")})
full_model = Model(Mutex, constants={"procs": PROCS}, domains={Proc: PROCS})
safety_model = Model(Mutex, constants={"procs": Symmetry(PROCS)}, domains={Proc: PROCS}, properties=())
bounded_model = Model(Counter, state_constraint=lambda s: s.x < 5)Model Configuration Fields#
| Field | Default | Meaning |
|---|---|---|
spec | required | The specification class or contract function to check. |
constants | {} | Mapping from Constant field name to concrete value (falls back to class-level defaults). |
domains | {} | Mapping from type (class, alias, or TypeVar) to a finite collection (range, frozenset, list). |
actions | None | Sequence of action names included in Next (all when None). |
invariants | None | Sequence of Invariant / ActionInvariant names to check (all when None). |
properties | None | Sequence of Property names to check (all when None; pass () to skip liveness). |
state_constraint | None | Level-1 predicate bounding exploration (CONSTRAINT). |
action_constraint | None | Level-2 predicate bounding explored steps (ACTION_CONSTRAINT). |
check_deadlock | True | Whether a reachable state with zero enabled actions is FAIL deadlock. Set False for terminating protocols. |
Domain Resolution Order#
domains is always keyed by type (never by parameter name). When resolving a parameter's type, the front-end checks in strict priority order:
- An exact entry for the type as written, alias included (e.g.
Positive). - For
Optional[T]/T | None: the domain ofTplusNone. - Inherently finite types:
bool,Literal[...], andEnumneed no entry. - The underlying base type under any
Whereclauses (e.g.intforPositive), then narrowed by everyWherepredicate.
A checker never guesses a domain (such as silently picking range(-5, 5) for int). Any quantified parameter without a resolved domain is an immediate ERROR [missing-domain]; an empty domain after Where narrowing is ERROR [vacuous].
Symmetry Reduction#
Wrapping a set of ModelValues in Symmetry(S) tells the checker that permutations of S are behaviourally equivalent (TLA⁺ SYMMETRY Permutations(S)), dramatically shrinking the state space (e.g., 160 states → 49 states in Two-Phase Commit).
Symmetry reduction is unsound for temporal properties and refinement because permuting states can hide unfair cycles. If a model uses Symmetry while checking any Property or Refines, the checker drops symmetry and emits WARN [symmetry-dropped]. Define a separate safety_model = Model(..., constants={...Symmetry(...)}, properties=()) to combine fast symmetric safety checks with full liveness checks.