math / data /lean /OAI /Combinatorics /EditApproximation /Queries /QueryDataBuffers.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
3.76 kB
import OAI.Combinatorics.EditApproximation.Queries.QuerySourceBuffers
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Counted local data buffers for the adaptive gathers. Bounds depend on
stored keys and the requested key, not on an unbounded ambient key type. -/
namespace EditApproximation
namespace BinaryFraction
theorem gatheredWordLookupWithWork_cost_on {ΞΊ : Type*}
(equal : ΞΊ β†’ ΞΊ β†’ Bool Γ— β„•) (C : β„•) (keys : List ΞΊ)
(values : List BinaryFraction) (query : ΞΊ)
(hC : βˆ€ key ∈ keys, (equal query key).2 ≀ C) :
(gatheredWordLookupWithWork equal keys values query).2 ≀
1 + keys.length * (C + 1) := by
induction keys generalizing values with
| nil => simp only [gatheredWordLookupWithWork, List.length_nil, Nat.zero_mul, Nat.add_zero, le_rfl]
| cons key keys ih =>
have hc := hC key List.mem_cons_self
have ht := ih (values.drop 1) (fun k hk => hC k (List.mem_cons_of_mem _ hk))
cases values with
| nil => simp only [gatheredWordLookupWithWork]; omega
| cons value values =>
simp only [List.drop_succ_cons, List.drop_zero] at ht
simp only [gatheredWordLookupWithWork]
split_ifs <;> simp only [List.length_cons, Nat.add_mul, Nat.one_mul] <;> omega
@[simp] theorem queryChildReadWithWork_value {M n : β„•}
(keys : List (Fin M Γ— TargetInterval n)) (values : List BinaryFraction)
(i : Fin M) (q : TargetInterval n) :
(queryChildReadWithWork keys values i q).1.value =
finiteAnswerTable keys (values.map value) (i, q) :=
gatheredWordLookupWithWork_value _ coordinateEqualWithWork_value keys values (i, q)
theorem queryChildReadWithWork_cost {M n : β„•} (keys : List (Fin M Γ— TargetInterval n))
(values : List BinaryFraction) (i : Fin M) (q : TargetInterval n)
(B : β„•) (hM : Nat.size M ≀ B) (hn : Nat.size n ≀ B) :
(queryChildReadWithWork keys values i q).2 ≀ 1 + keys.length * (24 * B + 9) := by
exact gatheredWordLookupWithWork_cost coordinateEqualWithWork (24 * B + 8)
(fun a b => coordinateEqualWithWork_cost a b B hM hn) keys values (i, q)
@[simp] theorem queryHistoryReadWithWork_value {M n : β„•}
(keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
(s : β„•) (input : Fin M Γ— TargetInterval n) :
(queryHistoryReadWithWork keys values s input).1.value =
finiteAnswerTable keys (values.map value) (input.1, s, input.2) :=
gatheredWordLookupWithWork_value _ queryHistoryEqualWithWork_value keys values (input.1, s, input.2)
theorem queryHistoryReadWithWork_cost {M n : β„•}
(keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
(s : β„•) (input : Fin M Γ— TargetInterval n) (B : β„•)
(hM : Nat.size M ≀ B) (hn : Nat.size n ≀ B) (hs : Nat.size s ≀ B)
(ht : βˆ€ key ∈ keys, Nat.size key.2.1 ≀ B) :
(queryHistoryReadWithWork keys values s input).2 ≀
1 + keys.length * (32 * B + 12) := by
apply gatheredWordLookupWithWork_cost_on queryHistoryEqualWithWork (32 * B + 11)
intro key hk
have hc := coordinateEqualWithWork_cost input (key.1, key.2.2) B hM hn
have he := naturalEqualWithWork_cost s key.2.1 B hs (ht key hk)
change (coordinateEqualWithWork input (key.1, key.2.2)).2 +
(naturalEqualWithWork s key.2.1).2 + 1 ≀ _
omega
theorem queryHistoryReadWithWork_width {M n : β„•}
(keys : List (Fin M Γ— β„• Γ— TargetInterval n)) (values : List BinaryFraction)
(s : β„•) (input : Fin M Γ— TargetInterval n) (B : β„•)
(hB : 2 ≀ B) (hv : βˆ€ v ∈ values, v.width ≀ B) :
(queryHistoryReadWithWork keys values s input).1.width ≀ B :=
gatheredWordLookupWithWork_width _ keys values _ B hB hv
end BinaryFraction
end EditApproximation
end OAI