Documentation

CslibFrontier.DataStructure.BTree.Comparisons.KeyOracle

B-trees under a key function #

The monadic lookup programs commute with mapping keys (BTree.mapKeys): looking up g k in the tree with keys g x under a comparison le is the same program as looking up k in the original tree under the comparison fun a b => le (g a) (g b). This lets a lookup be evaluated under an oracle that compares keys through a key function.

Main results #

theorem Cslib.DataStructure.BTree.lookupM_mapKeys {α α' β : Type} {m : Type → Type w} [Monad m] (le : α' → α' → m Bool) (visit : m Unit) (g : α → α') (k : α) (tr : BTree α β) :
lookupM le visit (g k) (mapKeys g tr) = lookupM (fun (a b : α) => le (g a) (g b)) visit k tr

Lookup in a tree with mapped keys, compared through the key function, is lookup in the original tree under the pulled-back comparison.

theorem Cslib.DataStructure.BTree.lookupBinM_mapKeys {α α' β : Type} {m : Type → Type w} [Monad m] (le : α' → α' → m Bool) (visit : m Unit) (g : α → α') (k : α) (tr : BTree α β) :
lookupBinM le visit (g k) (mapKeys g tr) = lookupBinM (fun (a b : α) => le (g a) (g b)) visit k tr

Lookup with binary in-node search in a tree with mapped keys, compared through the key function, is lookup in the original tree under the pulled-back comparison.

theorem Cslib.DataStructure.BTree.eval_lookupQ_keyOracle {α β W : Type} [LinearOrder W] (key : α → W) (k : α) (tr : BTree α β) :
FreeM.eval (fun {ι : Type} => Query.LEQuery.keyOracle key) (lookupQ k tr) = lookup (key k) (mapKeys key tr)

Under the comparison oracle of a key function, lookupQ evaluates to the pure lookup of the mapped key in the tree with mapped keys.

theorem Cslib.DataStructure.BTree.eval_lookupBinQ_keyOracle {α β W : Type} [LinearOrder W] (key : α → W) (k : α) (tr : BTree α β) :
FreeM.eval (fun {ι : Type} => Query.LEQuery.keyOracle key) (lookupBinQ k tr) = lookupBin (key k) (mapKeys key tr)

Under the comparison oracle of a key function, lookupBinQ evaluates to the pure lookupBin of the mapped key in the tree with mapped keys.