- I(a,t,s) ≡ t = length(s) ∧t \geqslant 0 ∧s = α(a,t)
slide: Abstraction function and representation invariant
In order to verify that our implementation
of the abstract data type stack is correct
(that is as long as the bound MAX is not exceeded),
we must show, given that the representation invariant holds,
that the pre-conditions of the
concrete operations imply the pre-conditions
of the corresponding abstract operations,
and, similarly, that the post-conditions
of the abstract operations imply the post-conditions
of the concrete operations.
First, we show that for the operation push
the post-condition of the
abstract type specification
is indeed stronger than the (implicit) post-condition
of the implementation.
This is expressed by the following formula.
Since we know that , we may derive that
and .
To establish the correctness of the operation pop,
we must prove that the pre-condition specified
for the abstract operation is indeed stronger
than the pre-condition specified for the concrete
operation, as expressed by the formula
It is easy to see that immediately follows
from the requirement that the sequence is non-empty.
Finally, to prove that the operator pop
leaves the stack in a correct state, we must prove that
which is done in a similar manner as for push.