Dijkstra-style IF---FI and DO---OD

May 3, 2014 at 11:54 AM
What's the best Dafny-up-to-date way of expressing Dijkstra-style

IF gd1 -> bd1 | gd2 -> bd2 FI
and
DO gd1 -> bd1 | gd2 -> bd2 OD

where the guards can overlap, causing a potential nondeterministic choice?

Thanks!

[ I'm aware of the nondeterministic constructs x:| and x:= *. ]
Coordinator
May 3, 2014 at 3:42 PM
Dafny supports these statements. The syntax is:
if {
  case gd1 => bd1;
  case gd2 => bd2;
}
while {
  case gd1 => bd1;
  case gd2 => bd2; 
}
If you need invariant, decreases, or modifies clauses for this loop, just place them before the open curly brace, as you would for the ordinary while statement.

By the way, another way to use nondeterminism in the language is in the guards of if and while statements, where you can write *. For example:
if * {
  Stmt0;
} else {
  Stmt1;
}
while * {
  Body;
}
This loop may or may not ever terminate, so to achieve termination you'll need to have some other break or return statement in Body. (Or, you can mark the loop with decreases *;, which says that you're okay with the possibility that the loop does not terminate and, thus, that don't want termination checking.

Rustan
Marked as answer by rustanleino on 5/3/2014 at 9:17 AM