math / data /lean /OAI /Combinatorics /EditApproximation /Binary /BinaryCellReadCosts.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.15 kB
import OAI.Combinatorics.EditApproximation.Binary.BinaryGroupReadCosts
import OAI.Combinatorics.EditApproximation.Binary.BinaryCellReads
namespace OAI
/-! The complete whole-cell estimator, including its ordered choice,
executes with a linear factor for each finite-buffer lookup. -/
namespace EditApproximation
namespace BinaryFraction
theorem cellCentersReadWithWork_factor {n : β„•} (P F b : β„•) (a theta : BinaryFraction)
(initial : TargetInterval n β†’ BinaryFraction Γ— β„•) (cell : β„• Γ— β„•)
(R : β„•) (hr : βˆ€ r, (initial r).2 ≀ R) :
(cellCentersReadWithWork P F b a theta initial cell).2 ≀
(cellCentersWithWork P F b a theta (fun r => (initial r).1) cell).2 * tableReadFactor R := by
have h := (cellCentersReadWithWork_eq_cost P F b a theta initial cell R hr).2
have hK : R + 1 ≀ tableReadFactor R := by unfold tableReadFactor; omega
exact h.trans (Nat.mul_le_mul_left _ hK)
section Cell
variable {Ξ± : Type*} (source target : List Ξ±) {M : β„•}
(parent : TargetInterval source.length) (b P F exponent Q : β„•) (hb : 0 < b) (hP : 0 < P)
(tau a : BinaryFraction)
(parentInitial : TargetInterval target.length β†’ BinaryFraction Γ— β„•)
(child initial current : Fin M β†’ TargetInterval target.length β†’ BinaryFraction Γ— β„•)
(R : β„•) (hc : βˆ€ i q, (child i q).2 ≀ R) (hi : βˆ€ i q, (initial i q).2 ≀ R)
(raw : List BinaryFraction) (hraw : raw.map value = groupDyadicScales M b (nat F).value)
(draw : βˆ€ t : Fin (groupDyadicScales M b (nat F).value).length,
Fin (groupSampleCount M Q b (groupDyadicScaleAt M b (nat F).value t)) β†’ Fin M)
theorem preparedCellGroupReadWithWork_factor (cell : β„• Γ— β„•)
(hp : βˆ€ r, (parentInitial r).2 ≀ R) (hn : βˆ€ i q, (current i q).2 ≀ R) :
(preparedCellGroupReadWithWork source target parent b P F exponent Q hb hP tau a
parentInitial child initial current R R hc hi raw hraw draw cell).2 ≀
(preparedCellGroupWithWork source target parent b P F exponent Q hb tau a
(fun r => (parentInitial r).1) (fun i q => (child i q).1)
(fun i q => (initial i q).1) (fun i q => (current i q).1) raw hraw draw hP cell).2 *
tableReadFactor R := by
have hcenters := cellCentersReadWithWork_factor P F b a (inversePowerTwo exponent)
parentInitial cell R hp
have hcentersq := (cellCentersReadWithWork_eq_cost P F b a (inversePowerTwo exponent)
parentInitial cell R hp).1
have hm := filterMapWithWork_factor
(preparedUnskippedReadWithWork source target parent b P exponent hb hP tau (nat F)
child initial R R hc hi)
(preparedUnskippedCandidateWithWork source target parent b P exponent hb hP tau (nat F)
(fun i q => (child i q).1) (fun i q => (initial i q).1))
(cellCentersWithWork P F b a (inversePowerTwo exponent) (fun r => (parentInitial r).1) cell).1
(tableReadFactor R) (tableReadFactor_pos R)
(fun center _ => preparedUnskippedReadWithWork_value source target parent b P exponent hb hP
tau (nat F) child initial R R hc hi center)
(fun center _ => preparedUnskippedReadWithWork_factor source target parent b P exponent hb hP
tau (nat F) child initial R hc hi center)
have hcm := Nat.add_le_add hcenters hm.2
rw [← Nat.add_mul] at hcm
unfold preparedCellGroupReadWithWork preparedCellGroupWithWork
dsimp only
simp only [hcentersq, hm.1]
split_ifs with hempty
Β· apply cost_replace_factor _ _ _ _ _ hcm (tableReadFactor_pos R) <;> omega
Β· have hs := sampledGroupActionReadWithWork_factor source target parent b P exponent Q tau
(nat F) (fun i q => (child i q).1) initial current
(indexedGroupScales raw M b (nat F).value hraw)
(fun t j => draw t (Fin.cast (congrArg (groupSampleCount M Q b)
(indexedGroupScales_value raw M b (nat F).value hraw t)) j))
_ hempty R hi hn
have h := Nat.add_le_add hcm hs
rw [← Nat.add_mul] at h
change _ ≀ _ at hs
unfold dyadicSampledGroupActionReadWithWork dyadicSampledGroupActionWithWork
dsimp only
apply cost_replace_factor _ _ _ _ _ h (tableReadFactor_pos R) <;> omega
end Cell
end BinaryFraction
end EditApproximation
end OAI