Code, Contracts & Types · Page 4 of 6
Ghost State, Pure & ActionInvariant
Real implementations rarely store full audit histories, yet specifications often need them. Three constructs make this effortless:
Ghost[T]declares a specification-only variable. Look atledger: the Python bodies ofdepositandwithdrawnever touchself.ledger! The checker updatesledgerfrom theActionpredicate while checking the body's realbalancechanges.Pure[T]marks a side-effect-free operator or property (likeavailable) that predicates may read (s.available).ActionInvariantasserts□[P]vars: a step-level invariant overs.xandprime(s.x), such asledger_append_only.
Try it: Click Check to explore all 884 states bounded by
len(s.ledger) <= 4. Then change self.balance -= amount to
self.balance -= amount + 1 and watch conformance catch the drift immediately!