State Machines in Dafny #5487
-
Hi, I am trying to write a state machine in dafny in the following way. There are two transition steps and they modify some particular state variables.
Is there any smart way in which I can write the variables which stays same in each of these transition steps instead of manually writing them all? i.e. In the transition predicates can I only mention the state variables that are changing? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Did you take a look at Modeling Concurrency in Dafny? You may not care about the "concurrency" part, but your example looks a lot like TLA+ and I consider this paper to be a quite general approach to translating TLA+ to Dafny, whether concurrent or not. |
Beta Was this translation helpful? Give feedback.
-
Yes, Dafny allows for "update expressions", where you can state which part of a datatype/collection changes and the rest remains the same. For example, in your case you could write TransitV as
This effectively says: "s' is equal to s, except for field u, which will be equal to s.u+1". A few more things:
|
Beta Was this translation helpful? Give feedback.
-
Thanks a lot. This is super helpful. |
Beta Was this translation helpful? Give feedback.
Yes, Dafny allows for "update expressions", where you can state which part of a datatype/collection changes and the rest remains the same. For example, in your case you could write TransitV as
This effectively says: "s' is equal to s, except for field u, which will be equal to s.u+1".
A few more things:
s' := s[i := new_value]
predicate Next(c: Constants, v: Variables, v': Variables) {...}
and write your overall sta…