Persistent queues — definitions
Lax755887.PersistentQueue · concepts/Lax755887/PersistentQueue.lean · lax-755887
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
Repeated calls may reuse one queue and spend its potential more than once. The telescoping contract deliberately omits compatibility of adjacent potentials.
Concept map
Lean source view on GitHub
| 1 | import Mathlib |
| 2 | |
| 3 | /-! |
| 4 | --- |
| 5 | title: Persistent queues — definitions |
| 6 | type: definition |
| 7 | --- |
| 8 | Repeated calls may reuse one queue and spend its potential more than once. The telescoping contract deliberately omits compatibility of adjacent potentials. |
| 9 | -/ |
| 10 | |
| 11 | namespace Lax755887.PersistentQueue |
| 12 | |
| 13 | structure Charge where |
| 14 | work : ℕ |
| 15 | before : ℕ |
| 16 | after : ℕ |
| 17 | |
| 18 | def amortized (s : Charge) : ℤ := s.work + s.after - s.before |
| 19 | |
| 20 | def totalWork (trace : List Charge) : ℕ := (trace.map Charge.work).sum |
| 21 | |
| 22 | def dequeue (n : ℕ) : Charge := ⟨n + 1, n, 0⟩ |
| 23 | |
| 24 | end Lax755887.PersistentQueue |
| 25 |
Builds on
none
Used by
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments