Hi Steve, all good questions.
1. Defining now()
Monotonically-increasing variables make model-checking difficult, because absent restrictions this means the system has an infinite number of possible states and so the model checker will never halt. My advice here is to think carefully about whether a monotonically-increasing global clock is really required for you to achieve the desired semantics. If you absolutely need the global clock, define it thus:VARIABLE GlobalClockModel-checking this is difficult. You'll have to define Nat to be a finite set like 1 .. 100, which means there exist behaviors which probably don't conform to the real world system - like an uninterrupted series of Tick relations until you hit GlobalClock = 100, after which other actions take place. You can mitigate this by not allowing Tick if other actions are enabled, but really this whole approach is messy and you're better off without a monotonically-increasing global clock. Why do you need one?
TypeInvariant == GlobalClock \in Nat
Init == GlobalClock = 0
Tick == GlobalClock' = GlobalClock + 1
You understand that spec defines a subset of all behaviors such that Init is true in the first state, and for all steps either the ExampleAction boolean formula is true or it is a stuttering step.you aren't saying "if x is 0 or 1, then assign 1 - x to x after this action executes". You're saying "the ExampleAction formula is true of a step in a behavior if in the first state x is either 0 or 1, and in the second state x' = 1 - x". This isn't pedantry; moving from the state machine paradigm to the behavior paradigm is critical for understanding the temporal logic component of TLA+. The purpose of a spec is to define a set of correct system behaviors, where a behavior is a sequence of states and a state is an assignment of values to variables. So when you see this:It's best to view primed variable "assignments" and postconditions as one and the same. This is tricky to understand, but when you have an action like this:2. Specifying postconditionsExampleAction ==/\ x \in {0, 1}/\ x' = 1 - xInit == x = 0
Spec == Init /\ [][ExampleAction]_<<x>>
If the first conjunct is true (which will probably always be the case) and the second conjunct (your postcondition) is not, TLC will simply not take this step. Personally I would use the first conjunct as the postcondition in and of itself.Here we have the "postcondition" check that x' is in the set {2, 3, 4}. It's impossible for ExampleAction to be true of any step, since the conjuncts are clearly contradictory and can never all be true. Tying this back to your example, we have these conjuncts:How does this all relate back to your question? Simply, a postcondition of the type you've given is perfectly fine. You can use primed variables in whatever logical statements and checks you want and it will not create a new outcome. What adding conjuncts can do is remove outcomes. For example, if we have the following:ExampleAction ==/\ x \in {0, 1}/\ x' = 1 - x/\ x' \in {2, 3, 4}/\ store' = [p \in (DOMAIN store \ path) |-> store[p]]
/\ ~has_entry(store', path) \* HERE
A minor stylistic note: rather than modifying the domain of your store variable, consider mapping undefined paths to a placeholder null value instead.
3. InvariantsI'm not sure I understand this question. Could you specify what doGet and doHead do, and what it means for them to be consistent?