~/bend-docscommunity

queue_proof.bend checks

raw source on the hub · import bend-kit-scheduler@0.4.2.0/queue_proof.bend as Queue_proof

6 imports
import Base
import bend-mathlib@0.8.0.0/nat.bend as MNat
import bend-mathlib@0.8.0.0/bool.bend as MBool
import bend-kit-collections@0.1.4.1/heap.bend as H
import ./queue.bend as Q
import ./queue_laws.bend as L

Definitions

def split source · line 8 · raw

@-P:(@_:Bool -> Type) -> @b:Bool -> @yes:(@_:{b == True{} : Bool} -> P(True{})) -> @no:(@_:{b == False{} : Bool} -> P(False{})) -> P(b)

def take_equivalent.step source · line 15 · raw

@-A:Data -> @b:Bool -> @t:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @rest:List<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @found:Maybe<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.take.keep(A, b, t, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Taken{rest, found}) == 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Taken{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.remove.list.keep(A, b, t, rest), 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.find.list.choose(A, b, t, found)} : 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Taken<A>}

def key_refl source · line 40 · raw

@+d:Nat -> @+i:Nat -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, d), i, i, d, d) == True{} : Bool}

def key_succ source · line 44 · raw

@b:Bool -> @i:Nat -> @j:Nat -> @d:Nat -> @e:Nat -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(b, i, j, 1n+d, 1n+e) == 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(b, i, j, d, e) : Bool}

def key_succ.premise source · line 51 · raw

@+d:Nat -> @+e:Nat -> @+i:Nat -> @+j:Nat -> @+b:Bool -> @p:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, 1n+d, 1n+e) == b : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, d, e) == b : Bool}

def key_succ.conclusion source · line 54 · raw

@+d:Nat -> @+e:Nat -> @+i:Nat -> @+j:Nat -> @p:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, d, e) == True{} : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, 1n+d, 1n+e) == True{} : Bool}

def key_flip source · line 57 · raw

@+d:Nat -> @+e:Nat -> @+i:Nat -> @+j:Nat -> @p:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, d, e) == False{} : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(e, d), j, i, e, d) == True{} : Bool}

def key_trans source · line 68 · raw

@+d:Nat -> @+e:Nat -> @+f:Nat -> @+i:Nat -> @+j:Nat -> @+k:Nat -> @p:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, e), i, j, d, e) == True{} : Bool} -> @q:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(e, f), j, k, e, f) == True{} : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le.same(Nat.is_eq(d, f), i, k, d, f) == True{} : Bool}

def le_refl source · line 87 · raw

@-A:Data -> @t:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, t, t) == True{} : Bool}

def le_flip source · line 92 · raw

@-A:Data -> @a:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @b:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @e:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, a, b) == False{} : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, b, a) == True{} : Bool}

def le_trans source · line 97 · raw

@-A:Data -> @a:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @b:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @c:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @e:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, a, b) == True{} : Bool} -> @f:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, b, c) == True{} : Bool} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, a, c) == True{} : Bool}

def below_trans source · line 126 · raw

@-A:Data -> @h:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+a:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @+b:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @e:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, a, b) == True{} : Bool} -> @eh:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.below(A, h, b) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.below(A, h, a)

def remove_absent.list source · line 200 · raw

@-A:Data -> @+xs:List<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+i:Nat -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.absent.list(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.remove.list(A, xs, i), i)

def selected_absent source · line 308 · raw

@-A:Data -> @+i:Nat -> @m:Maybe<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> Data

Templates

template merge_all source · line 104 · raw

@-A:Data -> @-P:(@_:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> Data) -> @+fuel:Nat -> @+a:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+b:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+ea:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, a) -> @+eb:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, b) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, 0x2e75a06e0acd57f098569f07516e8aae/heap.Heap.merge.go(0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>, x => y => 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, x, y), fuel, a, b))

Merging cannot introduce an element that violates any predicate P. Fuel zero returns the left heap, so this lemma does not trust cached heap sizes.

template merge_all.full source · line 123 · raw

@-A:Data -> @-P:(@_:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> Data) -> @+a:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+b:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @ea:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, a) -> @eb:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, b) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, 0x2e75a06e0acd57f098569f07516e8aae/heap.Heap.merge(0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>, x => y => 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, x, y), a, b))

template merge_ordered source · line 135 · raw

@-A:Data -> @+fuel:Nat -> @+a:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+b:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+ea:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, a) -> @+eb:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, b) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2e75a06e0acd57f098569f07516e8aae/heap.Heap.merge.go(0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>, x => y => 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, x, y), fuel, a, b))

template merge_ordered.full source · line 156 · raw

@-A:Data -> @+a:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+b:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @ea:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, a) -> @eb:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, b) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2e75a06e0acd57f098569f07516e8aae/heap.Heap.merge(0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>, x => y => 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, x, y), a, b))

template remove_all source · line 159 · raw

@-A:Data -> @-P:(@_:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> Data) -> @+h:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+i:Nat -> @+eh:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, h) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.all.heap(A, P, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.remove.heap(A, h, i))

template remove_ordered source · line 173 · raw

@-A:Data -> @+h:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+i:Nat -> @+eh:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, h) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.remove.heap(A, h, i))

template remove_absent.heap source · line 187 · raw

@-A:Data -> @+h:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @+i:Nat -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.absent.heap(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.remove.heap(A, h, i), i)

template requeue_absent source · line 258 · raw

@-A:Data -> @+i:Nat -> @d:Nat -> @+s:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.State<A> -> @e:{0x2b4eb91a76a70816d22bee0d99e7d13a/queue.find.list(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.running(A, s), i) == None{} : Maybe<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>>} -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.requeued(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.requeue(A, i, d, s)) == False{} : Bool}

template select_selected_absent source · line 315 · raw

@-A:Data -> @now:Nat -> @+i:Nat -> @+s:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.State<A> -> @eh:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.absent.heap(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.pending(A, s), i) -> selected_absent(A, i, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.selected(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.select(A, now, s)))

template push_ordered source · line 329 · raw

@-A:Data -> @t:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A> -> @h:0x2e75a06e0acd57f098569f07516e8aae/heap.Heap<0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @e:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, h) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2e75a06e0acd57f098569f07516e8aae/heap.Heap.push(0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>, x => y => 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.le(A, x, y), t, h))

template requeue_ordered.found source · line 352 · raw

@-A:Data -> @found:Maybe<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @d:Nat -> @+s:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.State<A> -> @e:0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.pending(A, s)) -> 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.ordered(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.pending(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.requeue.state(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.requeue.found(A, found, d, s))))

template requeue_counter.found source · line 398 · raw

@-A:Data -> @found:Maybe<&2, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.Ticket<A>> -> @d:Nat -> @+s:0x2b4eb91a76a70816d22bee0d99e7d13a/queue.State<A> -> {0x2b4eb91a76a70816d22bee0d99e7d13a/queue.next_id(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue_laws.requeue.state(A, 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.requeue.found(A, found, d, s))) == 0x2b4eb91a76a70816d22bee0d99e7d13a/queue.next_id(A, s) : Nat}