Skip to content

State Machines in Dafny #5487

Closed Answered by ekaprits
rsingha108 asked this question in Q&A
Discussion options

You must be logged in to vote

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

predicate TransitU(s : State , s' : State)
{
    s' == s.(u := s.u+1)
}

This effectively says: "s' is equal to s, except for field u, which will be equal to s.u+1".

A few more things:

  • For collections (e.g. sequence, map), the corresponding syntax is
    s' := s[i := new_value]
  • Sometimes parts of your state may never change. One way to not have to deal with these parts not changing is to write your transitions as
    predicate Next(c: Constants, v: Variables, v': Variables) {...}
    and write your overall sta…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rsingha108
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants