Refinement & Models · Page 1 of 5
Refinement (Refines[A])
A ring buffer is an efficient circular-array implementation of a bounded FIFO queue. How do
we prove every behaviour of RingBuffer[T] is a legal behaviour of
BoundedQueue[T]?
Write a refinement mapping method annotated -> Refines[BoundedQueue[T]]
returning Refines(v=e, ...) for each abstract constant and variable:
def refines_queue(self) -> Refines[BoundedQueue[T]]:
return Refines(
capacity=self.capacity,
items=tuple(self.buf[(self.head + i) % self.capacity] for i in range(self.size)),
)
The checker verifies C!Spec => A!Spec under that mapping: abstract
Init, stuttering-allowed □[A!Next], abstract
Fairness, and every abstract Invariant and Property
(including makes_space!). And because refines_queue is real Python,
unit tests can call it directly too.
Try it: Click Check to verify all 45 states of
RingBuffer refine BoundedQueue. Then introduce a wrap-around bug in
pop — change (self.head + 1) % self.capacity to
(self.head + 2) % self.capacity — and watch FAIL refinement catch it!