diff options
author | Rustan Leino <leino@microsoft.com> | 2012-07-03 01:13:44 -0700 |
---|---|---|
committer | Rustan Leino <leino@microsoft.com> | 2012-07-03 01:13:44 -0700 |
commit | 1316915c7dd7300a3e76ea6b8c2689710715dc36 (patch) | |
tree | 19dc6fef005ce4e6e5c2f66f328ce087c70a4790 /Test/dafny0/Coinductive.dfy | |
parent | 44c908246d375995e0885cef212490e75bbcd96d (diff) |
Dafny: added copredicates
Diffstat (limited to 'Test/dafny0/Coinductive.dfy')
-rw-r--r-- | Test/dafny0/Coinductive.dfy | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Test/dafny0/Coinductive.dfy b/Test/dafny0/Coinductive.dfy index 35f17c1c..431d6bb1 100644 --- a/Test/dafny0/Coinductive.dfy +++ b/Test/dafny0/Coinductive.dfy @@ -62,4 +62,45 @@ module TestCoinductiveDatatypes }
+// --------------- CoPredicates --------------------------
+
+module CoPredicateResolutionErrors {
+
+ codatatype Stream<T> = StreamCons(head: T, tail: Stream);
+
+ function Upward(n: int): Stream<int>
+ {
+ StreamCons(n, Upward(n + 1))
+ }
+
+ function Doubles(n: int): Stream<int>
+ {
+ StreamCons(2*n, Doubles(n + 1))
+ }
+
+ copredicate Pos(s: Stream<int>)
+ {
+ 0 < s.head && Pos(s.tail) && Even(s)
+ }
+
+ copredicate Even(s: Stream<int>)
+ {
+ s.head % 2 == 0 && Even(s.tail)
+ && (s.head == 17 ==> Pos(s))
+ && (Pos(s) ==> s.head == 17) // error: cannot make recursive copredicate call in negative position
+ && !Even(s) // error: cannot make recursive copredicate call in negative position
+ && (Even(s) <==> Even(s)) // error (x2): recursive copredicate calls allowed only in positive positions
+ }
+
+ copredicate Another(s: Stream<int>)
+ {
+ !Even(s) // here, negation is fine
+ }
+
+ ghost method Lemma(n: int)
+ ensures Even(Doubles(n));
+ {
+ }
+}
+
// --------------------------------------------------
|