math / data /lean /OAI /Combinatorics /EditApproximation /Refinement /ComputedCoarseScratchSpace.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.51 kB
import OAI.Combinatorics.EditApproximation.Coarse.CoarseInitialAllocation
import OAI.Combinatorics.EditApproximation.Refinement.ComputedCoarseHistorySpace
import OAI.Combinatorics.EditApproximation.Refinement.ComputedCoarseBitWork
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
open Filter
def physicalCoarseAllocationEntry {M J B : β„•} [NeZero B] (source target : List β„•) (N : β„•)
(depth : PhysicalEntry M J target.length β†’ β„•) (draw : PhysicalCoarseDraw source target B depth)
(entry : PhysicalEntry M J target.length) : β„• :=
BinaryFraction.coarseIndexedInitialAllocation (inputHeight N ^ 4) (64 * inputHeight N) N
(Nat.pos_of_neZero B) (pow_pos (Nat.two_pow_pos _) _)
(Nat.mul_pos (by decide) (Nat.two_pow_pos _))
(physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (draw entry)
theorem physicalCoarseAllocationEntry_fits {M J : β„•} :
βˆ€αΆ  N : β„• in atTop, βˆ€ B : β„•, βˆ€ (_hB : NeZero B),
βˆ€ (source target : List β„•) (depth : PhysicalEntry M J target.length β†’ β„•),
B = (integerParameters N).B β†’
(βˆ€ entry, depth entry = computedCoarseDepth N
(coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi))) β†’
source.length + target.length ≀ N β†’
(βˆ€ a ∈ source ++ target, Nat.size a ≀ inputHeight N ^ 3) β†’
βˆ€ (draw : PhysicalCoarseDraw source target B depth) (entry : PhysicalEntry M J target.length),
physicalCoarseAllocationEntry source target N depth draw entry ≀ (N + 2) ^ 181 := by
filter_upwards [BinaryFraction.computedCoarseIndexedInitialAllocation_polynomial] with N hN
intro B inst source target depth hB hd hsize hsymbols draw entry
have hx := physicalSource_length_le source entry.1
have hy : (substring target entry.2.lo entry.2.hi).length ≀ target.length := by
simp only [substring, List.length_drop, List.length_take]
exact (Nat.sub_le _ _).trans (min_le_right _ _)
have hs : βˆ€ a ∈ physicalSource source entry.1 ++ substring target entry.2.lo entry.2.hi,
Nat.size a ≀ inputHeight N ^ 3 := by
intro a ha
rcases List.mem_append.mp ha with ha | ha
Β· exact hsymbols a (List.mem_append_left _ (physicalSource_mem source entry.1 a ha))
Β· exact hsymbols a (List.mem_append_right _ (List.mem_of_mem_take (List.mem_of_mem_drop ha)))
exact hN B (depth entry) (physicalSource source entry.1)
(substring target entry.2.lo entry.2.hi) hB (hd entry)
(max_le (by omega) (by omega)) hs (Nat.pos_of_neZero B)
(pow_pos (Nat.two_pow_pos _) _) (Nat.mul_pos (by decide) (Nat.two_pow_pos _)) (draw entry)
/-- Reserve every fresh cell allocated by every coarse cache miss until
termination. This deliberately bounds more than simultaneously live scratch. -/
theorem computedFamilyCoarseScratchCapacity_eq (source target : List β„•) (N : β„•)
(input : ComputedFamilyInput source target N) :
computedFamilyCoarseScratchCapacity source target N input =
((computedFamilyResult source target N input).freshKeys.map
(coarseHistoryKeyCost (fun _ => (N + 2) ^ 181))).sum :=
computedFamilyKernelWork_eq_fresh_sum source target N input _
theorem computedFamilyCoarseScratchCapacity_bound (source target : List β„•) (N : β„•)
(input : ComputedFamilyInput source target N) :
computedFamilyCoarseScratchCapacity source target N input ≀
(N + 2) ^ 181 * (computedFamilyResult source target N input).requests := by
apply computedFamilyKernelWork_le
exact coarseHistoryKeyCost_le _ _ (fun _ => le_rfl)
theorem computedFamilyCoarseScratchCapacity_polynomial :
βˆ€αΆ  N : β„• in atTop, βˆ€ source target : List β„•, source.length + target.length ≀ N β†’
βˆ€ input : ComputedFamilyInput source target N,
computedFamilyCoarseScratchCapacity source target N input ≀ (N + 2) ^ 183 := by
filter_upwards [computedFamilyResult_requests_near_linear 1 (by norm_num)] with N hr
intro source target hsize input
have hrequests : (computedFamilyResult source target N input).requests ≀ (N + 2) ^ 2 := by
have h := hr source target hsize input
norm_num at h
exact_mod_cast h
calc
_ ≀ (N + 2) ^ 181 * (computedFamilyResult source target N input).requests :=
computedFamilyCoarseScratchCapacity_bound source target N input
_ ≀ (N + 2) ^ 181 * (N + 2) ^ 2 := Nat.mul_le_mul_left _ hrequests
_ = _ := by rw [← pow_add]
end EditApproximation
end OAI