math / data /lean /OAI /Combinatorics /EditApproximation /Binary /BinaryCellSourceSpace.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.5 kB
import OAI.Combinatorics.EditApproximation.Binary.BinaryGroupActionSourceSpace
import OAI.Combinatorics.EditApproximation.Binary.BinaryCellSourcePort
import OAI.Combinatorics.EditApproximation.Binary.BinaryUnskippedSpace
import OAI.Combinatorics.EditApproximation.Queries.QueryLocalRepresentativeSpace
namespace OAI
namespace EditApproximation.BinaryFraction
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 C : β„•) (hr : βˆ€ i q, (child i q).2 ≀ R) (hi : βˆ€ i q, (initial i q).2 ≀ C)
(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 Γ— β„•)
(parentAllocation : TargetInterval target.length β†’ β„•)
(childAllocation initialAllocation currentAllocation : Fin M β†’ TargetInterval target.length β†’ β„•)
(drawAllocation : βˆ€ t : Fin (groupDyadicScales M b (nat F).value).length,
Fin (groupSampleCount M Q b (groupDyadicScaleAt M b (nat F).value t)) β†’ β„•)
def preparedCellGroupSourceAllocation (cell : β„• Γ— β„•) : β„• :=
let centers := (cellCentersReadWithWork P F b a (inversePowerTwo exponent) parentInitial cell).1
let members := (filterMapWithWork
(preparedUnskippedReadWithWork source target parent b P exponent hb hP tau (nat F)
child initial R C hr hi) centers).1
cellCentersReadAllocation P F b a (inversePowerTwo exponent) parentInitial parentAllocation cell +
filterMapAllocation (preparedUnskippedReadWithWork source target parent b P exponent hb hP tau (nat F)
child initial R C hr hi)
(fun center => preparedUnskippedReadAllocation parent center b P exponent tau (nat F)
child initial childAllocation initialAllocation) centers +
if hempty : members = [] then 0 else
sampledGroupActionSourceAllocation source target parent b P exponent Q tau (nat F)
(fun i q => (child i q).1) initial current initialAllocation currentAllocation
(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))
(fun t j => drawAllocation t (Fin.cast (congrArg (groupSampleCount M Q b)
(indexedGroupScales_value raw M b (nat F).value hraw t)) j)) members hempty + 1
theorem preparedCellGroupSourceAllocation_le_work (cell : β„• Γ— β„•)
(hp : βˆ€ q, parentAllocation q ≀ (parentInitial q).2)
(hc : βˆ€ i q, childAllocation i q ≀ (child i q).2)
(hin : βˆ€ i q, initialAllocation i q ≀ (initial i q).2)
(hcur : βˆ€ i q, currentAllocation i q ≀ (current i q).2)
(hd : βˆ€ t i, drawAllocation t i ≀ (draw t i).2) :
preparedCellGroupSourceAllocation source target parent b P F exponent Q hb hP tau a
parentInitial child initial current R C hr hi raw hraw draw
parentAllocation childAllocation initialAllocation currentAllocation drawAllocation cell ≀
(preparedCellGroupSourceWithWork source target parent b P F exponent Q hb hP tau a
parentInitial child initial current R C hr hi raw hraw draw cell).2 := by
let centers := (cellCentersReadWithWork P F b a (inversePowerTwo exponent) parentInitial cell).1
let members := (filterMapWithWork
(preparedUnskippedReadWithWork source target parent b P exponent hb hP tau (nat F)
child initial R C hr hi) centers).1
have hcenters := cellCentersReadAllocation_le_work P F b a (inversePowerTwo exponent)
parentInitial parentAllocation cell hp
have hmembers := filterMapAllocation_le_work
(preparedUnskippedReadWithWork source target parent b P exponent hb hP tau (nat F)
child initial R C hr hi)
(fun center => preparedUnskippedReadAllocation parent center b P exponent tau (nat F)
child initial childAllocation initialAllocation) centers
(fun center _ => preparedUnskippedReadAllocation_le_work source target parent center b P exponent
hb hP tau (nat F) child initial childAllocation initialAllocation R C hr hi hc hin)
dsimp only [centers] at hmembers
unfold preparedCellGroupSourceAllocation preparedCellGroupSourceWithWork
dsimp only
split_ifs with hempty
Β· exact Nat.add_le_add (Nat.add_le_add hcenters hmembers) (by decide : 0 ≀ 1)
Β· have hsample := sampledGroupActionSourceAllocation_le_work source target parent b P exponent Q
tau (nat F) (fun i q => (child i q).1) initial current initialAllocation currentAllocation
(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))
(fun t j => drawAllocation t (Fin.cast (congrArg (groupSampleCount M Q b)
(indexedGroupScales_value raw M b (nat F).value hraw t)) j)) members hempty hin hcur
(fun t j => hd t _)
dsimp only [centers, members] at hmembers hsample
exact (Nat.add_assoc _ _ _).symm.le.trans
(Nat.add_le_add (Nat.add_le_add (Nat.add_le_add hcenters hmembers) hsample)
(by decide : 1 ≀ 2))
end Cell
end EditApproximation.BinaryFraction
end OAI