Documentation

CslibFrontier.Algorithms.Lean.Query.Sort.LEQuery.QueriedPairs

The comparisons made along an oracle's path #

Cslib.Query.LEQuery.queriedPairs oracle p lists, in order, the pairs (a, b) that the comparison program p : FreeM (LEQuery α) γ asks about (a ≤ b?) along the path that oracle determines. It has exactly p.countQueries oracle entries, and two oracles that answer these comparisons alike drive p along the same path, so they make the same comparisons and lead to the same result. These facts are the bookkeeping behind adversary and fooling arguments for comparison lower bounds.

Main definitions #

Main results #

def Cslib.Query.LEQuery.queriedPairs {α γ : Type} (oracle : {ι : Type} → LEQuery α ι → ι) :
FreeM (LEQuery α) γ → List (α × α)

The pairs (a, b) compared (a ≤ b?) along the path of p that oracle determines, in order.

@[simp]
theorem Cslib.Query.LEQuery.queriedPairs_pure {α γ : Type} (oracle : {ι : Type} → LEQuery α ι → ι) (x : γ) :
queriedPairs (fun {ι : Type} => oracle) (pure x) = []
@[simp]
theorem Cslib.Query.LEQuery.queriedPairs_liftBind {α γ : Type} (oracle : {ι : Type} → LEQuery α ι → ι) (a b : α) (cont : Bool → FreeM (LEQuery α) γ) :
queriedPairs (fun {ι : Type} => oracle) (FreeM.lift (le a b) >>= cont) = (a, b) :: queriedPairs (fun {ι : Type} => oracle) (cont (oracle (le a b)))
@[simp]
theorem Cslib.Query.LEQuery.length_queriedPairs {α γ : Type} (oracle : {ι : Type} → LEQuery α ι → ι) (p : FreeM (LEQuery α) γ) :
(queriedPairs (fun {ι : Type} => oracle) p).length = FreeM.countQueries (fun {ι : Type} => oracle) p

One entry per comparison: the list of compared pairs has length p.countQueries oracle.

theorem Cslib.Query.LEQuery.queriedPairs_eq_of_agree {α γ : Type} (oracle oracle' : {ι : Type} → LEQuery α ι → ι) (p : FreeM (LEQuery α) γ) (hagree : ∀ (a b : α), (a, b) ∈ queriedPairs (fun {ι : Type} => oracle) p → oracle (le a b) = oracle' (le a b)) :
queriedPairs (fun {ι : Type} => oracle') p = queriedPairs (fun {ι : Type} => oracle) p

If oracle' answers every comparison along oracle's path of p as oracle does, then it drives p along the same path and makes the same comparisons.

theorem Cslib.Query.LEQuery.eval_eq_of_agree {α γ : Type} (oracle oracle' : {ι : Type} → LEQuery α ι → ι) (p : FreeM (LEQuery α) γ) (hagree : ∀ (a b : α), (a, b) ∈ queriedPairs (fun {ι : Type} => oracle) p → oracle (le a b) = oracle' (le a b)) :
FreeM.eval (fun {ι : Type} => oracle') p = FreeM.eval (fun {ι : Type} => oracle) p

If oracle' answers every comparison along oracle's path of p as oracle does, then p evaluates to the same result under both.