Created
March 11, 2013 01:55
-
-
Save jbranchaud/5131417 to your computer and use it in GitHub Desktop.
Exercise 2 from Microsoft's Dafny on Rise4Fun.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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