This example accompanies Hillel Wayne's blog post Specification Refinement, which introduces refinement mappings in TLA⁺ using a two-thread counter:
abstract.tla(abstract.cfg): The high-level specification where two threads atomically increment a sharedcounterand transition from"start"to"done".bad.tla(bad.cfg): A lower-level specification that splits the increment into two non-atomic steps (GetCounterandIncCounter) using a thread-local variabletmpand an intermediate state"inc". CheckingPROPERTY Refinementwith TLC fails with a liveness/temporal property violation, exhibiting the race condition where both threads read0and both write1.good.tla(good.cfg): Adds alockvariable to make the read-modify-write critical section mutually exclusive. TLC verifies thatgoodrefines bothabstract(Refinement) andbad(RefinesBad).good_proof.tla: TLAPS machine-checked proofs thatgoodrefines bothabstract(THEOREM ImplementsAbstract == Spec => Refinement) andbad(THEOREM ImplementsBad == Spec => RefinesBad).