Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created March 11, 2013 01:55
Show Gist options
  • Save jbranchaud/5131417 to your computer and use it in GitHub Desktop.
Save jbranchaud/5131417 to your computer and use it in GitHub Desktop.
Exercise 2 from Microsoft's Dafny on Rise4Fun.com
/*
* Using a precondition, change Abs to say it can only be
* called on negative values. Simplify the body of Abs into
* just one return statement and make sure the method still
* verifies.
*/
method Abs(x: int) returns (y: int)
requires 0 > x;
ensures 0 <= y;
ensures 0 <= x ==> x == y;
ensures x < 0 ==> y == -x;
{
return -x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment