Documentation

Complexity.Algorithms.WordRAM.VanEmdeBoas.Insert

Native van Emde Boas insertion descent #

Insertion updates local extrema in place and recurses at most once per level: either into the summary when the target cluster was empty (after installing the cluster's singleton extrema directly), or into the already-occupied target cluster. Repeated insertion of a local minimum terminates immediately.

Main definitions #

Main results #

References #

The constant and traversal registers at entry to an unfinished insertion.

Instances For

    Mathematical description of one native insertion iteration.

    Instances For
      theorem Cslib.Algorithms.WordRAM.VanEmdeBoas.insertNext_constants {base key : ℕ} {s : WordRAM.Data 32} (hs : InsertEntry base key s) :
      (insertNext s base key).regs zero = 0 ∧ (insertNext s base key).regs one = 1 ∧ (insertNext s base key).regs two = 2 ∧ (insertNext s base key).regs three = 3 ∧ (insertNext s base key).regs four = 4 ∧ (insertNext s base key).regs five = 5

      Constant registers are preserved by an insertion iteration.

      theorem Cslib.Algorithms.WordRAM.VanEmdeBoas.writeBounds_update_min_max {mem : ℕ → ℕ} {base m M key : ℕ} (hpres : mem base = 1) (hm : mem (base + 1) = m) (hM : mem (base + 2) = M) (hle : m ≤ M) :
      (have m₁ := if key < m then Function.update mem (base + 1) key else mem; have displaced := if key < m then m else key; if M < displaced then Function.update m₁ (base + 2) displaced else m₁) = writeBounds mem base (some (min m key, max M key))

      Updating base + 1 and base + 2 in place on a valid occupied header agrees with writeBounds at every memory cell.

      An occupied node's displaced key max m key has valid cluster coordinates and lies in the parent record interval whenever key < universeSize (d + 1).

      theorem Cslib.Algorithms.WordRAM.VanEmdeBoas.insertBody_exec {d w base key : ℕ} {tree : Lean.VanEmdeBoas.Tree d} {s : WordRAM.Data 32} (hs : InsertEntry base key s) (ht : tree.Valid) (hr : Rep tree base s.mem) (hkey : key < Lean.VanEmdeBoas.universeSize d) (ha : WordRAM.Fits w (base + Lean.VanEmdeBoas.span d)) :

      One actual insertion iteration, including all branches and address calculations, executes within 37 instructions.

      theorem Cslib.Algorithms.WordRAM.VanEmdeBoas.insertLoop_spec {d w base key : ℕ} {tree : Lean.VanEmdeBoas.Tree d} {s : WordRAM.Data 32} (hs : InsertEntry base key s) (ht : tree.Valid) (hr : Rep tree base s.mem) (hkey : key < Lean.VanEmdeBoas.universeSize d) (ha : WordRAM.Fits w (base + Lean.VanEmdeBoas.span d)) :
      ∃ (z : WordRAM.Data 32), WordRAM.ExecWithin w insertLoop s z (39 * (d + 1) + 2) ∧ Rep (tree.insert key) base z.mem ∧ ∀ (a : ℕ), a < base ∨ base + Lean.VanEmdeBoas.span d ≤ a → z.mem a = s.mem a

      The insertion loop is correct for every depth and arbitrary surrounding memory. It executes within 39 * (d + 1) + 2 instructions, establishes Rep (tree.insert key) base z.mem, and leaves all memory outside [base, base + span d) unchanged.