Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5909d1b
feat(DataStructure/Memory): word-addressed memory oracle and named fi…
SamuelSchlesinger Nov 1, 2026
412f614
doc(bib): add Guéneau, Charguéraud and Pottier (ESOP 2018)
SamuelSchlesinger Nov 1, 2026
16a647f
feat(DataStructure/StateTransition): refinements by abstraction funct…
SamuelSchlesinger Nov 1, 2026
2f12c49
feat(DataStructure/StateTransition): weaken and rescale amortized ref…
SamuelSchlesinger Nov 1, 2026
fba5208
Merge the memory-oracle branch (#2211) into the queue slice
SamuelSchlesinger Nov 1, 2026
98e3290
fix(DataStructure/StateTransition): place productCharge beside produc…
SamuelSchlesinger Nov 1, 2026
02ba9f7
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
56232f9
refactor(DataStructure/StateTransition): make Refinement.Amortized a …
SamuelSchlesinger Nov 1, 2026
1b4e2ea
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
fe7d60d
wip: array stack over memory and queue method lemmas
SamuelSchlesinger Nov 1, 2026
aad5f3e
feat(Foundations): affine cost bounds are O(size)
SamuelSchlesinger Nov 1, 2026
78cf872
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
6698e86
wip: queue over memory
SamuelSchlesinger Nov 1, 2026
7dda248
refactor(DataStructure/StateTransition): product answer types via Sum…
SamuelSchlesinger Nov 1, 2026
93adf90
Merge the refinement branch (#2212) into the queue slice
SamuelSchlesinger Nov 1, 2026
412ad37
feat(DataStructure): queue over two array stacks over the memory oracle
SamuelSchlesinger Nov 1, 2026
e80dd97
feat(DataStructure): Fibonacci heap insert over a record of named cells
SamuelSchlesinger Nov 1, 2026
f40fe1c
feat(DataStructure): products over one memory, and glue charges for h…
SamuelSchlesinger Nov 1, 2026
7fde8d6
feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts o…
SamuelSchlesinger Nov 2, 2026
9e906e7
feat(DataStructure): Fibonacci heap extractMin with consolidation ove…
SamuelSchlesinger Nov 2, 2026
bf3c787
wip: assembly
SamuelSchlesinger Nov 2, 2026
fd5445e
Merge remote-tracking branch 'origin/feat/ram-products' into feat/fib…
SamuelSchlesinger Nov 2, 2026
d13042c
feat(DataStructure): Fibonacci heap as an amortized framed refinement…
SamuelSchlesinger Nov 2, 2026
6d8804b
fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; …
SamuelSchlesinger Nov 2, 2026
2279242
Merge branch 'feat/fibheap-memory' into feat/fibheap-decreasekey
SamuelSchlesinger Nov 2, 2026
e1a0cfc
fix(DataStructure): credit Renfei Zhou in the record decreaseKey; tes…
SamuelSchlesinger Nov 2, 2026
a23cede
fix(DataStructure): name the adapted module without a slash path
SamuelSchlesinger Nov 2, 2026
ef7af4e
Merge branch 'feat/fibheap-decreasekey' into feat/fibheap-extractmin
SamuelSchlesinger Nov 2, 2026
cec7479
fix(DataStructure): credit Renfei Zhou in the record extractMin; test…
SamuelSchlesinger Nov 2, 2026
783c302
Merge branch 'feat/fibheap-extractmin' into feat/fibheap-refinement
SamuelSchlesinger Nov 2, 2026
4dacd5f
refactor(DataStructure): factor extractMin's forest bookkeeping into …
SamuelSchlesinger Nov 2, 2026
ec1c399
Merge remote-tracking branch 'origin/main' into feat/ram-products
SamuelSchlesinger Nov 2, 2026
d653de2
Merge remote-tracking branch 'origin/main' into feat/fibheap-memory
SamuelSchlesinger Nov 2, 2026
c306afd
Merge branch 'feat/fibheap-memory' into feat/fibheap-decreasekey
SamuelSchlesinger Nov 2, 2026
a6ac6be
Merge branch 'feat/fibheap-decreasekey' into feat/fibheap-extractmin
SamuelSchlesinger Nov 2, 2026
580831c
Merge branch 'feat/fibheap-extractmin' into feat/fibheap-refinement
SamuelSchlesinger Nov 2, 2026
c6d6365
Merge remote-tracking branch 'origin/feat/ram-products' into feat/fib…
SamuelSchlesinger Nov 2, 2026
90822e9
Merge branch 'feat/fibheap-refinement' into feat/fibheap-extract-pure
SamuelSchlesinger Nov 2, 2026
42643d4
fix(Foundations): Perm imports Complexity.Init (checkInitImports)
SamuelSchlesinger Nov 2, 2026
f734604
refactor(FibonacciHeap): move the machine-free forest lemmas into For…
SamuelSchlesinger Nov 2, 2026
a57bbce
refactor(WordRAM/FibonacciHeap): derive extractMin and insert forest …
SamuelSchlesinger Nov 2, 2026
a5fd7b7
Merge remote-tracking branch 'origin/feat/fibheap-extract-pure' into …
SamuelSchlesinger Nov 2, 2026
4627572
refactor(FibonacciHeap): move the decreaseKey forest lemmas into Fore…
SamuelSchlesinger Nov 2, 2026
6ab74b8
refactor(WordRAM/FibonacciHeap): derive decreaseKey forest reasoning …
SamuelSchlesinger Nov 2, 2026
4393699
Merge origin/main into feat/fibheap-extractmin (after #2233)
SamuelSchlesinger Nov 2, 2026
de09665
Merge #2240 (feat/fibheap-extractmin, merged with main) into feat/fib…
SamuelSchlesinger Nov 2, 2026
c9eccb7
Merge origin/main into feat/fibheap-refinement (after #2239)
SamuelSchlesinger Nov 2, 2026
49aeb57
fix(DataStructure): the record Fibonacci heap's frame keeps the front…
SamuelSchlesinger Nov 2, 2026
5e8d822
Merge #2242 (feat/fibheap-refinement, merged with main) into feat/fib…
SamuelSchlesinger Nov 2, 2026
9fe74e9
Merge #2247 (feat/fibheap-extract-pure, merged with main) into feat/f…
SamuelSchlesinger Nov 2, 2026
fc9f54e
Merge #2275 (feat/fibheap-bridge, merged with main) into feat/fibheap…
SamuelSchlesinger Nov 2, 2026
58b7238
Merge origin/main into feat/fibheap-extract-pure (after #2242)
SamuelSchlesinger Nov 2, 2026
5de40ab
Merge #2247 (feat/fibheap-extract-pure, merged with main) into feat/f…
SamuelSchlesinger Nov 2, 2026
7f4310a
Merge #2275 (feat/fibheap-bridge, merged with main) into feat/fibheap…
SamuelSchlesinger Nov 2, 2026
ccae025
Merge fixed actual main into reviewed Fibonacci heap decrease-key bridge
SamuelSchlesinger Nov 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module
-- upstream: candidate

public import Complexity.DataStructure.PriorityQueue.FibonacciHeap.Basic
public import Complexity.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.Cut

/-!
# Fibonacci-heap `decreaseKey` over a record of named cells
Expand All @@ -17,17 +16,18 @@ public import Complexity.DataStructure.PriorityQueue.WordRAM.FibonacciHeap.Cut
root list, and `cascade` walks up the ancestors: a marked ancestor is cut in turn, the first
unmarked one is marked [Fredman and Tarjan][FredmanTarjan1987]
[Cormen et al., Section 19.3][CLRS2009]. Then `setKey` stores the key and makes `v` the minimum
root if it precedes it. Cutting before storing the key keeps every tree valid throughout, so no
pre-decrease copy of the state is needed, unlike the hand-stepped `cutNode_forest`.
root if it precedes it. Cutting before storing the key keeps every tree valid throughout. (The
hand-stepped `decreaseKeyCode` stores the key first; its proof reads the forest with the old keys,
through `CutsNode.withKey`.)

The proof splits as in `Basic.lean`:

* program evaluation: `wp_unlink`, `wp_toRoot` and `wp_cut` produce the effect `CutsNode` of one
cut on the raw view (the facts of the hand-stepped `cutNodeCode_raw`); `wp_cascade` runs the
cut on the raw view (as the hand-stepped `cutNodeCode_raw` does); `wp_cascade` runs the
cascade by induction on its fuel, which exceeds the number of marks; `wp_setKey` and
`wp_decreaseKey` assemble the three cases (root, no cut, cut);
* forest mathematics on `RawState n` alone: `cutsNode_cutState` (pointer surgery of one cut),
`CutsNode.cascading` (a cut keeps the forest `Cascading`, the content of `cutNode_forest`),
`CutsNode.cascading` (a cut keeps the forest `Cascading`),
`Cascading.clear_root` and `Cascading.mark` (the cascade stops), `Cascading.lowerRootKey` and
`FibRawInv.lowerKey_noCut` (storing the key), with the existing `ValidSubtree.exists_cut`,
`ValidSubtree.mark_pending`, `ValidSubtree.lower_key_no_cut` and `CutInv.to_fibRawInv`.
Expand All @@ -37,9 +37,10 @@ unmarked root, which releases `credit = 24`, so the cascade is paid by the poten
`decreaseKey` costs at most `104` operations amortized.

The module adapts Renfei Zhou's native formalization (`WordRAM/FibonacciHeap`, its `Cut.lean`) to
the record level: his cut (`cutNodeCode_raw`, `cutNode_forest`, with its circular-list uniqueness
argument) and cascading-cut development become `cut`, `CutsNode.cascading`,
`IsCircList.tail_unique` and `cascade`, and his forest lemmas are reused unchanged.
the record level: his cut (`cutNodeCode_raw` and its forest transition, with its circular-list
uniqueness argument) and cascading-cut development become `cut`, `CutsNode.cascading`,
`IsCircList.tail_unique` and `cascade`, and his forest lemmas are reused unchanged. The
hand-stepped proofs in turn now cite these lemmas.

## Main definitions

Expand Down Expand Up @@ -278,6 +279,39 @@ theorem cutsNode_cutState {n : ℕ} {st : RawState n} {cur p m : Fin n} {rtail :
Function.update_of_ne (hroot_ne m List.mem_cons_self x hpx),
Function.update_of_ne (hroot_ne r' hr'_roots x hpx)]

/-- A cut does not read or write keys: it has the same effect on states with other keys. -/
theorem CutsNode.withKey {n : ℕ} {st st' : RawState n} {cur p m : Fin n} {rtail : List (Fin n)}
(h : CutsNode st cur p m rtail st') (key : Fin n → ℕ) :
CutsNode { st with key := key } cur p m rtail { st' with key := key } :=
{ h with key := rfl }

/-- After `cur` is unlinked from its parent `p`, the minimum root `m` still has a right neighbour:
unlinking changes sibling pointers only among `p`'s children. -/
theorem exists_right_min_of_unlink {n : ℕ} {st : RawState n} {cur p m : Fin n}
{rtail : List (Fin n)}
(hdp2 : 2 ≤ st.deg p → ∃ (h : Fin n) (tail : List (Fin n)),
st.child p = h.val + 1 ∧ IsCircList st.left st.right (h :: tail) ∧
cur ∈ h :: tail ∧ 2 ≤ (h :: tail).length ∧ ∀ u ∈ h :: tail, st.par u = p.val + 1)
(hcirc_r : IsCircList st.left st.right (m :: rtail))
(hroots_par0 : ∀ u ∈ m :: rtail, st.par u = 0)
{left₁ right₁ : Fin n → ℕ} {child₁ : ℕ}
(hunlink : (st.deg p = 1 ∧ child₁ = 0 ∧ left₁ = st.left ∧ right₁ = st.right) ∨
(2 ≤ st.deg p ∧ ∃ r l : Fin n, st.right cur = r.val ∧ st.left cur = l.val ∧
child₁ = r.val + 1 ∧ left₁ = Function.update st.left r l.val ∧
right₁ = Function.update st.right l r.val)) :
∃ r' : Fin n, right₁ m = r'.val := by
obtain ⟨r', hr', -⟩ := hcirc_r.right_head
rcases hunlink with ⟨-, -, -, rfl⟩ | ⟨h2, r, l, -, hl, -, -, rfl⟩
· exact ⟨r', hr'⟩
· obtain ⟨h, tail, -, hcirc, hcur, hlen, hpar⟩ := hdp2 h2
obtain ⟨r₂, l₂, -, -, hl₂, -, hl₂m, -⟩ := hcirc.remove hcur hlen
obtain rfl : l₂ = l := Fin.ext (hl₂.symm.trans hl)
have hml : m ≠ l₂ := fun e => by
have := hroots_par0 m List.mem_cons_self
rw [e, hpar l₂ hl₂m] at this
omega
exact ⟨r', by rw [Function.update_of_ne hml]; exact hr'⟩

/-! ## Forest mathematics of cascading cuts -/

/-- The forest during cascading cuts from `v`: `FibRawInv` with one `pending` ancestor that may
Expand Down Expand Up @@ -339,8 +373,7 @@ theorem ValidSubtree.deg_lt_length {n : ℕ} {st : RawState n} {pending : Option
omega

/-- **A cut keeps the forest `Cascading`**, with the parent `p` now pending. The cut node `cur`
becomes the root of a new tree; its old tree loses that subtree. This is the forest part of the
hand-stepped `cutNode_forest`. -/
becomes the root of a new tree; its old tree loses that subtree. -/
theorem CutsNode.cascading {n K : ℕ} {s : IndexedMinPQ.State n} {st st' : RawState n}
{cur p v m : Fin n} {pending : Option (Fin n)} {ts : List (FHTree n)} {rtail : List (Fin n)}
(h : Cascading n K s st v m pending ts) (hperm_r : (m :: rtail).Perm (ts.map FHTree.root))
Expand Down Expand Up @@ -768,20 +801,7 @@ theorem wp_cut {g : Cell → ℕ} {cur p m : Fin n} {rtail : List (Fin n)}
Record.wp (Cell.ok n) w (cut cur p) Q g := by
rw [cut, Record.wp_bind]
refine wp_unlink hdp_pos hdp2 hdp_le hfit fun g₁ t₁ ht₁ left₁ right₁ child₁ hunlink hg₁ => ?_
-- The minimum root's right neighbour, after unlinking.
have hr₁ : ∃ r' : Fin n, right₁ m = r'.val := by
obtain ⟨r', hr', -⟩ := hcirc_r.right_head
rcases hunlink with ⟨-, -, -, rfl⟩ | ⟨h2, r, l, -, hl, -, -, rfl⟩
· exact ⟨r', hr'⟩
· obtain ⟨h, tail, -, hcirc, hcur, hlen, hpar⟩ := hdp2 h2
obtain ⟨r₂, l₂, -, -, hl₂, -, hl₂m, -⟩ := hcirc.remove hcur hlen
obtain rfl : l₂ = l := Fin.ext (hl₂.symm.trans hl)
have hml : m ≠ l₂ := fun e => by
have := hroots_par0 m List.mem_cons_self
rw [e, hpar l₂ hl₂m] at this
omega
exact ⟨r', by rw [Function.update_of_ne hml]; exact hr'⟩
obtain ⟨r', hr'⟩ := hr₁
obtain ⟨r', hr'⟩ := exists_right_min_of_unlink hdp2 hcirc_r hroots_par0 hunlink
refine wp_toRoot (by rw [hg₁]; exact hmin) (by rw [hg₁]; exact hr') hfit
(by rw [hg₁]; exact hnr) (by rw [hg₁]; exact hnm) fun g₂ hg₂ => hQ _ _ (by omega) ?_
rw [hg₂, hg₁]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module

public import Complexity.DataStructure.Memory.Frame
public import Complexity.DataStructure.PriorityQueue.FibonacciHeap.ExtractMin
public import Mathlib.Order.Interval.Finset.Nat

/-!
# The Fibonacci heap as an amortized refinement over memory
Expand Down
Loading
Loading