Documentation

CslibFrontier.DataStructure.BTree.WordRAM.Arena

Flat Word-RAM Arena Representation and Split/Insert Operations for Classic B-Trees #

Pure memory-layout geometry, deterministic BTree ℕ ℕ decoding (readTree, readNodeSet), node validity and key-order predicates (ValidNode, SortedNode), and index-level correctness of proactive top-down node splitting (memSplitRoot, memSplitChild) and leaf/internal updates (memOverwriteVal, memInsertLeaf) on a flat Word-RAM word array mem : ℕ → ℕ, following [CLRS09], Section 18.2.

Arena layout at base and minimum degree t ≥ 2 #

Main definitions #

Main results #

References #

1. Address geometry and field accessors #

Words per allocated B-tree node at minimum degree t.

Starting word address of 0-based node u in an arena at base of minimum degree t.

Total word footprint of an arena with capacity capNodes at minimum degree t.

theorem Cslib.DataStructure.BTree.WordRAM.nodeAddr_lt_arena {base t u o capNodes : ℕ} (hu : u < capNodes) (ho : o < nodeStride t) :
nodeAddr base t u + o < base + arenaWords t capNodes
theorem Cslib.DataStructure.BTree.WordRAM.base_lt_nodeAddr (base t u o : ℕ) :
base + 1 < nodeAddr base t u + o
theorem Cslib.DataStructure.BTree.WordRAM.nodeAddr_sep (base t : ℕ) {u v : ℕ} (huv : u ≠ v) :
nodeAddr base t u + nodeStride t ≤ nodeAddr base t v ∨ nodeAddr base t v + nodeStride t ≤ nodeAddr base t u
theorem Cslib.DataStructure.BTree.WordRAM.nodeAddr_disjoint {base t u v o₁ o₂ : ℕ} (huv : u ≠ v) (ho₁ : o₁ < nodeStride t) (ho₂ : o₂ < nodeStride t) :
nodeAddr base t u + o₁ ≠ nodeAddr base t v + o₂
def Cslib.DataStructure.BTree.WordRAM.leafFlag (base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :

Leaf flag (1 = leaf, 0 = internal) of node u.

def Cslib.DataStructure.BTree.WordRAM.numKeys (base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :

Stored key count m of node u.

def Cslib.DataStructure.BTree.WordRAM.keyAt (base t : ℕ) (mem : ℕ → ℕ) (u i : ℕ) :

i-th stored key of node u.

def Cslib.DataStructure.BTree.WordRAM.valAt (base t : ℕ) (mem : ℕ → ℕ) (u i : ℕ) :

i-th stored value of node u.

def Cslib.DataStructure.BTree.WordRAM.childAt (base t : ℕ) (mem : ℕ → ℕ) (u j : ℕ) :

j-th child node index of internal node u.

2. Deterministic tree & node-set decoding #

Deterministically decode a BTree ℕ ℕ of height l + 1 rooted at node u.

Set of allocated node indices visited when decoding readTree l base t mem u.

@[simp]
theorem Cslib.DataStructure.BTree.WordRAM.readNodeSet_zero (base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :
readNodeSet 0 base t mem u = {u}
theorem Cslib.DataStructure.BTree.WordRAM.self_mem_readNodeSet (l base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :
u ∈ readNodeSet l base t mem u
theorem Cslib.DataStructure.BTree.WordRAM.child_subset_readNodeSet (l base t : ℕ) (mem : ℕ → ℕ) (u j : ℕ) (hj : j < numKeys base t mem u + 1) :
readNodeSet l base t mem (childAt base t mem u j) ⊆ readNodeSet (l + 1) base t mem u
theorem Cslib.DataStructure.BTree.WordRAM.readTree_ne_leaf (l base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :
readTree l base t mem u ≠ leaf
@[simp]
theorem Cslib.DataStructure.BTree.WordRAM.rootKeys_readTree (l base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :
(readTree l base t mem u).rootKeys = numKeys base t mem u
theorem Cslib.DataStructure.BTree.WordRAM.mem_children_readTree_succ_iff (l base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) (c : BTree ℕ ℕ) :
c ∈ (readTree (l + 1) base t mem u).children ↔ ∃ j < numKeys base t mem u + 1, c = readTree l base t mem (childAt base t mem u j)

3. Structural validity (ValidNode) and memory framing #

Structural validity of a subtree of height l + 1 rooted at node u: valid leafFlag, 1 ≤ numKeys ≤ 2 * t - 1, t - 1 ≤ numKeys on all proper descendants, and pairwise disjoint node sets.

theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.leafFlag_eq {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) :
leafFlag base t mem u = if l = 0 then 1 else 0
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.numKeys_pos {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) :
1 ≤ numKeys base t mem u
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.numKeys_le {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) :
numKeys base t mem u ≤ 2 * t - 1
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.child_valid {l base t : ℕ} {mem : ℕ → ℕ} {u j : ℕ} (hv : ValidNode (l + 1) base t mem u) (hj : j < numKeys base t mem u + 1) :
ValidNode l base t mem (childAt base t mem u j)
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.child_numKeys_ge {l base t : ℕ} {mem : ℕ → ℕ} {u j : ℕ} (hv : ValidNode (l + 1) base t mem u) (hj : j < numKeys base t mem u + 1) :
t - 1 ≤ numKeys base t mem (childAt base t mem u j)
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.not_mem_child_readNodeSet {l base t : ℕ} {mem : ℕ → ℕ} {u j : ℕ} (hv : ValidNode (l + 1) base t mem u) (hj : j < numKeys base t mem u + 1) :
u ∉ readNodeSet l base t mem (childAt base t mem u j)
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.balanced_and_height {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) :
(readTree l base t mem u).Balanced ∧ (readTree l base t mem u).height = l + 1

Every valid node decodes to a balanced BTree of exact height l + 1.

theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.occupied_of_le {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) (hle : t - 1 ≤ numKeys base t mem u) :
Occupied t (readTree l base t mem u)
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.occupied_children {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hv : ValidNode l base t mem u) (c : BTree ℕ ℕ) :
c ∈ (readTree l base t mem u).children → Occupied t c

4. Membership in toList and strict key-order predicate (SortedNode) #

theorem Cslib.DataStructure.BTree.WordRAM.toList_readTree_zero (base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) :
(readTree 0 base t mem u).toList = List.ofFn fun (i : Fin (numKeys base t mem u)) => (keyAt base t mem u ↑i, valAt base t mem u ↑i)
theorem Cslib.DataStructure.BTree.WordRAM.mem_toList_readTree_zero (base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) (p : ℕ × ℕ) :
p ∈ (readTree 0 base t mem u).toList ↔ ∃ i < numKeys base t mem u, p = (keyAt base t mem u i, valAt base t mem u i)
theorem Cslib.DataStructure.BTree.WordRAM.mem_toList_readTree_succ (l base t : ℕ) (mem : ℕ → ℕ) (u : ℕ) (p : ℕ × ℕ) :
p ∈ (readTree (l + 1) base t mem u).toList ↔ (∃ i < numKeys base t mem u, p = (keyAt base t mem u i, valAt base t mem u i)) ∨ ∃ j < numKeys base t mem u + 1, p ∈ (readTree l base t mem (childAt base t mem u j)).toList

Index-level strict key-order predicate for a subtree of height l + 1 at node u.

theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.keys_strict {l base t : ℕ} {mem : ℕ → ℕ} {u i₁ i₂ : ℕ} (hs : SortedNode l base t mem u) (h12 : i₁ < i₂) (h2 : i₂ < numKeys base t mem u) :
keyAt base t mem u i₁ < keyAt base t mem u i₂
theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.child_sorted {l base t : ℕ} {mem : ℕ → ℕ} {u j : ℕ} (hs : SortedNode (l + 1) base t mem u) (hj : j < numKeys base t mem u + 1) :
SortedNode l base t mem (childAt base t mem u j)
theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.congr_mem {l base t : ℕ} {mem mem' : ℕ → ℕ} {u : ℕ} (ht : 1 ≤ t) (hv : ValidNode l base t mem u) (hmem : ∀ v ∈ readNodeSet l base t mem u, ∀ o < nodeStride t, mem' (nodeAddr base t v + o) = mem (nodeAddr base t v + o)) :
ValidNode l base t mem' u ∧ readTree l base t mem' u = readTree l base t mem u ∧ readNodeSet l base t mem' u = readNodeSet l base t mem u

Disjoint-node framing: if mem' agrees with mem on every node in readNodeSet l base t mem u, then ValidNode, readTree, and readNodeSet are preserved.

theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.congr_mem {l base t : ℕ} {mem mem' : ℕ → ℕ} {u : ℕ} (ht : 1 ≤ t) (hv : ValidNode l base t mem u) (hs : SortedNode l base t mem u) (hmem : ∀ v ∈ readNodeSet l base t mem u, ∀ o < nodeStride t, mem' (nodeAddr base t v + o) = mem (nodeAddr base t v + o)) :
SortedNode l base t mem' u
theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.child_lt_key {l base t : ℕ} {mem : ℕ → ℕ} {u j i : ℕ} (hs : SortedNode (l + 1) base t mem u) (hji : j ≤ i) (hi : i < numKeys base t mem u) {p : ℕ × ℕ} (hp : p ∈ (readTree l base t mem (childAt base t mem u j)).toList) :
p.1 < keyAt base t mem u i
theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.key_lt_child {l base t : ℕ} {mem : ℕ → ℕ} {u i j : ℕ} (hs : SortedNode (l + 1) base t mem u) (_hi : i < numKeys base t mem u) (hij : i + 1 ≤ j) (hj : j < numKeys base t mem u + 1) {p : ℕ × ℕ} (hp : p ∈ (readTree l base t mem (childAt base t mem u j)).toList) :
keyAt base t mem u i < p.1
theorem Cslib.DataStructure.BTree.WordRAM.SortedNode.isSortedAssoc {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (hs : SortedNode l base t mem u) :
(readTree l base t mem u).toList.IsSortedAssoc

SortedNode implies List.IsSortedAssoc on (readTree l base t mem u).toList.

theorem Cslib.DataStructure.BTree.WordRAM.ValidNode.isWF {l base t : ℕ} {mem : ℕ → ℕ} {u : ℕ} (ht : 2 ≤ t) (hv : ValidNode l base t mem u) (hs : SortedNode l base t mem u) :
IsWF t (readTree l base t mem u)

A valid sorted node at 2 ≤ t decodes to a well-formed BTree.IsWF t tree.

5. Within-node search (slotCount) and single-level lookup reduction #

def Cslib.DataStructure.BTree.WordRAM.slotCount (base t : ℕ) (mem : ℕ → ℕ) (u k : ℕ) :
ℕ → ℕ

Count how many keys in [0, j) of node u are strictly less than k.

theorem Cslib.DataStructure.BTree.WordRAM.slotCount_spec {base t : ℕ} {mem : ℕ → ℕ} {u k m : ℕ} (hkeys : ∀ (i₁ i₂ : ℕ), i₁ < i₂ → i₂ < m → keyAt base t mem u i₁ < keyAt base t mem u i₂) (j : ℕ) (hj : j ≤ m) :
have s := slotCount base t mem u k j; s ≤ j ∧ (∀ i < s, keyAt base t mem u i < k) ∧ ∀ (i : ℕ), s ≤ i → i < j → k ≤ keyAt base t mem u i
theorem Cslib.DataStructure.BTree.WordRAM.lookup_readTree_eq_some {l base t : ℕ} {mem : ℕ → ℕ} {u slot k : ℕ} (hs : SortedNode l base t mem u) (hslot : slot < numKeys base t mem u) (heq : keyAt base t mem u slot = k) :
lookup k (readTree l base t mem u) = some (valAt base t mem u slot)

When slot < numKeys and keyAt u slot = k, BTree.lookup k (readTree ...) returns some (valAt u slot).

theorem Cslib.DataStructure.BTree.WordRAM.lookup_readTree_leaf_none {base t : ℕ} {mem : ℕ → ℕ} {u k : ℕ} (hs : SortedNode 0 base t mem u) (hne : ∀ i < numKeys base t mem u, keyAt base t mem u i ≠ k) :
lookup k (readTree 0 base t mem u) = none

On a sorted leaf node u (l = 0), if keyAt u i ≠ k for all i < m, lookup returns none.

theorem Cslib.DataStructure.BTree.WordRAM.lookup_readTree_succ_eq_child {l base t : ℕ} {mem : ℕ → ℕ} {u slot k : ℕ} (hs : SortedNode (l + 1) base t mem u) (hslot : slot ≤ numKeys base t mem u) (hlt : ∀ i < slot, keyAt base t mem u i < k) (hgt : ∀ (i : ℕ), slot ≤ i → i < numKeys base t mem u → k < keyAt base t mem u i) :
lookup k (readTree (l + 1) base t mem u) = lookup k (readTree l base t mem (childAt base t mem u slot))

On a sorted internal node u (l + 1), when slot ≤ m satisfies keyAt u i < k for i < slot and k < keyAt u i for slot ≤ i < m, BTree.lookup reduces to child slot.

6. Generic forward-copy and backward-shift array helpers #

def Cslib.DataStructure.BTree.WordRAM.shiftArrRight (arrBase upper : ℕ) :
ℕ → (ℕ → ℕ) → ℕ → ℕ

Shift count words [upper - count .. upper - 1] right by 1 into [upper - count + 1 .. upper].

theorem Cslib.DataStructure.BTree.WordRAM.shiftArrRight_outside (arrBase upper count : ℕ) (mem : ℕ → ℕ) (hcount : count ≤ upper) (a : ℕ) (ha : a < arrBase + (upper - count) + 1 ∨ arrBase + upper < a) :
shiftArrRight arrBase upper count mem a = mem a
theorem Cslib.DataStructure.BTree.WordRAM.shiftArrRight_shifted (arrBase upper count : ℕ) (mem : ℕ → ℕ) (hcount : count ≤ upper) (i : ℕ) (hi₁ : upper - count < i) (hi₂ : i ≤ upper) :
shiftArrRight arrBase upper count mem (arrBase + i) = mem (arrBase + (i - 1))

7. Pure memory operations: init, overwrite, leaf insert, and split #

Initialize a 1-key leaf root at node 0 (root = 0, cnt = 1).

theorem Cslib.DataStructure.BTree.WordRAM.memInitSingle_spec {base t k v : ℕ} (ht : 2 ≤ t) (mem : ℕ → ℕ) :
have mem' := memInitSingle base t k v mem; mem' base = 0 ∧ mem' (base + 1) = 1 ∧ ValidNode 0 base t mem' 0 ∧ SortedNode 0 base t mem' 0 ∧ (readTree 0 base t mem' 0).toList = [(k, v)] ∧ readNodeSet 0 base t mem' 0 = {0}
def Cslib.DataStructure.BTree.WordRAM.memOverwriteVal (base t u slot v : ℕ) (mem : ℕ → ℕ) :
ℕ → ℕ

Overwrite the value at slot of node u with v.

theorem Cslib.DataStructure.BTree.WordRAM.memOverwriteVal_spec {l base t u slot k v : ℕ} {mem : ℕ → ℕ} (ht : 2 ≤ t) (hv_u : ValidNode l base t mem u) (hs_u : SortedNode l base t mem u) (hslot : slot < numKeys base t mem u) (hk_eq : keyAt base t mem u slot = k) :
have mem' := memOverwriteVal base t u slot v mem; ValidNode l base t mem' u ∧ SortedNode l base t mem' u ∧ readNodeSet l base t mem' u = readNodeSet l base t mem u ∧ (readTree l base t mem' u).toList = SortedAssoc.insert k v (readTree l base t mem u).toList
def Cslib.DataStructure.BTree.WordRAM.memInsertLeaf (base t u m slot k v : ℕ) (mem : ℕ → ℕ) :
ℕ → ℕ

Insert a new (k, v) pair into non-full leaf node u (m ≤ 2 * t - 2) at slot ≤ m.

theorem Cslib.DataStructure.BTree.WordRAM.memInsertLeaf_outside {base t u m slot k v : ℕ} (ht : 2 ≤ t) (hm_le : m ≤ 2 * t - 2) (hslot : slot ≤ m) (mem : ℕ → ℕ) (a : ℕ) (ha : a < nodeAddr base t u ∨ nodeAddr base t u + nodeStride t ≤ a) :
memInsertLeaf base t u m slot k v mem a = mem a
theorem Cslib.DataStructure.BTree.WordRAM.memInsertLeaf_spec {base t u slot k v : ℕ} {mem : ℕ → ℕ} (ht : 2 ≤ t) (hv_u : ValidNode 0 base t mem u) (hs_u : SortedNode 0 base t mem u) (hm_nonfull : numKeys base t mem u ≤ 2 * t - 2) (hslot : slot ≤ numKeys base t mem u) (hlt : ∀ i < slot, keyAt base t mem u i < k) (hgt : ∀ (i : ℕ), slot ≤ i → i < numKeys base t mem u → k < keyAt base t mem u i) :
have m := numKeys base t mem u; have mem' := memInsertLeaf base t u m slot k v mem; ValidNode 0 base t mem' u ∧ SortedNode 0 base t mem' u ∧ numKeys base t mem' u = m + 1 ∧ (readTree 0 base t mem' u).toList = SortedAssoc.insert k v (readTree 0 base t mem u).toList

8. Upper-half copy, root/child splitting, and child-insertion lifting #

def Cslib.DataStructure.BTree.WordRAM.memCopyUpper (base t c z : ℕ) (mem : ℕ → ℕ) :
ℕ → ℕ

Split full node c (2 * t - 1 keys) in place as the left (t - 1)-key half and initialize newly allocated node z as the right (t - 1)-key half.

theorem Cslib.DataStructure.BTree.WordRAM.memCopyUpper_outside {base t c z : ℕ} (ht : 2 ≤ t) (mem : ℕ → ℕ) (a : ℕ) (hac : a < nodeAddr base t c ∨ nodeAddr base t c + nodeStride t ≤ a) (haz : a < nodeAddr base t z ∨ nodeAddr base t z + nodeStride t ≤ a) :
memCopyUpper base t c z mem a = mem a
theorem Cslib.DataStructure.BTree.WordRAM.memCopyUpper_spec {l base t c z : ℕ} {mem : ℕ → ℕ} (ht : 2 ≤ t) (hv_c : ValidNode l base t mem c) (hs_c : SortedNode l base t mem c) (hfull : numKeys base t mem c = 2 * t - 1) (hz_fresh : z ∉ readNodeSet l base t mem c) :
have mem₁ := memCopyUpper base t c z mem; have k_med := keyAt base t mem c (t - 1); have v_med := valAt base t mem c (t - 1); ValidNode l base t mem₁ c ∧ SortedNode l base t mem₁ c ∧ numKeys base t mem₁ c = t - 1 ∧ ValidNode l base t mem₁ z ∧ SortedNode l base t mem₁ z ∧ numKeys base t mem₁ z = t - 1 ∧ readNodeSet l base t mem₁ c ⊆ readNodeSet l base t mem c ∧ readNodeSet l base t mem₁ z ⊆ insert z (readNodeSet l base t mem c) ∧ z ∉ readNodeSet l base t mem₁ c ∧ c ∉ readNodeSet l base t mem₁ z ∧ Disjoint (readNodeSet l base t mem₁ c) (readNodeSet l base t mem₁ z) ∧ (∀ p ∈ (readTree l base t mem₁ c).toList, p.1 < k_med) ∧ (∀ p ∈ (readTree l base t mem₁ z).toList, k_med < p.1) ∧ ∀ (p : ℕ × ℕ), p ∈ (readTree l base t mem c).toList ↔ p ∈ (readTree l base t mem₁ c).toList ∨ p = (k_med, v_med) ∨ p ∈ (readTree l base t mem₁ z).toList
def Cslib.DataStructure.BTree.WordRAM.memSplitRoot (base t oldRoot cnt : ℕ) (mem : ℕ → ℕ) :
ℕ → ℕ

Split full root oldRoot (2 * t - 1 keys), allocating right half cnt and new 1-key root cnt + 1, and updating the arena header mem base = cnt + 1, mem (base + 1) = cnt + 2.

theorem Cslib.DataStructure.BTree.WordRAM.memSplitRoot_spec {l base t oldRoot cnt : ℕ} {mem : ℕ → ℕ} (ht : 2 ≤ t) (hv_r : ValidNode l base t mem oldRoot) (hs_r : SortedNode l base t mem oldRoot) (hfull : numKeys base t mem oldRoot = 2 * t - 1) (hrange : readNodeSet l base t mem oldRoot ⊆ Finset.range cnt) :
have mem' := memSplitRoot base t oldRoot cnt mem; mem' base = cnt + 1 ∧ mem' (base + 1) = cnt + 2 ∧ ValidNode (l + 1) base t mem' (cnt + 1) ∧ SortedNode (l + 1) base t mem' (cnt + 1) ∧ numKeys base t mem' (cnt + 1) = 1 ∧ readNodeSet (l + 1) base t mem' (cnt + 1) ⊆ Finset.range (cnt + 2) ∧ (readTree (l + 1) base t mem' (cnt + 1)).toList = (readTree l base t mem oldRoot).toList
def Cslib.DataStructure.BTree.WordRAM.memSplitChild (base t u m slot c cnt : ℕ) (mem : ℕ → ℕ) :
ℕ → ℕ

Split full child c = childAt u slot (2 * t - 1 keys) of non-full internal parent u (m ≤ 2 * t - 2), allocating right half cnt, shifting u's keys/values/children, inserting the median at slot, and incrementing mem (base + 1) to cnt + 1.

theorem Cslib.DataStructure.BTree.WordRAM.memSplitChild_outside {base t u m slot c cnt : ℕ} (ht : 2 ≤ t) (hm_le : m ≤ 2 * t - 2) (hslot : slot ≤ m) (mem : ℕ → ℕ) (a : ℕ) (hne_b1 : a ≠ base + 1) (hau : a < nodeAddr base t u ∨ nodeAddr base t u + nodeStride t ≤ a) (hac : a < nodeAddr base t c ∨ nodeAddr base t c + nodeStride t ≤ a) (haz : a < nodeAddr base t cnt ∨ nodeAddr base t cnt + nodeStride t ≤ a) :
memSplitChild base t u m slot c cnt mem a = mem a
theorem Cslib.DataStructure.BTree.WordRAM.memSplitChild_spec {l base t u slot cnt : ℕ} {mem : ℕ → ℕ} (ht : 2 ≤ t) (hv_u : ValidNode (l + 1) base t mem u) (hs_u : SortedNode (l + 1) base t mem u) (hm_nonfull : numKeys base t mem u ≤ 2 * t - 2) (hslot : slot ≤ numKeys base t mem u) (hfull : numKeys base t mem (childAt base t mem u slot) = 2 * t - 1) (hcnt_fresh : cnt ∉ readNodeSet (l + 1) base t mem u) :
have m := numKeys base t mem u; have c := childAt base t mem u slot; have mem' := memSplitChild base t u m slot c cnt mem; mem' (base + 1) = cnt + 1 ∧ mem' base = mem base ∧ ValidNode (l + 1) base t mem' u ∧ SortedNode (l + 1) base t mem' u ∧ numKeys base t mem' u = m + 1 ∧ keyAt base t mem' u slot = keyAt base t mem c (t - 1) ∧ valAt base t mem' u slot = valAt base t mem c (t - 1) ∧ childAt base t mem' u slot = c ∧ childAt base t mem' u (slot + 1) = cnt ∧ numKeys base t mem' c = t - 1 ∧ numKeys base t mem' cnt = t - 1 ∧ readNodeSet (l + 1) base t mem' u ⊆ insert cnt (readNodeSet (l + 1) base t mem u) ∧ (readTree (l + 1) base t mem' u).toList = (readTree (l + 1) base t mem u).toList
theorem Cslib.DataStructure.BTree.WordRAM.childInsert_spec {l base t u slot k v cnt cnt' : ℕ} {mem mem' : ℕ → ℕ} (ht : 2 ≤ t) (hv_u : ValidNode (l + 1) base t mem u) (hs_u : SortedNode (l + 1) base t mem u) (hslot : slot ≤ numKeys base t mem u) (hlt : ∀ i < slot, keyAt base t mem u i < k) (hgt : ∀ (i : ℕ), slot ≤ i → i < numKeys base t mem u → k < keyAt base t mem u i) (hrange : readNodeSet (l + 1) base t mem u ⊆ Finset.range cnt) (hframe : ∀ w_id ∉ readNodeSet l base t mem (childAt base t mem u slot) ∪ Finset.Ico cnt cnt', ∀ o < nodeStride t, mem' (nodeAddr base t w_id + o) = mem (nodeAddr base t w_id + o)) (hv_c' : ValidNode l base t mem' (childAt base t mem u slot)) (hs_c' : SortedNode l base t mem' (childAt base t mem u slot)) (hnk_c' : t - 1 ≤ numKeys base t mem' (childAt base t mem u slot)) (hsub_c' : readNodeSet l base t mem' (childAt base t mem u slot) ⊆ readNodeSet l base t mem (childAt base t mem u slot) ∪ Finset.Ico cnt cnt') (htr_c' : (readTree l base t mem' (childAt base t mem u slot)).toList = SortedAssoc.insert k v (readTree l base t mem (childAt base t mem u slot)).toList) :
ValidNode (l + 1) base t mem' u ∧ SortedNode (l + 1) base t mem' u ∧ numKeys base t mem' u = numKeys base t mem u ∧ readNodeSet (l + 1) base t mem' u ⊆ readNodeSet (l + 1) base t mem u ∪ Finset.Ico cnt cnt' ∧ (readTree (l + 1) base t mem' u).toList = SortedAssoc.insert k v (readTree (l + 1) base t mem u).toList

Lift a recursive subtree insertion at c = childAt u slot back up to internal node u when mem' modifies no node in readNodeSet (l + 1) base t mem u \ readNodeSet l base t mem c.