Theory RealTimeDeque
section ‹Real-Time Deque Implementation›
theory RealTimeDeque
imports States
begin
text‹
The real-time deque can be in the following states:
➧ ‹Empty›: No values stored. No dequeue operation possible.
➧ ‹One›: One element in the deque.
➧ ‹Two›: Two elements in the deque.
➧ ‹Three›: Three elements in the deque.
➧ ‹Idles›: Deque with a left and a right end, fulfilling the following invariant:
▪ 3 * size of left end ‹≥› size of right end
▪ 3 * size of right end ‹≥› size of left end
▪ Neither of the ends is empty
➧ ‹Rebal›: Deque which violated the invariant of the ‹Idles› state by non-balanced dequeue and enqueue operations. The invariants during in this state are:
▪ The rebalancing is not done yet. The deque needs to be in ‹Idles› state otherwise.
▪ The rebalancing is in a valid state (Defined in theory ‹States›)
▪ The two ends of the deque are in a size window, such that after finishing the rebalancing the invariant of the ‹Idles› state will be met.
Functions:
➧ ‹is_empty›: Checks if a deque is in the ‹Empty› state
➧ ‹deqL'›: Dequeues an element on the left end and return the element and the deque without this element. If the deque is in ‹idle› state and the size invariant is violated either a ‹rebalancing› is started or if there are 3 or less elements left the respective states are used. On ‹rebalancing› start, six steps are executed initially. During ‹rebalancing› state four steps are executed and if it is finished the deque returns to ‹idle› state.
➧ ‹deqL›: Removes one element on the left end and only returns the new deque.
➧ ‹firstL›: Removes one element on the left end and only returns the element.
➧ ‹enqL›: Enqueues an element on the left and returns the resulting deque. Like in ‹deqL'› when violating the size invariant in ‹idle› state, a ‹rebalancing› with six initial steps is started. During ‹rebalancing› state four steps are executed and if it is finished the deque returns to ‹idle› state.
➧ ‹swap›: The two ends of the deque are swapped.
➧ ‹deqR'›, ‹deqR›, ‹firstR›, ‹enqR›: Same behaviour as the left-counterparts. Implemented using the left-counterparts by swapping the deque before and after the operation.
➧ ‹listL›, ‹listR›: Get all elements of the deque in a list starting at the left or right end. They are needed as list abstractions for the correctness proofs.
›