Last active
January 4, 2024 03:46
-
-
Save AlgorithmsAreCool/25d2976ff4c42d5f9aec74af0c69bc82 to your computer and use it in GitHub Desktop.
Dafny Blog Snippets
This file contains 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
type Timestamp = t: int| 0 <= t <= 9223372036854775808 //2^63 | |
class Entity | |
{ | |
var id : string | |
predicate isEqual(other : Entity) | |
reads this, other | |
{ | |
id == other.id | |
} | |
} |
This file contains 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
method sumAndZero(arr: array<int>) returns (sum: nat) | |
requires forall i :: 0 <= i < arr.Length ==> arr[i] >= 0 | |
modifies arr | |
{ | |
var i: int := 0; | |
sum := 0; | |
// | |
while(i < arr.Length) { | |
sum := sum + arr[i]; | |
arr[i] := arr[i]; | |
i := i + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment