diff --git a/doc/examples/stackExample/stack.dfy b/doc/examples/stackExample/stack.dfy new file mode 100644 index 000000000..e81ed0628 --- /dev/null +++ b/doc/examples/stackExample/stack.dfy @@ -0,0 +1,29 @@ +class BoundedStack { + var data : seq; + var curSize : int; + var maxSize : int; + + function valid() : bool + { + curSize >= 0 && curSize <= |data| && + maxSize >= curSize && maxSize == |data| + } + + method pop() returns (res : int) + requires curSize > 0 && valid(); + ensures curSize == old(curSize - 1) && valid() && res == data[curSize]; + { + var res : int; + res := data[curSize -1]; + curSize := curSize - 1; + } + + method push(n : int) + requires curSize < maxSize && valid(); + ensures data[curSize - 1] == n; + ensures curSize == old(curSize) + 1 && valid(); + { + data[curSize] := n; + curSize := curSize + 1; + } +} \ No newline at end of file diff --git a/doc/examples/stackExample/stack.dfy.proofs b/doc/examples/stackExample/stack.dfy.proofs new file mode 100644 index 000000000..05751a6a1 --- /dev/null +++ b/doc/examples/stackExample/stack.dfy.proofs @@ -0,0 +1,22 @@ + + + +Created by Algover at Tue May 21 13:57:20 CEST 2019 +expand on='... ((?match: this.valid())) ... |-'; +expand on='|- ... ((?match: this.valid()@$heap[this.curSize := this.curSize - 1])) ...'; +boogie ; + +expand on='... ((?match: this.valid())) ... |-'; +boogie ; + +expand on='... ((?match: this.valid())) ... |-'; +integerSimplification on='|- ... ((?match: this.data@($heap[this.curSize := this.curSize@($heap[this.data := $seq_upd<int>(this.data, this.curSize, n)]) + 1])[this.curSize] == n)) ...'; + +expand on='... ((?match: this.valid())) ... |-'; +boogie ; + +expand on='... ((?match: this.valid())) ... |-'; +expand on='|- ... ((?match: this.valid()@$heap[this.curSize := this.curSize@($heap[this.data := $seq_upd<int>(this.data, this.curSize, n)]) + 1])) ...'; +boogie ; + +