Add lean source and binary files (part 44)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageParameters.leanAdded+79
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageTime.leanAdded+67
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWarmupReadBudget.leanAdded+168
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWidthEnvelope.leanAdded+100
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryMass.leanAdded+71
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryStep.leanAdded+170
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundedQuery.leanAdded+162
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundsAllSeeds.leanAdded+162
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCachedWords.leanAdded+87
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseBitWork.leanAdded+59
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseExecution.leanAdded+53
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseInputWork.leanAdded+99
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarsePreparation.leanAdded+71
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSamplingWork.leanAdded+60
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSeedLaw.leanAdded+93
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCommonSource.leanAdded+153
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalComparisonBand.leanAdded+99
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalAccuracy.leanAdded+74
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalNode.leanAdded+165
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDenominator.leanAdded+256
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDependencyRank.leanAdded+240
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalExpectedRegret.leanAdded+159
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyAccuracy.leanAdded+91
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyCoarseWork.leanAdded+105
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyEncoding.leanAdded+47
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemo.leanAdded+95
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemoCoarse.leanAdded+100
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyOutput.leanAdded+128
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyProgram.leanAdded+96
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRejectionWork.leanAdded+71
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRuntime.leanAdded+81
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySampling.leanAdded+54
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySeedTrace.leanAdded+133
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyTrace.leanAdded+78
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyWork.leanAdded+96
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFinalAccuracy.leanAdded+160
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGenericRegret.leanAdded+181
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalQuery.leanAdded+60
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalValue.leanAdded+250
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGroupAccuracy.leanAdded+68
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalIndexedCoarseWork.leanAdded+54
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInitial.leanAdded+107
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputEncoding.leanAdded+72
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputGuard.leanAdded+92
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLeaves.leanAdded+80
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalDenominator.leanAdded+241
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupKeys.leanAdded+136
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupProgram.leanAdded+107
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalJointProgram.leanAdded+49
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalOnlineEquality.leanAdded+109
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import OAI.Combinatorics.EditApproximation.Refinement.StageParameterBoundsimport OAI.Combinatorics.EditApproximation.Geometry.TreeParameters
namespace OAI
/-! Numerical premises for the computed physical refinement stage. -/
namespace EditApproximation
theorem computed_stage_grid_bounds (N : ℕ) (hN : 0 < N) : 66 ≤ (integerParameters N).P ∧ (800 * (inputHeight N : ℝ) ^ 2) ≤ (integerParameters N).P ∧ 4 * ((integerParameters N).M : ℝ) / (integerParameters N).P ≤ 1 := by let H := inputHeight N let P := (integerParameters N).P let M := (integerParameters N).M have hHtwo : 2 ≤ H := by have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (heightExponent_pos N hN) simpa only [H, inputHeight, pow_one] using h have hHone : 1 ≤ H := by omega have hM : M ≤ H := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (Nat.div_le_self _ _) have hH18 : 800 ≤ H ^ 18 := by have h := Nat.pow_le_pow_left hHtwo 18 norm_num only [show (2 : ℕ) ^ 18 = 262144 by norm_num] at h omega have hP20 : H ^ 20 ≤ P := pow_le_pow_right₀ hHone (by omega : 20 ≤ coarseExponent (inputSmallLog N) + 20) have hP800 : 800 * H ^ 2 ≤ P := by calc 800 * H ^ 2 ≤ H ^ 18 * H ^ 2 := Nat.mul_le_mul_right _ hH18 _ = H ^ 20 := by rw [← pow_add] _ ≤ P := hP20 have hHP : (800 * (H : ℝ) ^ 2) ≤ P := by exact_mod_cast hP800 have hP66 : 66 ≤ P := by have h : 4 ≤ H ^ 2 := by nlinarith only [hHtwo] nlinarith only [hP800, h] have hPr : (0 : ℝ) < P := by exact_mod_cast (show 0 < P by omega) have hHr : (2 : ℝ) ≤ H := by exact_mod_cast hHtwo have hMr : (M : ℝ) ≤ H := by exact_mod_cast hM refine ⟨hP66, hHP, ?_⟩ apply (div_le_one₀ hPr).2 nlinarith only [hHP, hHr, hMr]
theorem computed_stage_tree_small (N nx : ℕ) (hN : 0 < N) (hnx : nx ≤ N) (hell : 200 ≤ inputSmallLog N) : (intervalTreeDepth (integerParameters N).M nx : ℝ) * (4 * ((integerParameters N).M : ℝ) / (integerParameters N).P) ≤ 1 / 2 := by let H := inputHeight N let M := (integerParameters N).M let P := (integerParameters N).P let J := intervalTreeDepth M nx have hdepth := computed_tree_depth_bound N nx hN hnx hell have hellone : 1 ≤ inputSmallLog N := Nat.one_le_two_pow have hJ : J ≤ 100 * H := by calc J = J * 1 := (Nat.mul_one J).symm _ ≤ J * inputSmallLog N := Nat.mul_le_mul_left J hellone _ ≤ 100 * H := hdepth have hJR : (J : ℝ) ≤ 100 * H := by exact_mod_cast hJ have hM : M ≤ H := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (Nat.div_le_self _ _) have hMR : (M : ℝ) ≤ H := by exact_mod_cast hM have hP800 := (computed_stage_grid_bounds N hN).2.1 have hPr : (0 : ℝ) < P := by exact_mod_cast (show 0 < P from lt_of_lt_of_le (by decide) (computed_stage_grid_bounds N hN).1) have hproduct := mul_le_mul hJR hMR (Nat.cast_nonneg M) (by positivity : (0 : ℝ) ≤ 100 * H) change (J : ℝ) * (4 * (M : ℝ) / P) ≤ _ rw [← mul_div_assoc] apply (div_le_iff₀ hPr).2 nlinarith only [hproduct, hP800]
theorem computed_stage_positive_counts (N : ℕ) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) : 0 < (integerParameters N).T ∧ 0 < (integerParameters N).S := by have hellone : (1 : ℝ) ≤ inputSmallLog N := by exact_mod_cast (Nat.one_le_two_pow (n := smallLogExponent N)) have hpow := (pow_le_pow_right₀ hellone (by decide : 2 ≤ 20000)).trans (inputHeight_polynomial_slack N hN hell) have hpowN : inputSmallLog N ^ 2 ≤ inputHeight N := by exact_mod_cast hpow have hellpos : 0 < inputSmallLog N := Nat.two_pow_pos _ exact ⟨Nat.two_pow_pos _, Nat.div_pos hpowN (pow_pos hellpos 2)⟩
end EditApproximation
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667import OAI.Combinatorics.EditApproximation.Refinement.ComputedStageParameters
namespace OAI
/-! Exact divisibility and power bounds for the computed time counts. -/
namespace EditApproximation
theorem computed_refinement_count_exact (N : ℕ) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) : (integerParameters N).S * inputSmallLog N ^ 2 = inputHeight N := by have hellone : (1 : ℝ) ≤ inputSmallLog N := by exact_mod_cast (Nat.one_le_two_pow (n := smallLogExponent N)) have hpowR := (pow_le_pow_right₀ hellone (by decide : 2 ≤ 20000)).trans (inputHeight_polynomial_slack N hN hell) have hpow : inputSmallLog N ^ 2 ≤ inputHeight N := by exact_mod_cast hpowR have hexponent : smallLogExponent N * 2 ≤ heightExponent N := by apply (Nat.pow_le_pow_iff_right (by decide : 1 < 2)).1 simpa only [inputSmallLog, inputHeight, ← pow_mul] using hpow have hdiv : inputSmallLog N ^ 2 ∣ inputHeight N := by simpa only [inputSmallLog, inputHeight, ← pow_mul] using Nat.pow_dvd_pow 2 hexponent exact Nat.div_mul_cancel hdiv
theorem computed_refinement_count_real (N : ℕ) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) : ((integerParameters N).S : ℝ) = (inputHeight N : ℝ) / (inputSmallLog N : ℝ) ^ 2 := by have hpos : (0 : ℝ) < inputSmallLog N := by exact_mod_cast Nat.two_pow_pos (smallLogExponent N) apply (eq_div_iff (pow_ne_zero 2 hpos.ne')).2 exact_mod_cast computed_refinement_count_exact N hN hell
theorem computed_warmup_count_power (N : ℕ) : inputHeight N ^ 3 ≤ (integerParameters N).T ^ 4 ∧ (integerParameters N).T ^ 4 ≤ 16 * inputHeight N ^ 3 := by let k := heightExponent N have hlow : 3 * k ≤ ((3 * k + 3) / 4) * 4 := by omega have hhigh : ((3 * k + 3) / 4) * 4 ≤ 3 * k + 4 := by omega constructor · simpa only [integerParameters, inputHeight, ← pow_mul, k, mul_comm] using pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) hlow · have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) hhigh simpa only [integerParameters, inputHeight, ← pow_mul, pow_add, k, show (2 : ℕ) ^ 4 = 16 by norm_num, mul_comm] using h
theorem computed_warmup_count_root (N : ℕ) : heightQuarterRoot N ^ 3 ≤ ((integerParameters N).T : ℝ) ∧ ((integerParameters N).T : ℝ) ≤ 2 * heightQuarterRoot N ^ 3 := by have hroot : 0 ≤ heightQuarterRoot N := Real.sqrt_nonneg _ have hT : (0 : ℝ) ≤ (integerParameters N).T := Nat.cast_nonneg _ have hpower := computed_warmup_count_power N have hlow : (inputHeight N : ℝ) ^ 3 ≤ ((integerParameters N).T : ℝ) ^ 4 := by exact_mod_cast hpower.1 have hhigh : ((integerParameters N).T : ℝ) ^ 4 ≤ 16 * (inputHeight N : ℝ) ^ 3 := by exact_mod_cast hpower.2 have hrootPower := heightQuarterRoot_fourth_power N constructor · apply (pow_le_pow_iff_left₀ (pow_nonneg hroot 3) hT (by decide : 4 ≠ 0)).1 calc (heightQuarterRoot N ^ 3) ^ 4 = (inputHeight N : ℝ) ^ 3 := by rw [← pow_mul, Nat.mul_comm 3 4, pow_mul, hrootPower] _ ≤ _ := hlow · apply (pow_le_pow_iff_left₀ hT (mul_nonneg (by norm_num) (pow_nonneg hroot 3)) (by decide : 4 ≠ 0)).1 calc _ ≤ 16 * (inputHeight N : ℝ) ^ 3 := hhigh _ = (2 * heightQuarterRoot N ^ 3) ^ 4 := by rw [mul_pow, ← pow_mul, Nat.mul_comm 3 4, pow_mul, hrootPower] norm_num
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168import OAI.Combinatorics.EditApproximation.Geometry.WarmupReadWorkimport OAI.Combinatorics.EditApproximation.Refinement.ComputedRefinementReadBudget
namespace OAI
/-! A polynomial earlier-edge bound for the complete charged warmupquery. It includes all preceding-pass copy reads and pass-zero coarsereads used by its initial cones. -/
namespace EditApproximation
def warmupReadBudget (scales window P F Amax M copies : ℕ) : ℕ := (1 + window * (64 * F * P + 2) ^ 2) * ((1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies) + window * (64 * F * P + 2) ^ 2 * M * (40 * P + 2) ^ 2
theorem warmupReadBudget_box (Z scales window P F Amax M copies : ℕ) (hZ : 64 ≤ Z) (hscales : scales ≤ Z) (hwindow : window ≤ Z) (hP : P ≤ Z) (hF : F ≤ Z) (hA : Amax ≤ Z) (hM : M ≤ Z) (hcopies : copies ≤ Z) : warmupReadBudget scales window P F Amax M copies ≤ Z ^ 24 := by have hZone : 1 ≤ Z := by omega have hZtwo : 2 ≤ Z := by omega have hbase (c x : ℕ) (hc : c ≤ Z) (hx : 2 ≤ x) : c * x + 2 ≤ Z ^ 2 * x := by have hcx := Nat.mul_le_mul_right x hc have hzx : 2 ≤ Z * x := hx.trans (Nat.le_mul_of_pos_left x hZone) have hcoeff := Nat.mul_le_mul_right x (show 2 * Z ≤ Z ^ 2 by nlinarith only [hZtwo]) nlinarith only [hcx, hzx, hcoeff] have hadd (k : ℕ) : 1 + Z ^ k ≤ Z ^ (k + 1) := by have hp : 1 ≤ Z ^ k := one_le_pow₀ hZone have hm := Nat.mul_le_mul_right (Z ^ k) hZtwo rw [pow_succ] nlinarith only [hp, hm] have h64 : 64 ≤ Z := hZ have h40 : 40 ≤ Z := by omega have hsmall : 64 * F * P + 2 ≤ Z ^ 4 := by calc _ ≤ 64 * Z * Z + 2 := Nat.add_le_add_right (Nat.mul_le_mul (Nat.mul_le_mul_left 64 hF) hP) 2 _ ≤ _ := by convert hbase 64 (Z ^ 2) h64 ((Nat.pow_le_pow_left hZtwo 2).trans' (by norm_num)) using 1 <;> ring have hinitialBase : 64 * Amax ^ 2 * P + 2 ≤ Z ^ 5 := by calc _ ≤ 64 * Z ^ 2 * Z + 2 := Nat.add_le_add_right (Nat.mul_le_mul (Nat.mul_le_mul_left 64 (Nat.pow_le_pow_left hA 2)) hP) 2 _ ≤ _ := by convert hbase 64 (Z ^ 3) h64 ((Nat.pow_le_pow_left hZtwo 3).trans' (by norm_num)) using 1 <;> ring have hwideBase : 40 * P + 2 ≤ Z ^ 3 := by calc _ ≤ 40 * Z + 2 := Nat.add_le_add_right (Nat.mul_le_mul_left 40 hP) 2 _ ≤ _ := by convert hbase 40 Z h40 hZtwo using 1; ring have hraw : window * (64 * F * P + 2) ^ 2 ≤ Z ^ 9 := by exact (Nat.mul_le_mul hwindow (Nat.pow_le_pow_left hsmall 2)).trans_eq (by ring) have hrawInitial : scales * (64 * Amax ^ 2 * P + 2) ^ 2 ≤ Z ^ 11 := by exact (Nat.mul_le_mul hscales (Nat.pow_le_pow_left hinitialBase 2)).trans_eq (by ring) have hinit : (1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies ≤ Z ^ 13 := by exact (Nat.mul_le_mul ((Nat.add_le_add_left hrawInitial 1).trans (hadd 11)) (max_le hZone hcopies)).trans_eq (by ring) have hfirst : (1 + window * (64 * F * P + 2) ^ 2) * ((1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies) ≤ Z ^ 23 := by exact (Nat.mul_le_mul ((Nat.add_le_add_left hraw 1).trans (hadd 9)) hinit).trans_eq (by ring) have hsecond : window * (64 * F * P + 2) ^ 2 * M * (40 * P + 2) ^ 2 ≤ Z ^ 23 := by calc _ ≤ Z ^ 9 * Z * (Z ^ 3) ^ 2 := Nat.mul_le_mul (Nat.mul_le_mul hraw hM) (Nat.pow_le_pow_left hwideBase 2) _ = Z ^ 16 := by ring _ ≤ _ := pow_le_pow_right₀ hZone (by decide) exact (Nat.add_le_add hfirst hsecond).trans (by have hm := Nat.mul_le_mul_right (Z ^ 23) hZtwo have heq : Z ^ 24 = Z ^ 23 * Z := pow_succ Z 23 calc Z ^ 23 + Z ^ 23 = 2 * Z ^ 23 := (two_mul _).symm _ ≤ Z * Z ^ 23 := hm _ = Z ^ 24 := by rw [heq]; exact Nat.mul_comm _ _)
theorem computed_dyadicScales_length (N : ℕ) (hH : 2 ≤ inputHeight N) : (dyadicScales N).length ≤ inputHeight N ^ 2 := by have hlog : Nat.log 2 N ≤ inputHeight N := by apply (Nat.log_le_clog 2 N).trans apply (Nat.clog_mono_right 2 (Nat.le_add_right N 2)).trans exact Nat.le_pow_clog (by decide : 1 < (2 : ℕ)) (Nat.clog 2 (N + 2)) simp only [dyadicScales, List.length_map, List.length_range] nlinarith only [hlog, hH]
theorem computed_warmupReadBudget_le (N M P copies : ℕ) (hN : 0 < N) (hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P) (hcopies : copies ≤ inputHeight N ^ 2) : warmupReadBudget (dyadicScales N).length (computedSeedInitialExponent N + 8) P (inputSmallLog N) (integerParameters N).initialFactor M copies ≤ inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by let H := inputHeight N let p := coarseExponent (inputSmallLog N) let Z := H ^ (p + 20) have hF := computed_smallLog_le_height N have hH : 64 ≤ H := (by omega : 64 ≤ inputSmallLog N).trans hF have hZone : 1 ≤ H := by omega have hHZ : H ≤ Z := by calc H = H ^ 1 := (pow_one H).symm _ ≤ H ^ (p + 20) := pow_le_pow_right₀ hZone (by omega) have hH2Z : H ^ 2 ≤ Z := pow_le_pow_right₀ hZone (by omega) have hH3Z : H ^ 3 ≤ Z := pow_le_pow_right₀ hZone (by omega) have hscales : (dyadicScales N).length ≤ Z := (computed_dyadicScales_length N (by omega)).trans hH2Z have hwindow : computedSeedInitialExponent N + 8 ≤ Z := (computed_window_le_height_cube N hN (by omega) (by omega)).trans hH3Z have hPZ : P ≤ Z := by change P ≤ (integerParameters N).P; exact hP.le have hAZ : (integerParameters N).initialFactor ≤ Z := pow_le_pow_right₀ hZone (by omega) have hMZ : M ≤ Z := by rw [hM] exact (pow_le_pow_right₀ (by decide : (1 : ℕ) ≤ 2) (Nat.div_le_self _ _)).trans hHZ have hbound := warmupReadBudget_box Z (dyadicScales N).length (computedSeedInitialExponent N + 8) P (inputSmallLog N) (integerParameters N).initialFactor M copies (hH.trans hHZ) hscales hwindow hPZ (hF.trans hHZ) hAZ hMZ (hcopies.trans hH2Z) apply hbound.trans dsimp only [Z] rw [← pow_mul] exact pow_le_pow_right₀ hZone (by dsimp only [p]; omega)
theorem computed_chargedWarmupQuery_reads {α : Type*} [DecidableEq α] {M J passes copies T S : ℕ} (source target : List α) (N P : ℕ) (hN : 0 < N) (hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P) (hcopies : copies ≤ inputHeight N ^ 2) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (parent : {r : PhysicalTableRequest M J target.length // r.Bounded passes copies T S}) (oracle) (hA : 1 ≤ factor parent.val.pass) (hAmax : factor parent.val.pass ≤ ((integerParameters N).initialFactor : ℚ)) : (chargedWarmupQuery source target N P (inputSmallLog N) factor multiplier parent).cost oracle (fun _ => 1) ≤ inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by have hPpos : 0 < P := by rw [hP] change 0 < inputHeight N ^ _ exact pow_pos (Nat.two_pow_pos _) _ exact (chargedWarmupQuery_cost_le source target N P (inputSmallLog N) (integerParameters N).initialFactor (computedSeedInitialExponent N + 8) factor multiplier parent oracle hPpos (by omega) hA hAmax (fun w => computed_refinement_window N hN (by omega) (factor parent.val.pass) w hAmax)).trans (computed_warmupReadBudget_le N M P copies hN hell hM hP hcopies)
theorem computed_chargedInitialQuery_reads {α : Type*} [DecidableEq α] {M J passes copies T S : ℕ} (source target : List α) (N P : ℕ) (hN : 0 < N) (hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P) (hcopies : copies ≤ inputHeight N ^ 2) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (parent : {r : PhysicalTableRequest M J target.length // r.Bounded passes copies T S}) (oracle) (hA : 1 ≤ factor parent.val.pass) (hAmax : factor parent.val.pass ≤ ((integerParameters N).initialFactor : ℚ)) : (physicalInitialQuery source target N P (inputSmallLog N) (factor parent.val.pass) (chargedSeedQuery N multiplier parent) (parent.val.node, parent.val.state)).cost oracle (fun _ => 1) ≤ inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by have hPpos : 0 < P := by rw [hP] change 0 < inputHeight N ^ _ exact pow_pos (Nat.two_pow_pos _) _ let initialCost := (1 + (dyadicScales N).length * (64 * (integerParameters N).initialFactor ^ 2 * P + 2) ^ 2) * max 1 copies have hi : (physicalInitialQuery source target N P (inputSmallLog N) (factor parent.val.pass) (chargedSeedQuery N multiplier parent) (parent.val.node, parent.val.state)).cost oracle (fun _ => 1) ≤ initialCost := physicalInitialQuery_cost_le source target N P (inputSmallLog N) (integerParameters N).initialFactor (max 1 copies) _ _ _ _ oracle hPpos hA hAmax (fun r => chargedSeedQuery_cost_le N multiplier parent _ oracle) have hb : initialCost ≤ warmupReadBudget (dyadicScales N).length (computedSeedInitialExponent N + 8) P (inputSmallLog N) (integerParameters N).initialFactor M copies := by exact (Nat.le_mul_of_pos_left initialCost (by omega)).trans (Nat.le_add_right _ _) exact hi.trans (hb.trans (computed_warmupReadBudget_le N M P copies hN hell hM hP hcopies))
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import OAI.Combinatorics.EditApproximation.Refinement.ComputedActualBandWork
namespace OAI
/-! A parameter-only majorant for every executed dependency tree. It isindependent of the accepted random values and of all accuracy events. -/
namespace EditApproximation
open Filteropen scoped Topology
noncomputable def computedWidthEnvelope (N : ℕ) : ℝ := (N + 2 : ℝ) * (inputHeight N : ℝ) ^ 2 * Real.exp (computedDependencyOverheadExponent 257 512 N)
theorem computedWidthEnvelope_nonneg (N : ℕ) : 0 ≤ computedWidthEnvelope N := by unfold computedWidthEnvelope positivity
theorem computed_widthWork_le_envelope (N n : ℕ) (hN : 0 < N) (hn : n ≤ N) (hell : 200 ≤ inputSmallLog N) (hH : 105 ≤ inputHeight N) (tree : DependencyExpansion) (hv : tree.Valid ((integerParameters N).M * inputSmallLog N ^ 257) (inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)))) (hd : tree.depth = intervalTreeDepth (integerParameters N).M n) (hk : tree.rank ≤ computedDependencyIndexCount N) : (tree.widthWork (integerParameters N).M n : ℝ) ≤ computedWidthEnvelope N := by have hw := DependencyExpansion.widthWork_le (integerParameters N).M n _ _ _ (computed_branching_bounds N hN hell).1 tree hv hd hk (Real.exp (computedDependencyOverheadExponent 257 512 N)) (Real.exp_nonneg _) (by intro j hj exact computed_dependency_path_envelope N 257 512 j (hj.trans (intervalTreeDepth_le_computedMax N n hn))) have hpref := computed_width_prefactor_le N n hN hn hell hH have hprefR : (((intervalTreeDepth (integerParameters N).M n + 1) * n + 4 * (integerParameters N).M * max 1 n : ℕ) : ℝ) ≤ (N + 2 : ℝ) * (inputHeight N : ℝ) ^ 2 := by exact_mod_cast hpref exact hw.trans (mul_le_mul_of_nonneg_right hprefR (Real.exp_nonneg _))
theorem computedWidthEnvelope_mul_exp_near_linear (f : ℕ → ℝ) (hf : Tendsto (fun N => f N / inputHeight N) atTop (𝓝 0)) (epsilon : ℝ) (hepsilon : 0 < epsilon) : ∀ᶠ N in atTop, computedWidthEnvelope N * Real.exp (f N) ≤ (N + 2 : ℝ) ^ (1 + epsilon) := by have hlog : Tendsto (fun N => Real.log (inputHeight N : ℝ) / inputHeight N) atTop (𝓝 0) := Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp inputHeight_real_tendsto have hlimit := ((computedDependencyOverheadExponent_tendsto 257 512).add (hlog.const_mul 2)).add hf simp only [mul_zero, add_zero] at hlimit have hfinal := sublinear_height_near_linear (fun N => computedDependencyOverheadExponent 257 512 N + 2 * Real.log (inputHeight N : ℝ) + f N) (by convert hlimit using 1 ext N ring) epsilon hepsilon filter_upwards [hfinal] with N hN convert hN using 1 unfold computedWidthEnvelope rw [Real.exp_add, Real.exp_add] have hp : Real.exp (2 * Real.log (inputHeight N : ℝ)) = (inputHeight N : ℝ) ^ 2 := by simpa using (nat_pow_eq_exp_log (inputHeight N) 2 (Nat.two_pow_pos _)).symm rw [hp] ring
theorem computedWidthEnvelope_weighted_near_linear (C : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : ∀ᶠ N in atTop, computedWidthEnvelope N * (inputHeight N : ℝ) ^ C ≤ (N + 2 : ℝ) ^ (1 + epsilon) := by have hlog : Tendsto (fun N => Real.log (inputHeight N : ℝ) / inputHeight N) atTop (𝓝 0) := Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp inputHeight_real_tendsto have hlimit := hlog.const_mul (C : ℝ) simp only [mul_zero] at hlimit have hf : Tendsto (fun N => ((C : ℝ) * Real.log (inputHeight N : ℝ)) / inputHeight N) atTop (𝓝 0) := by convert hlimit using 1; ext N; ring filter_upwards [computedWidthEnvelope_mul_exp_near_linear _ hf epsilon hepsilon] with N hN rwa [← nat_pow_eq_exp_log (inputHeight N) C (Nat.two_pow_pos _)] at hN
theorem computedWidthEnvelope_coarse_near_linear (epsilon : ℝ) (hepsilon : 0 < epsilon) : ∀ᶠ N in atTop, computedWidthEnvelope N * computedCoarseWidthOverhead N ≤ (N + 2 : ℝ) ^ (1 + epsilon) := by filter_upwards [computedWidthEnvelope_mul_exp_near_linear _ (computedCoarseOverheadExponent_tendsto 10) epsilon hepsilon, eventually_ge_atTop 1] with N hN hpos exact (mul_le_mul_of_nonneg_left (computedCoarseWidthOverhead_exp_le N (by omega)) (computedWidthEnvelope_nonneg N)).trans hN
theorem computedWidthEnvelope_band_near_linear (C : ℕ) (epsilon : ℝ) (hepsilon : 0 < epsilon) : ∀ᶠ N in atTop, computedWidthEnvelope N * computedActualBandBitBudget C N ≤ (N + 2 : ℝ) ^ (1 + epsilon) := by filter_upwards [computedWidthEnvelope_mul_exp_near_linear _ (computedActualBandBitExponent_tendsto C) epsilon hepsilon, eventually_ge_atTop 1] with N hN hpos exact (mul_le_mul_of_nonneg_left (computedActualBandBitBudget_exp_bound C N (by omega)) (computedWidthEnvelope_nonneg N)).trans hN
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import OAI.Combinatorics.EditApproximation.Binary.BinaryWarmupAverageimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalRefinement
namespace OAI
/-! The child mass is built from the actual gathered warmup words. Themean and construction of its finite input list both contribute to work. -/
namespace EditApproximation
def physicalWarmupMassWithWork {ny : ℕ} (T : ℕ) (words : ℕ → TargetInterval ny → BinaryFraction) (query : TargetInterval ny) : BinaryFraction × ℕ := let mean := BinaryFraction.warmupAverageWithWork (List.ofFn fun j : Fin T => words j.val query) (mean.1, mean.2 + T + 1)
theorem physicalWarmupMassWithWork_value {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F T : ℕ) (A : ℚ) (node : PhysicalNode M J) (words : ℕ → TargetInterval target.length → BinaryFraction) (hwords : ∀ j < T, ∀ r, (words j r).value = physicalLocalWarmup source target U N P F A j (node, r)) (query : TargetInterval target.length) : (physicalWarmupMassWithWork T words query).1.value = physicalLocalWarmupMass source target U N P F A T (node, query) := by rw [physicalWarmupMassWithWork, BinaryFraction.warmupAverageWithWork_ofFn_value] unfold physicalLocalWarmupMass congr 1 rw [← Fin.sum_univ_eq_sum_range (fun j => physicalLocalWarmup source target U N P F A j (node, query))] apply Finset.sum_congr rfl intro j _hj exact hwords j.val j.isLt query
theorem physicalWarmupMassWithWork_bounds {ny : ℕ} (T B : ℕ) (words : ℕ → TargetInterval ny → BinaryFraction) (hwords : ∀ j < T, ∀ r, (words j r).width ≤ B) (query : TargetInterval ny) : (physicalWarmupMassWithWork T words query).1.width ≤ BinaryFraction.warmupAverageWordBudget T B ∧ (physicalWarmupMassWithWork T words query).2 ≤ BinaryFraction.warmupAverageBitBudget T B + T + 1 := by have hmean := BinaryFraction.warmupAverageWithWork_bounds (List.ofFn fun j : Fin T => words j.val query) B (by intro value hv obtain ⟨j, rfl⟩ := List.mem_ofFn.mp hv exact hwords j.val j.isLt query) simp only [List.length_ofFn] at hmean exact ⟨hmean.1, Nat.add_le_add_right (Nat.add_le_add_right hmean.2 T) 1⟩
theorem warmupAverageWordBudget_le_power (H T B : ℕ) (hH : 64 ≤ H) (hT : T ≤ H ^ 2) (hB : B ≤ H ^ 3) : BinaryFraction.warmupAverageWordBudget T B ≤ H ^ 8 := by have hHp : 0 < H := by omega have hHone : 1 ≤ H := by omega have hsize : Nat.size T ≤ H ^ 2 := (Nat.size_le.mpr Nat.lt_two_pow_self).trans hT have h23 : H ^ 2 ≤ H ^ 3 := Nat.pow_le_pow_right hHp (by decide) have h35 : H ^ 3 ≤ H ^ 5 := Nat.pow_le_pow_right hHp (by decide) have hone : 1 ≤ H ^ 3 := one_le_pow₀ hHone have hproduct : T * (B + 1) ≤ 2 * H ^ 5 := by calc _ ≤ H ^ 2 * (2 * H ^ 3) := Nat.mul_le_mul hT (by omega) _ = 2 * H ^ 5 := by ring have hsmall : BinaryFraction.warmupAverageWordBudget T B ≤ 64 * H ^ 5 := by unfold BinaryFraction.warmupAverageWordBudget BinaryFraction.bandMassTotalStorageBudget nlinarith only [hsize, hB, h23, h35, hproduct, hone] have h64 : 64 ≤ H ^ 3 := (by omega : 64 ≤ H).trans (Nat.le_pow (by decide)) exact hsmall.trans (by calc 64 * H ^ 5 ≤ H ^ 3 * H ^ 5 := Nat.mul_le_mul_right _ h64 _ = H ^ 8 := by ring)
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import OAI.Combinatorics.EditApproximation.Geometry.PreparedCachedKernelWorkimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCachedWords
namespace OAI
/-! The Boolean refinement kernel at a physical node uses cached wordsfor its child and table requests. -/
namespace EditApproximation
attribute [local irreducible] BinaryFraction.preparedLocalKernelWithWork
section Step
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (N P F exponent H Q eM eF : ℕ) (hP : 0 < P) (hM : M = 2 ^ eM) (hF : F = 2 ^ eF) (tauWord aWord etaWord kappaWord deltaWord : BinaryFraction) (parentWords : TargetInterval target.length → BinaryFraction) (massWords initialWords : Fin M → TargetInterval target.length → BinaryFraction) (historyWords : ℕ → Fin M × TargetInterval target.length → BinaryFraction) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ) (query : TargetInterval target.length)
def physicalPreparedStepWithWork : BinaryFraction × ℕ := BinaryFraction.preparedLocalKernelWithWork source target (physicalSourceInterval source.length node) N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords t (draw ⟨node, hbelow⟩ (t + 1)) (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query
omit [DecidableEq α] intheorem physicalPreparedStepWithWork_bounds (B E S : ℕ) (hPdyadic : ∃ j : ℕ, P = 2 ^ j) (hb : BinaryFraction.PreparedKernelInputBounds (nx := source.length) N P F exponent H Q eM eF B E S t tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords (integer ⟨node, hbelow⟩ (Fin.ofNat R t))) : (physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query).1.width ≤ BinaryFraction.preparedKernelWordBudget M B ∧ (physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query).2 ≤ BinaryFraction.preparedKernelBitBudget N M P F exponent eM eF B S := BinaryFraction.preparedLocalKernelWithWork_bounds source target (physicalSourceInterval source.length node) N P F exponent H Q eM eF B E S hP hM hF hPdyadic tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords t (draw ⟨node, hbelow⟩ (t + 1)) (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query hb
variable (U : PhysicalEntry M J target.length → ℕ) (A tau eta kappa delta : ℚ) (T : ℕ) (ha : aWord.value = refinementFactor A F) (htau : tauWord.value = tau) (heta : etaWord.value = eta) (hkappa : kappaWord.value = kappa) (hdelta : deltaWord.value = delta) (hparent : ∀ r, (parentWords r).value = stageInitial source target U N P F A (node, r)) (hmass : ∀ i r, (massWords i r).value = physicalLocalChildMass source target U N P F A T node hbelow i r) (hinitial : ∀ i r, (initialWords i r).value = stageInitial source target U N P F A (physicalChild node hbelow i, r)) (hhistory : ∀ s i r, (historyWords s (i, r)).value = physicalLocalRefinement source target U N P F exponent Q A tau delta T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) (physicalChild node hbelow i) s r) (hwide : ¬ (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1)
include ha htau heta hkappa hdelta hparent hmass hinitial hhistory hwide intheorem physicalPreparedStepWithWork_value : (physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query).1.value = physicalLocalRefinement source target U N P F exponent Q A tau delta T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node (t + 1) query := by let children : PhysicalChildTables M target.length := fun i => physicalLocalRefinement source target U N P F exponent Q A tau delta T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) (physicalChild node hbelow i) have honline : physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer node children (t + 1) query = localOnlineCandidates source target (physicalSourceInterval source.length node) N P F exponent H tau (refinementFactor A F) eta kappa (fun r => stageInitial source target U N P F A (node, r)) (physicalLocalChildMass source target U N P F A T node hbelow) (physicalBandChildInitial source target U N P F A node hbelow) children t (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query := by rw [physicalLocalOnline, dite_eq_left hbelow] simp only [Nat.add_sub_cancel] unfold physicalPreparedStepWithWork rw [BinaryFraction.preparedLocalKernelWithWork_value] simp_rw [ha, htau, heta, hkappa, hdelta, hparent, hmass, hinitial, hhistory] conv_rhs => rw [physicalLocalRefinement] rw [dite_eq_left hbelow, ite_eq_right hwide] dsimp only rw [honline] rfl
include hparent hinitial hhistory intheorem physicalPreparedStep_input_ranges (hd : 0 ≤ delta) : (∀ r, 0 ≤ (parentWords r).value) ∧ (∀ s ≤ t + 1, ∀ i r, 0 ≤ (historyWords s (i, r)).value ∧ (historyWords s (i, r)).value ≤ (initialWords i r).value) := by constructor · intro r rw [hparent] exact stageInitial_nonneg_all_seeds source target U N P F A (node, r) · intro s _hs i r rw [hhistory, hinitial] exact physicalLocalRefinement_bounds source target U N P F exponent Q A tau delta T hd draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) (physicalChild node hbelow i) s r
def physicalCachedStepWithWork (base : List Bool) (hbase : 0 < bitWordValue base) : BinaryFraction × ℕ := BinaryFraction.finishCachedWithWork (physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query) base hbase (J - node.1.val)
omit [DecidableEq α] intheorem physicalCachedStepWithWork_cost (base : List Bool) (hbase : 0 < bitWordValue base) (B E S D : ℕ) (hbaseWidth : base.length ≤ D) (hPdyadic : ∃ j : ℕ, P = 2 ^ j) (hb : BinaryFraction.PreparedKernelInputBounds (nx := source.length) N P F exponent H Q eM eF B E S t tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords (integer ⟨node, hbelow⟩ (Fin.ofNat R t))) : (physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query base hbase).2 ≤ BinaryFraction.preparedKernelBitBudget N M P F exponent eM eF B S + BinaryFraction.powerDenominatorBitBudget (J - node.1.val) (BinaryFraction.preparedKernelWordBudget M B) D + 1 := by have hk := physicalPreparedStepWithWork_bounds source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query B E S hPdyadic hb have hc := BinaryFraction.powerDenominatorWithWork_cost (physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query).1 base hbase (J - node.1.val) (BinaryFraction.preparedKernelWordBudget M B) D hk.1 hbaseWidth exact Nat.add_le_add_right (Nat.add_le_add hk.2 hc) 1
include ha htau heta hkappa hdelta hparent hmass hinitial hhistory hwide intheorem physicalCachedStepWithWork_value_width (ell : ℕ) (hell : 0 < ell) (hdeltaExact : delta = 1 / (ell : ℚ) ^ 10) (hsize : source.length + target.length ≤ N) (base : List Bool) (hbase : bitWordValue base = ell ^ 10 + 1) : (physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query base (by rw [hbase]; omega)).1.value = physicalLocalRefinement source target U N P F exponent Q A tau delta T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node (t + 1) query ∧ (physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query base (by rw [hbase]; omega)).1.width ≤ Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 := by rcases hdeltaExact with rfl have hraw := physicalPreparedStepWithWork_value source target N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords draw integer node hbelow t query U A tau eta kappa _ T ha htau heta hkappa hdelta hparent hmass hinitial hhistory hwide have hstored := physicalLocalOnlineRefinement_cached_word source target U N P F exponent H Q A tau eta kappa hsize T ell hell draw integer node (t + 1) query _ hraw base hbase exact ⟨hstored.1.trans hraw, hstored.2⟩
end Step
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162import OAI.Combinatorics.EditApproximation.Refinement.PhysicalGlobalValueimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementReadWorkimport OAI.Combinatorics.EditApproximation.Geometry.WarmupQueryKeysimport OAI.Combinatorics.EditApproximation.Geometry.RankedProgramRestrictionimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRequestEncoding
namespace OAI
/-! The actual global read program stays within the bounded cache-keydomain. Restricting its type therefore preserves the complete local-passvalue and gives an injectively encoded memo evaluator. -/
namespace EditApproximation
instance PhysicalTableRequest.decidableBounded {M J ny : ℕ} (passes copies T S : ℕ) : DecidablePred (PhysicalTableRequest.Bounded (M := M) (J := J) (ny := ny) passes copies T S) := fun request => inferInstanceAs (Decidable (request.pass < passes ∧ request.copy < copies ∧ request.index ≤ T + S))
theorem globalSeedRead_keys_bounded {M J ny : ℕ} (N T S passes copies : ℕ) (multiplier : ℕ → ℕ) (initial : PhysicalEntry M J ny → ℕ) (parent : PhysicalTableRequest M J ny) (hparent : parent.Bounded passes copies T S) (state : PhysicalEntry M J ny) (oracle) : ∀ key ∈ (globalSeedRead N T S copies multiplier initial parent state).keys oracle, key.val.Bounded passes copies T S := by unfold globalSeedRead split_ifs with hnode hpass · intro key hk exact False.elim (List.not_mem_nil hk) · unfold physicalMedianSeedQuery apply FiniteQuery.keys_all_collect · intro copy _ key hk simp only [previousPassRead, FiniteQuery.keys, List.mem_singleton] at hk subst key exact ⟨Nat.lt_of_le_of_lt (Nat.sub_le _ _) hparent.1, copy.isLt, le_rfl⟩ · intro values key hk exact False.elim (List.not_mem_nil hk) · intro key hk exact False.elim (List.not_mem_nil hk)
section Bounded
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (N P F exponent H Q T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) (integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (initial : PhysicalEntry M J target.length → ℕ)
theorem physicalGlobalQuery_keys_bounded (request : PhysicalTableRequest M J target.length) (hrequest : request.Bounded passes copies T S) (oracle) : ∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request).keys oracle, key.val.Bounded passes copies T S := by rcases request with ⟨pass, copy, node, index, q⟩ obtain ⟨hpass, hcopy, hindex⟩ := hrequest dsimp only at hpass hcopy hindex by_cases hj : index ≤ T · change ∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q)).keys oracle, key.val.Bounded passes copies T S rw [physicalGlobalQuery_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node index hj q] apply physicalWarmupRequestQuery_keys_bounded source target N P F (factor pass) passes copies pass copy T S index hpass hcopy hj node q _ oracle intro r key hk exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _ ⟨hpass, hcopy, hindex⟩ _ oracle key hk · obtain ⟨t, hi⟩ : ∃ t, index = T + t := ⟨index - T, by omega⟩ subst index have ht : 0 < t := by omega have htS : t ≤ S := by omega change ∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q)).keys oracle, key.val.Bounded passes copies T S by_cases hbelow : node.1.val < J · by_cases hshort : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1 · unfold physicalGlobalQuery dsimp only erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T from hj), dite_eq_left hbelow, dite_eq_left hshort] apply physicalInitialQuery_keys_all intro r key hk exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _ ⟨hpass, hcopy, hindex⟩ _ oracle key hk · unfold physicalGlobalQuery dsimp only erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T from hj), dite_eq_left hbelow, dite_eq_right hshort] erw [FiniteQuery.mapKeys_keys] intro key hk obtain ⟨child, hc, rfl⟩ := List.mem_map.mp hk exact physicalRefinementDataRequest_keys_bounded source target N P F exponent H Q tau (refinementFactor (factor pass) F) eta kappa delta passes copies pass copy T S (T + t - T) (by omega) (by omega) hpass hcopy node hbelow _ _ q _ child hc · unfold physicalGlobalQuery dsimp only erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T from hj), dite_eq_right hbelow] apply physicalInitialQuery_keys_all intro r key hk exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _ ⟨hpass, hcopy, hindex⟩ _ oracle key hk
def physicalBoundedQuery (request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) : FiniteQuery {child : {child : PhysicalTableRequest M J target.length // child.Bounded passes copies T S} // child.val.combinedRank T S < request.val.combinedRank T S} := restrictRankedProgram (PhysicalTableRequest.combinedRank T S) (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial) (PhysicalTableRequest.Bounded passes copies T S) request
theorem physicalBoundedQuery_value (request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) : (physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial request).value (fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial child.val.val) = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request.val := by unfold physicalBoundedQuery rw [restrictRankedProgram_value _ _ _ _ request (physicalGlobalQuery_keys_bounded source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial request.val request.property _)] exact physicalGlobalQuery_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request.val
def physicalMemoEvaluate (request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) := rankedMemoEvaluate (fun request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S} => request.val.combinedRank T S) (physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial) (PhysicalTableRequest.bits M J target.length passes copies T S) (fun request => PhysicalTableRequest.code copies T S request.val) request .empty
theorem physicalMemoEvaluate_value (hM : 1 ≤ M) (request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) : (physicalMemoEvaluate source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial request).value = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request.val := by unfold physicalMemoEvaluate exact rankedMemoEvaluate_specification (fun request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S} => request.val.combinedRank T S) (physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial) (fun request => localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request.val) (physicalBoundedQuery_value source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta group integer initial) _ _ (PhysicalTableRequest.code_injective hM passes copies T S) (PhysicalTableRequest.code_fits hM passes copies T S) request
end Bounded
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementInvariants
namespace OAI
/-! Nonnegativity and size bounds hold on every seed and every sample outcome. -/
namespace EditApproximation
open Finset
theorem rationalActualWideActions_connection_nonneg {nx ny M : ℕ} (parent : TargetInterval nx) (representatives : List (ℕ × TargetInterval ny)) (P : ℕ) (action : PhysicalRationalAction M ny) (ha : action ∈ rationalActualWideActions parent representatives P) : 0 ≤ action.connection := by obtain ⟨br, _, hmem⟩ := List.mem_flatMap.mp ha obtain ⟨states, _, rfl⟩ := List.mem_map.mp hmem exact Nat.cast_nonneg _
theorem localInitialConeTable_nonneg {α : Type*} (source target : List α) (U : TargetInterval target.length → ℕ) (N P F : ℕ) (A a : ℚ) (q : TargetInterval target.length) : 0 ≤ localInitialConeTable source target U N P F A a q := by unfold localInitialConeTable split_ifs · exact le_rfl · apply (le_rationalMinimum_iff _ _ _).2 refine ⟨by positivity, ?_⟩ intro v hv obtain ⟨r, _, rfl⟩ := List.mem_map.mp hv unfold initialConeValue scaledSeedValue positivity
theorem stageInitial_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (state : PhysicalEntry M J target.length) : 0 ≤ stageInitial source target U N P F A state := by unfold stageInitial physicalInitialTable dsimp only split_ifs · exact Nat.cast_nonneg _ · exact localInitialConeTable_nonneg _ _ _ _ _ _ _ _ _
theorem stageInitial_upper_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (state : PhysicalEntry M J target.length) : stageInitial source target U N P F A state ≤ (32 * F + 1 : ℚ) * N := by unfold stageInitial physicalInitialTable dsimp only split_ifs with hleaf · rw [shortSourceCost_eq_edit _ _ hleaf] have hcost : (stateEditCost (physicalSource source state.1) target state.2 : ℚ) ≤ N := by exact_mod_cast physical_state_cost_le source target N hsize state change (stateEditCost (physicalSource source state.1) target state.2 : ℚ) ≤ _ have hcoef : (1 : ℚ) ≤ 32 * F + 1 := by have hF : (0 : ℚ) ≤ F := Nat.cast_nonneg _ linarith exact hcost.trans (by simpa only [one_mul] using mul_le_mul_of_nonneg_right hcoef (Nat.cast_nonneg (α := ℚ) N)) · unfold localInitialConeTable split_ifs · positivity · exact rationalMinimum_le_fallback _ _
theorem rationalPhysicalBellman_nonneg {α : Type*} {M J : ℕ} (source target : List α) (P : ℕ) (L : ℚ) (hL : 0 ≤ L) (initial : PhysicalEntry M J target.length → ℚ) (representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length)) (hinitial : ∀ state, 0 ≤ initial state) (value : PhysicalEntry M J target.length → ℚ) (hvalue : ∀ state, 0 ≤ value state) (state : PhysicalEntry M J target.length) : 0 ≤ rationalPhysicalBellman source target P L initial representatives value state := by unfold rationalPhysicalBellman dsimp only split_ifs · exact hinitial state · apply (le_rationalMinimum_iff _ _ _).2 refine ⟨hinitial state, ?_⟩ intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv unfold rationalActionValue exact add_nonneg (add_nonneg (mul_nonneg hL (Nat.cast_nonneg _)) (rationalActualWideActions_connection_nonneg _ _ _ action ha)) (sum_nonneg fun i _ => hvalue _) · exact hinitial state
theorem stageWarmup_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) : 0 ≤ stageWarmup source target U N P F A t state := by induction t generalizing state with | zero => exact stageInitial_nonneg_all_seeds source target U N P F A state | succ t ih => exact rationalPhysicalBellman_nonneg source target P (128 * F) (by positivity) _ _ (stageInitial_nonneg_all_seeds source target U N P F A) _ ih state
theorem stageWarmup_le_initial_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) : stageWarmup source target U N P F A t state ≤ stageInitial source target U N P F A state := by cases t with | zero => exact le_rfl | succ t => change rationalPhysicalBellman source target P (128 * F) _ _ _ state ≤ _ unfold rationalPhysicalBellman dsimp only split_ifs · exact le_rfl · exact rationalMinimum_le_fallback _ _ · exact le_rfl
theorem physicalRefinement_upper_all_seeds {�� : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (T : ℕ) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : physicalRefinement source target U N P F A T delta choices node t q ≤ (32 * F + 1 : ℚ) * N := by exact (physicalRefinement_le_warmup source target U N P F A T delta choices node t q).trans ((stageWarmup_le_initial_all_seeds source target U N P F A T (node, q)).trans (stageInitial_upper_all_seeds source target U N P F A hsize (node, q)))
theorem physicalRefinement_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : 0 ≤ physicalRefinement source target U N P F A T delta choices node t q := by by_cases hbelow : node.1.val < J · by_cases hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1 · rw [physicalRefinement_at_terminal source target U N P F A T delta choices node (Or.inr hleaf)] exact stageInitial_nonneg_all_seeds source target U N P F A (node, q) · have hpost := (physicalRefinement_bellman_invariants source target U N P F A T delta choices node t q).1 have hnonneg : 0 ≤ rationalPhysicalBellman source target P (128 * F) (stageInitial source target U N P F A) (stageRepresentatives source target U N P F A) (fun state => physicalRefinement source target U N P F A T delta choices state.1 t state.2) (node, q) := by unfold rationalPhysicalBellman dsimp only rw [dite_eq_left hbelow, ite_eq_right hleaf] apply (le_rationalMinimum_iff _ _ _).2 refine ⟨stageInitial_nonneg_all_seeds source target U N P F A (node, q), ?_⟩ intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv unfold rationalActionValue apply add_nonneg · exact add_nonneg (mul_nonneg (by positivity) (Nat.cast_nonneg _)) (rationalActualWideActions_connection_nonneg _ _ _ action ha) · apply sum_nonneg intro i _ exact physicalRefinement_nonneg_all_seeds source target U N P F A T delta choices (physicalChild node hbelow (action.childState i).1) t (action.childState i).2 exact hnonneg.trans hpost · rw [physicalRefinement_at_terminal source target U N P F A T delta choices node (Or.inl hbelow)] exact stageInitial_nonneg_all_seeds source target U N P F A (node, q)termination_by J - node.1.valdecreasing_by unfold physicalChild dsimp only omega
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687import OAI.Combinatorics.EditApproximation.Binary.BinaryPowerStorageimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalDenominator
namespace OAI
/-! The cache normalization algorithm applied to the actual all-seed localtable invariants. These word bounds require neither a good-seed event nor abound on the temporary numerator and denominator before normalization. -/
namespace EditApproximation
theorem physicalLocalRefinement_cached_word {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent Q : ℕ) (A tau : ℚ) (hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ → TargetInterval target.length → List (PhysicalRationalAction M target.length)) (honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) (raw : BinaryFraction) (hraw : raw.value = physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw online node t q) (base : List Bool) (hbase : bitWordValue base = ell ^ 10 + 1) : let result := BinaryFraction.powerDenominatorWithWork raw base (by rw [hbase]; omega) (J - node.1.val) result.1.value = raw.value ∧ result.1.width ≤ Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 := by dsimp only have hd : raw.value.den ∣ bitWordValue base ^ (J - node.1.val) := by rw [hraw, hbase] exact physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw online honline node t q have hb := physicalLocalRefinement_bounds source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T (by positivity) draw online node t q have hv : |raw.value| ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by rw [hraw, abs_of_nonneg hb.1] simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using hb.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize (node, q)) refine ⟨BinaryFraction.powerDenominatorWithWork_value raw base _ _ hd, ?_⟩ have hw := BinaryFraction.powerDenominatorWithWork_width raw base (by rw [hbase]; omega) (J - node.1.val) ((32 * F + 1) * N) base.length le_rfl hd hv simpa only [Nat.mul_add, Nat.mul_one, Nat.mul_assoc, Nat.add_assoc] using hw
theorem physicalLocalOnlineRefinement_cached_word {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent H Q : ℕ) (A tau eta kappa : ℚ) (hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) (raw : BinaryFraction) (hraw : raw.value = physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node t q) (base : List Bool) (hbase : bitWordValue base = ell ^ 10 + 1) : let result := BinaryFraction.powerDenominatorWithWork raw base (by rw [hbase]; omega) (J - node.1.val) result.1.value = raw.value ∧ result.1.width ≤ Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 := physicalLocalRefinement_cached_word source target U N P F exponent Q A tau hsize T ell hell draw _ (physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer) node t q raw hraw base hbase
theorem physicalLocalWarmup_cached_word {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (t : ℕ) (state : PhysicalEntry M J target.length) (raw : BinaryFraction) (hraw : raw.value = physicalLocalWarmup source target U N P F A t state) : let result := BinaryFraction.fixedDenominatorWithWork raw [true] (by decide) result.1.value = raw.value ∧ result.1.width ≤ Nat.size ((32 * F + 1) * N) + 3 := by dsimp only have hd : raw.value.den ∣ bitWordValue [true] := by rw [hraw, physicalLocalWarmup_den_one] exact one_dvd _ have hb := physicalLocalWarmup_bounds source target U N P F A t state have hv : |raw.value| ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by rw [hraw, abs_of_nonneg hb.1] simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using hb.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize state) exact ⟨BinaryFraction.fixedDenominatorWithWork_value raw [true] (by decide) hd, BinaryFraction.fixedDenominatorWithWork_width raw [true] (by decide) hd ((32 * F + 1) * N) 1 hv (by decide)⟩
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import OAI.Combinatorics.EditApproximation.Coarse.CoarseEntryCostSumimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWork
namespace OAI
namespace EditApproximation
section Coarsevariable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B] (source target : List ℕ) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies) (depth : PhysicalEntry M J target.length → ℕ)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
/-- Bit arithmetic is executed once for each fresh coarse source request. -/noncomputable def physicalFamilyCoarseBitWork (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) (coarse : PhysicalCoarseDraw source target B depth) : ℝ := let initial := clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse) let result := chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root coarseEntryCostSum source target N depth coarse (fun entry => Sum.inr (Sum.inl entry) ∈ result.freshKeys)
theorem physicalFamilyCoarseBitWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) (coarse : PhysicalCoarseDraw source target B depth) (C : ℝ) (hc : ∀ entry : PhysicalEntry M J target.length, (coarseEntryBinaryCost N B (depth entry) (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) ≤ C * ((coarseInitialArrayWork B (depth entry) (initialThresholdQ N) (initialLambda N) (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) + ((physicalSource source entry.1).length + 1 : ℕ))) : physicalFamilyCoarseBitWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw depth bits encode root coarse ≤ C * (physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth bits encode root coarse + physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) draw bits encode root) := by unfold physicalFamilyCoarseBitWork physicalFamilyMemoCoarseWork physicalFamilyCoarseInputWork exact coarseEntryCostSum_bound source target N depth coarse _ C hc
end Coarseend EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLawimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyRuntimeimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximationopen MeasureTheory
section Executionvariable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H B : ℕ) (depth : PhysicalEntry M J target.length → ℕ)
variable [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
noncomputable def physicalCoarseExecutionLaw : Measure (PhysicalCoarseExecution (R := R) source target N P H B depth) := (coarseFullSeedMeasure B depth (fun entry => physicalSource source entry.1) (fun entry => substring target entry.2.lo entry.2.hi)).prod (rejectionRuntimeArrayLaw (physicalFamilyRange (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) (computedSeedPassCount N) (H ^ 2)))
omit [NeZero M] [NeZero R] [NeZero B] in theorem physicalCoarseExecutionProjection_measurable : Measurable (physicalCoarseExecutionProjection (R := R) source target N P H B depth) := by unfold physicalCoarseExecutionProjection exact ((measurable_of_finite (physicalCoarseSeedTable source target N B depth)).comp measurable_fst).prodMk measurable_snd
omit [NeZero R] in theorem physicalCoarseExecutionProjection_law : (physicalCoarseExecutionLaw (R := R) source target N P H B depth).map (physicalCoarseExecutionProjection (R := R) source target N P H B depth) = physicalFamilyRuntimeLaw (R := R) target N P H (physicalCoarseSeedLaw source target N B depth) := by unfold physicalCoarseExecutionLaw physicalCoarseExecutionProjection physicalFamilyRuntimeLaw change ((_ : Measure (PhysicalCoarseDraw source target B depth)).prod _).map (Prod.map (physicalCoarseSeedTable source target N B depth) id) = _ rw [← Measure.map_prod_map _ _ (measurable_of_finite _) measurable_id, Measure.map_id] rfl
end Executionend EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemoCoarse
namespace OAI
namespace EditApproximation
section Coarsevariable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
/-- Source scans and a constant setup charge for each first coarse request. -/noncomputable def physicalFamilyCoarseInputWork (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) : ℝ := let result := chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root ∑ entry, selectionIndicator (Sum.inr (Sum.inl entry) ∈ result.freshKeys) * ((physicalSource source entry.1).length + 1 : ℕ)
theorem physicalFamilyCoarseQuery_input_cost_le_width (root : Table) (hroot : root.depth = J) : (physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier tau eta kappa delta draw root).cost (fun entry => (initial entry : ℚ)) (fun entry => (physicalSource source entry.1).length + 1) ≤ (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hP draw root).widthWork M source.length := by apply (FiniteQuery.cost_mono_weights _ _ _ _ ?_).trans (chargedRandomCoarseQuery_width_cost_le source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial (physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies draw) (physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta hP draw initial) (physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) root hroot) intro entry rw [physicalSource_length_eq] simpa only [physicalSourceInterval, Nat.add_comm] using Nat.add_le_add_right (sourceIntervalAt_width M source.length entry.1.1.val (Nat.pos_of_neZero M) entry.1.2) 1
theorem physicalFamilyCoarseInputWork_le (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (root : Table) (hroot : root.depth = J) : physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier tau eta kappa delta initial draw bits encode root ≤ ((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hP draw root).widthWork M source.length : ℝ) := by classical let query := physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier tau eta kappa delta draw root have hkey (entry : PhysicalEntry M J target.length) := chargedRandomMemo_coarse_key source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial (physicalFamilyRequestValue source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) (physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) bits encode hinjective hbounded root entry have hs := sum_selected_nat_weights_le (query.keys (fun entry => (initial entry : ℚ))) (fun entry => (physicalSource source entry.1).length + 1) have hc := physicalFamilyCoarseQuery_input_cost_le_width source target N P H T S passes copies factor multiplier tau eta kappa delta initial hP draw root hroot change query.cost (fun entry => (initial entry : ℚ)) (fun entry => (physicalSource source entry.1).length + 1) ≤ _ at hc rw [FiniteQuery.cost_eq_sum] at hc apply le_trans (b := ∑ entry, selectionIndicator (entry ∈ query.keys (fun entry => (initial entry : ℚ))) * ((physicalSource source entry.1).length + 1 : ℕ)) · unfold physicalFamilyCoarseInputWork apply Finset.sum_le_sum intro entry _ apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) by_cases he : Sum.inr (Sum.inl entry) ∈ (chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root).freshKeys · have hq := hkey entry he change entry ∈ query.keys (fun entry => (initial entry : ℚ)) at hq simp only [selectionIndicator, he, hq, ite_true, le_refl] · simp only [selectionIndicator, he, ite_false] split <;> norm_num · exact hs.trans (by exact_mod_cast hc)
end Coarseend EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import OAI.Combinatorics.EditApproximation.Coarse.CoarseInputPreparationimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWorkimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
theorem physicalCoarsePreparationCost_bound {M J : ℕ} (source target : List ℕ) (H : ℕ) (hH : 100 ≤ H) (hs : Nat.size source.length ≤ H ^ 3) (ht : Nat.size target.length ≤ H ^ 3) (hsymbol : ∀ a ∈ source ++ target, Nat.size a ≤ H ^ 3) (entry : PhysicalEntry M J target.length) : physicalCoarsePreparationCost source target entry ≤ H ^ 6 * ((physicalSource source entry.1).length + 1) := by unfold physicalCoarsePreparationCost rw [physicalSource_length_eq] exact coarsePreparedSlicesWithWork_height_bound source target (physicalSourceInterval source.length entry.1).lo (physicalSourceInterval source.length entry.1).hi entry.2.lo entry.2.hi H (physicalSourceInterval source.length entry.1).ordered (physicalSourceInterval source.length entry.1).valid entry.2.ordered entry.2.valid hH hs ht hsymbol
section Coarsevariable {M J R : ℕ} [NeZero M] [NeZero R] (source target : List ℕ) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (initial : PhysicalEntry M J target.length → ℕ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
theorem physicalFamilyCoarsePreparationWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) (hH : 100 ≤ H) (hs : Nat.size source.length ≤ H ^ 3) (ht : Nat.size target.length ≤ H ^ 3) (hsymbol : ∀ a ∈ source ++ target, Nat.size a ≤ H ^ 3) : physicalFamilyCoarsePreparationWork source target N P H T S passes copies factor multiplier tau eta kappa delta initial draw bits encode root ≤ (H : ℝ) ^ 6 * physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier tau eta kappa delta initial draw bits encode root := by classical unfold physicalFamilyCoarsePreparationWork physicalFamilyCoarseInputWork rw [Finset.mul_sum] apply Finset.sum_le_sum intro entry _ have hc : (physicalCoarsePreparationCost source target entry : ℝ) ≤ (H : ℝ) ^ 6 * ((physicalSource source entry.1).length + 1 : ℕ) := by exact_mod_cast physicalCoarsePreparationCost_bound source target H hH hs ht hsymbol entry have hp := mul_le_mul_of_nonneg_left hc (show 0 ≤ selectionIndicator (Sum.inr (Sum.inl entry) ∈ (chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root).freshKeys) by unfold selectionIndicator; split <;> norm_num) exact hp.trans_eq (by ring)
end Coarseend EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import OAI.Combinatorics.EditApproximation.Coarse.CoarseInitialLabelsimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWorkimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
section Coarsevariable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B] (source target : List ℕ) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies) (depth : PhysicalEntry M J target.length → ℕ)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
/- One binary word is consumed for every threshold label actually exposed. -/
omit [NeZero B] intheorem physicalFamilyCoarseSamplingWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) (coarse : PhysicalCoarseDraw source target B depth) : physicalFamilyCoarseSamplingWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw depth bits encode root coarse ≤ (Nat.size B : ℝ) * physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth bits encode root coarse := by classical unfold physicalFamilyCoarseSamplingWork physicalFamilyMemoCoarseWork rw [Finset.mul_sum] apply Finset.sum_le_sum intro entry _ have h := coarseInitialLabelCount_le_arrayWork B (depth entry) (initialThresholdQ N) (initialLambda N) (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) have hs : 0 ≤ selectionIndicator (Sum.inr (Sum.inl entry) ∈ (chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) answer bits encode root).freshKeys) := by unfold selectionIndicator split <;> norm_num push_cast exact (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left (Nat.cast_le.mpr h) (Nat.cast_nonneg (Nat.size B))) hs).trans_eq (by ring)
end Coarseend EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import OAI.Combinatorics.EditApproximation.Refinement.PhysicalSeedTablesimport OAI.Combinatorics.EditApproximation.Coarse.CoarseGlobalSeedimport OAI.Combinatorics.EditApproximation.Geometry.StateDomainimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The clamped incoming seed table is the image of the actual completecoarse sampler. Its simultaneous initial accuracy is a derived fact. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section CoarseLaw
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (N B : ℕ) (depth : PhysicalEntry M J target.length → ℕ)
variable [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
noncomputable def physicalCoarseSeedLaw : Measure (ClampedPhysicalSeed M J target.length N) := by classical exact (coarseFullSeedMeasure B depth (fun state : PhysicalEntry M J target.length => physicalSource source state.1) (fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi)).map (physicalCoarseSeedTable source target N B depth)
instance physicalCoarseSeedLaw_probability : IsProbabilityMeasure (physicalCoarseSeedLaw source target N B depth) := by unfold physicalCoarseSeedLaw infer_instance
theorem physicalCoarseSeedLaw_failure (hN : 0 < N) (hsize : source.length + target.length ≤ N) (hell : 200 ≤ inputSmallLog N) (hB : B = (integerParameters N).B) (hM : M = (integerParameters N).M) (hJ : J = intervalTreeDepth M source.length) (hdepth : ∀ state, depth state = computedCoarseDepth N (coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi))) (bernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B => (PMF.uniformOfFintype (Fin B)).toMeasure)) : (physicalCoarseSeedLaw source target N B depth).real {seed | ¬ physicalSeedGood source target ((integerParameters N).initialFactor : ℚ) seed} < 1 / 100 := by classical have hwidth (state : PhysicalEntry M J target.length) : coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi) ≤ N := by apply max_le · exact (physicalSource_length_le source state.1).trans (by omega) · have hlen : (substring target state.2.lo state.2.hi).length ≤ target.length := by simp only [substring, List.length_drop, List.length_take] exact (Nat.sub_le _ _).trans (min_le_right _ _) exact hlen.trans (by omega) have hcount : Fintype.card (PhysicalEntry M J target.length) ≤ 2 ^ (5 * inputHeight N) := by rw [hJ, hM] exact computed_labeledEntry_card_le N source.length target.length hN (by omega) (by omega) hell have h := computed_fullSeedTable_accuracy N B depth (fun state : PhysicalEntry M J target.length => physicalSource source state.1) (fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi) hB hdepth hN hwidth hcount hell bernstein rw [physicalCoarseSeedLaw, map_measureReal_apply (measurable_of_finite _) (Set.toFinite _).measurableSet] have hevents : (physicalCoarseSeedTable source target N B depth) ⁻¹' {seed | ¬ physicalSeedGood source target ((integerParameters N).initialFactor : ℚ) seed} = {draw : PhysicalCoarseDraw source target B depth | ¬ ∀ state : PhysicalEntry M J target.length, stateEditCost (physicalSource source state.1) target state.2 ≤ coarseFullSeedTable N B depth (fun state : PhysicalEntry M J target.length => physicalSource source state.1) (fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi) draw state ∧ coarseFullSeedTable N B depth (fun state : PhysicalEntry M J target.length => physicalSource source state.1) (fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi) draw state ≤ (integerParameters N).initialFactor * stateEditCost (physicalSource source state.1) target state.2} := by ext draw apply not_congr unfold physicalSeedGood clampedSeedNat physicalCoarseSeedTable constructor · intro hg state exact ⟨(hg state).1, by exact_mod_cast (hg state).2⟩ · intro hg state exact ⟨(hg state).1, by exact_mod_cast (hg state).2⟩ rw [hevents] exact h
end CoarseLaw
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153import OAI.Combinatorics.EditApproximation.Geometry.CommonRangeSourceimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalProgramLawimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The actual bounded physical program can share one source universeacross incoming seed tables. Online coordinates include their requestedrange; group coordinates share whole-cell arrays. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
abbrev PhysicalCommonCoordinate (M J N n exponent F Q R B : ℕ) (key : PhysicalCommonKey M J N n exponent B) : Type := match key with | .inl online => Fin R → Fin online.2.val.val | .inr group => PhysicalLocalGroupArray M J N n exponent F Q R group
section Source
variable (M J N n exponent F Q R B : ℕ) [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
instance physicalCommonCoordinateFintype (key : PhysicalCommonKey M J N n exponent B) : Fintype (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by cases key <;> dsimp only [PhysicalCommonCoordinate] <;> infer_instance
instance physicalCommonCoordinateMeasurable (key : PhysicalCommonKey M J N n exponent B) : MeasurableSpace (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by cases key <;> dsimp only [PhysicalCommonCoordinate] <;> infer_instance
instance physicalCommonCoordinateSingleton (key : PhysicalCommonKey M J N n exponent B) : MeasurableSingletonClass (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by cases key <;> dsimp only [PhysicalCommonCoordinate, physicalCommonCoordinateMeasurable] <;> infer_instance
noncomputable def physicalCommonCoordinateLaw (key : PhysicalCommonKey M J N n exponent B) : Measure (PhysicalCommonCoordinate M J N n exponent F Q R B key) := match key with | .inl online => Measure.pi fun _ : Fin R => (PMF.uniformOfFintype (Fin online.2.val.val)).toMeasure | .inr group => physicalLocalGroupArrayLaw M J N n exponent F Q R group
instance physicalCommonCoordinateLaw_probability (key : PhysicalCommonKey M J N n exponent B) : IsProbabilityMeasure (physicalCommonCoordinateLaw M J N n exponent F Q R B key) := by cases key <;> dsimp only [physicalCommonCoordinateLaw, PhysicalCommonCoordinate, physicalCommonCoordinateMeasurable] <;> infer_instance
abbrev PhysicalCommonDraw := ∀ key : PhysicalCommonKey M J N n exponent B, PhysicalCommonCoordinate M J N n exponent F Q R B key
noncomputable def physicalCommonLaw : Measure (PhysicalCommonDraw M J N n exponent F Q R B) := Measure.pi (physicalCommonCoordinateLaw M J N n exponent F Q R B)
instance physicalCommonLaw_probability : IsProbabilityMeasure (physicalCommonLaw M J N n exponent F Q R B) := by unfold physicalCommonLaw infer_instance
end Source
section Selection
variable {α : Type*} [DecidableEq α] {M J : ℕ} [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T exponent H Q R B : ℕ) (tau : ℚ) (hbound : ∀ key, physicalLocalOnlineMass source target U N P F A T exponent H tau key ≤ B)
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] intheorem physicalCommonMass_positive (key : PhysicalLocalOnlineKey M J N target.length) : 0 < physicalLocalOnlineMass source target U N P F A T exponent H tau key := optimizerTriangularMass_positive _ (pow_pos (physicalLocalOnlineBandG_positive source target U N P F A T exponent H tau key) 80)
def physicalCommonSelectedOnlineKey (online : PhysicalLocalOnlineKey M J N target.length) : CommonRangeKey (PhysicalLocalOnlineKey M J N target.length) B := (online, positiveDrawRangeOfLE B (physicalLocalOnlineMass source target U N P F A T exponent H tau online) (physicalCommonMass_positive source target U N P F A T exponent H tau online) (hbound online))
def physicalCommonSelectedKey (key : PhysicalLocalProgramKey M J N target.length exponent) : PhysicalCommonKey M J N target.length exponent B := match key with | .inl online => .inl (physicalCommonSelectedOnlineKey source target U N P F A T exponent H B tau hbound online) | .inr group => .inr group
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] intheorem physicalCommonSelectedKey_injective : Function.Injective (physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound) := by intro left right heq cases left with | inl left => cases right with | inl right => exact congrArg Sum.inl (congrArg Prod.fst (Sum.inl.inj heq)) | inr right => exact False.elim (Sum.inl_ne_inr heq) | inr left => cases right with | inl right => exact False.elim (Sum.inr_ne_inl heq) | inr right => exact congrArg Sum.inr (Sum.inr.inj heq)
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] intheorem physicalCommonSelectedOnlineKey_range (online : PhysicalLocalOnlineKey M J N target.length) : (physicalCommonSelectedOnlineKey source target U N P F A T exponent H B tau hbound online).2.val.val = physicalLocalOnlineMass source target U N P F A T exponent H tau online := by exact positiveDrawRangeOfLE_val B _ (physicalCommonMass_positive source target U N P F A T exponent H tau online) (hbound online)
def physicalCommonCoordinateImage (key : PhysicalLocalProgramKey M J N target.length exponent) : PhysicalCommonCoordinate M J N target.length exponent F Q R B (physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound key) → PhysicalLocalProgramCoordinate (R := R) source target U N P F A T exponent H Q tau key := match key with | .inl online => fun array time => Fin.cast (physicalCommonSelectedOnlineKey_range source target U N P F A T exponent H B tau hbound online) (array time) | .inr _ => id
def physicalCommonSample (draw : PhysicalCommonDraw M J N target.length exponent F Q R B) : PhysicalLocalProgramDraw (R := R) source target U N P F A T exponent H Q tau := fun key => physicalCommonCoordinateImage source target U N P F A T exponent H Q R B tau hbound key (draw (physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound key))
theorem physicalCommonSample_law : (physicalCommonLaw M J N target.length exponent F Q R B).map (physicalCommonSample source target U N P F A T exponent H Q R B tau hbound) = physicalLocalProgramDrawLaw (R := R) source target U N P F A T exponent H Q tau := by have h := finite_pi_restrict_image_map (physicalCommonCoordinateLaw M J N target.length exponent F Q R B) (physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound) (physicalCommonSelectedKey_injective source target U N P F A T exponent H B tau hbound) (physicalCommonCoordinateImage source target U N P F A T exponent H Q R B tau hbound) (fun _ => measurable_of_finite _) refine h.trans ?_ unfold physicalLocalProgramDrawLaw congr 1 funext key cases key with | inl online => exact finite_uniform_array_cast R _ _ (physicalCommonSelectedOnlineKey_range source target U N P F A T exponent H B tau hbound online) | inr group => exact Measure.map_id
end Selection
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899import OAI.Combinatorics.EditApproximation.Refinement.PhysicalUnskippedComparisonimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegretimport OAI.Combinatorics.EditApproximation.Refinement.StageComparisonEnergyimport OAI.Combinatorics.EditApproximation.Refinement.ComputedBandSpacing
namespace OAI
/-! Non-bad, low-velocity comparison children belong to an actual unskipped cell band. -/
namespace EditApproximation
open Finset
section Node
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (hM : 0 < M) (U : PhysicalEntry M J target.length → ℕ) (N P : ℕ) (A : ℚ) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) (hMeq : M = (integerParameters N).M) (hPeq : P = (integerParameters N).P) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (T : ℕ) (hT : 0 < T) (node : PhysicalNode M J) (hbelow : node.1.val < J) (q : TargetInterval target.length) (hc : 0 < stateEditCost (physicalSource source node) target q)
local notation "F" => inputSmallLog Nlocal notation "parent" => physicalSourceInterval source.length nodelocal notation "b" => (2 ^ Nat.log 2 (stateEditCost (physicalSource source node) target q) : ℕ)local notation "r" => roundInterval (seedGridSpacing b P) qlocal notation "action" => comparisonChildren source target hM P hP parent q hclocal notation "child" => physicalBandChildMassTable source target U N P F A T node hbelowlocal notation "childR" => fun i s => (child i s : ℝ)local notation "initial" => physicalBandChildInitial source target U N P F A node hbelowlocal notation "tau" => RationalParameters.tau (rationalParameters (inputSmallLog N))local notation "theta" => RationalParameters.theta (rationalParameters (inputSmallLog N))local notation "thetaExponent" => 40 * smallLogExponent N
include hN hell hMeq hPeq hsize hA hseed hT in theorem physicalComparison_unskipped (hscale : 2 * (refinementFactor A F : ℝ) ≤ P) (hMP : 4 * (M : ℝ) / P ≤ 1) (hnonempty : wideActionList M parent r b P ≠ []) (hvelocity : |rationalStateGap (physicalSource source node) target r / rationalWideActionMinimum parent r b P hnonempty child| ≤ 1 - tau) (hKsmall : comparisonActionCurvature source target parent r action childR ≤ b / heightQuarterRoot N) (hGsmall : comparisonActionMass action childR - wideActionMinimum parent r b P hnonempty childR ≤ b / heightQuarterRoot N) : ∃ member : UnskippedBand source target parent b P thetaExponent tau F child initial, member ∈ physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent tau (targetCell (theta * b) r) ∧ member.center = r ∧ action ∈ member.actions := by have hF : 1 ≤ F := Nat.one_le_two_pow have hell2 : 2 ≤ F := by have h : 2 ≤ (2 : ℕ) ^ 1000 := by simpa only [pow_one] using pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (by decide : 1 ≤ 1000) exact h.trans hell have hspec := comparisonChildren_spec source target hM P hP parent q hc have hrep := stageRounded_representative_mem source target U N P F A hsize hP hF hA hseed node q hc have hdyadic := cost_dyadicScale _ _ hc le_rfl have hcR : (stateEditCost (physicalSource source node) target q : ℝ) ≤ 2 * (b : ℝ) := by exact_mod_cast hdyadic.2.2.le have hcost := comparisonChildren_cost_bound source target hM P hP parent q hc change (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤ (1 + 4 * (M : ℝ) / P) * stateEditCost (physicalSource source node) target q at hcost have hcostSum : (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤ 4 * b := by have h := mul_le_mul_of_nonneg_right hMP (Nat.cast_nonneg (α := ℝ) (stateEditCost (physicalSource source node) target q)) nlinarith only [hcost, hcR, h] have ha : (1 : ℝ) ≤ refinementFactor A F := by simpa only [Rat.cast_one] using (Rat.cast_le (K := ℝ)).mpr (refinementFactor_spec A F (by omega)).1 have hlower := stageWarmupMass_child_lower source target hM U N P F A hsize hP hF hA hseed T hT node hbelow have hupper (i : Fin M) : (child i (action i) : ℝ) ≤ 2 * F * stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) := by dsimp only [physicalBandChildMassTable] have h := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT (physicalChild node hbelow i, action i) simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using (Rat.cast_le (K := ℝ)).mpr (h.2.2.1.trans h.2.2.2) have hpositive := (stageComparison_positive_movement source target hM U N P F A hsize hP hF hA hseed T hT node q hc hscale).1 have hband := computed_comparison_band_mem source target N hN hell hM hMeq parent r action hspec.1 hnonempty child (refinementFactor A F : ℝ) ha hlower hupper hcostSum hpositive hspec.2.1 hspec.2.2.2.1 hvelocity hKsmall hGsmall have hnum := computed_band_basic_constants N hell2 have hspacing := computed_band_spacing_dominates N hN hell rw [← hMeq, ← hPeq, computed_theta_dyadic] at hspacing rw [computed_theta_dyadic] at hnum have hmember := physical_comparison_unskipped source target hM U N P F A hsize hP hF hA hseed T node hbelow b thetaExponent (Nat.two_pow_pos _) ⟨_, rfl⟩ ⟨_, hPeq.trans (computed_P_dyadic N)⟩ tau hnum.1 hnum.2.2.1 hnum.2.2.2.1 hnum.2.2.2.2 hspacing r hrep action (by simpa only [← computed_theta_dyadic, physicalSource] using hband) (by exact_mod_cast hcostSum) simpa only [physicalNodeCellBands, computed_theta_dyadic] using hmember
end Node
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFinalAccuracyimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLawimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Conditional accuracy of coarse sampling, adaptive median passes and the final fresh query. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Conditional
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (source target : List α) (N P T S H B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] (depth : PhysicalEntry M J target.length → ℕ)
noncomputable def wholeFinalAnswer (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : ℕ := finalProgramAnswer (R := R) source target N P T S H (finalTargetState target.length) pair
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] intheorem wholeFinalAnswer_equal (heq : source = target) (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : wholeFinalAnswer (R := R) source target N P T S H pair = 0 := by apply finalProgramAnswer_equal simpa only [finalTargetState, substring, List.take_length, List.drop_zero] using heq
theorem physical_conditional_accuracy (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) (hsize : source.length + target.length ≤ N) (hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length) (hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T) (hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N) (hB : B = (integerParameters N).B) (hdepth : ∀ state, depth state = computedCoarseDepth N (coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi))) (coarseBernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B => (PMF.uniformOfFintype (Fin B)).toMeasure)) (groupBernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length, FiniteBernsteinInput (Measure.pi fun _ : Fin (groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) => (PMF.uniformOfFintype (Fin M)).toMeasure)) (epsilon : ℝ) (hepsilon : 0 < epsilon) (haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) : (2 / 3 : ℝ) ≤ (finalProgramLaw (R := R) source target N P T S H (physicalCoarseSeedLaw source target N B depth)).real {pair | EditDistortion.edit source target ≤ wholeFinalAnswer (R := R) source target N P T S H pair ∧ (wholeFinalAnswer (R := R) source target N P T S H pair : ℝ) ≤ (1 + epsilon) * EditDistortion.edit source target} := by classical have hsmall : 256 ≤ (2 : ℕ) ^ 1000 := by have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (by decide : 8 ≤ 1000) norm_num only [show (2 : ℕ) ^ 8 = 256 by norm_num] at h exact h have hcut : 200 ≤ inputSmallLog N := by omega have hinitial := physicalCoarseSeedLaw_failure source target N B depth hN hsize hcut hB hMeq hJeq hdepth coarseBernstein have h := finalProgram_accuracy (R := R) source target N P T S H hN hell hMeq hJeq hPeq hTeq hSeq hHeq hsize groupBernstein (physicalCoarseSeedLaw source target N B depth) hinitial.le (finalTargetState target.length) epsilon hepsilon haccuracy apply (by norm_num : (2 / 3 : ℝ) ≤ 4 / 5).trans simpa only [wholeFinalAnswer, stateEditCost, finalTargetState, substring, List.take_length, List.drop_zero] using h
end Conditional
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165import OAI.Combinatorics.EditApproximation.Refinement.PhysicalParentDrawimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalResampledRegret
namespace OAI
/-!# Conditional expected regret in a fixed child environment
Finite Bernstein bounds control the parent product draws. Agreement ofdeeper selection functions fixes all child histories by locality, andlist membership connects the sampled actions to the refinement recurrence.-/
namespace EditApproximation
open Finset MeasureTheory ProbabilityTheory
abbrev BandParentSpace (R M b F Q K : ℕ) := ParentRandomSpace R (optimizerTriangularMass K) M (groupDyadicScales M b F).length (fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))
noncomputable def bandParentLaw (R M b F Q K : ℕ) [NeZero M] [NeZero (optimizerTriangularMass K)] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] : Measure (BandParentSpace R M b F Q K) := parentDrawLaw R (optimizerTriangularMass K) M (groupDyadicScales M b F).length (fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))
theorem physical_conditional_node_regret {α : Type*} [DecidableEq α] (source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N) {M J P F b Q thetaExponent R H G K : ℕ} [NeZero M] [NeZero R] [NeZero (optimizerTriangularMass K)] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (hM : 0 < M) (hMeq : M = (integerParameters N).M) (hPeq : P = (integerParameters N).P) (hFeq : F = inputSmallLog N) (eb : ℕ) (hbeq : b = 2 ^ eb) (hQeq : Q = inputSmallLog N ^ 80) (hthetaeq : thetaExponent = 40 * smallLogExponent N) (hHeq : H = inputHeight N) (hH : 4 ≤ H) (U : PhysicalEntry M J target.length → ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (T : ℕ) (hT : 0 < T) (delta η κ : ℚ) (hdelta : 0 < delta) (hη : 0 < η) (hκ : 0 ≤ κ) (hκhalf : κ ≤ 1 / 2) (reference : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (hbelow : node.1.val < J) (hleaf : ¬ (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (cell : ℕ × ℕ) (hnonempty : physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent (rationalParameters F).tau cell ≠ []) (specified : UnskippedBand source target (physicalSourceInterval source.length node) b P thetaExponent (rationalParameters F).tau F (physicalBandChildMassTable source target U N P F A T node hbelow) (physicalBandChildInitial source target U N P F A node hbelow)) (hspecified : specified ∈ physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent (rationalParameters F).tau cell) (hrep : (b, specified.center) ∈ stageRepresentatives source target U N P F A node) (q : TargetInterval target.length) (hb : (b : ℝ) ≤ stateEditCost (physicalSource source node) target q) (comparison : Fin M → TargetInterval target.length) (hc : comparison ∈ specified.actions) (hG : G = H + (bandCoordinates specified.actions.toFinset).card + 2) (hK : K = G ^ 80) (htau : 0 < (rationalParameters F).tau) (hηrange : (η : ℝ) * (2 * (delta : ℝ) + 8 * ((128 * F : ℚ) : ℝ) * (((2 : ℚ) ^ (-(thetaExponent : ℤ))) : ℝ)) ≤ (κ : ℝ)) (herror : 2 * (rationalParameters F).gamma + 512 * (128 * F : ℚ) * F * (2 : ℚ) ^ (-(thetaExponent : ℤ)) ≤ κ * delta) (realizations : BandParentSpace R M b F Q K → PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (hgroupsFixed : ∀ ω label, node.1.val < label.1.val → (realizations ω).groups label = reference.groups label) (honlineFixed : ∀ ω label, node.1.val < label.1.val → (realizations ω).online label = reference.online label) (honlineWire : ∀ ω t, sharedBandRationalAction specified.center (physicalBandOnlineDraw source target U N P F A T delta reference node hbelow b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t (parentOnlineDraw ω t)) ∈ physicalNodeOnline source target U N P F A T delta (realizations ω) node hbelow t q) (hgroupWire : ∀ ω t, (physicalNodeSelectedGroup source target U N P F A T delta reference node hbelow b thetaExponent Q (rationalParameters F).tau cell hnonempty t (parentGroupDraw ω t)).rationalAction ∈ physicalNodeGroups source target U N P F A T delta (realizations ω) node hbelow t) (bernstein : ∀ scale : Fin (groupDyadicScales M b F).length, FiniteBernsteinInput (Measure.pi fun _ : Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) => (PMF.uniformOfFintype (Fin M)).toMeasure)) (S : ℕ) : let c : ℝ := stateEditCost (physicalSource source node) target q let charge : ℝ := ((128 * F : ℚ) : ℝ) * targetEndpointDistance q specified.center let clipped := physicalComparisonClipped source target U N P F A T delta reference node hbelow comparison (∫ ω, (∑ t ∈ range S, (max c (physicalRefinement source target U N P F A T delta (realizations ω) node (t + 1) q : ℝ) - charge - clipped (t + 1))) ∂bandParentLaw R M b F Q K) ≤ ((∑ child, specified.envelope child : ℚ) : ℝ) * (Real.log (bandCoordinates specified.actions.toFinset).card / (η : ℝ) + 2 * (κ : ℝ) + (S : ℝ) / (H : ℝ) ^ 3) + 2 * (delta : ℝ) * c + 2 * S * (1 / (H : ℝ) ^ 4) * F * c := by let c : ℝ := stateEditCost (physicalSource source node) target q let charge : ℝ := ((128 * F : ℚ) : ℝ) * targetEndpointDistance q specified.center let history := physicalBandHistory source target U N P F A T delta reference node hbelow let clipped := physicalComparisonClipped source target U N P F A T delta reference node hbelow comparison let sample := fun t integer => physicalBandOnlineDraw source target U N P F A T delta reference node hbelow b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t integer let failure := fun t draw => physicalNodeGroupFailure source target U N P F A T delta reference node hbelow b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma let crossing := firstCrossing specified.actions.toFinset S (fun t => bandActionCost charge (fun t coordinate => (history t coordinate : ℝ)) (t + 1)) c let prefixPayoff := fun t integer => sampledPrefixRegret charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ)) clipped (fun j => sample j integer) t let regret := fun ω t => max c (physicalRefinement source target U N P F A T delta (realizations ω) node (t + 1) q : ℝ) - charge - clipped (t + 1) let budget := ((∑ child, specified.envelope child : ℚ) : ℝ) * (Real.log (bandCoordinates specified.actions.toFinset).card / (η : ℝ) + 2 * (κ : ℝ) + (S : ℝ) / (H : ℝ) ^ 3) have hpoint (ω : BandParentSpace R M b F Q K) : (∑ t ∈ range S, regret ω t) ≤ (∑ t ∈ range crossing, prefixPayoff t (parentOnlineDraw ω t)) + 2 * (delta : ℝ) * c + (2 * (F : ℝ) * c) * ∑ t ∈ range S, (if failure t (parentGroupDraw ω t) then (1 : ℝ) else 0) := by have hdet := physicalNode_resampled_regret source target U N P F A T delta reference (realizations ω) node hbelow hM hsize hP hF hA hseed hT (hgroupsFixed ω) (honlineFixed ω) hleaf b thetaExponent Q (rationalParameters F).tau (rationalParameters F).gamma κ htau hdelta hκ hκhalf cell hnonempty specified hspecified hrep q hb comparison hc (fun t => sample t (parentOnlineDraw ω t)) (fun t => physicalBandOnlineDraw_mem source target U N P F A T delta reference node hbelow b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t (parentOnlineDraw ω t)) (fun t => parentGroupDraw ω t) (honlineWire ω) (hgroupWire ω) herror S have hprefixEq : (∑ t ∈ range crossing, sampledPrefixRegret charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ)) clipped (fun j => sample j (parentOnlineDraw ω j)) t) = ∑ t ∈ range crossing, prefixPayoff t (parentOnlineDraw ω t) := by apply sum_congr rfl intro t _ exact sampledPrefixRegret_current_sample_congr charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ)) clipped (fun j => sample j (parentOnlineDraw ω j)) (fun j => sample j (parentOnlineDraw ω t)) t rfl change (∑ t ∈ range S, regret ω t) ≤ (∑ t ∈ range crossing, sampledPrefixRegret charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ)) clipped (fun j => sample j (parentOnlineDraw ω j)) t) + 2 * (delta : ℝ) * c + (2 * (F : ℝ) * c) * ∑ t ∈ range S, (if failure t (parentGroupDraw ω t) then (1 : ℝ) else 0) at hdet rw [hprefixEq] at hdet exact hdet have hprefix : (∑ t ∈ range crossing, uniformMean (prefixPayoff t)) ≤ budget := by exact physicalBand_prefix_expected_regret source target U N P F A T delta reference node hbelow b thetaExponent (rationalParameters F).tau specified.center hM hsize hP hF hA hseed hT htau hdelta.le specified.nonempty crossing S H G K (firstCrossing_le _ _ _ _) η κ hG hK comparison hc hH hη hκ hκhalf hηrange charge have hfailure t (_ht : t < S) : (groupSharedDrawLaw (M := M) (fun scale : Fin (groupDyadicScales M b F).length => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))).real {draw | failure t draw = true} ≤ 1 / (H : ℝ) ^ 4 := by rw [hHeq] exact physicalNode_groupFailure_probability source target N hN hell hM hMeq hPeq hFeq eb hbeq hQeq hthetaeq U A hsize hP hA hseed T hT delta reference node hbelow t cell bernstein have hbound := parentDrawLaw_firstCrossing_bound R (optimizerTriangularMass K) M (groupDyadicScales M b F).length (fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) S crossing regret prefixPayoff failure budget (2 * (delta : ℝ) * c) (2 * (F : ℝ) * c) (1 / (H : ℝ) ^ 4) (mul_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) (Nat.cast_nonneg F)) (Nat.cast_nonneg _)) hpoint hprefix hfailure dsimp only change (∫ ω, (∑ t ∈ range S, regret ω t) ∂bandParentLaw R M b F Q K) ≤ budget + 2 * (delta : ℝ) * c + 2 * S * (1 / (H : ℝ) ^ 4) * F * c have hchargeEq : (2 * (F : ℝ) * c) * (S : ℝ) * (1 / (H : ℝ) ^ 4) = 2 * S * (1 / (H : ℝ) ^ 4) * F * c := by ring exact hbound.trans_eq (by rw [hchargeEq])
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256import OAI.Combinatorics.EditApproximation.Refinement.PhysicalBoundsAllSeedsimport Mathlib.Data.Rat.Lemmas
namespace OAI
/-! The actual returned values have one additional fixed denominator per tree level. -/
namespace EditApproximation
open Finset
theorem rat_den_add_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) : (x + y).den ∣ D := (Rat.add_den_dvd_lcm x y).trans (Nat.lcm_dvd hx hy)
theorem rat_den_min_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) : (min x y).den ∣ D := by by_cases h : x ≤ y · simpa only [min_eq_left h] using hx · simpa only [min_eq_right (le_of_not_ge h)] using hy
theorem rat_den_max_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) : (max x y).den ∣ D := by by_cases h : x ≤ y · simpa only [max_eq_right h] using hy · simpa only [max_eq_left (le_of_not_ge h)] using hx
theorem rat_den_sum_dvd {ι : Type*} (s : Finset ι) (f : ι → ℚ) (D : ℕ) (hf : ∀ i ∈ s, (f i).den ∣ D) : (∑ i ∈ s, f i).den ∣ D := by classical induction s using Finset.induction_on with | empty => simp only [sum_empty, Rat.den_zero, one_dvd] | @insert i s hi ih => rw [sum_insert hi] exact rat_den_add_dvd (hf i (mem_insert_self _ _)) (ih fun j hj => hf j (mem_insert_of_mem hj))
theorem rationalMinimum_den_dvd (fallback : ℚ) (values : List ℚ) (D : ℕ) (hfallback : fallback.den ∣ D) (hvalues : ∀ v ∈ values, v.den ∣ D) : (rationalMinimum fallback values).den ∣ D := by induction values with | nil => exact hfallback | cons v rest ih => exact rat_den_min_dvd (hvalues v (by simp)) (ih fun w hw => hvalues w (by simp [hw]))
theorem rationalActualWideActions_connection_den {nx ny M : ℕ} (parent : TargetInterval nx) (representatives : List (ℕ × TargetInterval ny)) (P : ℕ) (action : PhysicalRationalAction M ny) (ha : action ∈ rationalActualWideActions parent representatives P) : action.connection.den = 1 := by obtain ⟨br, _, hmem⟩ := List.mem_flatMap.mp ha obtain ⟨states, _, rfl⟩ := List.mem_map.mp hmem exact Rat.den_natCast _
theorem rationalActionValue_den_dvd {Parent Child : Type*} {M D : ℕ} (distance : Parent → Parent → ℚ) (L : ℚ) (child : Child → ℚ) (q : Parent) (action : RationalBellmanAction Parent Child M) (hdistance : (distance q action.center).den = 1) (hL : L.den = 1) (ha : action.connection.den = 1) (hchild : ∀ i, (child (action.childState i)).den ∣ D) : (rationalActionValue distance L child q action).den ∣ D := by unfold rationalActionValue apply rat_den_add_dvd · apply rat_den_add_dvd · have h := Rat.mul_den_dvd L (distance q action.center) rw [hL, hdistance, one_mul] at h exact h.trans (one_dvd D) · rw [ha] exact one_dvd D · exact rat_den_sum_dvd univ _ D (fun i _ => hchild i)
theorem stageInitial_den_one {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (state : PhysicalEntry M J target.length) : (stageInitial source target U N P F A state).den = 1 := by have hmin (fallback : ℚ) (values : List ℚ) (hf : fallback.den = 1) (hv : ∀ v ∈ values, v.den = 1) : (rationalMinimum fallback values).den = 1 := Nat.eq_one_of_dvd_one (rationalMinimum_den_dvd fallback values 1 (by rw [hf]) (fun v h => by rw [hv v h])) unfold stageInitial physicalInitialTable dsimp only split_ifs · exact Rat.den_natCast _ · unfold localInitialConeTable split_ifs · exact Rat.den_zero · apply hmin · simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using Rat.den_natCast ((32 * F + 1) * N) · intro v hv obtain ⟨r, _, rfl⟩ := List.mem_map.mp hv unfold initialConeValue scaledSeedValue apply Nat.eq_one_of_dvd_one apply rat_den_add_dvd · apply rat_den_max_dvd · simp only [Rat.den_natCast, dvd_refl] · have heq : rationalStateGap (physicalSource source state.1) target r = (((r.hi : ℤ) - r.lo - (physicalSource source state.1).length : ℤ) : ℚ) := by simp only [rationalStateGap, Int.cast_sub, Int.cast_natCast] rw [heq, ← Int.cast_abs] simp only [Rat.den_intCast, dvd_refl] · have heq : (32 * F : ℚ) * targetEndpointDistance state.2 r = ((32 * F * targetEndpointDistance state.2 r : ℕ) : ℚ) := by push_cast; rfl rw [heq, Rat.den_natCast]
theorem rationalPhysicalBellman_den_dvd {α : Type*} {M J D : ℕ} (source target : List α) (P F : ℕ) (initial : PhysicalEntry M J target.length → ℚ) (representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length)) (hinitial : ∀ state, (initial state).den ∣ D) (value : PhysicalEntry M J target.length → ℚ) (hvalue : ∀ state, (value state).den ∣ D) (state : PhysicalEntry M J target.length) : (rationalPhysicalBellman source target P (128 * F) initial representatives value state).den ∣ D := by unfold rationalPhysicalBellman dsimp only split_ifs · exact hinitial state · apply rationalMinimum_den_dvd _ _ D (hinitial state) intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv exact rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _) (by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F)) (rationalActualWideActions_connection_den _ _ _ action ha) (fun i => hvalue _) · exact hinitial state
theorem stageWarmup_den_one {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) : (stageWarmup source target U N P F A t state).den = 1 := by induction t generalizing state with | zero => exact stageInitial_den_one source target U N P F A state | succ t ih => apply Nat.eq_one_of_dvd_one exact rationalPhysicalBellman_den_dvd source target P F _ _ (fun s => by rw [stageInitial_den_one source target U N P F A s]) _ (fun s => by change (stageWarmup source target U N P F A t s).den ∣ 1 rw [ih s]) state
theorem rat_inverse_shift_den_dvd (m : ℕ) (hm : 0 < m) : (1 / (1 + 1 / (m : ℚ))).den ∣ m + 1 := by have hmp : (0 : ℚ) < m := by exact_mod_cast hm have heq : (1 / (1 + 1 / (m : ℚ))) = (m : ℚ) / (m + 1 : ℕ) := by push_cast field_simp rw [heq] have h : (((m : ℚ) / (m + 1 : ℕ)).den : ℤ) ∣ (m + 1 : ℕ) := by simpa only [Rat.divInt_eq_div, Int.cast_natCast] using Rat.den_dvd (m : ℤ) (m + 1 : ℕ) exact Int.natCast_dvd_natCast.mp h
theorem rationalRefinementUpdate_den_dvd (m D : ℕ) (hm : 0 < m) (cone : ℚ) (online : Option ℚ) (hcone : cone.den ∣ D) (honline : ∀ v, online = some v → v.den ∣ D) : (rationalRefinementUpdate (1 / (m : ℚ)) cone online).den ∣ D * (m + 1) := by have hstep : D ∣ D * (m + 1) := dvd_mul_right _ _ cases online with | none => exact hcone.trans hstep | some v => apply rat_den_min_dvd (hcone.trans hstep) apply rat_den_max_dvd _ ((honline v rfl).trans hstep) rw [div_eq_mul_one_div] exact (Rat.mul_den_dvd cone _).trans (Nat.mul_dvd_mul hcone (rat_inverse_shift_den_dvd m hm))
theorem rationalOnlineMinimum_den_dvd (values : List ℚ) (D : ℕ) (hvalues : ∀ v ∈ values, v.den ∣ D) (v : ℚ) (heq : rationalOnlineMinimum values = some v) : v.den ∣ D := by cases values with | nil => cases heq | cons first rest => have hv : rationalMinimum first rest = v := Option.some.inj heq rw [← hv] exact rationalMinimum_den_dvd first rest D (hvalues first (by simp)) (fun w hw => hvalues w (by simp [hw]))
theorem rationalWideStep_den_dvd {nx ny M D : ℕ} (parent : TargetInterval nx) (representatives : List (ℕ × TargetInterval ny)) (P F m : ℕ) (hm : 0 < m) (initial : TargetInterval ny → ℚ) (hinitial : ∀ q, (initial q).den ∣ D) (old current : Fin M × TargetInterval ny → ℚ) (hold : ∀ is, (old is).den ∣ D) (hcurrent : ∀ is, (current is).den ∣ D) (groups online : List (PhysicalRationalAction M ny)) (hgroups : ∀ a ∈ groups, a ∈ rationalActualWideActions parent representatives P) (honline : ∀ a ∈ online, a ∈ rationalActualWideActions parent representatives P) (q : TargetInterval ny) : (rationalWideStep parent representatives P initial (128 * F) (1 / (m : ℚ)) old current groups online q).den ∣ D * (m + 1) := by have hvalue (child : Fin M × TargetInterval ny → ℚ) (hchild : ∀ is, (child is).den ∣ D) (action : PhysicalRationalAction M ny) (ha : action ∈ rationalActualWideActions parent representatives P) : (rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F) child q action).den ∣ D := rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _) (by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F)) (rationalActualWideActions_connection_den _ _ _ action ha) (fun i => hchild _) unfold rationalWideStep apply rationalRefinementUpdate_den_dvd m D hm · unfold rationalWideStepCone rationalBellman apply rationalMinimum_den_dvd · apply rationalMinimum_den_dvd _ _ D (hinitial q) intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv exact hvalue old hold action ha · intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv exact hvalue current hcurrent action (hgroups action ha) · intro v hv apply rationalOnlineMinimum_den_dvd _ D _ v hv intro w hw obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hw exact hvalue current hcurrent action (honline action ha)
theorem physicalRefinement_den_dvd {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T ell : ℕ) (hell : 0 < ell) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : (physicalRefinement source target U N P F A T (1 / (ell : ℚ) ^ 10) choices node t q).den ∣ (ell ^ 10 + 1) ^ (J - node.1.val) := by have hdelta : (1 / (ell : ℚ) ^ 10) = 1 / ((ell ^ 10 : ℕ) : ℚ) := by rw [Nat.cast_pow] by_cases hbelow : node.1.val < J · by_cases hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1 · rw [physicalRefinement_at_terminal source target U N P F A T _ choices node (Or.inr hleaf), stageInitial_den_one source target U N P F A] exact one_dvd _ · cases t with | zero => rw [physicalRefinement_zero source target U N P F A T _ choices node q, stageWarmup_den_one source target U N P F A] exact one_dvd _ | succ t => rw [physicalRefinement_succ source target U N P F A T _ choices node hbelow hleaf] dsimp only have hheight : J - node.1.val = (J - (node.1.val + 1)) + 1 := by omega rw [hheight] conv_rhs => rw [pow_succ] rw [hdelta] apply rationalWideStep_den_dvd _ _ P F (ell ^ 10) (pow_pos hell 10) · intro r rw [stageInitial_den_one source target U N P F A] exact one_dvd _ · intro is simpa only [Nat.cast_pow, physicalChild] using physicalRefinement_den_dvd source target U N P F A T ell hell choices (physicalChild node hbelow is.1) t is.2 · intro is simpa only [Nat.cast_pow, physicalChild] using physicalRefinement_den_dvd source target U N P F A T ell hell choices (physicalChild node hbelow is.1) (t + 1) is.2 · exact choices.groups_mem node _ (t + 1) · exact choices.online_mem node _ (t + 1) q · rw [physicalRefinement_at_terminal source target U N P F A T _ choices node (Or.inl hbelow), stageInitial_den_one source target U N P F A] exact one_dvd _termination_by J - node.1.valdecreasing_by all_goals unfold physicalChild dsimp only omega
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240import OAI.Combinatorics.EditApproximation.Refinement.PhysicalWarmupimport OAI.Combinatorics.EditApproximation.Geometry.DependencyExpansionimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Concrete table requests and their dependency order. A single tableindex identifies the end of warmup with refinement time zero. Copy labelsremain part of a request but do not reset its dependency rank. -/
namespace EditApproximation
namespace PhysicalTableRequest
variable {M J ny : ℕ}
theorem refinement_zero_eq_warmup (pass copy : ℕ) (node : PhysicalNode M J) (T : ℕ) (state : TargetInterval ny) : refinement pass copy node T 0 state = warmup pass copy node T state := by simp only [refinement, warmup, Nat.add_zero]
def changeCopy (request : PhysicalTableRequest M J ny) (copy : ℕ) : PhysicalTableRequest M J ny := { request with copy := copy }
@[simp] theorem rank_changeCopy (T S : ℕ) (request : PhysicalTableRequest M J ny) (copy : ℕ) : rank T S (changeCopy request copy) = rank T S request := rfl
@[simp] theorem remainingDepth_changeCopy (request : PhysicalTableRequest M J ny) (copy : ℕ) : remainingDepth (changeCopy request copy) = remainingDepth request := rfl
@[simp] theorem warmup_rank (pass copy : ℕ) (node : PhysicalNode M J) (T S j : ℕ) (state : TargetInterval ny) : rank T S (warmup pass copy node j state) = pass * (T + S + 1) + j := rfl
@[simp] theorem refinement_rank (pass copy : ℕ) (node : PhysicalNode M J) (T S t : ℕ) (state : TargetInterval ny) : rank T S (refinement pass copy node T t state) = pass * (T + S + 1) + (T + t) := rfl
theorem remainingDepth_le_of_no_ancestor (first second : PhysicalTableRequest M J ny) (hnode : first.node.1.val ≤ second.node.1.val) : second.remainingDepth ≤ first.remainingDepth := Nat.sub_le_sub_left hnode J
theorem remainingDepth_lt_of_descendant (first second : PhysicalTableRequest M J ny) (hnode : first.node.1.val < second.node.1.val) : second.remainingDepth < first.remainingDepth := by have hsecond : second.node.1.val ≤ J := Nat.le_of_lt_succ second.node.1.isLt unfold remainingDepth omega
theorem sameIndexChild_progress (T S : ℕ) (request : PhysicalTableRequest M J ny) (hbelow : request.node.1.val < J) (i : Fin M) (state : TargetInterval ny) : (sameIndexChild request hbelow i state).remainingDepth < request.remainingDepth ∧ rank T S (sameIndexChild request hbelow i state) ≤ rank T S request := by constructor · unfold remainingDepth sameIndexChild physicalChild dsimp only omega · exact le_rfl
theorem rank_lt_same_pass (T S : ℕ) (first second : PhysicalTableRequest M J ny) (hpass : second.pass = first.pass) (hindex : second.index < first.index) : rank T S second < rank T S first := by unfold rank rw [hpass] exact Nat.add_lt_add_left hindex _
/-- A warmup predecessor lies at the physical child and at the precedingunified table index. -/theorem warmup_previous_child_progress (pass copy T S j : ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J) (i : Fin M) (state previousState : TargetInterval ny) (hj : 0 < j) : (warmup pass copy (physicalChild node hbelow i) (j - 1) previousState).remainingDepth < (warmup pass copy node j state).remainingDepth ∧ rank T S (warmup pass copy (physicalChild node hbelow i) (j - 1) previousState) < rank T S (warmup pass copy node j state) := by constructor · unfold remainingDepth warmup physicalChild dsimp only omega · dsimp only [rank, warmup] omega
/-- Old refinement values and all optimistic-history values havestrictly smaller rank, even if their copy label changes. -/theorem refinement_history_progress (pass copy previousCopy T S t s : ℕ) (node previousNode : PhysicalNode M J) (state previousState : TargetInterval ny) (hnode : node.1.val ≤ previousNode.1.val) (hs : s < t) : (refinement pass previousCopy previousNode T s previousState).remainingDepth ≤ (refinement pass copy node T t state).remainingDepth ∧ rank T S (refinement pass previousCopy previousNode T s previousState) < rank T S (refinement pass copy node T t state) := by constructor · exact Nat.sub_le_sub_left hnode J · simp only [refinement_rank] omega
theorem refinement_history_child_progress (pass copy T S t s : ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J) (i : Fin M) (state previousState : TargetInterval ny) (hs : s < t) : (refinement pass copy (physicalChild node hbelow i) T s previousState).remainingDepth < (refinement pass copy node T t state).remainingDepth ∧ rank T S (refinement pass copy (physicalChild node hbelow i) T s previousState) < rank T S (refinement pass copy node T t state) := by constructor · unfold remainingDepth refinement physicalChild dsimp only omega · dsimp only [rank, refinement] omega
/-- A previous pass can request any of its warmup/refinement indices.The added one in the pass stride makes its last index strictly earlierthan the next pass's first index. -/theorem rank_lt_previous_pass (T S : ℕ) (first second : PhysicalTableRequest M J ny) (hpass : second.pass < first.pass) (hindex : second.index ≤ T + S) : rank T S second < rank T S first := by have hblock : second.pass * (T + S + 1) + second.index < (second.pass + 1) * (T + S + 1) := by nlinarith only [hindex] have hnext := Nat.mul_le_mul_right (T + S + 1) (Nat.succ_le_of_lt hpass) exact hblock.trans_le (hnext.trans (Nat.le_add_right _ _))
theorem previous_pass_progress (T S : ℕ) (first second : PhysicalTableRequest M J ny) (hpass : second.pass < first.pass) (hindex : second.index ≤ T + S) (hnode : first.node.1.val ≤ second.node.1.val) : second.remainingDepth ≤ first.remainingDepth ∧ rank T S second < rank T S first := ⟨remainingDepth_le_of_no_ancestor first second hnode, rank_lt_previous_pass T S first second hpass hindex⟩
theorem rank_lt_pass_bound (T S passes : ℕ) (request : PhysicalTableRequest M J ny) (hpass : request.pass < passes) (hindex : request.index ≤ T + S) : rank T S request < passes * (T + S + 1) := by have hblock : request.pass * (T + S + 1) + request.index < (request.pass + 1) * (T + S + 1) := by nlinarith only [hindex] exact hblock.trans_le (Nat.mul_le_mul_right (T + S + 1) (Nat.succ_le_of_lt hpass))
theorem warmup_index_bound (pass copy : ℕ) (node : PhysicalNode M J) (T S j : ℕ) (state : TargetInterval ny) (hj : j ≤ T) : (warmup pass copy node j state).index ≤ T + S := by change j ≤ T + S omega
theorem refinement_index_bound (pass copy : ℕ) (node : PhysicalNode M J) (T S t : ℕ) (state : TargetInterval ny) (ht : t ≤ S) : (refinement pass copy node T t state).index ≤ T + S := by change T + t ≤ T + S omega
theorem warmup_bounded (passes copies pass copy : ℕ) (node : PhysicalNode M J) (T S j : ℕ) (state : TargetInterval ny) (hpass : pass < passes) (hcopy : copy < copies) (hj : j ≤ T) : Bounded passes copies T S (warmup pass copy node j state) := ⟨hpass, hcopy, warmup_index_bound pass copy node T S j state hj⟩
theorem refinement_bounded (passes copies pass copy : ℕ) (node : PhysicalNode M J) (T S t : ℕ) (state : TargetInterval ny) (hpass : pass < passes) (hcopy : copy < copies) (ht : t ≤ S) : Bounded passes copies T S (refinement pass copy node T t state) := ⟨hpass, hcopy, refinement_index_bound pass copy node T S t state ht⟩
theorem bounded_changeCopy (passes copies T S : ℕ) (request : PhysicalTableRequest M J ny) (hrequest : Bounded passes copies T S request) (copy : ℕ) (hcopy : copy < copies) : Bounded passes copies T S (changeCopy request copy) := ⟨hrequest.1, hcopy, hrequest.2.2⟩
theorem bounded_sameIndexChild (passes copies T S : ℕ) (request : PhysicalTableRequest M J ny) (hrequest : Bounded passes copies T S request) (hbelow : request.node.1.val < J) (i : Fin M) (state : TargetInterval ny) : Bounded passes copies T S (sameIndexChild request hbelow i state) := hrequest
theorem bounded_of_earlier_same_pass (passes copies T S : ℕ) (first second : PhysicalTableRequest M J ny) (hfirst : Bounded passes copies T S first) (hpass : second.pass = first.pass) (hcopy : second.copy < copies) (hindex : second.index ≤ first.index) : Bounded passes copies T S second := by exact ⟨hpass.symm ▸ hfirst.1, hcopy, hindex.trans hfirst.2.2⟩
theorem bounded_of_previous_pass (passes copies T S : ℕ) (first second : PhysicalTableRequest M J ny) (hfirst : Bounded passes copies T S first) (hpass : second.pass < first.pass) (hcopy : second.copy < copies) (hindex : second.index ≤ T + S) : Bounded passes copies T S second := ⟨hpass.trans hfirst.1, hcopy, hindex⟩
/-- Bounded requests have an explicit finite coordinate representation;the copy coordinate is retained even though the progress rank ignores it. -/def boundedTuple (passes copies T S : ℕ) (request : {r : PhysicalTableRequest M J ny // Bounded passes copies T S r}) : Fin passes × Fin copies × PhysicalNode M J × Fin (T + S + 1) × TargetInterval ny := (⟨request.1.pass, request.2.1⟩, ⟨request.1.copy, request.2.2.1⟩, request.1.node, ⟨request.1.index, Nat.lt_succ_of_le request.2.2.2⟩, request.1.state)
theorem boundedTuple_injective (passes copies T S : ℕ) : Function.Injective (@boundedTuple M J ny passes copies T S) := by intro first second heq apply Subtype.ext have hpass := congrArg (fun t => t.1.val) heq have hcopy := congrArg (fun t => t.2.1.val) heq have hnode := congrArg (fun t => t.2.2.1) heq have hindex := congrArg (fun t => t.2.2.2.1.val) heq have hstate := congrArg (fun t => t.2.2.2.2) heq cases first with | mk first hf => cases second with | mk second hs => cases first cases second simp only [boundedTuple] at hpass hcopy hnode hindex hstate cases hpass cases hcopy cases hnode cases hindex cases hstate rfl
instance boundedRequestFinite (passes copies T S : ℕ) : Finite {r : PhysicalTableRequest M J ny // Bounded passes copies T S r} := Finite.of_injective (boundedTuple passes copies T S) (boundedTuple_injective passes copies T S)
end PhysicalTableRequestend EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159import OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegretimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalGroupAccuracy
namespace OAI
/-! Conditional prefix regret from the exact physical-band sampler. -/
namespace EditApproximation
open Finset MeasureTheory ProbabilityTheory
theorem uniformMean_sub {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) : uniformMean (fun ω => f ω - g ω) = uniformMean f - uniformMean g := by simp only [uniformMean, sum_sub_distrib, sub_div]
theorem sampledPrefixRegret_child_identity {β σ : Type*} [Fintype β] (charge κ : ℝ) (table : ℕ → β × σ → ℝ) (clipped : ℕ → ℝ) (sample : ℕ → β → σ) (t : ℕ) : sampledPrefixRegret charge κ table clipped sample t = (∑ child, table (t + 1) (child, sample t child)) + κ * ((∑ child, table t (child, sample t child)) - ∑ child, table (t + 1) (child, sample t child)) - clipped (t + 1) := by unfold sampledPrefixRegret bandActionCost ring
section PhysicalPrefix
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (hbelow : node.1.val < J) (b thetaExponent : ℕ) (tau : ℚ) (r : TargetInterval target.length)
local notation "band" => physicalBandActions source target U N P F A T node hbelow b thetaExponent tau rlocal notation "mass" => physicalBandEnvelope source target U N P F A T node hbelow b thetaExponent tau rlocal notation "history" => physicalBandHistory source target U N P F A T delta choices node hbelowlocal notation "theta" => (2 : ℚ) ^ (-(thetaExponent : ℤ))
variable (hM : 0 < M) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (hT : 0 < T)
include hM hsize hP hF hA hseed hT in/-- Every deterministic prefix uses the same actual computed online mixtures.Clipping comparison children only decreases the prefix regret. -/theorem physicalBand_prefix_expected_regret (htau : 0 < tau) (hdelta : 0 ≤ delta) (hband : band ≠ []) (C S H G K : ℕ) (hCS : C ≤ S) (η κ : ℚ) (hG : G = H + (bandCoordinates (band).toFinset).card + 2) (hK : K = G ^ 80) (comparison : Fin M → TargetInterval target.length) (hc : comparison ∈ band) (hH : 4 ≤ H) (hη : 0 < η) (hκ : 0 ≤ κ) (hκhalf : κ ≤ 1 / 2) (hηrange : (η : ℝ) * (2 * (delta : ℝ) + 8 * ((128 * F : ℚ) : ℝ) * (theta : ℝ)) ≤ (κ : ℝ)) (charge : ℝ) : (∑ t ∈ range C, uniformMean (fun integer : Fin (optimizerTriangularMass K) => sampledPrefixRegret charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ)) (physicalComparisonClipped source target U N P F A T delta choices node hbelow comparison) (fun j => physicalBandOnlineDraw source target U N P F A T delta choices node hbelow b thetaExponent tau r hband η κ G K j integer) t)) ≤ ((∑ child, mass child : ℚ) : ℝ) * (Real.log (bandCoordinates (band).toFinset).card / (η : ℝ) + 2 * (κ : ℝ) + (S : ℝ) / (H : ℝ) ^ 3) := by have hGpos : 0 < G := by omega have hKpos : 0 < K := by rw [hK]; exact pow_pos hGpos 80 let : NeZero (optimizerTriangularMass K) := ⟨Nat.ne_of_gt (optimizerTriangularMass_positive K hKpos)⟩ have hcost := physicalBandOnlineDraw_cost_regret source target U N P F A T delta choices node hbelow b thetaExponent tau r hM hsize hP hF hA hseed hT htau hdelta hband C H G K η κ hG hK hc hH hη hκ hκhalf hηrange have hcomparison : (∑ t ∈ range C, ∑ child, (history (t + 1) (child, comparison child) : ℝ)) ≤ ∑ t ∈ range C, physicalComparisonClipped source target U N P F A T delta choices node hbelow comparison (t + 1) := by apply sum_le_sum intro t _ exact sum_le_sum fun i _ => le_max_right _ _ have hmass : (0 : ℝ) ≤ ((∑ child, mass child : ℚ) : ℝ) := (Rat.cast_nonneg (K := ℝ)).mpr (sum_nonneg fun i _ => (physicalBandEnvelope_pos source target U N P F A T node hbelow b thetaExponent tau r i).le) have hprefix : (C : ℝ) / (H : ℝ) ^ 3 ≤ (S : ℝ) / (H : ℝ) ^ 3 := div_le_div_of_nonneg_right (by exact_mod_cast hCS) (pow_nonneg (Nat.cast_nonneg H) 3) have hbudget := mul_le_mul_of_nonneg_left hprefix hmass simp_rw [sampledPrefixRegret_child_identity, uniformMean_sub, uniformMean_const] rw [sum_sub_distrib] nlinarith only [hcost, hcomparison, hbudget]
end PhysicalPrefix
theorem unskippedGroupFailure_true {α : Type*} (source target : List α) {M : ℕ} (parent : TargetInterval source.length) (b P thetaExponent : ℕ) (tau F : ℚ) (child initial value : Fin M → TargetInterval target.length → ℚ) (Q : ℕ) (members : List (UnskippedBand source target parent b P thetaExponent tau F child initial)) (draw : ∀ scale : Fin (groupDyadicScales M b F).length, Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) → Fin M) (gamma : ℚ) : unskippedGroupFailure source target parent b P thetaExponent tau F child initial value Q members draw gamma = true ↔ ∃ member ∈ members, gamma * b < |dyadicUnskippedGroupEstimate Q value member draw - rationalEndpointActionValue member.center member.rounded value| := by simp only [unskippedGroupFailure, List.any_eq_true, decide_eq_true_eq]
/-- Per-scale finite Bernstein bounds imply the whole-cell failure probability. -/theorem physicalNode_groupFailure_probability {α : Type*} [DecidableEq α] (source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N) {M J P F b Q thetaExponent : ℕ} [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (hM : 0 < M) (hMeq : M = (integerParameters N).M) (hPeq : P = (integerParameters N).P) (hFeq : F = inputSmallLog N) (eb : ℕ) (hbeq : b = 2 ^ eb) (hQeq : Q = inputSmallLog N ^ 80) (hthetaeq : thetaExponent = 40 * smallLogExponent N) (U : PhysicalEntry M J target.length → ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (T : ℕ) (hT : 0 < T) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ) (cell : ℕ × ℕ) (bernstein : ∀ scale : Fin (groupDyadicScales M b F).length, FiniteBernsteinInput (Measure.pi fun _ : Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) => (PMF.uniformOfFintype (Fin M)).toMeasure)) : (groupSharedDrawLaw (fun scale : Fin (groupDyadicScales M b F).length => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))).real {draw | physicalNodeGroupFailure source target U N P F A T delta choices node hbelow b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma = true} ≤ 1 / (inputHeight N : ℝ) ^ 4 := by subst F let F := inputSmallLog N let scales := groupDyadicScaleAt M b (F : ℚ) let count := fun scale : Fin (groupDyadicScales M b F).length => groupSampleCount M Q b (scales scale) have hscales : List.ofFn scales = groupDyadicScales M b F := List.ofFn_get _ have hprob := physical_cellGroupEstimate_failure source target N hN hell hM hMeq hPeq eb hbeq hQeq hthetaeq U A hsize hP hA hseed T hT delta choices node hbelow (t + 1) cell scales count hscales (fun _ => rfl) bernstein dsimp only at hprob let members := physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent (rationalParameters F).tau cell let value := fun i s => physicalBandHistory source target U N P F A T delta choices node hbelow (t + 1) (i, s) have hevent : {draw | physicalNodeGroupFailure source target U N P F A T delta choices node hbelow b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma = true} = {draw | ∃ member ∈ members, ((rationalParameters F).gamma : ℝ) * b < |((dyadicUnskippedGroupEstimate Q value member draw - rationalEndpointActionValue member.center member.rounded value : ℚ) : ℝ)|} := by ext draw simp only [Set.mem_ofPred_eq, physicalNodeGroupFailure, unskippedGroupFailure_true] change (∃ member ∈ members, (rationalParameters F).gamma * b < |dyadicUnskippedGroupEstimate Q value member draw - rationalEndpointActionValue member.center member.rounded value|) ↔ _ constructor · rintro ⟨member, hm, he⟩ refine ⟨member, hm, ?_⟩ exact_mod_cast he · rintro ⟨member, hm, he⟩ refine ⟨member, hm, ?_⟩ exact_mod_cast he rw [hevent] exact hprob
end EditApproximation
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemoimport OAI.Combinatorics.EditApproximation.Geometry.LocalFinalAccuracy
namespace OAI
/-! The finite family is consumed through actual source reads in the sharedmemo evaluator. Its final value and law agree with the proved local answer. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Accuracy
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H : ℕ)
local notation "Seed" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "passes" => computedSeedPassCount Nlocal notation "tau" => RationalParameters.tau (rationalParameters ell)local notation "eta" => RationalParameters.eta (rationalParameters ell)local notation "kappa" => RationalParameters.kappa (rationalParameters ell)local notation "delta" => RationalParameters.delta (rationalParameters ell)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
theorem physicalFamilyMemoAnswer_event (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (incoming : Measure Seed) [IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) (event : Set ℕ) : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2))).real {input | physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ input ∈ event} = (localFinalProgramLaw (R := R) source target N P T S H incoming).real {input | localFinalProgramAnswer (R := R) source target N P T S H rootQ input ∈ event} := by classical have h := congrArg (fun law : Measure ℕ => law.real event) (physicalFamilyMemoAnswer_law source target N P T S H hP hH bits encode hinjective hbounded incoming rootQ) simpa only [map_measureReal_apply (measurable_of_finite _) (Set.to_countable _).measurableSet, Set.preimage] using h
variable (B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] (depth : PhysicalEntry M J target.length → ℕ)
/-- Accuracy of the shared source/table memo evaluator under finite Bernstein bounds. -/ theorem physicalFamilyMemoAnswer_conditional_accuracy (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) (hsize : source.length + target.length ≤ N) (hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length) (hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T) (hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N) (hB : B = (integerParameters N).B) (hdepth : ∀ state, depth state = computedCoarseDepth N (coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi))) (coarseBernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B => (PMF.uniformOfFintype (Fin B)).toMeasure)) (groupBernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length, FiniteBernsteinInput (Measure.pi fun _ : Fin (groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) => (PMF.uniformOfFintype (Fin M)).toMeasure)) (epsilon : ℝ) (hepsilon : 0 < epsilon) (haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) : (2 / 3 : ℝ) ≤ ((physicalCoarseSeedLaw source target N B depth).prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2))).real {input | EditDistortion.edit source target ≤ physicalFamilyMemoAnswer source target N P T S H hH bits encode (finalTargetState target.length) input ∧ (physicalFamilyMemoAnswer source target N P T S H hH bits encode (finalTargetState target.length) input : ℝ) ≤ (1 + epsilon) * EditDistortion.edit source target} := by have hevent := physicalFamilyMemoAnswer_event source target N P T S H hP hH bits encode hinjective hbounded (physicalCoarseSeedLaw source target N B depth) (finalTargetState target.length) {answer | EditDistortion.edit source target ≤ answer ∧ (answer : ℝ) ≤ (1 + epsilon) * EditDistortion.edit source target} simp only [Set.mem_ofPred_eq] at hevent rw [hevent] exact local_physical_conditional_accuracy source target N P T S H B depth hN hell hsize hMeq hJeq hPeq hTeq hSeq hHeq hB hdepth coarseBernstein groupBernstein epsilon hepsilon haccuracy
end Accuracy
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyWorkimport OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomCoarseWorkimport OAI.Combinatorics.EditApproximation.Coarse.CoarseFirstRequestCostimport OAI.Combinatorics.EditApproximation.Geometry.BalancedWidthsimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLaw
namespace OAI
namespace EditApproximation
section Coarse
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "group" => physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies drawlocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
noncomputable def physicalFamilyCoarseQuery (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : FiniteQuery (PhysicalEntry M J target.length) := chargedRandomCoarseQuery source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer root
theorem physicalFamilyCoarseQuery_cost_le_width (initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P) (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) (hroot : root.depth = J) : (physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier tau eta kappa delta draw root).cost (fun entry => (initial entry : ℚ)) (fun entry => (physicalSource source entry.1).length) ≤ (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hP draw root).widthWork M source.length := by apply (FiniteQuery.cost_mono_weights _ _ _ _ ?_).trans (chargedRandomCoarseQuery_width_cost_le source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial group (physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta hP draw initial) (physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) root hroot) intro entry rw [physicalSource_length_eq] exact (sourceIntervalAt_width M source.length entry.1.1.val (Nat.pos_of_neZero M) entry.1.2).trans (Nat.le_add_left _ 1)
variable (B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] (depth : PhysicalEntry M J target.length → ℕ)
noncomputable def physicalFamilyCoarseWork (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) (coarse : PhysicalCoarseDraw source target B depth) : ℝ := coarseFirstRequestWork N B depth (fun entry => physicalSource source entry.1) (fun entry => substring target entry.2.lo entry.2.hi) (physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier tau eta kappa delta draw root) coarse
theorem physicalFamilyCoarseWork_expected_le (hP : 0 < P) (hN : 0 < N) (hell : 200 ≤ ell) (hB : B = (integerParameters N).B) (hsize : source.length + target.length ≤ N) (hdepth : ∀ entry, depth entry = computedCoarseDepth N (coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi))) (hinverse : coarseInverseAllowanceFactor B (initialThresholdQ N) (initialLambda N) ≤ (inputHeight N : ℝ) ^ 8) (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) (hroot : root.depth = J) (budget : ℝ) (hwidth : ∀ coarse : PhysicalCoarseDraw source target B depth, ((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) hP draw root).widthWork M source.length : ℝ) ≤ budget) : (∫ coarse, physicalFamilyCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth root coarse ∂coarseFullSeedMeasure B depth (fun entry => physicalSource source entry.1) (fun entry => substring target entry.2.lo entry.2.hi)) ≤ budget * computedCoarseWidthOverhead N := by have hentries (entry : PhysicalEntry M J target.length) : coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) ≤ N := by apply max_le · exact (physicalSource_length_le source entry.1).trans (by omega) · have hl : (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 _ _) exact hl.trans (by omega) apply coarseFirstRequestWork_expected_le N B depth _ _ _ hB hN hell hdepth hentries hinverse budget intro coarse have hc := physicalFamilyCoarseQuery_cost_le_width source target N P H T S passes copies factor multiplier tau eta kappa delta draw (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) hP root hroot exact ((Nat.cast_le (α := ℝ)).mpr hc).trans (hwidth coarse)
end Coarse
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarCodeBitsimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamilyimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
section Encoding
variable {α : Type*} {M J R : ℕ} (target : List α) (N P F exponent H Q passes copies : ℕ)
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P F exponent H Q passes copies
theorem physicalFamilyCode_injective (hM : 1 ≤ M) : Function.Injective (physicalFamilyCode (M := M) (J := J) (R := R) target N P F exponent H Q passes copies) := by intro first second h obtain ⟨hp, h⟩ := Nat.pair_eq_pair.mp h obtain ⟨hc, hs⟩ := Nat.pair_eq_pair.mp h exact Prod.ext (Fin.ext hp) (Prod.ext (Fin.ext hc) (physicalScalarCode_injective hM hs))
theorem physicalFamilyCode_bound (k : ℕ) (hpass : passes + 1 ≤ 2 ^ k) (hcopy : copies + 1 ≤ 2 ^ k) (hscalar : ∀ key : PhysicalScalarKey M J N target.length exponent F Q R (localOnlineMassBound M P H), physicalScalarCode key < 2 ^ (64 * k + 1)) (key : Key) : physicalFamilyCode target N P F exponent H Q passes copies key < 2 ^ (256 * k + 4) := by have hk : k ≤ 64 * k + 1 := by omega have hp := key.1.isLt.trans_le (hpass.trans (Nat.pow_le_pow_right (by decide) hk)) have hc := key.2.1.isLt.trans_le (hcopy.trans (Nat.pow_le_pow_right (by decide) hk)) have hi := natPair_lt_two_pow hc (hscalar key.2.2) have ho := natPair_lt_two_pow_scaled hp hi (by decide : 1 ≤ 2) change Nat.pair _ (Nat.pair _ _) < _ convert ho using 1 congr 1 omega
end Encoding
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyOutputimport OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemoimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The finite family is consumed through actual source reads in the sharedmemo evaluator. Its final value and law agree with the proved local answer. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Memo
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H : ℕ)
local notation "Seed" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "passes" => computedSeedPassCount Nlocal notation "tau" => RationalParameters.tau (rationalParameters ell)local notation "eta" => RationalParameters.eta (rationalParameters ell)local notation "kappa" => RationalParameters.kappa (rationalParameters ell)local notation "delta" => RationalParameters.delta (rationalParameters ell)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
theorem physicalFamilyMemoResult_value (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (rootQ : TargetInterval target.length) (input : Seed × Family) : ((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ input).value : ℝ) = physicalFamilyFinalValue source target N P T S H hP rootQ input := by unfold physicalFamilyMemoResult rw [chargedRandomMemoEvaluate_value source target N P ell exponent H (ell ^ 80) T S (passes + 1) (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta (physicalFamilyGroupRead target N P ell exponent H (ell ^ 80) passes (H ^ 2)) (physicalFamilyOnlineRead target N P ell exponent H (ell ^ 80) passes (H ^ 2)) (clampedSeedNat input.1) (physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2) (physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2) (physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2 (clampedSeedNat input.1))] · rfl · exact physicalFamilyGroupRead_value target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2 · exact physicalFamilyOnlineRead_value source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2 (clampedSeedNat input.1) · exact hinjective · exact hbounded
noncomputable def physicalFamilyMemoAnswer (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (input : Seed × Family) : ℕ := if source = substring target rootQ.lo rootQ.hi then 0 else integerAnswer N ((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ input).value : ℝ)
theorem physicalFamilyMemoAnswer_eq (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (rootQ : TargetInterval target.length) (input : Seed × Family) : physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ input = physicalFamilyFinalAnswer source target N P T S H hP rootQ input := by unfold physicalFamilyMemoAnswer physicalFamilyFinalAnswer rw [physicalFamilyMemoResult_value source target N P T S H hP hH bits encode hinjective hbounded]
theorem physicalFamilyMemoAnswer_law (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (incoming : Measure Seed) [IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map (physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ) = (localFinalProgramLaw (R := R) source target N P T S H incoming).map (localFinalProgramAnswer (R := R) source target N P T S H rootQ) := by have heq : physicalFamilyMemoAnswer (R := R) source target N P T S H hH bits encode rootQ = physicalFamilyFinalAnswer source target N P T S H hP rootQ := by funext input exact physicalFamilyMemoAnswer_eq source target N P T S H hP hH bits encode hinjective hbounded rootQ input rw [heq] exact physicalFamilyFinalAnswer_law source target N P T S H hP hH incoming rootQ
end Memo
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyCoarseWorkimport OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomCoarseKeysimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
open MeasureTheory
private theorem selectionIndicator_le {p q : Prop} (h : p → q) : selectionIndicator p ≤ selectionIndicator q := by classical by_cases hp : p · have hq := h hp simp only [selectionIndicator, hp, hq, ite_true, le_refl] · simp only [selectionIndicator, hp, ite_false] split <;> norm_num
section Coarse
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies) (B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] (depth : PhysicalEntry M J target.length → ℕ)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
omit [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] in theorem physicalFamilyMemoCoarseWork_le (hP : 0 < P) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (root : Table) (coarse : PhysicalCoarseDraw source target B depth) : physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth bits encode root coarse ≤ physicalFamilyCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth root coarse := by classical let initial := clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse) have hkey (entry : PhysicalEntry M J target.length) := chargedRandomMemo_coarse_key source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial (physicalFamilyRequestValue source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) (physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw) bits encode hinjective hbounded root entry unfold physicalFamilyMemoCoarseWork physicalFamilyCoarseWork coarseFirstRequestWork apply Finset.sum_le_sum intro entry _ apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _) exact selectionIndicator_le (hkey entry)
theorem physicalFamilyMemoCoarseWork_expected_le (hP : 0 < P) (hN : 0 < N) (hell : 200 ≤ ell) (hB : B = (integerParameters N).B) (hsize : source.length + target.length ≤ N) (hdepth : ∀ entry, depth entry = computedCoarseDepth N (coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi))) (hinverse : coarseInverseAllowanceFactor B (initialThresholdQ N) (initialLambda N) ≤ (inputHeight N : ℝ) ^ 8) (bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (root : Table) (hroot : root.depth = J) (budget : ℝ) (hwidth : ∀ coarse : PhysicalCoarseDraw source target B depth, ((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) hP draw root).widthWork M source.length : ℝ) ≤ budget) : (∫ coarse, physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth bits encode root coarse ∂coarseFullSeedMeasure B depth (fun entry => physicalSource source entry.1) (fun entry => substring target entry.2.lo entry.2.hi)) ≤ budget * computedCoarseWidthOverhead N := by classical apply (integral_mono Integrable.of_finite Integrable.of_finite (fun coarse => physicalFamilyMemoCoarseWork_le source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth hP bits encode hinjective hbounded root coarse)).trans exact physicalFamilyCoarseWork_expected_le source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth hP hN hell hB hsize hdepth hinverse root hroot budget hwidth
end Coarse
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySeedTraceimport OAI.Combinatorics.EditApproximation.Geometry.LocalCommonOutput
namespace OAI
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Output
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H : ℕ) (hP : 0 < P)
local notation "SeedState" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "passes" => computedSeedPassCount Nlocal notation "tau" => RationalParameters.tau (rationalParameters ell)local notation "eta" => RationalParameters.eta (rationalParameters ell)local notation "kappa" => RationalParameters.kappa (rationalParameters ell)local notation "delta" => RationalParameters.delta (rationalParameters ell)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)
noncomputable def physicalFamilyFinalValue (rootQ : TargetInterval target.length) (input : SeedState × Family) : ℝ := localRequestValue source target N P ell exponent H (ell ^ 80) T S (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta (physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2) (physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2 (clampedSeedNat input.1)) (clampedSeedNat input.1) (PhysicalTableRequest.refinement passes 0 (Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit) T S rootQ)
noncomputable def physicalFamilyFinalAnswer (rootQ : TargetInterval target.length) (input : SeedState × Family) : ℕ := if source = substring target rootQ.lo rootQ.hi then 0 else integerAnswer N (physicalFamilyFinalValue source target N P T S H hP rootQ input)
theorem physicalFamily_localPassValue (seed : SeedState) (draw : Family) (pass copy : ℕ) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : localPassValue source target N P ell exponent H (ell ^ 80) T (scheduledSeedFactor N) tau eta kappa delta (physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw) (physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw (clampedSeedNat seed)) (physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw (clampedSeedNat seed) pass) pass copy node t q = physicalLocalJointValue source target (physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw (clampedSeedNat seed) pass) N P ell (scheduledSeedFactor N pass) T exponent H (ell ^ 80) tau eta kappa delta (physicalFamilySample source target N P ell exponent H (ell ^ 80) T passes (H ^ 2) (scheduledSeedFactor N) tau hP draw (physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw (clampedSeedNat seed) pass) pass copy) node t q := rfl
theorem physicalFamilyFinalValue_eq (rootQ : TargetInterval target.length) (input : SeedState × Family) : physicalFamilyFinalValue source target N P T S H hP rootQ input = let outcome := physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) input localFinalProgramValue source target N P T S H rootQ (localCommonSeed source target N P T S H hP passes outcome.1) (localCommonTerminalSample source target N P T H hP (localCommonSeed source target N P T S H hP passes outcome.1) outcome.2) := by rcases input with ⟨seed, draw⟩ dsimp only rw [physicalFamilyToTrace_fst, physicalFamilyToTrace_snd] unfold physicalFamilyFinalValue rw [localRequestValue_refinement, physicalFamilySeed_eq, physicalFamily_localPassValue] have hseed := physicalFamilySeed_prefix source target N P T S H passes hP draw seed passes le_rfl rw [hseed] unfold localFinalProgramValue localCommonTerminalSample dsimp only [Prod.snd] have hs := physicalFamilySample_fin source target N P T H passes hP draw (localCommonSeed source target N P T S H hP passes (physicalFamilyPrefix target N P H passes draw seed passes le_rfl)) (Fin.last passes) 0 simp only [Fin.val_last, Fin.val_zero] at hs rw [hs]
theorem physicalFamilyFinalAnswer_eq (hH : 0 < H) (rootQ : TargetInterval target.length) (input : SeedState × Family) : physicalFamilyFinalAnswer source target N P T S H hP rootQ input = localCommonMemoAnswer (M := M) (J := J) (R := R) source target N P T S H hP hH rootQ (physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) input) := by rw [localCommonMemoAnswer_eq] unfold physicalFamilyFinalAnswer localFinalProgramAnswer freshSeedValue rw [physicalFamilyFinalValue_eq]
theorem physicalFamilyFinalAnswer_law (hH : 0 < H) (incoming : Measure SeedState) [IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map (physicalFamilyFinalAnswer source target N P T S H hP rootQ) = (localFinalProgramLaw (R := R) source target N P T S H incoming).map (localFinalProgramAnswer (R := R) source target N P T S H rootQ) := by classical let : MeasurableSingletonClass (PhysicalCommonDraw M J N target.length exponent ell (ell ^ 80) R (localOnlineMassBound M P H)) := inferInstance let := commonSeedTraceFintype SeedState (fun _ => LocalCommonDraw (M := M) (J := J) (R := R) target N P H) passes let := commonSeedTraceSingleton SeedState (fun _ => LocalCommonDraw (M := M) (J := J) (R := R) target N P H) passes have heq : physicalFamilyFinalAnswer (R := R) source target N P T S H hP rootQ = localCommonMemoAnswer (M := M) (J := J) (R := R) source target N P T S H hP hH rootQ ∘ physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) := by funext input exact physicalFamilyFinalAnswer_eq source target N P T S H hP hH rootQ input have htrace : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map (physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2)) = localCommonFinalLaw (M := M) (J := J) (R := R) target N P H incoming := by exact physicalFamilyToTrace_law (Seed := SeedState) (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) incoming rw [heq, ← Measure.map_map (measurable_of_finite _) (measurable_of_finite _), htrace] exact localCommonMemoAnswer_law source target N P T S H hP hH incoming rootQ
end Output
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarReadCostimport OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemoimport OAI.Combinatorics.EditApproximation.Refinement.ComputedChargedRandomSourceCostimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The actual scalar family supplies the body-value and source-readbounds required by the mixed source/table dependency analysis. -/
namespace EditApproximation
section Program
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P F exponent H Q T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (initial : PhysicalEntry M J target.length → ℕ)
variable (hP : 0 < P) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies)
noncomputable def physicalFamilyRequestValue := chargedRequestValue source target N P F exponent H Q T S (passes + 1) copies factor multiplier tau eta kappa delta (physicalFamilyGroup target N P F exponent H Q passes copies draw) (physicalFamilyInteger source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta hP draw initial) initial
theorem physicalFamilyProgram_value (request : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (physicalFamilyProgram source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta initial request).value (Sum.elim (physicalFamilyAnswer target N P F exponent H Q passes copies draw) (fun child => physicalFamilyRequestValue source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta initial hP draw child.val)) = physicalFamilyRequestValue source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta initial hP draw request := by exact chargedRandomGlobalQuery_value source target N P F exponent H Q T S (passes + 1) copies factor multiplier tau eta kappa delta _ _ initial _ _ _ (physicalRandomBoundedQuery_localValue source target N P F exponent H Q T S (passes + 1) copies factor multiplier tau eta kappa delta _ _ initial _ _ _ (physicalFamilyGroupRead_value target N P F exponent H Q passes copies draw) (physicalFamilyOnlineRead_value source target N P F exponent H Q T S passes copies factor multiplier tau eta kappa delta hP draw initial)) request
end Program
section ComputedCost
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
theorem computed_physicalFamilyProgram_source_cost (hN : 0 < N) (hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M) (hA : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ)) (request : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (physicalFamilyProgram source target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) T S passes copies factor multiplier tau eta kappa delta initial request).cost (Sum.elim (physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies draw) (fun child => physicalFamilyRequestValue source target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hP draw child.val)) (Sum.elim (fun _ => 1) (fun _ => 0)) ≤ inputHeight N ^ 91 := by have hg := physicalFamilyGroupRead_cost_le target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies (physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies draw) (fun _ => 1) 1 (fun _ => le_rfl) have ho := physicalFamilyOnlineRead_cost_le target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies (physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies draw) (fun _ => 1) 1 (fun _ => le_rfl) simpa only [physicalFamilyProgram, physicalFamilyRequestValue, Nat.mul_one] using (computed_chargedRandomGlobalQuery_source_cost source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta (physicalFamilyGroup target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies draw) (physicalFamilyInteger source target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) T S passes copies factor multiplier tau eta kappa delta hP draw initial) initial _ _ _ (fun _ => 1) 1 hN hell hM hA hg ho request)
end ComputedCost
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemoimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySamplingimport OAI.Combinatorics.EditApproximation.Probability.RejectionMemoCostimport OAI.Combinatorics.EditApproximation.Refinement.ComputedFamilyEncodingimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Work
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H : ℕ)
local notation "SeedState" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "passes" => computedSeedPassCount Nlocal notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T Slocal notation "FamilyRange" => physicalFamilyRange (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)
theorem physicalFamilyMemoBits_integrable (hH : 0 < H) (bits : ℕ) (encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (seed : SeedState) : Integrable (physicalFamilyMemoBits source target N P T S H hH bits encode rootQ seed) (rejectionRuntimeArrayLaw FamilyRange) := rejectionSelectedBits_integrable _ _
theorem physicalFamilyMemoBits_expected_le (hH : 0 < H) (bits sourceBits : ℕ) (encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (seed : SeedState) (budget : ℝ) (hrequests : ∀ draw, ((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ (seed, draw)).requests : ℝ) ≤ budget) (hbits : ∀ key, rejectionBitCount (FamilyRange key) ≤ sourceBits) : (∫ execution, physicalFamilyMemoBits source target N P T S H hH bits encode rootQ seed execution ∂rejectionRuntimeArrayLaw FamilyRange) ≤ 2 * (budget * sourceBits) := by classical let : Fintype Table := Fintype.ofInjective (fun key : Table => (⟨ChargedPhysicalRequest.code key, ChargedPhysicalRequest.code_bound (Nat.one_le_iff_ne_zero.mpr (NeZero.ne M)) key⟩ : Fin (ChargedPhysicalRequest.capacity M J target.length (passes + 1) (H ^ 2) T S))) (fun _ _ h => ChargedPhysicalRequest.code_injective (Nat.one_le_iff_ne_zero.mpr (NeZero.ne M)) (congrArg Fin.val h)) apply memo_rejectionBits_expected_le_real FamilyRange _ budget sourceBits _ hbits intro draw have hf : (physicalFamilyMemoResult source target N P T S H hH bits encode rootQ (seed, draw)).freshKeys.length ≤ (physicalFamilyMemoResult source target N P T S H hH bits encode rootQ (seed, draw)).requests := (rankedMemoEvaluate_resource_bounds _ _ _ _ _ _).1 exact (Nat.cast_le (α := ℝ)).mpr hf |>.trans (hrequests draw)
theorem physicalFamilyMemo_nodes_polynomial (hH : 0 < H) (encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (input : SeedState × PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)) : (physicalFamilyMemoResult source target N P T S H hH (16384 * inputHeight N + 5) encode rootQ input).memory.nodes + 1 ≤ (N + 2) ^ 65542 := computed_mixed_cache_nodes N _ _ encode _
end Work
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyAccuracyimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySamplingimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The source family is the projection of terminating rejection-sampling executions. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Runtime
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H : ℕ)
local notation "SeedState" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "passes" => computedSeedPassCount Nlocal notation "FamilyRange" => physicalFamilyRange (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
noncomputable def physicalFamilyRuntimeLaw (incoming : Measure SeedState) : Measure (PhysicalFamilyRuntimeOutcome (M := M) (J := J) (R := R) target N P H) := incoming.prod (rejectionRuntimeArrayLaw FamilyRange)
instance physicalFamilyRuntimeLaw_probability (incoming : Measure SeedState) [IsProbabilityMeasure incoming] : IsProbabilityMeasure (physicalFamilyRuntimeLaw (R := R) target N P H incoming) := by unfold physicalFamilyRuntimeLaw infer_instance
omit [DecidableEq α] [NeZero R] in theorem physicalFamilyRuntimeAccepted_law (incoming : Measure SeedState) [IsProbabilityMeasure incoming] : (physicalFamilyRuntimeLaw (R := R) target N P H incoming).map (physicalFamilyRuntimeAccepted (R := R) target N P H) = incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)) := by change (incoming.prod (rejectionRuntimeArrayLaw FamilyRange)).map (Prod.map id Prod.snd) = _ rw [← Measure.map_prod_map _ _ measurable_id measurable_snd, Measure.map_id, physicalFamily_rejection_runtime_law]
noncomputable def physicalFamilyRuntimeAnswer (hH : 0 < H) (bits : ℕ) (encode : Sum (PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)) Table → ℕ) (rootQ : TargetInterval target.length) (execution : PhysicalFamilyRuntimeOutcome (M := M) (J := J) (R := R) target N P H) : ℕ := physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ (physicalFamilyRuntimeAccepted target N P H execution)
theorem physicalFamilyRuntimeAnswer_event (hP : 0 < P) (hH : 0 < H) (bits : ℕ) (encode : Sum (PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)) Table → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (incoming : Measure SeedState) [IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) (event : Set ℕ) : (physicalFamilyRuntimeLaw (R := R) target N P H incoming).real {execution | physicalFamilyRuntimeAnswer source target N P T S H hH bits encode rootQ execution ∈ event} = (localFinalProgramLaw (R := R) source target N P T S H incoming).real {input | localFinalProgramAnswer (R := R) source target N P T S H rootQ input ∈ event} := by rw [← physicalFamilyMemoAnswer_event source target N P T S H hP hH bits encode hinjective hbounded incoming rootQ event, ← physicalFamilyRuntimeAccepted_law target N P H incoming, map_measureReal_apply (by unfold physicalFamilyRuntimeAccepted; fun_prop) (by exact (Set.toFinite _).measurableSet)] rfl
end Runtime
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamilyLawimport OAI.Combinatorics.EditApproximation.Probability.RejectionSelectedLawimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The finite scalar family is exactly the accepted output of theindependent literal rejection samplers. Only requested coordinates needbe generated; their failure counts have a product law. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Family
variable {α : Type*} {M J R : ℕ} [NeZero M] (target : List α) (N P F exponent H Q passes copies : ℕ)
theorem physicalFamilyLaw_eq_rejectionAcceptedLaw : physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies = rejectionAcceptedLaw (physicalFamilyRange (M := M) (J := J) (R := R) target N P F exponent H Q passes copies) := rfl
theorem physicalFamily_rejection_runtime_law : (rejectionRuntimeArrayLaw (physicalFamilyRange (M := M) (J := J) (R := R) target N P F exponent H Q passes copies)).map Prod.snd = physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies := rejectionRuntimeArrayLaw_accepted _
omit [NeZero M] in theorem physicalFamilyRange_bits_le (bits : ℕ) (hM : M ≤ 2 ^ bits) (hB : localOnlineMassBound M P H ≤ 2 ^ bits) (key : PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P F exponent H Q passes copies) : rejectionBitCount (physicalFamilyRange target N P F exponent H Q passes copies key) ≤ bits := by apply (Nat.clog_le_iff_le_pow (by decide : 1 < (2 : ℕ))).2 rcases key with ⟨pass, copy, scalar, index⟩ cases scalar with | inl online => change online.2.val.val ≤ 2 ^ bits exact (Nat.le_of_lt_succ online.2.val.isLt).trans hB | inr group => exact hM
end Family
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyTraceimport OAI.Combinatorics.EditApproximation.Geometry.LocalCommonTrace
namespace OAI
namespace EditApproximation
section SourceFamily
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P T S H passes : ℕ) (hP : 0 < P)
local notation "SeedState" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "tau" => RationalParameters.tau (rationalParameters ell)local notation "eta" => RationalParameters.eta (rationalParameters ell)local notation "kappa" => RationalParameters.kappa (rationalParameters ell)local notation "delta" => RationalParameters.delta (rationalParameters ell)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2)
variable (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H ((inputSmallLog N) ^ 80) passes (H ^ 2))
noncomputable def physicalFamilyPrefix (seed : SeedState) (n : ℕ) (hn : n ≤ passes) : LocalCommonTrace (M := M) (J := J) (R := R) target N P H n := let rows : Fin n → LocalCommonDraw (M := M) (J := J) (R := R) target N P H := fun p copy => physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw ⟨p.val, Nat.lt_succ_of_le (p.isLt.le.trans hn)⟩ copy.castSucc commonArrayToTrace (Seed := SeedState) (Ω := LocalCommonDraw (M := M) (J := J) (R := R) target N P H) n (seed, rows)
omit [DecidableEq α] [NeZero M] [NeZero R] in theorem physicalFamilyDraw_fin (pass : Fin (passes + 1)) (copy : Fin (H ^ 2 + 1)) : physicalFamilyDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass.val copy.val = physicalFamilyCurry (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass copy := by funext key unfold physicalFamilyDraw physicalFamilyCurry have hp : Fin.ofNat (passes + 1) pass.val = pass := Fin.ext (Nat.mod_eq_of_lt pass.isLt) have hc : Fin.ofNat (H ^ 2 + 1) copy.val = copy := Fin.ext (Nat.mod_eq_of_lt copy.isLt) rw [hp, hc]
omit [DecidableEq α] [NeZero M] [NeZero R] in theorem physicalFamilyPrefix_succ (seed : SeedState) (n : ℕ) (hn : n + 1 ≤ passes) : physicalFamilyPrefix target N P H passes draw seed (n + 1) hn = (physicalFamilyPrefix target N P H passes draw seed n (by omega), fun copy : Fin (H ^ 2) => physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw ⟨n, by omega⟩ copy.castSucc) := rfl
omit [DecidableEq α] [NeZero M] [NeZero R] in theorem physicalFamilyToTrace_fst (seed : SeedState) : (physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) (seed, draw)).1 = physicalFamilyPrefix target N P H passes draw seed passes le_rfl := by unfold physicalFamilyToTrace commonArrayFinal dsimp only rw [mapCommonTrace_array] rfl
omit [DecidableEq α] [NeZero M] [NeZero R] in theorem physicalFamilyToTrace_snd (seed : SeedState) : (physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) (seed, draw)).2 = physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw (Fin.last passes) 0 := rfl
omit [NeZero M] [NeZero R] in theorem physicalFamilySample_fin (seed : SeedState) (pass : Fin (passes + 1)) (copy : Fin (H ^ 2 + 1)) : physicalFamilySample source target N P ell exponent H (ell ^ 80) T passes (H ^ 2) (scheduledSeedFactor N) tau hP draw (clampedSeedNat seed) pass.val copy.val = physicalCommonSample source target (clampedSeedNat seed) N P ell (scheduledSeedFactor N pass.val) T exponent H (ell ^ 80) R (localOnlineMassBound M P H) tau (physicalLocalOnlineMass_le source target (clampedSeedNat seed) N P ell (scheduledSeedFactor N pass.val) T exponent H tau hP) (physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass copy) := by unfold physicalFamilySample physicalFamilyPack rw [physicalFamilyDraw_fin]
theorem localScheduledSeedNext_nat_value (pass : ℕ) (previous : SeedState) (samples : LocalScheduledSeedDraw (R := R) source target N P T H pass previous) : clampedSeedNat (localScheduledSeedNext source target N P T S H pass previous samples) = fun state => min N (upperMedian (List.ofFn fun copy : Fin (H ^ 2) => ⌈(scheduledSeedMultiplier N pass : ℚ) * physicalLocalJointValue source target (clampedSeedNat previous) N P ell (scheduledSeedFactor N pass) T exponent H (ell ^ 80) tau eta kappa delta (samples copy) state.1 S state.2⌉₊)) := rfl
theorem physicalFamilySeed_prefix [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (seed : SeedState) : ∀ (n : ℕ) (hn : n ≤ passes), physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw (clampedSeedNat seed) n = clampedSeedNat (localCommonSeed source target N P T S H hP n (physicalFamilyPrefix target N P H passes draw seed n hn)) := by intro n induction n with | zero => intro hn; rfl | succ n ih => intro hn let previous := localCommonSeed source target N P T S H hP n (physicalFamilyPrefix target N P H passes draw seed n (by omega)) let row := fun copy : Fin (H ^ 2) => physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw ⟨n, by omega⟩ copy.castSucc have hnext : localCommonSeed source target N P T S H hP (n + 1) (physicalFamilyPrefix target N P H passes draw seed (n + 1) hn) = localScheduledSeedNext source target N P T S H n previous (localCommonSample source target N P T H hP n previous row) := rfl have hsamples : (fun copy : Fin (H ^ 2) => physicalFamilySample source target N P ell exponent H (ell ^ 80) T passes (H ^ 2) (scheduledSeedFactor N) tau hP draw (clampedSeedNat previous) n copy.val) = localCommonSample source target N P T H hP n previous row := by funext copy exact physicalFamilySample_fin source target N P T H passes hP draw previous ⟨n, by omega⟩ copy.castSucc rw [hnext, localScheduledSeedNext_nat_value, physicalFamilySeed, ih (by omega)] rw [← hsamples]
end SourceFamily
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamilyLawimport OAI.Combinatorics.EditApproximation.Probability.FiniteArrayMarginal
namespace OAI
/-! The literal finite scalar family supplies the independent commonsource trace and its final draw, after removing unused extra copies. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section SourceFamily
variable {Seed α : Type} {M J R : ℕ} [NeZero M] (target : List α) (N P F exponent H Q passes copies : ℕ)
local notation "Draw" => PhysicalCommonDraw M J N target.length exponent F Q R (localOnlineMassBound M P H)local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P F exponent H Q passes copieslocal notation "μ" => physicalCommonLaw M J N target.length exponent F Q R (localOnlineMassBound M P H)
def physicalFamilyToTrace (input : Seed × Family) : CommonSeedTrace Seed (fun _ => Fin copies → Draw) passes × Draw := let packed := physicalFamilyPack target N P F exponent H Q passes copies input.2 let rows := commonArrayFinal passes (input.1, packed) (mapCommonTrace (fun row (copy : Fin copies) => row copy.castSucc) passes rows.1, rows.2 0)
variable [Fintype Seed] [MeasurableSpace Seed] [MeasurableSingletonClass Seed] (incoming : Measure Seed)
theorem physicalFamilyToTrace_law : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies)).map (physicalFamilyToTrace (Seed := Seed) target N P F exponent H Q passes copies) = (commonTraceLaw (fun _ => Measure.pi fun _ : Fin copies => μ) incoming passes).prod μ := by classical let : MeasurableSingletonClass Draw := inferInstance let : MeasurableSingletonClass (Fin (copies + 1) → Draw) := inferInstance let : MeasurableSingletonClass (Fin (passes + 1) → Fin (copies + 1) → Draw) := inferInstance let := commonSeedTraceFintype Seed (fun _ => Fin (copies + 1) → Draw) passes let := commonSeedTraceSingleton Seed (fun _ => Fin (copies + 1) → Draw) passes let rowLaw : Measure (Fin (copies + 1) → Draw) := Measure.pi fun _ => μ let trim : (Fin (copies + 1) → Draw) → (Fin copies → Draw) := fun row copy => row copy.castSucc let finish : (Fin (copies + 1) → Draw) → Draw := fun row => row 0 let pack : Seed × Family → Seed × (Fin (passes + 1) → Fin (copies + 1) → Draw) := Prod.map (id : Seed → Seed) (physicalFamilyPack target N P F exponent H Q passes copies) let finalMap := Prod.map (mapCommonTrace (Seed := Seed) trim passes) finish have hpack : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies)).map pack = incoming.prod (Measure.pi fun _ : Fin (passes + 1) => rowLaw) := by dsimp only [pack, rowLaw] rw [← Measure.map_prod_map _ _ measurable_id (measurable_of_finite _), Measure.map_id, physicalFamilyPack_law] have hrow : rowLaw.map trim = Measure.pi fun _ : Fin copies => μ := finite_init_law μ copies have hlast : rowLaw.map finish = μ := by simpa only [measure_univ, Finset.prod_const_one, one_smul] using (Measure.pi_map_eval (fun _ : Fin (copies + 1) => μ) 0) have hmap : ((commonTraceLaw (fun _ => rowLaw) incoming passes).prod rowLaw).map finalMap = (commonTraceLaw (fun _ => Measure.pi fun _ : Fin copies => μ) incoming passes).prod μ := by dsimp only [finalMap] rw [← Measure.map_prod_map _ _ (measurable_of_finite _) (measurable_of_finite _), mapCommonTrace_law incoming rowLaw trim passes, hrow, hlast] have heq : physicalFamilyToTrace (Seed := Seed) target N P F exponent H Q passes copies = finalMap ∘ commonArrayFinal passes ∘ pack := rfl rw [heq, ← Measure.map_map (measurable_of_finite _) (measurable_of_finite _), ← Measure.map_map (measurable_of_finite _) (measurable_of_finite _), hpack, commonArrayFinal_law incoming rowLaw passes] exact hmap
end SourceFamily
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyProgramimport OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemoWork
namespace OAI
namespace EditApproximation
section Work
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (initial : PhysicalEntry M J target.length → ℕ) (hPpos : 0 < P) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "group" => physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies drawlocal notation "integer" => physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta hPpos draw initiallocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies drawlocal notation "bodyValue" => physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies factor multiplier tau eta kappa delta initial hPpos draw
noncomputable def physicalFamilyDependencyTree (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : DependencyExpansion := chargedRandomDependencyTree source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer bodyValue root
theorem physicalFamilyDependencyTree_depth (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw root).depth = root.depth := by exact queryDependencyExpansion_depth _ _ _ (chargedRandomRequestList_progress source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer bodyValue) root
theorem physicalFamilyDependencyTree_rank (hpasses : passes = computedSeedPassCount N) (hT : T = (integerParameters N).T) (hS : S = (integerParameters N).S) (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw root).rank ≤ computedDependencyIndexCount N := by have heq : (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw root).rank = root.index := queryDependencyExpansion_index _ _ _ (chargedRandomRequestList_progress source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer bodyValue) root rw [heq] apply (chargedRequest_index_le root).trans_eq simp only [computedDependencyIndexCount, hpasses, hT, hS]
theorem physicalFamilyDependencyTree_valid (hN : 0 < N) (hell : 200 ≤ ell) (hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P) (hT : T = (integerParameters N).T) (hS : S = (integerParameters N).S) (hcopies : copies ≤ inputHeight N ^ 2) (hAmin : ∀ pass, 1 ≤ factor pass) (hAmax : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ)) (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw root).Valid (M * ell ^ 257) (inputHeight N ^ (512 * (coarseExponent ell + 1))) := chargedRandomDependencyTree_valid source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer bodyValue hN hell hM hP hT hS hcopies hAmin hAmax root
theorem physicalFamilyMemo_requests_le_width (hN : 0 < N) (hell : 200 ≤ ell) (hM : M = (integerParameters N).M) (hAmax : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ)) (bits : ℕ) (encode : Sum (PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copies) (ChargedPhysicalRequest M J target.length (passes + 1) copies T S) → ℕ) (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) (root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : (chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root).requests ≤ (inputHeight N ^ 91 + 1) * (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw root).widthWork M source.length := chargedRandomMemoEvaluate_requests_le_widthWork source target N P H T S (passes + 1) copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer bodyValue (inputHeight N ^ 91) bits encode hinjective hbounded (computed_physicalFamilyProgram_source_cost source target N P H T S passes copies factor multiplier tau eta kappa delta initial hPpos draw hN hell hM hAmax) root
end Work
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import OAI.Combinatorics.EditApproximation.Refinement.PhysicalSeedScheduleimport OAI.Combinatorics.EditApproximation.Probability.FiniteSeedFinal
namespace OAI
/-! Accuracy of the final fresh refinement after adaptive median seed passes,under finite Bernstein bounds and an explicit incoming seed failure bound. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
section Final
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (source target : List α) (N P T S H : ℕ)
local notation "Seed" => ClampedPhysicalSeed M J target.length Nlocal notation "ell" => inputSmallLog Nlocal notation "terminalFactor" => scheduledSeedFactor N (computedSeedPassCount N)local notation "thetaExponent" => (40 * smallLogExponent N : ℕ)local notation "eta" => RationalParameters.eta (rationalParameters ell)local notation "kappa" => RationalParameters.kappa (rationalParameters ell)local notation "delta" => RationalParameters.delta (rationalParameters ell)local notation "tau" => RationalParameters.tau (rationalParameters ell)
abbrev FinalProgramDraw (seed : Seed) := PhysicalProgramDraw (R := R) source target (clampedSeedNat seed) N P ell terminalFactor T thetaExponent H (ell ^ 80) tau
noncomputable def finalProgramDrawLaw (seed : Seed) : Measure (FinalProgramDraw (R := R) source target N P T H seed) := physicalProgramDrawLaw (R := R) source target (clampedSeedNat seed) N P ell terminalFactor T thetaExponent H (ell ^ 80) tau
instance finalProgramDrawLaw_probability (seed : Seed) : IsProbabilityMeasure (finalProgramDrawLaw (R := R) source target N P T H seed) := by unfold finalProgramDrawLaw infer_instance
noncomputable def finalProgramValue (rootQ : TargetInterval target.length) (seed : Seed) (draw : FinalProgramDraw (R := R) source target N P T H seed) : ℝ := physicalRefinement source target (clampedSeedNat seed) N P ell terminalFactor T delta (physicalProgramDrawSelections source target (clampedSeedNat seed) N P ell terminalFactor T thetaExponent H (ell ^ 80) tau eta kappa draw) (Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J) S rootQ
abbrev FinalProgramOutcome := Seed × (∀ seed : Seed, FinalProgramDraw (R := R) source target N P T H seed)
noncomputable def finalProgramLaw (incoming : Measure Seed) : Measure (FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) := by classical exact (scheduledSeedLaw (R := R) source target N P T S H incoming (computedSeedPassCount N)).prod (Measure.pi (finalProgramDrawLaw (R := R) source target N P T H))
instance finalProgramLaw_probability (incoming : Measure Seed) [IsProbabilityMeasure incoming] : IsProbabilityMeasure (finalProgramLaw (R := R) source target N P T S H incoming) := by unfold finalProgramLaw infer_instance
/-- Equality is tested before the final query, so equal strings return zeroon every execution, including executions with a bad seed. -/noncomputable def finalProgramAnswer (rootQ : TargetInterval target.length) (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : ℕ := if source = substring target rootQ.lo rootQ.hi then 0 else integerAnswer N (freshSeedValue (finalProgramValue (M := M) (J := J) (R := R) source target N P T S H rootQ) pair)
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] intheorem finalProgramAnswer_equal (rootQ : TargetInterval target.length) (heq : source = substring target rootQ.lo rootQ.hi) (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : finalProgramAnswer (R := R) source target N P T S H rootQ pair = 0 := by simp only [finalProgramAnswer, heq, ite_true]
variable (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) (hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length) (hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T) (hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N) (hsize : source.length + target.length ≤ N) (bernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length, FiniteBernsteinInput (Measure.pi fun _ : Fin (groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) => (PMF.uniformOfFintype (Fin M)).toMeasure))
include hN hell hMeq hJeq hPeq hTeq hSeq hHeq hsize bernstein intheorem finalProgram_accuracy (incoming : Measure Seed) [IsProbabilityMeasure incoming] (hinitial : incoming.real {seed | ¬ physicalSeedGood source target ((integerParameters N).initialFactor : ℚ) seed} ≤ 1 / 100) (rootQ : TargetInterval target.length) (epsilon : ℝ) (hepsilon : 0 < epsilon) (haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) : (4 / 5 : ℝ) ≤ (finalProgramLaw (R := R) source target N P T S H incoming).real {pair | stateEditCost source target rootQ ≤ finalProgramAnswer (R := R) source target N P T S H rootQ pair ∧ (finalProgramAnswer (R := R) source target N P T S H rootQ pair : ℝ) ≤ (1 + epsilon) * stateEditCost source target rootQ} := by classical by_cases heq : source = substring target rootQ.lo rootQ.hi · have hcost : stateEditCost source target rootQ = 0 := (EditDistortion.cost_eq_zero_iff (s := true)).mpr heq have hans (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : finalProgramAnswer (R := R) source target N P T S H rootQ pair = 0 := finalProgramAnswer_equal source target N P T S H rootQ heq pair simp only [hans, hcost, Nat.cast_zero, mul_zero, le_refl, and_self, Set.ofPred_true, probReal_univ] norm_num have hD : 0 < stateEditCost source target rootQ := Nat.pos_of_ne_zero (fun h => heq ((EditDistortion.cost_eq_zero_iff (s := true)).mp h)) have hf : 3 ≤ smallLogExponent N := by have h := (Nat.pow_le_pow_iff_right (by decide : 1 < (2 : ℕ))).mp hell omega have hA : (1 : ℚ) ≤ terminalFactor := by unfold scheduledSeedFactor exact one_le_pow₀ (by norm_num) have hAupper : terminalFactor ≤ ((integerParameters N).initialFactor : ℚ) := by unfold scheduledSeedFactor rw [← computedSeed_initial_factor] exact dyadicSeedFactor_bound _ _ _ have ha := scheduledSeedFactor_terminal_refinement N hf have hbranch : 0 < M := Nat.pos_of_ne_zero (NeZero.ne M) have hP := computed_program_grid_lower N P hN hPeq have hF : 1 ≤ ell := Nat.one_le_two_pow have hT : 0 < T := by rw [hTeq]; exact (computed_stage_positive_counts N hN hell).1 have hEll : (0 : ℝ) < ell := Nat.cast_pos.2 (Nat.two_pow_pos _) let terminalLaw := scheduledSeedLaw (R := R) source target N P T S H incoming (computedSeedPassCount N) let good : Seed → Prop := physicalSeedGood source target terminalFactor let value := finalProgramValue (M := M) (J := J) (R := R) source target N P T S H rootQ have hseed : terminalLaw.real {seed | ¬ good seed} ≤ 1 / 10 := (scheduledSeedLaw_failure_lt (R := R) source target N P T S H hN hell hMeq hJeq hPeq hTeq hSeq hHeq hsize bernstein incoming hinitial).le have hlower (seed : Seed) (hg : good seed) (draw : FinalProgramDraw (R := R) source target N P T H seed) : (stateEditCost source target rootQ : ℝ) ≤ value seed draw := by have h := (physicalRefinement_stage_bounds source target hbranch (clampedSeedNat seed) N P ell terminalFactor hsize hP hF hA hg T hT delta (physicalProgramDrawSelections source target (clampedSeedNat seed) N P ell terminalFactor T thetaExponent H (ell ^ 80) tau eta kappa draw) (Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J) S rootQ).1 have hleft := (le_max_left _ _).trans h simpa only [value, finalProgramValue, ha, Rat.cast_one, div_one, physicalSource, physicalSourceInterval, sourceIntervalAt, substring, List.take_length, List.drop_zero] using hleft have hmoment (seed : Seed) (hg : good seed) : (∫ draw, max (value seed draw - stateEditCost source target rootQ) 0 ∂finalProgramDrawLaw (R := R) source target N P T H seed) ≤ (stateEditCost source target rootQ : ℝ) / ell := by have h := physicalProgram_expected_root_excess (R := R) source target N hN hell hMeq hJeq (clampedSeedNat seed) P hPeq terminalFactor hA hAupper hsize hg T S hTeq hSeq hHeq bernstein rootQ simpa only [value, finalProgramValue, finalProgramDrawLaw, one_div_mul_eq_div] using h have hDN : stateEditCost source target rootQ ≤ N := by have h := physical_state_cost_le (M := M) (J := J) source target N hsize ((Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J), rootQ) simpa only [physicalSource, physicalSourceInterval, sourceIntervalAt, substring, List.take_length, List.drop_zero] using h have h := freshSeed_answer_accuracy (finalProgramDrawLaw (R := R) source target N P T H) terminalLaw good value hDN hD hEll hepsilon haccuracy hseed hlower hmoment simpa only [finalProgramLaw, finalProgramAnswer, heq, ite_false, terminalLaw, value] using h
end Final
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181import OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegretimport OAI.Combinatorics.EditApproximation.Refinement.StageComparisonEnergy
namespace OAI
/-! The generic regret bound for the actual complete physical recurrence. -/
namespace EditApproximation
open Finset
section Node
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (hM : 0 < M) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (T : ℕ) (hT : 0 < T) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (hbelow : node.1.val < J) (hleaf : ¬ (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) (hc : 0 < stateEditCost (physicalSource source node) target q)
local notation "parent" => physicalSourceInterval source.length nodelocal notation "b" => 2 ^ Nat.log 2 (stateEditCost (physicalSource source node) target q)local notation "r" => roundInterval (seedGridSpacing b P) qlocal notation "action" => comparisonChildren source target hM P hP parent q hclocal notation "mass" => fun i s => (stageWarmupMass source target U N P F A T (physicalChild node hbelow i, s) : ℝ)local notation "W" => comparisonActionMass action masslocal notation "value" => fun t (s : PhysicalEntry M J target.length) => (physicalRefinement source target U N P F A T delta choices (Prod.fst s) t (Prod.snd s) : ℝ)local notation "regret" => fun t => max (stateEditCost (physicalSource source node) target q : ℝ) (value (t + 1) (node, q)) - (128 * (F : ℝ)) * targetEndpointDistance q r - physicalComparisonClipped source target U N P F A T delta choices node hbelow action (t + 1)
include hsize hF hA hseed hT hleaf in theorem physicalNode_generic_regret (S : ℕ) : (∑ t ∈ range S, regret t) ≤ W - |stateLengthGap (physicalSource source node) target r| := by have hspec := comparisonChildren_spec source target hM P hP parent q hc have hzero : endpointActionConnection r action = 0 := hspec.2.1 have hrep := stageRounded_representative_mem source target U N P F A hsize hP hF hA hseed node q hc have hL : (1 : ℝ) ≤ 128 * F := by have hFR : (1 : ℝ) ≤ F := by exact_mod_cast hF linarith only [hFR] have hsplit : (stateEditCost (physicalSource source node) target q : ℝ) ≤ (128 * (F : ℝ)) * targetEndpointDistance q r + ∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ) := by have h := comparisonChildren_lower source target hM P hP parent q hc have he := mul_le_mul_of_nonneg_right hL (Nat.cast_nonneg (α := ℝ) (targetEndpointDistance q r)) change (stateEditCost (physicalSource source node) target q : ℝ) ≤ (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) + targetEndpointDistance q r at h simp only [one_mul] at he linarith only [h, he] have hbellman (t : ℕ) (_ht : t < S) : value (t + 1) (node, q) ≤ (128 * (F : ℝ)) * targetEndpointDistance q r + ∑ i, value t (physicalChild node hbelow i, action i) := by have hQ := (physicalRefinement_bellman_invariants source target U N P F A T delta choices node t q).2 have hR := (Rat.cast_le (K := ℝ)).mpr hQ rw [rationalPhysicalBellman_cast] at hR have h := physicalBellman_le_action source target P ((128 * F : ℚ) : ℝ) (fun s => (stageInitial source target U N P F A s : ℝ)) (stageRepresentatives source target U N P F A) (value t) node hbelow hleaf q r b hrep action hspec.1 rw [hzero, Nat.cast_zero, add_zero] at h simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using hR.trans h have hmono (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) : value S (physicalChild node hbelow i, action i) ≤ value 0 (physicalChild node hbelow i, action i) := by apply Rat.cast_le.mpr have hantitone : Antitone (fun t => physicalRefinement source target U N P F A T delta choices (physicalChild node hbelow i) t (action i)) := antitone_nat_of_succ_le (fun t => physicalRefinement_nonincreasing source target U N P F A T delta choices (physicalChild node hbelow i) t (action i)) exact hantitone (Nat.zero_le S) have hinv (i : Fin M) := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT (physicalChild node hbelow i, action i) have hinit (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) : value 0 (physicalChild node hbelow i, action i) ≤ mass i (action i) := by dsimp only rw [physicalRefinement_zero] exact Rat.cast_le.mpr (hinv i).2.1 have hgapMass (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) : |stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)| ≤ mass i (action i) := ((le_max_right _ _).trans (hinv i).1).trans (Rat.cast_le.mpr (hinv i).2.1) have h := generic_regret_mass_bound univ S (stateEditCost (physicalSource source node) target q : ℝ) ((128 * (F : ℝ)) * targetEndpointDistance q r) (fun i => (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) (fun i => mass i (action i)) (fun i => stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)) (fun t => value t (node, q)) (fun t i => value t (physicalChild node hbelow i, action i)) hsplit hbellman hmono hinit (fun i _ => stateEditCost_length_lower _ _ _) hgapMass apply h.trans have hsum := sum_mass_sub_abs_le univ (fun i => mass i (action i)) (fun i => stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)) have hgapSum : (∑ i, stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)) = stateLengthGap (physicalSource source node) target r := zero_connection_gap_sum source target hM parent r action hzero rw [hgapSum] at hsum exact hsum
include hsize hF hA hseed hT in theorem physicalComparison_mass_upper (hMP : 4 * (M : ℝ) / P ≤ 1) : W ≤ 4 * F * stateEditCost (physicalSource source node) target q := by have hcost := comparisonChildren_cost_bound source target hM P hP parent q hc change (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤ (1 + 4 * (M : ℝ) / P) * stateEditCost (physicalSource source node) target q at hcost have hsum : W ≤ 2 * (F : ℝ) * ∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ) := by change (∑ i, mass i (action i)) ≤ _ rw [mul_sum] apply sum_le_sum intro i _ have h := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT (physicalChild node hbelow i, action i) have hQ := h.2.2.1.trans h.2.2.2 simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using (Rat.cast_le (K := ℝ)).mpr hQ have hfactor := mul_le_mul_of_nonneg_left hcost (show (0 : ℝ) ≤ 2 * F by positivity) have hcost0 : (0 : ℝ) ≤ stateEditCost (physicalSource source node) target q := Nat.cast_nonneg _ have hfactor2 := mul_le_mul_of_nonneg_right hMP hcost0 have hfactor3 := mul_le_mul_of_nonneg_left hfactor2 (show (0 : ℝ) ≤ 2 * F by positivity) nlinarith only [hsum, hfactor, hfactor3]
include hsize hF hA hseed hT hleaf in theorem physicalNode_generic_regret_upper (hMP : 4 * (M : ℝ) / P ≤ 1) (S : ℕ) : (∑ t ∈ range S, regret t) ≤ 4 * F * stateEditCost (physicalSource source node) target q := by exact (physicalNode_generic_regret source target hM U N P F A hsize hP hF hA hseed T hT delta choices node hbelow hleaf q hc S).trans ((sub_le_self _ (abs_nonneg _)).trans (physicalComparison_mass_upper source target hM U N P F A hsize hP hF hA hseed T hT node hbelow q hc hMP))
include hsize hF hA hseed hT hleaf in theorem physicalNode_near_length_gap_regret (hscale : 2 * (refinementFactor A F : ℝ) ≤ P) (hMP : 4 * (M : ℝ) / P ≤ 1) (hnonempty : wideActionList M parent r b P ≠ []) (tau : ℚ) (htau : 0 ≤ tau) (hprediction : 1 - tau < |rationalStateGap (physicalSource source node) target r / rationalWideActionMinimum parent r b P hnonempty (physicalBandChildMassTable source target U N P F A T node hbelow)|) (ratio : ℝ) (hdiscrepancy : W - wideActionMinimum parent r b P hnonempty mass ≤ ratio * stateEditCost (physicalSource source node) target q) (S : ℕ) : (∑ t ∈ range S, regret t) ≤ (ratio + 4 * (tau : ℝ) * F) * stateEditCost (physicalSource source node) target q := by let Z := wideActionMinimum parent r b P hnonempty mass have hspec := comparisonChildren_spec source target hM P hP parent q hc have ha : (1 : ℝ) ≤ refinementFactor A F := by simpa only [Rat.cast_one] using (Rat.cast_le (K := ℝ)).mpr (refinementFactor_spec A F (by omega)).1 have hlower := wideActionMinimum_lower source target hM parent r b P hnonempty (refinementFactor A F : ℝ) ha mass (stageWarmupMass_child_lower source target hM U N P F A hsize hP hF hA hseed T hT node hbelow) have hpositive := (stageComparison_positive_movement source target hM U N P F A hsize hP hF hA hseed T hT node q hc hscale).1 have hcostPos : (0 : ℝ) < stateEditCost (physicalSource source node) target r := by exact_mod_cast hpositive have hZ : 0 < Z := (div_pos hcostPos (by linarith only [ha])).trans_le ((le_max_left _ _).trans hlower) have hZW : Z ≤ W := by have h := wideActionMinimum_le_member parent r hnonempty mass action hspec.1 have hzero : endpointActionConnection r action = 0 := hspec.2.1 simpa only [Z, endpointActionValue, hzero, Nat.cast_zero, zero_add, comparisonActionMass] using h have hpred : 1 - (tau : ℝ) < |stateLengthGap (physicalSource source node) target r| / Z := by have h := (Rat.cast_lt (K := ℝ)).mpr hprediction simp only [Rat.cast_sub, Rat.cast_one, Rat.cast_abs, Rat.cast_div, rationalStateGap_cast, rationalWideActionMinimum_cast, abs_div] at h change 1 - (tau : ℝ) < |stateLengthGap (physicalSource source node) target r| / |Z| at h rwa [abs_of_pos hZ] at h have hnear := near_length_gap_regret_bound W Z (stateLengthGap (physicalSource source node) target r) (tau : ℝ) ratio F (stateEditCost (physicalSource source node) target q) hZ hZW ((Rat.cast_nonneg (K := ℝ)).mpr htau) hpred hdiscrepancy (physicalComparison_mass_upper source target hM U N P F A hsize hP hF hA hseed T hT node hbelow q hc hMP) exact (physicalNode_generic_regret source target hM U N P F A hsize hP hF hA hseed T hT delta choices node hbelow hleaf q hc S).trans hnear
end Node
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import OAI.Combinatorics.EditApproximation.Probability.FiniteQueryRestrictionimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementDataRequestimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalMedianQueryimport OAI.Combinatorics.EditApproximation.Geometry.LocalSeedSequenceimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The global query body. A seed read at pass zero evaluates the coarseseed entry; every later pass reads the preceding pass's copy medians.All warmup and refinement dependencies carry strict physical ranks. -/
namespace EditApproximation
section Program
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (N P F exponent H Q T S copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) (integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (initial : PhysicalEntry M J target.length → ℕ)
def physicalGlobalQuery (request : PhysicalTableRequest M J target.length) : FiniteQuery {child : PhysicalTableRequest M J target.length // child.combinedRank T S < request.combinedRank T S} := by let seedRead := globalSeedRead N T S copies multiplier initial request by_cases hwarmup : request.index ≤ T · exact physicalWarmupRequestQuery source target N P F (factor request.pass) request.pass request.copy T S request.index request.node request.state seedRead · by_cases hbelow : request.node.1.val < J · by_cases hshort : (physicalSourceInterval source.length request.node).hi - (physicalSourceInterval source.length request.node).lo ≤ 1 · exact physicalInitialQuery source target N P F (factor request.pass) seedRead (request.node, request.state) · have ht : 0 < request.index - T := by omega have hrequest : PhysicalTableRequest.refinement request.pass request.copy request.node T (request.index - T) request.state = request := by have hi : T + (request.index - T) = request.index := by omega unfold PhysicalTableRequest.refinement rw [hi] have program := physicalRefinementDataRequestQuery source target N P F exponent H Q tau (refinementFactor (factor request.pass) F) eta kappa delta request.pass request.copy T S (request.index - T) ht request.node hbelow (group request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1))) (integer request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1))) request.state exact FiniteQuery.mapKeys (fun child => ⟨child.val, by simpa only [hrequest] using child.property⟩) program · exact physicalInitialQuery source target N P F (factor request.pass) seedRead (request.node, request.state)
end Program
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250import OAI.Combinatorics.EditApproximation.Refinement.PhysicalGlobalQueryimport OAI.Combinatorics.EditApproximation.Geometry.RankedMemoSimulation
namespace OAI
/-! The global query body computes the local pass recurrence on every seed and draw. -/
namespace EditApproximation
section Value
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (N P F exponent H Q T S copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) (integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (initial : PhysicalEntry M J target.length → ℕ)
theorem physicalGlobalQuery_warmup (pass copy : ℕ) (node : PhysicalNode M J) (j : ℕ) (hj : j ≤ T) (q : TargetInterval target.length) : physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node j q) = physicalWarmupRequestQuery source target N P F (factor pass) pass copy T S j node q (globalSeedRead N T S copies multiplier initial (PhysicalTableRequest.warmup pass copy node j q)) := by unfold physicalGlobalQuery dsimp only erw [dite_eq_left (show (PhysicalTableRequest.warmup pass copy node j q).index ≤ T from hj)] rfl
theorem physicalGlobalQuery_refinement_value (request : PhysicalTableRequest M J target.length) (hindex : T < request.index) (hbelow : request.node.1.val < J) (hshort : ¬ (physicalSourceInterval source.length request.node).hi - (physicalSourceInterval source.length request.node).lo ≤ 1) (values : PhysicalTableRequest M J target.length → ℚ) : (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request).value (fun child => values child.val) = (physicalRefinementDataRequestQuery source target N P F exponent H Q tau (refinementFactor (factor request.pass) F) eta kappa delta request.pass request.copy T S (request.index - T) (Nat.sub_pos_of_lt hindex) request.node hbelow (group request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1))) (integer request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1))) request.state).value (fun child => values child.val) := by unfold physicalGlobalQuery dsimp only erw [dite_eq_right (Nat.not_le.mpr hindex), dite_eq_left hbelow, dite_eq_right hshort] rw [FiniteQuery.mapKeys_value] rfl
theorem globalSeedRead_value (parent : PhysicalTableRequest M J target.length) (q : TargetInterval target.length) : (globalSeedRead N T S copies multiplier initial parent (parent.node, q)).value (fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial child.val) = (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial parent.pass (parent.node, q) : ℚ) := by by_cases hp : parent.pass = 0 · rw [globalSeedRead, ite_eq_left rfl, dite_eq_left hp] change (initial (parent.node, q) : ℚ) = _ rw [hp] rfl · simp only [globalSeedRead, ite_true, dite_eq_right hp] rw [physicalMedianSeedQuery_value] have hprev (copy : Fin copies) : previousPassRequest T S copy.val parent q = PhysicalTableRequest.refinement (parent.pass - 1) copy.val parent.node T S q := rfl simp only [hprev, localRequestValue_refinement] obtain ⟨pass, hpass⟩ := Nat.exists_eq_succ_of_ne_zero hp simp only [hpass, Nat.succ_eq_add_one, Nat.add_sub_cancel, localSeedSequence]
theorem localRequestValue_initial (pass copy : ℕ) (node : PhysicalNode M J) (q : TargetInterval target.length) : localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node 0 q) = stageInitial source target (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by rw [localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node 0 (Nat.zero_le T)] rfl
theorem localRequestValue_mass (pass copy : ℕ) (node : PhysicalNode M J) (q : TargetInterval target.length) : (∑ j : Fin T, localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node j.val q)) / T = physicalLocalWarmupMass source target (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) N P F (factor pass) T (node, q) := by unfold physicalLocalWarmupMass rw [← Fin.sum_univ_eq_sum_range] congr 1 exact Finset.sum_congr rfl (fun j _ => localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node j.val (Nat.le_of_lt j.isLt) q)
theorem localPassValue_step (seed : PhysicalEntry M J target.length → ℕ) (pass copy : ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J) (hshort : ¬ (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (t : ℕ) (ht : 0 < t) (q : TargetInterval target.length) : let children := fun i s r => localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer seed pass copy (physicalChild node hbelow i) s r localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer seed pass copy node t q = rationalLocalWideStep source target (physicalSourceInterval source.length node) N P F exponent Q tau (refinementFactor (factor pass) F) delta (fun r => stageInitial source target seed N P F (factor pass) (node, r)) (physicalLocalChildMass source target seed N P F (factor pass) T node hbelow) (fun i r => stageInitial source target seed N P F (factor pass) (physicalChild node hbelow i, r)) (fun i r => children i (t - 1) r) (fun i r => children i t r) (group pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) (localOnlineCandidates source target (physicalSourceInterval source.length node) N P F exponent H tau (refinementFactor (factor pass) F) eta kappa (fun r => stageInitial source target seed N P F (factor pass) (node, r)) (physicalLocalChildMass source target seed N P F (factor pass) T node hbelow) (fun i r => stageInitial source target seed N P F (factor pass) (physicalChild node hbelow i, r)) children (t - 1) (integer pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q) q := by dsimp only cases t with | zero => omega | succ t => unfold localPassValue rw [physicalLocalRefinement] simp only [dite_eq_left hbelow, ite_eq_right hshort, Nat.add_sub_cancel, physicalLocalOnline] rfl
theorem physicalRefinementDataRequestQuery_localValue (pass copy : ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J) (hshort : ¬ (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (t : ℕ) (ht : 0 < t) (q : TargetInterval target.length) : (physicalRefinementDataRequestQuery source target N P F exponent H Q tau (refinementFactor (factor pass) F) eta kappa delta pass copy T S t ht node hbelow (group pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) (integer pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q).value (fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial child.val) = localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) pass copy node t q := by rw [physicalRefinementDataRequestQuery_value] dsimp only simp_rw [localRequestValue_initial source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial, localRequestValue_mass source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial, localRequestValue_refinement source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial] exact (localPassValue_step source target N P F exponent H Q T factor tau eta kappa delta group integer _ pass copy node hbelow hshort t ht q).symm
theorem physicalGlobalQuery_value (request : PhysicalTableRequest M J target.length) : (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request).value (fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial child.val) = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request := by rcases request with ⟨pass, copy, node, index, q⟩ by_cases hj : index ≤ T · change (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q)).value _ = _ rw [physicalGlobalQuery_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node index hj q] change _ = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q) rw [localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node index hj q] apply physicalWarmupRequestQuery_value_local · intro r exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial _ r · intro hbelow input exact localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy (physicalChild node hbelow input.1) (index - 1) (by omega) input.2 · obtain ⟨t, hi⟩ : ∃ t, index = T + t := ⟨index - T, by omega⟩ subst index have ht : 0 < t := by omega change (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q)).value _ = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q) rw [localRequestValue_refinement source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node t q] by_cases hbelow : node.1.val < J · by_cases hshort : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1 · have hterminal : localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) pass copy node t q = stageInitial source target (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by unfold localPassValue rw [physicalLocalRefinement, dite_eq_left hbelow, ite_eq_left hshort] rw [hterminal] unfold physicalGlobalQuery dsimp only erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T from hj), dite_eq_left hbelow, dite_eq_left hshort] apply physicalInitialQuery_value_local intro r exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial _ r · erw [physicalGlobalQuery_refinement_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q) (by change T < T + t; omega) hbelow hshort] refine (physicalRefinementDataRequestQuery_localValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass copy node hbelow hshort (T + t - T) (by omega) q).trans ?_ rw [Nat.add_sub_cancel_left] · have hterminal : localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) pass copy node t q = stageInitial source target (localSeedSequence source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by unfold localPassValue rw [physicalLocalRefinement, dite_eq_right hbelow] rw [hterminal] unfold physicalGlobalQuery dsimp only erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T from hj), dite_eq_right hbelow] apply physicalInitialQuery_value_local intro r exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial _ r
theorem physicalGlobalProgramValue (request : PhysicalTableRequest M J target.length) : rankedProgramValue (PhysicalTableRequest.combinedRank T S) (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial) request = localRequestValue source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial request := rankedProgramValue_eq _ _ _ (physicalGlobalQuery_value source target N P F exponent H Q T S copies factor multiplier tau eta kappa delta group integer initial) request
end Value
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768import OAI.Combinatorics.EditApproximation.Refinement.ComputedGroupAccuracyimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementSpatial
namespace OAI
/-! Group concentration specialized to the actual stage and complete child histories. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
theorem physical_cellGroupEstimate_failure {α : Type*} [DecidableEq α] (source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N) {M J P b Q thetaExponent K : ℕ} [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (hM : 0 < M) (hMeq : M = (integerParameters N).M) (hPeq : P = (integerParameters N).P) (eb : ℕ) (hbeq : b = 2 ^ eb) (hQeq : Q = inputSmallLog N ^ 80) (hthetaeq : thetaExponent = 40 * smallLogExponent N) (U : PhysicalEntry M J target.length → ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (T : ℕ) (hT : 0 < T) (delta : ℚ) (choices : PhysicalSelections M J source.length target.length P (stageRepresentatives source target U N P (inputSmallLog N) A)) (node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ) (cell : ℕ × ℕ) (scales : Fin K → ℚ) (count : Fin K → ℕ) (hscales : List.ofFn scales = groupDyadicScales M b (inputSmallLog N)) (hcount : ∀ scale, count scale = groupSampleCount M Q b (scales scale)) (bernstein : ∀ scale : Fin K, FiniteBernsteinInput (Measure.pi fun _ : Fin (count scale) => (PMF.uniformOfFintype (Fin M)).toMeasure)) : let F := inputSmallLog N let initial := fun i s => stageInitial source target U N P F A (physicalChild node hbelow i, s) let child := fun i s => stageWarmupMass source target U N P F A T (physicalChild node hbelow i, s) let value := fun i s => physicalRefinement source target U N P F A T delta choices (physicalChild node hbelow i) t s let members := cellUnskippedBands source target (physicalSourceInterval source.length node) b P F thetaExponent (rationalParameters F).tau (refinementFactor A F) (fun s => stageInitial source target U N P F A (node, s)) child initial cell (groupSharedDrawLaw count).real {draw | ∃ member ∈ members, ((rationalParameters F).gamma : ℝ) * b < |((unskippedGroupEstimate scales count value member draw - rationalEndpointActionValue member.center member.rounded value : ℚ) : ℝ)|} ≤ 1 / (inputHeight N : ℝ) ^ 4 := by have hF : 1 ≤ inputSmallLog N := Nat.one_le_two_pow apply computed_cellGroupEstimate_failure source target N hN hell hM hMeq hPeq eb hbeq hQeq hthetaeq (physicalSourceInterval source.length node) (refinementFactor A (inputSmallLog N)) (fun s => stageInitial source target U N P (inputSmallLog N) A (node, s)) (fun i s => stageWarmupMass source target U N P (inputSmallLog N) A T (physicalChild node hbelow i, s)) (fun i s => stageInitial source target U N P (inputSmallLog N) A (physicalChild node hbelow i, s)) (fun i s => physicalRefinement source target U N P (inputSmallLog N) A T delta choices (physicalChild node hbelow i) t s) cell scales count hscales hcount · intro i s r have hf := refinementFactor_spec A (inputSmallLog N) (by omega) exact physicalInitialTable_spatial source target U N P (inputSmallLog N) A (refinementFactor A (inputSmallLog N)) hsize hP hF hA hf.1 hf.2 hseed (physicalChild node hbelow i) s r · intro i s have h := physicalRefinement_stage_bounds source target hM U N P (inputSmallLog N) A hsize hP hF hA hseed T hT delta choices (physicalChild node hbelow i) t s exact ⟨physicalRefinement_nonneg source target hM U N P (inputSmallLog N) A hsize hP hF hA hseed T hT delta choices (physicalChild node hbelow i) t s, h.2.1.trans (h.2.2.1.trans h.2.2.2.1)⟩ · exact bernstein
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import OAI.Combinatorics.EditApproximation.Coarse.CoarseIndexedEntryCostimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWorkimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
section Coarsevariable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B] (source target : List ℕ) (N P H T S passes copies : ℕ) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R) target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies) (depth : PhysicalEntry M J target.length → ℕ)
local notation "ell" => inputSmallLog Nlocal notation "exponent" => (40 * smallLogExponent N : ℕ)local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T Slocal notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes copieslocal notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
/-- Bit arithmetic is executed once for each fresh coarse source request. -/
theorem physicalFamilyIndexedCoarseWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ) (root : Table) (coarse : PhysicalCoarseDraw source target B depth) (C : ℝ) (hc : ∀ entry : PhysicalEntry M J target.length, (coarseIndexedEntryBinaryCost N B (depth entry) (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) ≤ C * ((coarseInitialArrayWork B (depth entry) (initialThresholdQ N) (initialLambda N) (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) + ((physicalSource source entry.1).length + 1 : ℕ))) : physicalFamilyIndexedCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw depth bits encode root coarse ≤ C * (physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier tau eta kappa delta draw B depth bits encode root coarse + physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) draw bits encode root) := by unfold physicalFamilyIndexedCoarseWork physicalFamilyMemoCoarseWork physicalFamilyCoarseInputWork exact coarseIndexedEntryCostSum_bound source target N depth coarse _ C hc
end Coarseend EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107import OAI.Combinatorics.EditApproximation.Refinement.PhysicalWarmupimport OAI.Combinatorics.EditApproximation.Geometry.LocalInitialConesimport OAI.Combinatorics.EditApproximation.Geometry.Leavesimport OAI.Combinatorics.EditApproximation.Probability.Exactimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The actual initial table uses exact empty/singleton leaves and local cones elsewhere. -/
namespace EditApproximation
open EditDistortion
theorem shortSourceCost_eq_edit {α : Type*} [DecidableEq α] (source target : List α) (hsource : source.length ≤ 1) : shortSourceCost source target = edit source target := by cases source with | nil => exact (edit_nil_left target).symm | cons a rest => have hrest : rest = [] := List.length_eq_zero_iff.mp (by simp only [List.length_cons] at hsource omega) subst rest exact singletonCost_eq_edit a target
def physicalInitialTable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A a : ℚ) (state : PhysicalEntry M J target.length) : ℚ := let piece := physicalSource source state.1 if piece.length ≤ 1 then shortSourceCost piece (substring target state.2.lo state.2.hi) else localInitialConeTable piece target (fun q => U (state.1, q)) N P F A a state.2
theorem physicalSource_length_le {α : Type*} {M J : ℕ} (source : List α) (node : PhysicalNode M J) : (physicalSource source node).length ≤ source.length := by simp only [physicalSource, substring, List.length_drop, List.length_take] exact (Nat.sub_le _ _).trans (min_le_right _ _)
theorem physical_state_cost_le {α : Type*} {M J : ℕ} (source target : List α) (N : ℕ) (hsize : source.length + target.length ≤ N) (state : PhysicalEntry M J target.length) : stateEditCost (physicalSource source state.1) target state.2 ≤ N := by apply (edit_le_max_length _ _).trans apply max_le · exact (physicalSource_length_le source state.1).trans (by omega) · have hlen : (substring target state.2.lo state.2.hi).length ≤ target.length := by simp only [substring, List.length_drop, List.length_take] exact (Nat.sub_le _ _).trans (min_le_right _ _) exact hlen.trans (by omega)
theorem physicalInitialTable_bounds {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A a : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (ha : 1 ≤ a) (hfactor : A ≤ a * F) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (state : PhysicalEntry M J target.length) : max ((stateEditCost (physicalSource source state.1) target state.2 : ℚ) / a) |rationalStateGap (physicalSource source state.1) target state.2| ≤ physicalInitialTable source target U N P F A a state ∧ physicalInitialTable source target U N P F A a state ≤ 2 * F * stateEditCost (physicalSource source state.1) target state.2 := by unfold physicalInitialTable dsimp only split_ifs with hleaf · rw [shortSourceCost_eq_edit _ _ hleaf] change max ((stateEditCost _ _ _ : ℚ) / a) |rationalStateGap _ _ _| ≤ stateEditCost _ _ _ ∧ (stateEditCost _ _ _ : ℚ) ≤ 2 * F * stateEditCost _ _ _ have hc : (0 : ℚ) ≤ stateEditCost (physicalSource source state.1) target state.2 := Nat.cast_nonneg _ have hFQ : (1 : ℚ) ≤ F := by exact_mod_cast hF have hgap := stateEditCost_length_lower (physicalSource source state.1) target state.2 rw [← rationalStateGap_cast] at hgap constructor · apply max_le · apply (div_le_iff₀ (by linarith : 0 < a)).2 nlinarith · exact_mod_cast hgap · nlinarith · rw [localInitialConeTable_eq_global _ _ _ N P F A a hP hF hA ha hfactor (fun q => physical_state_cost_le source target N hsize (state.1, q)) (fun q => hseed (state.1, q))] exact globalInitialConeTable_bounds _ _ _ N P F A a hP hF hA ha hfactor (fun q => physical_state_cost_le source target N hsize (state.1, q)) (fun q => hseed (state.1, q)) state.2
theorem physicalInitialTable_real_lower {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A a : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (ha : 1 ≤ a) (hfactor : A ≤ a * F) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) : physicalLower source target (a : ℝ) ≤ fun state => (physicalInitialTable source target U N P F A a state : ℝ) := by intro state have h := (physicalInitialTable_bounds source target U N P F A a hsize hP hF hA ha hfactor hseed state).1 have hR : ((max ((stateEditCost (physicalSource source state.1) target state.2 : ℚ) / a) |rationalStateGap (physicalSource source state.1) target state.2| : ℚ) : ℝ) ≤ (physicalInitialTable source target U N P F A a state : ℝ) := Rat.cast_le.mpr h simpa only [Rat.cast_max, Rat.cast_div, Rat.cast_natCast, Rat.cast_abs, rationalStateGap_cast, physicalLower] using hR
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import OAI.Combinatorics.EditApproximation.Geometry.GatheredLocalStepimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Fixed-width binary keys for gathered child states. The encoding usesmixed radix arithmetic on the child label and the two state endpoints. -/
namespace EditApproximation
theorem mixedRadix_injective {radix lo lo' hi hi' : ℕ} (hlo : lo < radix) (hlo' : lo' < radix) (heq : lo + radix * hi = lo' + radix * hi') : lo = lo' ∧ hi = hi' := by have hmod := congrArg (fun n => n % radix) heq simp only [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hlo, Nat.mod_eq_of_lt hlo'] at hmod refine ⟨hmod, ?_⟩ apply Nat.mul_left_cancel (by omega : 0 < radix) omega
theorem childInputCode_injective (M n : ℕ) : Function.Injective (@childInputCode M n) := by rintro ⟨i, q⟩ ⟨i', q'⟩ heq obtain ⟨hi, hq⟩ := mixedRadix_injective i.isLt i'.isLt heq have hqlo : q.lo < n + 1 := by have := q.ordered.trans q.valid; omega have hqlo' : q'.lo < n + 1 := by have := q'.ordered.trans q'.valid; omega obtain ⟨hlo, hhi⟩ := mixedRadix_injective hqlo hqlo' hq have hqeq : q = q' := by cases q; cases q'; cases hlo; cases hhi; rfl exact Prod.ext (Fin.ext hi) hqeq
theorem childInputCode_bound {M n : ℕ} (input : Fin M × TargetInterval n) : childInputCode input < M * (n + 1) ^ 2 := by have hlow := input.2.ordered.trans input.2.valid have hhigh := input.2.valid have hlabel := input.1.isLt have hM : 0 < M := by omega have hinner : input.2.lo + (n + 1) * input.2.hi < (n + 1) ^ 2 := by nlinarith only [hlow, hhigh] unfold childInputCode nlinarith only [hlabel, Nat.mul_le_mul_left M (Nat.succ_le_of_lt hinner)]
def childInputBits (M n : ℕ) : ℕ := Nat.clog 2 (M * (n + 1) ^ 2 + 1)
theorem childInputCode_fits {M n : ℕ} (input : Fin M × TargetInterval n) : childInputCode input < 2 ^ childInputBits M n := by exact (childInputCode_bound input).trans_le ((Nat.le_succ _).trans (Nat.le_pow_clog (by decide : 1 < 2) _))
theorem childInputBinaryKey_injective (M n : ℕ) : Function.Injective (fun input : Fin M × TargetInterval n => binaryMemoKey (childInputBits M n) (childInputCode input)) := by intro input other heq apply childInputCode_injective M n exact binaryMemoKey_injective _ (childInputCode_fits input) (childInputCode_fits other) heq
theorem childInputBits_le (M n H : ℕ) (hM : M ≤ 2 ^ H) (hn : n + 1 ≤ 2 ^ H) : childInputBits M n ≤ 3 * H + 1 := by apply (Nat.clog_le_iff_le_pow (by decide : 1 < 2)).2 have hproduct : M * (n + 1) ^ 2 ≤ 2 ^ (3 * H) := by calc _ ≤ 2 ^ H * (2 ^ H) ^ 2 := Nat.mul_le_mul hM (Nat.pow_le_pow_left hn 2) _ = _ := by rw [← pow_mul, ← pow_add]; congr 1; omega have hone : 1 ≤ 2 ^ (3 * H) := one_le_pow₀ (by decide : 1 ≤ (2 : ℕ)) calc _ ≤ 2 ^ (3 * H) + 2 ^ (3 * H) := Nat.add_le_add hproduct hone _ = 2 ^ (3 * H + 1) := by rw [pow_succ]; omega
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import OAI.Combinatorics.EditApproximation.Geometry.ParameterNumericalConstructionimport OAI.Combinatorics.EditApproximation.Binary.BinaryAffineGuardimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalUniformAccuracyimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
namespace EditApproximation
/-- Prefix rejection precedes arithmetic involving the accuracy word. -/
theorem physicalLargeInputWithWork_value (N : ℕ) (epsilon : BinaryFraction) : (physicalLargeInputWithWork N epsilon).1 = decide (physicalLargeInput N epsilon) := by apply Bool.eq_iff_iff.mpr by_cases hi : (inspectAccuracyWithWork (inputHeight N) epsilon).1.isSome = true · have hc : (binaryNaturalCompareWithWork (inputSmallLog N) (2 ^ 1000)).1 ≠ .lt ↔ 2 ^ 1000 ≤ inputSmallLog N := by rw [ne_eq, binaryNaturalCompareWithWork_lt, not_lt] have ha : (BinaryFraction.ltWithWork (BinaryFraction.canonicalMulWithWork (BinaryFraction.nat (inputSmallLog N)) epsilon).1 (BinaryFraction.nat 10)).1 ≠ true ↔ 10 ≤ (inputSmallLog N : ℚ) * epsilon.value := by rw [ne_eq, BinaryFraction.ltWithWork_value, BinaryFraction.canonicalMulWithWork_value, BinaryFraction.nat_value, BinaryFraction.nat_value, not_lt] norm_num have hm : (binaryNaturalCompareWithWork (inputHeight N) (inputBitLengthWithWork (onlineMassWithWork (integerParameters N).M (integerParameters N).P (inputHeight N)).1).1).1 ≠ .lt ↔ Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P (inputHeight N)) ≤ inputHeight N := by rw [ne_eq, binaryNaturalCompareWithWork_lt, inputBitLengthWithWork_spec, onlineMassWithWork_value, not_lt] simp only [physicalLargeInputWithWork, hi, ite_true, decide_eq_true_eq, physicalLargeInput, largeAccuracyInput, hc, ha, hm, true_and, and_assoc] · simp only [physicalLargeInputWithWork, hi, ite_false, Bool.false_eq_true, decide_eq_true_eq, physicalLargeInput, false_and]
theorem physicalLargeInputWithWork_cost (N : ℕ) (epsilon : BinaryFraction) (hmass : Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P (inputHeight N)) ≤ inputHeight N) : (physicalLargeInputWithWork N epsilon).2 ≤ 100000 * (inputHeight N + 1005) ^ 2 := by let B := (inputHeight N) + 1005 have hi := inspectAccuracyWithWork_cost (inputHeight N) epsilon by_cases haccepted : (inspectAccuracyWithWork (inputHeight N) epsilon).1.isSome = true · have hepsilon : epsilon.width ≤ (inputHeight N) := by rw [inspectAccuracyWithWork_spec] at haccepted split_ifs at haccepted with he · exact he · cases haccepted have hell : Nat.size (inputSmallLog N) + 2 ≤ B := by have hs := Nat.size_le_size (computed_smallLog_le_height N) have hh : Nat.size (inputHeight N) ≤ (inputHeight N) + 1 := by apply Nat.size_le.mpr exact Nat.lt_two_pow_self.trans_le (Nat.pow_le_pow_right (by decide) (Nat.le_succ (inputHeight N))) dsimp only [B] omega have hleft : (BinaryFraction.nat (inputSmallLog N)).width ≤ B := (BinaryFraction.nat_width_le _).trans hell have hright : epsilon.width ≤ B := hepsilon.trans (by dsimp [B]; omega) have hten : (BinaryFraction.nat 10).width ≤ 4 * B + 2 := by have ht := BinaryFraction.nat_width_le 10 rw [show Nat.size 10 = 4 from by decide] at ht dsimp only [B] omega have hp := BinaryFraction.canonicalMulWithWork_cost (BinaryFraction.nat (inputSmallLog N)) epsilon B hleft hright have hpw := BinaryFraction.canonicalMulWithWork_width (BinaryFraction.nat (inputSmallLog N)) epsilon B hleft hright have ha := BinaryFraction.ltWithWork_cost (BinaryFraction.canonicalMulWithWork (BinaryFraction.nat (inputSmallLog N)) epsilon).1 (BinaryFraction.nat 10) (4 * B + 2) hpw hten have ht := binaryNaturalCompareWithWork_cost (inputSmallLog N) (2 ^ 1000) have hc := binaryNaturalCompareWithWork_cost (inputHeight N) (Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P (inputHeight N))) have hHsize : Nat.size (inputHeight N) ≤ (inputHeight N) + 1 := by apply Nat.size_le.mpr exact Nat.lt_two_pow_self.trans_le (Nat.pow_le_pow_right (by decide) (Nat.le_succ (inputHeight N))) have hmsize : Nat.size (Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P (inputHeight N))) ≤ (inputHeight N) + 1 := (Nat.size_le_size hmass).trans hHsize simp only [Nat.size_pow] at ht simp only [physicalLargeInputWithWork, haccepted, ite_true, inputBitLengthWithWork_spec, onlineMassWithWork_value, onlineMassWithWork_cost] change _ ≤ 100000 * B ^ 2 dsimp only [B] at hp ha hell ⊢ nlinarith only [hp, ha, ht, hi, hc, hHsize, hmsize, hmass, hell] · simp only [physicalLargeInputWithWork, haccepted, Bool.false_eq_true, ite_false] nlinarith only [hi, Nat.zero_le (inputHeight N)]
end EditApproximation
end OAI1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import OAI.Combinatorics.EditApproximation.Refinement.StageWarmup
namespace OAI
/-! Exact source leaves remain exact throughout the actual physical warmup. -/
namespace EditApproximation
open Finset
theorem physicalSource_length_eq {α : Type*} {M J : ℕ} (source : List α) (node : PhysicalNode M J) : (physicalSource source node).length = (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo := by simp only [physicalSource, substring, List.length_drop, List.length_take, Nat.min_eq_left (physicalSourceInterval source.length node).valid]
theorem physicalBellman_at_leaf {α : Type*} {M J : ℕ} (source target : List α) (P : ℕ) (L : ℝ) (initial : PhysicalEntry M J target.length → ℝ) (representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length)) (value : PhysicalEntry M J target.length → ℝ) (node : PhysicalNode M J) (hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) : physicalBellman source target P L initial representatives value (node, q) = initial (node, q) := by classical unfold physicalBellman dsimp only split_ifs <;> rfl
theorem physicalWarmup_at_leaf {α : Type*} {M J : ℕ} (source target : List α) (P : ℕ) (L : ℝ) (initial : PhysicalEntry M J target.length → ℝ) (representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length)) (t : ℕ) (node : PhysicalNode M J) (hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) : physicalWarmup source target P L initial representatives t (node, q) = initial (node, q) := by cases t with | zero => rfl | succ t => exact physicalBellman_at_leaf source target P L initial representatives _ node hleaf q
theorem rationalPhysicalWarmup_at_leaf {α : Type*} {M J : ℕ} (source target : List α) (P : ℕ) (L : ℚ) (initial : PhysicalEntry M J target.length → ℚ) (representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length)) (t : ℕ) (node : PhysicalNode M J) (hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) : rationalPhysicalWarmup source target P L initial representatives t (node, q) = initial (node, q) := by apply (Rat.cast_inj (α := ℝ)).mp rw [rationalPhysicalWarmup_cast] exact physicalWarmup_at_leaf source target P (L : ℝ) (fun s => (initial s : ℝ)) representatives t node hleaf q
theorem stageWarmup_at_leaf {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (t : ℕ) (node : PhysicalNode M J) (hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) : stageWarmup source target U N P F A t (node, q) = stateEditCost (physicalSource source node) target q := by unfold stageWarmup rw [rationalPhysicalWarmup_at_leaf source target P (128 * F) _ _ t node hleaf q] have hlength : (physicalSource source node).length ≤ 1 := (physicalSource_length_eq source node).trans_le hleaf simp only [stageInitial, physicalInitialTable, ite_eq_left hlength] rw [shortSourceCost_eq_edit _ _ hlength] rfl
theorem stageWarmupMass_at_leaf {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T : ℕ) (hT : 0 < T) (node : PhysicalNode M J) (hleaf : (physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) : stageWarmupMass source target U N P F A T (node, q) = stateEditCost (physicalSource source node) target q := by change (∑ t ∈ range T, stageWarmup source target U N P F A t (node, q)) / T = _ simp_rw [stageWarmup_at_leaf source target U N P F A _ node hleaf q] simp only [sum_const, card_range, nsmul_eq_mul] have hTr : (T : ℚ) ≠ 0 := by exact_mod_cast hT.ne' exact mul_div_cancel_left₀ _ hTr
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241import OAI.Combinatorics.EditApproximation.Refinement.PhysicalValueBitsimport OAI.Combinatorics.EditApproximation.Geometry.LocalOnlineProgram
namespace OAI
/-! Denominator and bit bounds for the local evaluator on every incomingseed. The proofs use the literal local candidates and do not pass throughthe good-seed equality with the complete evaluator. -/
namespace EditApproximation
open Finset
theorem physicalLocalWarmup_den_one {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) : (physicalLocalWarmup source target U N P F A t state).den = 1 := by induction t generalizing state with | zero => exact stageInitial_den_one source target U N P F A state | succ t ih => rw [physicalLocalWarmup] split_ifs · exact stageInitial_den_one source target U N P F A state · apply Nat.eq_one_of_dvd_one apply rationalMinimum_den_dvd · rw [stageInitial_den_one source target U N P F A] · intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv exact rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _) (by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F)) (rationalActualWideActions_connection_den _ _ _ action ha) (fun i => by rw [ih]) · exact stageInitial_den_one source target U N P F A state
theorem rationalLocalWideStep_den_dvd {α : Type*} (source target : List α) {M D : ℕ} (parent : TargetInterval source.length) (N P F exponent Q m : ℕ) (hm : 0 < m) (tau a : ℚ) (parentInitial : TargetInterval target.length → ℚ) (childMass childInitial old current : Fin M → TargetInterval target.length → ℚ) (draw : CellGroupDraws M F Q) (online : List (PhysicalRationalAction M target.length)) (hinitial : ∀ q, (parentInitial q).den ∣ D) (hold : ∀ i r, (old i r).den ∣ D) (hcurrent : ∀ i r, (current i r).den ∣ D) (honline : ∀ action ∈ online, action.connection.den = 1) (q : TargetInterval target.length) : (rationalLocalWideStep source target parent N P F exponent Q tau a (1 / (m : ℚ)) parentInitial childMass childInitial old current draw online q).den ∣ D * (m + 1) := by have hvalue (child : Fin M → TargetInterval target.length → ℚ) (hchild : ∀ i r, (child i r).den ∣ D) (action : PhysicalRationalAction M target.length) (hconn : action.connection.den = 1) : (rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F) (fun is => child is.1 is.2) q action).den ∣ D := rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _) (by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F)) hconn (fun i => hchild _ _) unfold rationalLocalWideStep apply rationalRefinementUpdate_den_dvd m D hm · apply rationalMinimum_den_dvd · apply rationalMinimum_den_dvd _ _ D (hinitial q) intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv exact hvalue old hold action (rationalActualWideActions_connection_den _ _ _ action ha) · intro v hv obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv have hwide := completeCellGroupActions_wide source target parent N P F exponent Q tau a parentInitial childMass childInitial current draw action (localCellGroupActions_subset source target parent N P F exponent Q tau a parentInitial childMass childInitial current draw q action ha) exact hvalue current hcurrent action (rationalActualWideActions_connection_den _ _ _ action hwide) · intro v hv apply rationalOnlineMinimum_den_dvd _ D _ v hv intro value hvalueMem obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hvalueMem exact hvalue current hcurrent action (honline action ha)
theorem keyedOnlineCandidate_connection_den {α : Type*} (source target : List α) {M : ℕ} (parent : TargetInterval source.length) (P F exponent H b : ℕ) (tau eta kappa : ℚ) (child initial : Fin M → TargetInterval target.length → ℚ) (children : PhysicalChildTables M target.length) (t : ℕ) (r : TargetInterval target.length) (integer : ℕ) (action : PhysicalRationalAction M target.length) (h : keyedOnlineCandidate source target parent P F exponent H b tau eta kappa child initial children t r integer = some action) : action.connection.den = 1 := by unfold keyedOnlineCandidate at h dsimp only at h split_ifs at h split at h · cases h · cases Option.some.inj h exact Rat.den_zero
theorem localOnlineCandidates_connection_den {α : Type*} (source target : List α) {M : ℕ} (parent : TargetInterval source.length) (N P F exponent H : ℕ) (tau a eta kappa : ℚ) (parentInitial : TargetInterval target.length → ℚ) (child initial : Fin M → TargetInterval target.length → ℚ) (children : PhysicalChildTables M target.length) (t : ℕ) (integer : ℕ → TargetInterval target.length → ℕ) (q : TargetInterval target.length) (action : PhysicalRationalAction M target.length) (ha : action ∈ localOnlineCandidates source target parent N P F exponent H tau a eta kappa parentInitial child initial children t integer q) : action.connection.den = 1 := by obtain ⟨b, _, _, hcandidate⟩ := (localOnlineCandidates_mem source target parent N P F exponent H tau a eta kappa parentInitial child initial children t integer q action).mp ha exact keyedOnlineCandidate_connection_den source target parent P F exponent H b tau eta kappa child initial children t _ _ action hcandidate
theorem physicalLocalOnline_connection_den {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent H T : ℕ) (A tau eta kappa : ℚ) (integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (node : PhysicalNode M J) (children : PhysicalChildTables M target.length) (t : ℕ) (q : TargetInterval target.length) (action : PhysicalRationalAction M target.length) (ha : action ∈ physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer node children t q) : action.connection.den = 1 := by unfold physicalLocalOnline at ha split_ifs at ha with hbelow · exact localOnlineCandidates_connection_den source target (physicalSourceInterval source.length node) N P F exponent H tau (refinementFactor A F) eta kappa _ _ _ children (t - 1) _ q action ha · exact False.elim (List.not_mem_nil ha)
theorem physicalLocalRefinement_den_dvd {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent Q : ℕ) (A tau : ℚ) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ → TargetInterval target.length → List (PhysicalRationalAction M target.length)) (honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : (physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw online node t q).den ∣ (ell ^ 10 + 1) ^ (J - node.1.val) := by rw [physicalLocalRefinement] split_ifs with hbelow hleaf · rw [stageInitial_den_one source target U N P F A] exact one_dvd _ · dsimp only cases t with | zero => rw [physicalLocalWarmup_den_one source target U N P F A] exact one_dvd _ | succ t => have hheight : J - node.1.val = (J - (node.1.val + 1)) + 1 := by omega rw [hheight] conv_rhs => rw [pow_succ] have hdelta : (1 / (ell : ℚ) ^ 10) = 1 / ((ell ^ 10 : ℕ) : ℚ) := by rw [Nat.cast_pow] rw [hdelta] apply rationalLocalWideStep_den_dvd source target _ N P F exponent Q (ell ^ 10) (pow_pos hell 10) tau (refinementFactor A F) · intro r rw [stageInitial_den_one source target U N P F A] exact one_dvd _ · intro i r simpa only [Nat.cast_pow, physicalChild] using physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw online honline (physicalChild node hbelow i) t r · intro i r simpa only [Nat.cast_pow, physicalChild] using physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw online honline (physicalChild node hbelow i) (t + 1) r · exact honline _ _ _ _ · rw [stageInitial_den_one source target U N P F A] exact one_dvd _termination_by J - node.1.valdecreasing_by all_goals unfold physicalChild dsimp only omega
theorem physicalLocalRefinement_encoding_bits {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent Q : ℕ) (A tau : ℚ) (hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ → TargetInterval target.length → List (PhysicalRationalAction M target.length)) (honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : rationalEncodingBits (physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw online node t q) ≤ Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * Nat.size (ell ^ 10 + 1) + 3 := by let value := physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw online node t q have hbounds := physicalLocalRefinement_bounds source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T (by positivity) draw online node t q have hupper : value ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using hbounds.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize (node, q)) have h := rationalEncodingBits_of_den_dvd value ((32 * F + 1) * N) ((ell ^ 10 + 1) ^ (J - node.1.val)) (by rw [abs_of_nonneg hbounds.1]; exact hupper) (pow_pos (by omega) _) (physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw online honline node t q) have hpower := natural_power_bit_length (ell ^ 10 + 1) (J - node.1.val) have hpowerTwice := Nat.mul_le_mul_left 2 hpower simp only [Nat.mul_add, Nat.mul_one, ← Nat.mul_assoc] at hpowerTwice change rationalEncodingBits value ≤ _ omega
theorem physicalLocalOnlineRefinement_den_dvd {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent H Q : ℕ) (A tau eta kappa : ℚ) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : (physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node t q).den ∣ (ell ^ 10 + 1) ^ (J - node.1.val) := physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw _ (physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer) node t q
theorem physicalLocalWarmup_encoding_bits {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N) (t : ℕ) (state : PhysicalEntry M J target.length) : rationalEncodingBits (physicalLocalWarmup source target U N P F A t state) ≤ Nat.size ((32 * F + 1) * N) + 3 := by let value := physicalLocalWarmup source target U N P F A t state have hbounds := physicalLocalWarmup_bounds source target U N P F A t state have hupper : value ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using hbounds.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize state) have hden : value.den ∣ 1 := by rw [physicalLocalWarmup_den_one source target U N P F A] have h := rationalEncodingBits_of_den_dvd value ((32 * F + 1) * N) 1 (by rw [abs_of_nonneg hbounds.1]; exact hupper) (by decide) hden simpa only [Nat.size_one, Nat.mul_one, Nat.add_assoc] using h
theorem physicalLocalOnlineRefinement_encoding_bits {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent H Q : ℕ) (A tau eta kappa : ℚ) (hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell) (draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q) (integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ) (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : rationalEncodingBits (physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10) T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node t q) ≤ Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * Nat.size (ell ^ 10 + 1) + 3 := physicalLocalRefinement_encoding_bits source target U N P F exponent Q A tau hsize T ell hell draw _ (physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer) node t q
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalOnlineKeysimport OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Every whole-cell stream used by the complete program has a boundedphysical key. Its two cell coordinates are at most n*2^exponent. -/
namespace EditApproximation
open MeasureTheory ProbabilityTheory
theorem list_eraseDups_nodup {α : Type*} [BEq α] [LawfulBEq α] (items : List α) : items.eraseDups.Nodup := by cases items with | nil => simp | cons first rest => rw [List.eraseDups_cons, List.nodup_cons] refine ⟨?_, list_eraseDups_nodup _⟩ intro hmem have hfalse := (List.mem_filter.mp (List.mem_eraseDups.mp hmem)).2 simp at hfalsetermination_by items.lengthdecreasing_by simpa only [List.length_cons] using Nat.lt_succ_of_le (List.length_filter_le (fun item => !(item == first)) rest)
theorem targetCell_coordinate_bound {n : ℕ} (exponent b : ℕ) (hb : 1 ≤ b) (q : TargetInterval n) : (targetCell ((2 : ℚ) ^ (-(exponent : ℤ)) * b) q).1 ≤ n * 2 ^ exponent ∧ (targetCell ((2 : ℚ) ^ (-(exponent : ℤ)) * b) q).2 ≤ n * 2 ^ exponent := by have hside : (0 : ℚ) < (2 : ℚ) ^ (-(exponent : ℤ)) * b := by positivity have hcoordinate (p : ℕ) (hp : p ≤ n) : ⌊(p : ℚ) / ((2 : ℚ) ^ (-(exponent : ℤ)) * b)⌋₊ ≤ n * 2 ^ exponent := by have hcancel : ((n * 2 ^ exponent : ℕ) : ℚ) * ((2 : ℚ) ^ (-(exponent : ℤ)) * b) = n * b := by push_cast rw [zpow_neg, zpow_natCast] field_simp have hmul : (p : ℚ) ≤ ((n * 2 ^ exponent : ℕ) : ℚ) * ((2 : ℚ) ^ (-(exponent : ℤ)) * b) := by rw [hcancel] exact_mod_cast hp.trans (Nat.le_mul_of_pos_right n (by omega)) have h := Nat.floor_le_floor ((div_le_iff₀ hside).2 hmul) simpa only [Nat.floor_natCast] using h exact ⟨hcoordinate q.lo (q.ordered.trans q.valid), hcoordinate q.hi q.valid⟩
section Keys
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent : ℕ) (A : ℚ)
theorem physicalProgramCells_bounds (node : PhysicalNode M J) (b : ℕ) (hb : 1 ≤ b) (cell : ℕ × ℕ) (hcell : cell ∈ physicalProgramCells source target U N P F A exponent node b) : cell.1 ≤ target.length * 2 ^ exponent ∧ cell.2 ≤ target.length * 2 ^ exponent := by obtain ⟨br, _, rfl⟩ := List.mem_map.mp (List.mem_eraseDups.mp hcell) exact targetCell_coordinate_bound exponent b hb br.2
theorem physicalGroupScale_positive (key : PhysicalGroupKey source target U N P F A exponent) : 1 ≤ (dyadicScales N).get key.2.1 := by have hm := List.get_mem (dyadicScales N) key.2.1 obtain ⟨e, _, heq⟩ := List.mem_map.mp hm exact heq ▸ Nat.one_le_two_pow
def physicalGroupRawKey (key : PhysicalGroupKey source target U N P F A exponent) : PhysicalLocalGroupKey M J N target.length exponent := let cell := (physicalProgramCells source target U N P F A exponent key.1.1 ((dyadicScales N).get key.2.1)).get key.2.2 let bounds := physicalProgramCells_bounds source target U N P F exponent A key.1.1 ((dyadicScales N).get key.2.1) (physicalGroupScale_positive source target U N P F exponent A key) cell (List.get_mem _ key.2.2) (key.1, key.2.1, ⟨cell.1, Nat.lt_succ_of_le bounds.1⟩, ⟨cell.2, Nat.lt_succ_of_le bounds.2⟩)
theorem physicalGroupRawKey_injective : Function.Injective (physicalGroupRawKey source target U N P F exponent A) := by rintro ⟨node, scale, cell⟩ ⟨node', scale', cell'⟩ heq have hn := congrArg Prod.fst heq change node = node' at hn subst node' have hs := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.1) heq change scale = scale' at hs subst scale' have hlo := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.2.1.val) heq have hhi := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.2.2.val) heq simp only [physicalGroupRawKey] at hlo hhi have hnodup : (physicalProgramCells source target U N P F A exponent node.1 ((dyadicScales N).get scale)).Nodup := list_eraseDups_nodup _ have hcell := hnodup.injective_get (Prod.ext hlo hhi) cases hcell rfl
end Keys
abbrev PhysicalLocalGroupArray (M J N n exponent F Q R : ℕ) (key : PhysicalLocalGroupKey M J N n exponent) := Fin R → ParentGroupDraw M (groupDyadicScales M ((dyadicScales N).get key.2.1) F).length (fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1) (groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h))
noncomputable def physicalLocalGroupArrayLaw (M J N n exponent F Q R : ℕ) [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (key : PhysicalLocalGroupKey M J N n exponent) : Measure (PhysicalLocalGroupArray M J N n exponent F Q R key) := Measure.pi fun _ : Fin R => groupSharedDrawLaw (M := M) (fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1) (groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h))
instance physicalLocalGroupArrayLaw_probability (M J N n exponent F Q R : ℕ) [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (key : PhysicalLocalGroupKey M J N n exponent) : IsProbabilityMeasure (physicalLocalGroupArrayLaw M J N n exponent F Q R key) := by unfold physicalLocalGroupArrayLaw infer_instance
theorem physicalLocalGroupDrawLaw_restrict {α : Type*} [DecidableEq α] {M J : ℕ} [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent Q R : ℕ) (A : ℚ) : (Measure.pi (physicalLocalGroupArrayLaw M J N target.length exponent F Q R)).map (fun draw (key : PhysicalGroupKey source target U N P F A exponent) => draw (physicalGroupRawKey source target U N P F exponent A key)) = Measure.pi (fun key : PhysicalGroupKey source target U N P F A exponent => Measure.pi (fun _ : Fin R => groupSharedDrawLaw (M := M) (fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1) (groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h)))) := finite_pi_restrict_map _ _ (physicalGroupRawKey_injective source target U N P F exponent A)
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107import OAI.Combinatorics.EditApproximation.Geometry.LocalGroupConesimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalSelectionProgram
namespace OAI
/-! The finite indexed group program has an equivalent cell-keyedrealization. Good initial seeds permit its whole cone to be evaluatedusing only the directly enumerated query cells. -/
namespace EditApproximation
section Program
variable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent Q : ℕ) (A : ℚ)
def physicalGroupStreamsOfKeys {R : ℕ} (draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) : PhysicalGroupStreams source target U N P F A exponent Q R := fun node scale cell time => draw node time ((dyadicScales N).get scale) ((physicalProgramCells source target U N P F A exponent node.1 ((dyadicScales N).get scale)).get cell)
theorem physicalProgramCells_keyed (node : PhysicalNode M J) (b : ℕ) : physicalProgramCells source target U N P F A exponent node b = representativeCells N P F b (refinementFactor A F) ((2 : ℚ) ^ (-(exponent : ℤ))) (fun q => stageInitial source target U N P F A (node, q)) := rfl
theorem physicalProgramGroups_keyed (T : ℕ) (tau : ℚ) {R : ℕ} [NeZero R] (draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) (node : PhysicalNode M J) (hbelow : node.1.val < J) (children : PhysicalChildTables M target.length) (t : ℕ) : physicalProgramGroups source target U N P F A T exponent Q tau (physicalGroupStreamsOfKeys source target U N P F exponent Q A draw) node children t = completeCellGroupActions source target (physicalSourceInterval source.length node) N P F exponent Q tau (refinementFactor A F) (fun q => stageInitial source target U N P F A (node, q)) (physicalBandChildMassTable source target U N P F A T node hbelow) (physicalBandChildInitial source target U N P F A node hbelow) (fun i q => children i t q) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) := by unfold physicalProgramGroups rw [dite_eq_left hbelow] unfold completeCellGroupActions conv_rhs => rw [← List.map_get_finRange (dyadicScales N)] rw [List.flatMap_map] apply List.flatMap_congr intro scale _ rw [← physicalProgramCells_keyed source target U N P F exponent A node] conv_rhs => rw [← List.map_get_finRange (physicalProgramCells source target U N P F A exponent node ((dyadicScales N).get scale))] simp only [List.filterMap_map, Function.comp_def, physicalGroupStreamsOfKeys]
/-- Actual chosen-group cone at one node, evaluated by bounded querycell loops. The old-child fallback is arbitrary provided it is at mostthe literal initial value. -/theorem physicalProgramGroups_local_minimum (T : ℕ) (tau : ℚ) {R : ℕ} [NeZero R] (draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) (node : PhysicalNode M J) (hbelow : node.1.val < J) (children : PhysicalChildTables M target.length) (t : ℕ) (q : TargetInterval target.length) (fallback : ℚ) (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (hfallback : fallback ≤ stageInitial source target U N P F A (node, q)) (hchild : ∀ i r, 0 ≤ children i t r) : rationalMinimum fallback ((localCellGroupActions source target (physicalSourceInterval source.length node) N P F exponent Q tau (refinementFactor A F) (fun r => stageInitial source target U N P F A (node, r)) (physicalBandChildMassTable source target U N P F A T node hbelow) (physicalBandChildInitial source target U N P F A node hbelow) (fun i r => children i t r) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q).map (rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F) (fun is => children is.1 t is.2) q)) = rationalMinimum fallback ((physicalProgramGroups source target U N P F A T exponent Q tau (physicalGroupStreamsOfKeys source target U N P F exponent Q A draw) node children t).map (rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F) (fun is => children is.1 t is.2) q)) := by rw [physicalProgramGroups_keyed source target U N P F exponent Q A T tau draw node hbelow children t] have hfactor := refinementFactor_spec A F (by omega : 0 < F) have hspatial : ∀ r, |stageInitial source target U N P F A (node, q) - stageInitial source target U N P F A (node, r)| ≤ 32 * F * targetEndpointDistance q r := by intro r have hqr := physicalInitialTable_spatial source target U N P F A (refinementFactor A F) hsize hP hF hA hfactor.1 hfactor.2 hseed node q r have hrq := physicalInitialTable_spatial source target U N P F A (refinementFactor A F) hsize hP hF hA hfactor.1 hfactor.2 hseed node r q have hsym : targetEndpointDistance r q = targetEndpointDistance q r := by exact congrArg₂ (· + ·) (Nat.dist_comm _ _) (Nat.dist_comm _ _) rw [hsym] at hrq apply abs_le.mpr constructor <;> dsimp only [stageInitial] <;> linarith only [hqr, hrq] exact localCellGroupMinimum_eq source target (physicalSourceInterval source.length node) N P F exponent Q tau (refinementFactor A F) (fun r => stageInitial source target U N P F A (node, r)) (physicalBandChildMassTable source target U N P F A T node hbelow) (physicalBandChildInitial source target U N P F A node hbelow) (fun i r => children i t r) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q fallback hfactor.1 hF hfallback hchild hspatial
end Program
end EditApproximation
end OAI12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalProgramLawimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRawOnlineProgramimport OAI.Combinatorics.EditApproximation.Refinement.PhysicalRawGroupProgram
namespace OAI
/-! Direct evaluation from the bounded joint random source agrees withcomplete refinement. All complete-table indexing occurs in the proof. -/
namespace EditApproximation
section Joint
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ) (T exponent H Q : ℕ) (tau eta kappa delta : ℚ) (draw : PhysicalLocalProgramDraw (R := R) source target U N P F A T exponent H Q tau)
def physicalLocalJointValue (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : ℚ := physicalLocalRefinement source target U N P F exponent Q A tau delta T (fun label s => physicalRawGroupDraws M J N target.length exponent F Q R (fun key => draw (.inr key)) label (Fin.ofNat R (s - 1))) (physicalLocalOnline source target U N P F exponent H T A tau eta kappa (physicalRawOnlineIntegers source target U N P F A T exponent H tau (fun key => draw (.inl key)))) node t q
variable (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
theorem physicalLocalJointValue_eq (node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) : physicalLocalJointValue source target U N P F A T exponent H Q tau eta kappa delta draw node t q = physicalRefinement source target U N P F A T delta (physicalProgramDrawSelections source target U N P F A T exponent H Q tau eta kappa (physicalLocalProgramToComplete source target U N P F A T exponent H Q tau hsize hP hF hA hseed draw)) node t q := by unfold physicalLocalJointValue rw [physicalRawOnlineProgram_eq source target U N P F A T exponent H tau eta kappa (fun key => draw (.inl key)) hsize hP hF hA hseed] rw [physicalGroupStreamsOfRaw] rfl
end Joint
end EditApproximation
end OAI123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import OAI.Combinatorics.EditApproximation.Geometry.LocalOnlineProgram
namespace OAI
/-! A proof adapter couples the bounded online query loop to the originalfinite product slots. The adapter is used only to compare laws: localexecution uses scale/center keys and never searches a complete table. -/
namespace EditApproximation
section Program
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R] (source target : List α) (U : PhysicalEntry M J target.length → ℕ) (N P F exponent H T : ℕ) (A tau eta kappa : ℚ) (online : PhysicalOnlineStreams source target U N P F A T exponent H tau R)
local notation "representatives" => stageRepresentatives source target U N P F A
noncomputable def physicalRepresentativeFin (node : PhysicalNode M J) (br : ℕ × TargetInterval target.length) (hbr : br ∈ representatives node) : Fin (representatives node).length := Classical.choose (List.mem_iff_get.mp hbr)
theorem physicalRepresentativeFin_get (node : PhysicalNode M J) (br : ℕ × TargetInterval target.length) (hbr : br ∈ representatives node) : (representatives node).get (physicalRepresentativeFin source target U N P F A node br hbr) = br := Classical.choose_spec (List.mem_iff_get.mp hbr)
noncomputable def physicalOnlineIntegersOfStreams (node : PhysicalInternalNode M J) (time : Fin R) (b : ℕ) (r : TargetInterval target.length) : ℕ := if hbr : (b, r) ∈ representatives node.1 then (online node (physicalRepresentativeFin source target U N P F A node.1 (b, r) hbr) time).val else 0
omit [NeZero R] intheorem physicalOnlineIntegersOfStreams_get (node : PhysicalInternalNode M J) (representative : Fin (representatives node.1).length) (time : Fin R) : physicalOnlineIntegersOfStreams source target U N P F exponent H T A tau online node time ((representatives node.1).get representative).1 ((representatives node.1).get representative).2 = (online node representative time).val := by unfold physicalOnlineIntegersOfStreams rw [dite_eq_left (List.get_mem _ _)] have heq : physicalRepresentativeFin source target U N P F A node.1 ((representatives node.1).get representative) (List.get_mem _ _) = representative := by apply (representativeList_nodup N P F _ _).injective_get exact physicalRepresentativeFin_get source target U N P F A node.1 _ _ rw [heq]
theorem physicalLocalOnline_mem_iff (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧ (U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) (node : PhysicalInternalNode M J) (children : PhysicalChildTables M target.length) (t : ℕ) (q : TargetInterval target.length) (action : PhysicalRationalAction M target.length) : action ∈ physicalLocalOnline source target U N P F exponent H T A tau eta kappa (physicalOnlineIntegersOfStreams source target U N P F exponent H T A tau online) node.1 children t q ↔ action ∈ physicalProgramOnline source target U N P F A T exponent H tau eta kappa online node.1 children t q := by have hmass : physicalLocalChildMass source target U N P F A T node.1 node.2 = physicalBandChildMassTable source target U N P F A T node.1 node.2 := by funext i r exact physicalLocalWarmupMass_eq source target U N P F A hsize hP hF hA hseed T (physicalChild node.1 node.2 i, r) unfold physicalLocalOnline physicalProgramOnline rw [dite_eq_left node.2, dite_eq_left node.2] rw [localOnlineCandidates_mem] constructor · rintro ⟨b, hb, hrep, hselected⟩ obtain ⟨representative, hget⟩ := List.mem_iff_get.mp hrep change (representatives node.1).get representative = (b, roundInterval (seedGridSpacing b P) q) at hget have hinteger := physicalOnlineIntegersOfStreams_get source target U N P F exponent H T A tau online node representative (Fin.ofNat R (t - 1)) rw [hget] at hinteger rw [hmass, hinteger] at hselected have heq := keyedOnlineCandidate_eq_physical source target U N P F exponent H T A tau eta kappa node representative children (t - 1) (online node representative (Fin.ofNat R (t - 1))) rw [hget] at heq rw [heq] at hselected apply List.mem_filterMap.mpr refine ⟨representative, List.mem_filter.mpr ⟨List.mem_finRange _, ?_⟩, hselected⟩ apply decide_eq_true unfold physicalProgramOnlineGuard rw [hget] exact ⟨rfl, of_decide_eq_true (List.mem_filter.mp hb).2⟩ · intro ha obtain ⟨representative, hrep, hselected⟩ := List.mem_filterMap.mp ha have hguard := of_decide_eq_true (List.mem_filter.mp hrep).2 let br := (representatives node.1).get representative have hget : (representatives node.1).get representative = (br.1, roundInterval (seedGridSpacing br.1 P) q) := Prod.ext rfl hguard.1 refine ⟨br.1, List.mem_filter.mpr ⟨?_, decide_eq_true hguard.2⟩, ?_, ?_⟩ · exact representativeList_scale_mem _ _ (List.get_mem _ representative) · exact hget ▸ List.get_mem _ representative · have hinteger := physicalOnlineIntegersOfStreams_get source target U N P F exponent H T A tau online node representative (Fin.ofNat R (t - 1)) rw [hget] at hinteger rw [hmass, hinteger] have heq := keyedOnlineCandidate_eq_physical source target U N P F exponent H T A tau eta kappa node representative children (t - 1) (online node representative (Fin.ofNat R (t - 1))) rw [hget] at heq exact heq.trans hselected
end Program
end EditApproximation
end OAIlean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageParameters.leanAdded+79
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageTime.leanAdded+67
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWarmupReadBudget.leanAdded+168
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWidthEnvelope.leanAdded+100
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryMass.leanAdded+71
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryStep.leanAdded+170
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundedQuery.leanAdded+162
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundsAllSeeds.leanAdded+162
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCachedWords.leanAdded+87
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseBitWork.leanAdded+59
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseExecution.leanAdded+53
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseInputWork.leanAdded+99
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarsePreparation.leanAdded+71
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSamplingWork.leanAdded+60
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSeedLaw.leanAdded+93
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCommonSource.leanAdded+153
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalComparisonBand.leanAdded+99
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalAccuracy.leanAdded+74
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalNode.leanAdded+165
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDenominator.leanAdded+256
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDependencyRank.leanAdded+240
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalExpectedRegret.leanAdded+159
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyAccuracy.leanAdded+91
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyCoarseWork.leanAdded+105
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyEncoding.leanAdded+47
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemo.leanAdded+95
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemoCoarse.leanAdded+100
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyOutput.leanAdded+128
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyProgram.leanAdded+96
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRejectionWork.leanAdded+71
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRuntime.leanAdded+81
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySampling.leanAdded+54
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySeedTrace.leanAdded+133
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyTrace.leanAdded+78
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyWork.leanAdded+96
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFinalAccuracy.leanAdded+160
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGenericRegret.leanAdded+181
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalQuery.leanAdded+60
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalValue.leanAdded+250
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGroupAccuracy.leanAdded+68
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalIndexedCoarseWork.leanAdded+54
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInitial.leanAdded+107
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputEncoding.leanAdded+72
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputGuard.leanAdded+92
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLeaves.leanAdded+80
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalDenominator.leanAdded+241
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupKeys.leanAdded+136
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupProgram.leanAdded+107
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalJointProgram.leanAdded+49
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalOnlineEquality.leanAdded+109