summaryrefslogtreecommitdiff
path: root/Test/VerifyThis2015/Problem3.dfy
diff options
context:
space:
mode:
authorGravatar leino <unknown>2015-04-28 19:48:33 -0700
committerGravatar leino <unknown>2015-04-28 19:48:33 -0700
commit8af694583e86b36d8fcc81485ea2f02c9961d96c (patch)
tree81c8c439236c5cf744fc5d5327586e328a64335d /Test/VerifyThis2015/Problem3.dfy
parent84b3df3615af4f83df753b042b276b994a97b18b (diff)
Changes to the VerifyThis2015 test programs
Diffstat (limited to 'Test/VerifyThis2015/Problem3.dfy')
-rw-r--r--Test/VerifyThis2015/Problem3.dfy20
1 files changed, 20 insertions, 0 deletions
diff --git a/Test/VerifyThis2015/Problem3.dfy b/Test/VerifyThis2015/Problem3.dfy
index fb95637d..4205035d 100644
--- a/Test/VerifyThis2015/Problem3.dfy
+++ b/Test/VerifyThis2015/Problem3.dfy
@@ -123,3 +123,23 @@ class DoublyLinkedList {
Nodes := Nodes[..k] + [x] + Nodes[k..];
}
}
+
+// --------------------------------------------------------
+// If it were not required to build a data structure (like the class above) that supports the
+// Remove and PutBack operations, the operations can easily be verified to compose into the
+// identity transformation. The following method shows that the two operations, under a suitable
+// precondition, have no net effect on any .L or .R field.
+
+method Alt(x: Node)
+ requires x != null && x.L != null && x.R != null
+ requires x.L.R == x && x.R.L == x // links are mirrored
+ modifies x, x.L, x.R
+ ensures forall y: Node :: y != null ==> y.L == old(y.L) && y.R == old(y.R)
+{
+ // remove
+ x.R.L := x.L;
+ x.L.R := x.R;
+ // put back
+ x.R.L := x;
+ x.L.R := x;
+}