summaryrefslogtreecommitdiff
path: root/Test/dafny3/CalcExample.dfy
diff options
context:
space:
mode:
authorGravatar Rustan Leino <leino@microsoft.com>2013-01-20 14:02:09 -0800
committerGravatar Rustan Leino <leino@microsoft.com>2013-01-20 14:02:09 -0800
commit724cd08bb69546967483e13fdd1a7c7b9797f59b (patch)
treee0f7cf732ba1daf05b7e574bf57e723d0c5ef7b8 /Test/dafny3/CalcExample.dfy
parent0f380d0d99aa2439b59814ec43305bc18cb0ff64 (diff)
Added some co- test cases. Fixed some bugs.
Diffstat (limited to 'Test/dafny3/CalcExample.dfy')
-rw-r--r--Test/dafny3/CalcExample.dfy27
1 files changed, 27 insertions, 0 deletions
diff --git a/Test/dafny3/CalcExample.dfy b/Test/dafny3/CalcExample.dfy
new file mode 100644
index 00000000..c94c18d2
--- /dev/null
+++ b/Test/dafny3/CalcExample.dfy
@@ -0,0 +1,27 @@
+function f(x: int, y: int): int
+
+ghost method Associativity(x: int, y: int, z: int)
+ ensures f(x, f(y, z)) == f(f(x, y), z);
+
+ghost method Monotonicity(y: int, z: int)
+ requires y <= z;
+ ensures forall x :: f(x, y) <= f(x, z);
+
+ghost method DiagonalIdentity(x: int)
+ ensures f(x, x) == x;
+
+method M(a: int, b: int, c: int, x: int)
+ requires c <= x == f(a, b);
+{
+ calc {
+ f(a, f(b, c));
+ { Associativity(a, b, c); }
+ f(f(a, b), c);
+ { assert f(a, b) == x; }
+ f(x, c);
+ { assert c <= x; Monotonicity(c, x); }
+ <= f(x, x);
+ { DiagonalIdentity(x); }
+ x;
+ }
+}