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).
@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)#
Assumes predicate(s) over constants before state exploration.
Init(predicate, description=None)#
Constrains the initial state(s). Multiple Init clauses and field defaults are conjoined.
Invariant(predicate, description=None)#
Claims predicate(s) holds in every reachable state.
ActionInvariant(predicate, description=None)#
Claims predicate(s) (using s.x and prime(s.x)) holds on every transition step.
Property(predicate, description=None)#
Claims a temporal formula (using always, eventually, leads_to) holds of every behaviour.
Fairness(predicate, description=None)#
Adds scheduler fairness assumptions built from weak_fairness and strong_fairness to Spec.
Method & Contract Clauses#
Action(predicate=None, description=None)#
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)#
Action enabling guard or function contract precondition. Multiple Requires clauses are conjoined.
Ensures(predicate, description=None)#
Postcondition over s.x, prime(s.x), parameters, and result.
Modifies(*variables: str)#
Explicit action frame: the action may modify only the named state/ghost variables; all others remain unchanged.
class Refines(Generic[T]): Refines(**mapping)#
Return type and runtime mapping for a refinement method def m(self) -> Refines[Abstract]. Claims C!Spec ⇒ Abstract!Spec under the mapping.
def refines_queue(self) -> Refines[BoundedQueue[T]]:
return Refines(capacity=self.capacity, items=tuple(...))