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
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageParameters.lean +79 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageTime.lean +67 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWarmupReadBudget.lean +168 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWidthEnvelope.lean +100 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryMass.lean +71 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryStep.lean +170 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundedQuery.lean +162 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundsAllSeeds.lean +162 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCachedWords.lean +87 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseBitWork.lean +59 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseExecution.lean +53 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseInputWork.lean +99 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarsePreparation.lean +71 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSamplingWork.lean +60 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSeedLaw.lean +93 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCommonSource.lean +153 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalComparisonBand.lean +99 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalAccuracy.lean +74 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalNode.lean +165 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDenominator.lean +256 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDependencyRank.lean +240 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalExpectedRegret.lean +159 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyAccuracy.lean +91 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyCoarseWork.lean +105 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyEncoding.lean +47 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemo.lean +95 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemoCoarse.lean +100 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyOutput.lean +128 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyProgram.lean +96 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRejectionWork.lean +71 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRuntime.lean +81 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySampling.lean +54 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySeedTrace.lean +133 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyTrace.lean +78 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyWork.lean +96 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFinalAccuracy.lean +160 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGenericRegret.lean +181 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalQuery.lean +60 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalValue.lean +250 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGroupAccuracy.lean +68 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalIndexedCoarseWork.lean +54 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInitial.lean +107 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputEncoding.lean +72 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputGuard.lean +92 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLeaves.lean +80 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalDenominator.lean +241 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupKeys.lean +136 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupProgram.lean +107 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalJointProgram.lean +49 -0
- lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalOnlineEquality.lean +109 -0
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageParameters.lean
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.StageParameterBounds
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.TreeParameters
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! Numerical premises for the computed physical refinement stage. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
theorem computed_stage_grid_bounds (N : ℕ) (hN : 0 < N) :
|
| 11 |
+
66 ≤ (integerParameters N).P ∧
|
| 12 |
+
(800 * (inputHeight N : ℝ) ^ 2) ≤ (integerParameters N).P ∧
|
| 13 |
+
4 * ((integerParameters N).M : ℝ) / (integerParameters N).P ≤ 1 := by
|
| 14 |
+
let H := inputHeight N
|
| 15 |
+
let P := (integerParameters N).P
|
| 16 |
+
let M := (integerParameters N).M
|
| 17 |
+
have hHtwo : 2 ≤ H := by
|
| 18 |
+
have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (heightExponent_pos N hN)
|
| 19 |
+
simpa only [H, inputHeight, pow_one] using h
|
| 20 |
+
have hHone : 1 ≤ H := by omega
|
| 21 |
+
have hM : M ≤ H := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (Nat.div_le_self _ _)
|
| 22 |
+
have hH18 : 800 ≤ H ^ 18 := by
|
| 23 |
+
have h := Nat.pow_le_pow_left hHtwo 18
|
| 24 |
+
norm_num only [show (2 : ℕ) ^ 18 = 262144 by norm_num] at h
|
| 25 |
+
omega
|
| 26 |
+
have hP20 : H ^ 20 ≤ P := pow_le_pow_right₀ hHone (by omega : 20 ≤ coarseExponent (inputSmallLog N) + 20)
|
| 27 |
+
have hP800 : 800 * H ^ 2 ≤ P := by
|
| 28 |
+
calc
|
| 29 |
+
800 * H ^ 2 ≤ H ^ 18 * H ^ 2 := Nat.mul_le_mul_right _ hH18
|
| 30 |
+
_ = H ^ 20 := by rw [← pow_add]
|
| 31 |
+
_ ≤ P := hP20
|
| 32 |
+
have hHP : (800 * (H : ℝ) ^ 2) ≤ P := by exact_mod_cast hP800
|
| 33 |
+
have hP66 : 66 ≤ P := by
|
| 34 |
+
have h : 4 ≤ H ^ 2 := by nlinarith only [hHtwo]
|
| 35 |
+
nlinarith only [hP800, h]
|
| 36 |
+
have hPr : (0 : ℝ) < P := by exact_mod_cast (show 0 < P by omega)
|
| 37 |
+
have hHr : (2 : ℝ) ≤ H := by exact_mod_cast hHtwo
|
| 38 |
+
have hMr : (M : ℝ) ≤ H := by exact_mod_cast hM
|
| 39 |
+
refine ⟨hP66, hHP, ?_⟩
|
| 40 |
+
apply (div_le_one₀ hPr).2
|
| 41 |
+
nlinarith only [hHP, hHr, hMr]
|
| 42 |
+
|
| 43 |
+
theorem computed_stage_tree_small (N nx : ℕ) (hN : 0 < N) (hnx : nx ≤ N)
|
| 44 |
+
(hell : 200 ≤ inputSmallLog N) :
|
| 45 |
+
(intervalTreeDepth (integerParameters N).M nx : ℝ) *
|
| 46 |
+
(4 * ((integerParameters N).M : ℝ) / (integerParameters N).P) ≤ 1 / 2 := by
|
| 47 |
+
let H := inputHeight N
|
| 48 |
+
let M := (integerParameters N).M
|
| 49 |
+
let P := (integerParameters N).P
|
| 50 |
+
let J := intervalTreeDepth M nx
|
| 51 |
+
have hdepth := computed_tree_depth_bound N nx hN hnx hell
|
| 52 |
+
have hellone : 1 ≤ inputSmallLog N := Nat.one_le_two_pow
|
| 53 |
+
have hJ : J ≤ 100 * H := by
|
| 54 |
+
calc
|
| 55 |
+
J = J * 1 := (Nat.mul_one J).symm
|
| 56 |
+
_ ≤ J * inputSmallLog N := Nat.mul_le_mul_left J hellone
|
| 57 |
+
_ ≤ 100 * H := hdepth
|
| 58 |
+
have hJR : (J : ℝ) ≤ 100 * H := by exact_mod_cast hJ
|
| 59 |
+
have hM : M ≤ H := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (Nat.div_le_self _ _)
|
| 60 |
+
have hMR : (M : ℝ) ≤ H := by exact_mod_cast hM
|
| 61 |
+
have hP800 := (computed_stage_grid_bounds N hN).2.1
|
| 62 |
+
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)
|
| 63 |
+
have hproduct := mul_le_mul hJR hMR (Nat.cast_nonneg M) (by positivity : (0 : ℝ) ≤ 100 * H)
|
| 64 |
+
change (J : ℝ) * (4 * (M : ℝ) / P) ≤ _
|
| 65 |
+
rw [← mul_div_assoc]
|
| 66 |
+
apply (div_le_iff₀ hPr).2
|
| 67 |
+
nlinarith only [hproduct, hP800]
|
| 68 |
+
|
| 69 |
+
theorem computed_stage_positive_counts (N : ℕ) (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N) :
|
| 70 |
+
0 < (integerParameters N).T ∧ 0 < (integerParameters N).S := by
|
| 71 |
+
have hellone : (1 : ℝ) ≤ inputSmallLog N := by exact_mod_cast (Nat.one_le_two_pow (n := smallLogExponent N))
|
| 72 |
+
have hpow := (pow_le_pow_right₀ hellone (by decide : 2 ≤ 20000)).trans (inputHeight_polynomial_slack N hN hell)
|
| 73 |
+
have hpowN : inputSmallLog N ^ 2 ≤ inputHeight N := by exact_mod_cast hpow
|
| 74 |
+
have hellpos : 0 < inputSmallLog N := Nat.two_pow_pos _
|
| 75 |
+
exact ⟨Nat.two_pow_pos _, Nat.div_pos hpowN (pow_pos hellpos 2)⟩
|
| 76 |
+
|
| 77 |
+
end EditApproximation
|
| 78 |
+
|
| 79 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedStageTime.lean
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedStageParameters
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
/-! Exact divisibility and power bounds for the computed time counts. -/
|
| 6 |
+
|
| 7 |
+
namespace EditApproximation
|
| 8 |
+
|
| 9 |
+
theorem computed_refinement_count_exact (N : ℕ) (hN : 0 < N)
|
| 10 |
+
(hell : 2 ^ 1000 ≤ inputSmallLog N) :
|
| 11 |
+
(integerParameters N).S * inputSmallLog N ^ 2 = inputHeight N := by
|
| 12 |
+
have hellone : (1 : ℝ) ≤ inputSmallLog N := by exact_mod_cast (Nat.one_le_two_pow (n := smallLogExponent N))
|
| 13 |
+
have hpowR := (pow_le_pow_right₀ hellone (by decide : 2 ≤ 20000)).trans
|
| 14 |
+
(inputHeight_polynomial_slack N hN hell)
|
| 15 |
+
have hpow : inputSmallLog N ^ 2 ≤ inputHeight N := by exact_mod_cast hpowR
|
| 16 |
+
have hexponent : smallLogExponent N * 2 ≤ heightExponent N := by
|
| 17 |
+
apply (Nat.pow_le_pow_iff_right (by decide : 1 < 2)).1
|
| 18 |
+
simpa only [inputSmallLog, inputHeight, ← pow_mul] using hpow
|
| 19 |
+
have hdiv : inputSmallLog N ^ 2 ∣ inputHeight N := by
|
| 20 |
+
simpa only [inputSmallLog, inputHeight, ← pow_mul] using Nat.pow_dvd_pow 2 hexponent
|
| 21 |
+
exact Nat.div_mul_cancel hdiv
|
| 22 |
+
|
| 23 |
+
theorem computed_refinement_count_real (N : ℕ) (hN : 0 < N)
|
| 24 |
+
(hell : 2 ^ 1000 ≤ inputSmallLog N) :
|
| 25 |
+
((integerParameters N).S : ℝ) = (inputHeight N : ℝ) / (inputSmallLog N : ℝ) ^ 2 := by
|
| 26 |
+
have hpos : (0 : ℝ) < inputSmallLog N := by exact_mod_cast Nat.two_pow_pos (smallLogExponent N)
|
| 27 |
+
apply (eq_div_iff (pow_ne_zero 2 hpos.ne')).2
|
| 28 |
+
exact_mod_cast computed_refinement_count_exact N hN hell
|
| 29 |
+
|
| 30 |
+
theorem computed_warmup_count_power (N : ℕ) :
|
| 31 |
+
inputHeight N ^ 3 ≤ (integerParameters N).T ^ 4 ∧
|
| 32 |
+
(integerParameters N).T ^ 4 ≤ 16 * inputHeight N ^ 3 := by
|
| 33 |
+
let k := heightExponent N
|
| 34 |
+
have hlow : 3 * k ≤ ((3 * k + 3) / 4) * 4 := by omega
|
| 35 |
+
have hhigh : ((3 * k + 3) / 4) * 4 ≤ 3 * k + 4 := by omega
|
| 36 |
+
constructor
|
| 37 |
+
· simpa only [integerParameters, inputHeight, ← pow_mul, k, mul_comm] using
|
| 38 |
+
pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) hlow
|
| 39 |
+
· have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) hhigh
|
| 40 |
+
simpa only [integerParameters, inputHeight, ← pow_mul, pow_add, k,
|
| 41 |
+
show (2 : ℕ) ^ 4 = 16 by norm_num, mul_comm] using h
|
| 42 |
+
|
| 43 |
+
theorem computed_warmup_count_root (N : ℕ) :
|
| 44 |
+
heightQuarterRoot N ^ 3 ≤ ((integerParameters N).T : ℝ) ∧
|
| 45 |
+
((integerParameters N).T : ℝ) ≤ 2 * heightQuarterRoot N ^ 3 := by
|
| 46 |
+
have hroot : 0 ≤ heightQuarterRoot N := Real.sqrt_nonneg _
|
| 47 |
+
have hT : (0 : ℝ) ≤ (integerParameters N).T := Nat.cast_nonneg _
|
| 48 |
+
have hpower := computed_warmup_count_power N
|
| 49 |
+
have hlow : (inputHeight N : ℝ) ^ 3 ≤ ((integerParameters N).T : ℝ) ^ 4 := by exact_mod_cast hpower.1
|
| 50 |
+
have hhigh : ((integerParameters N).T : ℝ) ^ 4 ≤ 16 * (inputHeight N : ℝ) ^ 3 := by exact_mod_cast hpower.2
|
| 51 |
+
have hrootPower := heightQuarterRoot_fourth_power N
|
| 52 |
+
constructor
|
| 53 |
+
· apply (pow_le_pow_iff_left₀ (pow_nonneg hroot 3) hT (by decide : 4 ≠ 0)).1
|
| 54 |
+
calc
|
| 55 |
+
(heightQuarterRoot N ^ 3) ^ 4 = (inputHeight N : ℝ) ^ 3 := by
|
| 56 |
+
rw [← pow_mul, Nat.mul_comm 3 4, pow_mul, hrootPower]
|
| 57 |
+
_ ≤ _ := hlow
|
| 58 |
+
· apply (pow_le_pow_iff_left₀ hT (mul_nonneg (by norm_num) (pow_nonneg hroot 3)) (by decide : 4 ≠ 0)).1
|
| 59 |
+
calc
|
| 60 |
+
_ ≤ 16 * (inputHeight N : ℝ) ^ 3 := hhigh
|
| 61 |
+
_ = (2 * heightQuarterRoot N ^ 3) ^ 4 := by
|
| 62 |
+
rw [mul_pow, ← pow_mul, Nat.mul_comm 3 4, pow_mul, hrootPower]
|
| 63 |
+
norm_num
|
| 64 |
+
|
| 65 |
+
end EditApproximation
|
| 66 |
+
|
| 67 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWarmupReadBudget.lean
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.WarmupReadWork
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedRefinementReadBudget
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! A polynomial earlier-edge bound for the complete charged warmup
|
| 7 |
+
query. It includes all preceding-pass copy reads and pass-zero coarse
|
| 8 |
+
reads used by its initial cones. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
def warmupReadBudget (scales window P F Amax M copies : ℕ) : ℕ :=
|
| 13 |
+
(1 + window * (64 * F * P + 2) ^ 2) *
|
| 14 |
+
((1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies) +
|
| 15 |
+
window * (64 * F * P + 2) ^ 2 * M * (40 * P + 2) ^ 2
|
| 16 |
+
|
| 17 |
+
theorem warmupReadBudget_box (Z scales window P F Amax M copies : ℕ)
|
| 18 |
+
(hZ : 64 ≤ Z) (hscales : scales ≤ Z) (hwindow : window ≤ Z)
|
| 19 |
+
(hP : P ≤ Z) (hF : F ≤ Z) (hA : Amax ≤ Z) (hM : M ≤ Z)
|
| 20 |
+
(hcopies : copies ≤ Z) : warmupReadBudget scales window P F Amax M copies ≤ Z ^ 24 := by
|
| 21 |
+
have hZone : 1 ≤ Z := by omega
|
| 22 |
+
have hZtwo : 2 ≤ Z := by omega
|
| 23 |
+
have hbase (c x : ℕ) (hc : c ≤ Z) (hx : 2 ≤ x) : c * x + 2 ≤ Z ^ 2 * x := by
|
| 24 |
+
have hcx := Nat.mul_le_mul_right x hc
|
| 25 |
+
have hzx : 2 ≤ Z * x := hx.trans (Nat.le_mul_of_pos_left x hZone)
|
| 26 |
+
have hcoeff := Nat.mul_le_mul_right x (show 2 * Z ≤ Z ^ 2 by nlinarith only [hZtwo])
|
| 27 |
+
nlinarith only [hcx, hzx, hcoeff]
|
| 28 |
+
have hadd (k : ℕ) : 1 + Z ^ k ≤ Z ^ (k + 1) := by
|
| 29 |
+
have hp : 1 ≤ Z ^ k := one_le_pow₀ hZone
|
| 30 |
+
have hm := Nat.mul_le_mul_right (Z ^ k) hZtwo
|
| 31 |
+
rw [pow_succ]
|
| 32 |
+
nlinarith only [hp, hm]
|
| 33 |
+
have h64 : 64 ≤ Z := hZ
|
| 34 |
+
have h40 : 40 ≤ Z := by omega
|
| 35 |
+
have hsmall : 64 * F * P + 2 ≤ Z ^ 4 := by
|
| 36 |
+
calc
|
| 37 |
+
_ ≤ 64 * Z * Z + 2 := Nat.add_le_add_right (Nat.mul_le_mul (Nat.mul_le_mul_left 64 hF) hP) 2
|
| 38 |
+
_ ≤ _ := by
|
| 39 |
+
convert hbase 64 (Z ^ 2) h64 ((Nat.pow_le_pow_left hZtwo 2).trans' (by norm_num)) using 1 <;> ring
|
| 40 |
+
have hinitialBase : 64 * Amax ^ 2 * P + 2 ≤ Z ^ 5 := by
|
| 41 |
+
calc
|
| 42 |
+
_ ≤ 64 * Z ^ 2 * Z + 2 :=
|
| 43 |
+
Nat.add_le_add_right (Nat.mul_le_mul (Nat.mul_le_mul_left 64 (Nat.pow_le_pow_left hA 2)) hP) 2
|
| 44 |
+
_ ≤ _ := by
|
| 45 |
+
convert hbase 64 (Z ^ 3) h64 ((Nat.pow_le_pow_left hZtwo 3).trans' (by norm_num)) using 1 <;> ring
|
| 46 |
+
have hwideBase : 40 * P + 2 ≤ Z ^ 3 := by
|
| 47 |
+
calc
|
| 48 |
+
_ ≤ 40 * Z + 2 := Nat.add_le_add_right (Nat.mul_le_mul_left 40 hP) 2
|
| 49 |
+
_ ≤ _ := by convert hbase 40 Z h40 hZtwo using 1; ring
|
| 50 |
+
have hraw : window * (64 * F * P + 2) ^ 2 ≤ Z ^ 9 := by
|
| 51 |
+
exact (Nat.mul_le_mul hwindow (Nat.pow_le_pow_left hsmall 2)).trans_eq (by ring)
|
| 52 |
+
have hrawInitial : scales * (64 * Amax ^ 2 * P + 2) ^ 2 ≤ Z ^ 11 := by
|
| 53 |
+
exact (Nat.mul_le_mul hscales (Nat.pow_le_pow_left hinitialBase 2)).trans_eq (by ring)
|
| 54 |
+
have hinit : (1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies ≤ Z ^ 13 := by
|
| 55 |
+
exact (Nat.mul_le_mul ((Nat.add_le_add_left hrawInitial 1).trans (hadd 11))
|
| 56 |
+
(max_le hZone hcopies)).trans_eq (by ring)
|
| 57 |
+
have hfirst : (1 + window * (64 * F * P + 2) ^ 2) *
|
| 58 |
+
((1 + scales * (64 * Amax ^ 2 * P + 2) ^ 2) * max 1 copies) ≤ Z ^ 23 := by
|
| 59 |
+
exact (Nat.mul_le_mul ((Nat.add_le_add_left hraw 1).trans (hadd 9)) hinit).trans_eq (by ring)
|
| 60 |
+
have hsecond : window * (64 * F * P + 2) ^ 2 * M * (40 * P + 2) ^ 2 ≤ Z ^ 23 := by
|
| 61 |
+
calc
|
| 62 |
+
_ ≤ Z ^ 9 * Z * (Z ^ 3) ^ 2 :=
|
| 63 |
+
Nat.mul_le_mul (Nat.mul_le_mul hraw hM) (Nat.pow_le_pow_left hwideBase 2)
|
| 64 |
+
_ = Z ^ 16 := by ring
|
| 65 |
+
_ ≤ _ := pow_le_pow_right₀ hZone (by decide)
|
| 66 |
+
exact (Nat.add_le_add hfirst hsecond).trans (by
|
| 67 |
+
have hm := Nat.mul_le_mul_right (Z ^ 23) hZtwo
|
| 68 |
+
have heq : Z ^ 24 = Z ^ 23 * Z := pow_succ Z 23
|
| 69 |
+
calc
|
| 70 |
+
Z ^ 23 + Z ^ 23 = 2 * Z ^ 23 := (two_mul _).symm
|
| 71 |
+
_ ≤ Z * Z ^ 23 := hm
|
| 72 |
+
_ = Z ^ 24 := by rw [heq]; exact Nat.mul_comm _ _)
|
| 73 |
+
|
| 74 |
+
theorem computed_dyadicScales_length (N : ℕ) (hH : 2 ≤ inputHeight N) :
|
| 75 |
+
(dyadicScales N).length ≤ inputHeight N ^ 2 := by
|
| 76 |
+
have hlog : Nat.log 2 N ≤ inputHeight N := by
|
| 77 |
+
apply (Nat.log_le_clog 2 N).trans
|
| 78 |
+
apply (Nat.clog_mono_right 2 (Nat.le_add_right N 2)).trans
|
| 79 |
+
exact Nat.le_pow_clog (by decide : 1 < (2 : ℕ)) (Nat.clog 2 (N + 2))
|
| 80 |
+
simp only [dyadicScales, List.length_map, List.length_range]
|
| 81 |
+
nlinarith only [hlog, hH]
|
| 82 |
+
|
| 83 |
+
theorem computed_warmupReadBudget_le (N M P copies : ℕ) (hN : 0 < N)
|
| 84 |
+
(hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M)
|
| 85 |
+
(hP : P = (integerParameters N).P) (hcopies : copies ≤ inputHeight N ^ 2) :
|
| 86 |
+
warmupReadBudget (dyadicScales N).length (computedSeedInitialExponent N + 8)
|
| 87 |
+
P (inputSmallLog N) (integerParameters N).initialFactor M copies ≤
|
| 88 |
+
inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by
|
| 89 |
+
let H := inputHeight N
|
| 90 |
+
let p := coarseExponent (inputSmallLog N)
|
| 91 |
+
let Z := H ^ (p + 20)
|
| 92 |
+
have hF := computed_smallLog_le_height N
|
| 93 |
+
have hH : 64 ≤ H := (by omega : 64 ≤ inputSmallLog N).trans hF
|
| 94 |
+
have hZone : 1 ≤ H := by omega
|
| 95 |
+
have hHZ : H ≤ Z := by
|
| 96 |
+
calc
|
| 97 |
+
H = H ^ 1 := (pow_one H).symm
|
| 98 |
+
_ ≤ H ^ (p + 20) := pow_le_pow_right₀ hZone (by omega)
|
| 99 |
+
have hH2Z : H ^ 2 ≤ Z := pow_le_pow_right₀ hZone (by omega)
|
| 100 |
+
have hH3Z : H ^ 3 ≤ Z := pow_le_pow_right₀ hZone (by omega)
|
| 101 |
+
have hscales : (dyadicScales N).length ≤ Z := (computed_dyadicScales_length N (by omega)).trans hH2Z
|
| 102 |
+
have hwindow : computedSeedInitialExponent N + 8 ≤ Z :=
|
| 103 |
+
(computed_window_le_height_cube N hN (by omega) (by omega)).trans hH3Z
|
| 104 |
+
have hPZ : P ≤ Z := by change P ≤ (integerParameters N).P; exact hP.le
|
| 105 |
+
have hAZ : (integerParameters N).initialFactor ≤ Z :=
|
| 106 |
+
pow_le_pow_right₀ hZone (by omega)
|
| 107 |
+
have hMZ : M ≤ Z := by
|
| 108 |
+
rw [hM]
|
| 109 |
+
exact (pow_le_pow_right₀ (by decide : (1 : ℕ) ≤ 2) (Nat.div_le_self _ _)).trans hHZ
|
| 110 |
+
have hbound := warmupReadBudget_box Z (dyadicScales N).length (computedSeedInitialExponent N + 8)
|
| 111 |
+
P (inputSmallLog N) (integerParameters N).initialFactor M copies (hH.trans hHZ)
|
| 112 |
+
hscales hwindow hPZ (hF.trans hHZ) hAZ hMZ (hcopies.trans hH2Z)
|
| 113 |
+
apply hbound.trans
|
| 114 |
+
dsimp only [Z]
|
| 115 |
+
rw [← pow_mul]
|
| 116 |
+
exact pow_le_pow_right₀ hZone (by dsimp only [p]; omega)
|
| 117 |
+
|
| 118 |
+
theorem computed_chargedWarmupQuery_reads {α : Type*} [DecidableEq α]
|
| 119 |
+
{M J passes copies T S : ℕ} (source target : List α) (N P : ℕ)
|
| 120 |
+
(hN : 0 < N) (hell : 200 ≤ inputSmallLog N)
|
| 121 |
+
(hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P)
|
| 122 |
+
(hcopies : copies ≤ inputHeight N ^ 2) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ)
|
| 123 |
+
(parent : {r : PhysicalTableRequest M J target.length // r.Bounded passes copies T S})
|
| 124 |
+
(oracle) (hA : 1 ≤ factor parent.val.pass)
|
| 125 |
+
(hAmax : factor parent.val.pass ≤ ((integerParameters N).initialFactor : ℚ)) :
|
| 126 |
+
(chargedWarmupQuery source target N P (inputSmallLog N) factor multiplier parent).cost
|
| 127 |
+
oracle (fun _ => 1) ≤ inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by
|
| 128 |
+
have hPpos : 0 < P := by
|
| 129 |
+
rw [hP]
|
| 130 |
+
change 0 < inputHeight N ^ _
|
| 131 |
+
exact pow_pos (Nat.two_pow_pos _) _
|
| 132 |
+
exact (chargedWarmupQuery_cost_le source target N P (inputSmallLog N)
|
| 133 |
+
(integerParameters N).initialFactor (computedSeedInitialExponent N + 8) factor multiplier parent oracle
|
| 134 |
+
hPpos (by omega) hA hAmax (fun w => computed_refinement_window N hN (by omega)
|
| 135 |
+
(factor parent.val.pass) w hAmax)).trans
|
| 136 |
+
(computed_warmupReadBudget_le N M P copies hN hell hM hP hcopies)
|
| 137 |
+
|
| 138 |
+
theorem computed_chargedInitialQuery_reads {α : Type*} [DecidableEq α]
|
| 139 |
+
{M J passes copies T S : ℕ} (source target : List α) (N P : ℕ)
|
| 140 |
+
(hN : 0 < N) (hell : 200 ≤ inputSmallLog N)
|
| 141 |
+
(hM : M = (integerParameters N).M) (hP : P = (integerParameters N).P)
|
| 142 |
+
(hcopies : copies ≤ inputHeight N ^ 2) (factor : ℕ → ℚ) (multiplier : ℕ → ℕ)
|
| 143 |
+
(parent : {r : PhysicalTableRequest M J target.length // r.Bounded passes copies T S})
|
| 144 |
+
(oracle) (hA : 1 ≤ factor parent.val.pass)
|
| 145 |
+
(hAmax : factor parent.val.pass ≤ ((integerParameters N).initialFactor : ℚ)) :
|
| 146 |
+
(physicalInitialQuery source target N P (inputSmallLog N) (factor parent.val.pass)
|
| 147 |
+
(chargedSeedQuery N multiplier parent) (parent.val.node, parent.val.state)).cost oracle (fun _ => 1) ≤
|
| 148 |
+
inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1)) := by
|
| 149 |
+
have hPpos : 0 < P := by
|
| 150 |
+
rw [hP]
|
| 151 |
+
change 0 < inputHeight N ^ _
|
| 152 |
+
exact pow_pos (Nat.two_pow_pos _) _
|
| 153 |
+
let initialCost := (1 + (dyadicScales N).length *
|
| 154 |
+
(64 * (integerParameters N).initialFactor ^ 2 * P + 2) ^ 2) * max 1 copies
|
| 155 |
+
have hi : (physicalInitialQuery source target N P (inputSmallLog N) (factor parent.val.pass)
|
| 156 |
+
(chargedSeedQuery N multiplier parent) (parent.val.node, parent.val.state)).cost oracle (fun _ => 1) ≤
|
| 157 |
+
initialCost :=
|
| 158 |
+
physicalInitialQuery_cost_le source target N P (inputSmallLog N) (integerParameters N).initialFactor
|
| 159 |
+
(max 1 copies) _ _ _ _ oracle hPpos hA hAmax
|
| 160 |
+
(fun r => chargedSeedQuery_cost_le N multiplier parent _ oracle)
|
| 161 |
+
have hb : initialCost ≤ warmupReadBudget (dyadicScales N).length
|
| 162 |
+
(computedSeedInitialExponent N + 8) P (inputSmallLog N) (integerParameters N).initialFactor M copies := by
|
| 163 |
+
exact (Nat.le_mul_of_pos_left initialCost (by omega)).trans (Nat.le_add_right _ _)
|
| 164 |
+
exact hi.trans (hb.trans (computed_warmupReadBudget_le N M P copies hN hell hM hP hcopies))
|
| 165 |
+
|
| 166 |
+
end EditApproximation
|
| 167 |
+
|
| 168 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/ComputedWidthEnvelope.lean
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedActualBandWork
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
/-! A parameter-only majorant for every executed dependency tree. It is
|
| 6 |
+
independent of the accepted random values and of all accuracy events. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open Filter
|
| 11 |
+
open scoped Topology
|
| 12 |
+
|
| 13 |
+
noncomputable def computedWidthEnvelope (N : ℕ) : ℝ :=
|
| 14 |
+
(N + 2 : ℝ) * (inputHeight N : ℝ) ^ 2 *
|
| 15 |
+
Real.exp (computedDependencyOverheadExponent 257 512 N)
|
| 16 |
+
|
| 17 |
+
theorem computedWidthEnvelope_nonneg (N : ℕ) : 0 ≤ computedWidthEnvelope N := by
|
| 18 |
+
unfold computedWidthEnvelope
|
| 19 |
+
positivity
|
| 20 |
+
|
| 21 |
+
theorem computed_widthWork_le_envelope (N n : ℕ) (hN : 0 < N) (hn : n ≤ N)
|
| 22 |
+
(hell : 200 ≤ inputSmallLog N) (hH : 105 ≤ inputHeight N)
|
| 23 |
+
(tree : DependencyExpansion)
|
| 24 |
+
(hv : tree.Valid ((integerParameters N).M * inputSmallLog N ^ 257)
|
| 25 |
+
(inputHeight N ^ (512 * (coarseExponent (inputSmallLog N) + 1))))
|
| 26 |
+
(hd : tree.depth = intervalTreeDepth (integerParameters N).M n)
|
| 27 |
+
(hk : tree.rank ≤ computedDependencyIndexCount N) :
|
| 28 |
+
(tree.widthWork (integerParameters N).M n : ℝ) ≤ computedWidthEnvelope N := by
|
| 29 |
+
have hw := DependencyExpansion.widthWork_le (integerParameters N).M n _ _ _
|
| 30 |
+
(computed_branching_bounds N hN hell).1 tree hv hd hk
|
| 31 |
+
(Real.exp (computedDependencyOverheadExponent 257 512 N)) (Real.exp_nonneg _) (by
|
| 32 |
+
intro j hj
|
| 33 |
+
exact computed_dependency_path_envelope N 257 512 j
|
| 34 |
+
(hj.trans (intervalTreeDepth_le_computedMax N n hn)))
|
| 35 |
+
have hpref := computed_width_prefactor_le N n hN hn hell hH
|
| 36 |
+
have hprefR : (((intervalTreeDepth (integerParameters N).M n + 1) * n +
|
| 37 |
+
4 * (integerParameters N).M * max 1 n : ℕ) : ℝ) ≤
|
| 38 |
+
(N + 2 : ℝ) * (inputHeight N : ℝ) ^ 2 := by exact_mod_cast hpref
|
| 39 |
+
exact hw.trans (mul_le_mul_of_nonneg_right hprefR (Real.exp_nonneg _))
|
| 40 |
+
|
| 41 |
+
theorem computedWidthEnvelope_mul_exp_near_linear (f : ℕ → ℝ)
|
| 42 |
+
(hf : Tendsto (fun N => f N / inputHeight N) atTop (𝓝 0))
|
| 43 |
+
(epsilon : ℝ) (hepsilon : 0 < epsilon) :
|
| 44 |
+
∀ᶠ N in atTop, computedWidthEnvelope N * Real.exp (f N) ≤
|
| 45 |
+
(N + 2 : ℝ) ^ (1 + epsilon) := by
|
| 46 |
+
have hlog : Tendsto (fun N => Real.log (inputHeight N : ℝ) / inputHeight N)
|
| 47 |
+
atTop (𝓝 0) :=
|
| 48 |
+
Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp inputHeight_real_tendsto
|
| 49 |
+
have hlimit := ((computedDependencyOverheadExponent_tendsto 257 512).add
|
| 50 |
+
(hlog.const_mul 2)).add hf
|
| 51 |
+
simp only [mul_zero, add_zero] at hlimit
|
| 52 |
+
have hfinal := sublinear_height_near_linear
|
| 53 |
+
(fun N => computedDependencyOverheadExponent 257 512 N +
|
| 54 |
+
2 * Real.log (inputHeight N : ℝ) + f N) (by
|
| 55 |
+
convert hlimit using 1
|
| 56 |
+
ext N
|
| 57 |
+
ring) epsilon hepsilon
|
| 58 |
+
filter_upwards [hfinal] with N hN
|
| 59 |
+
convert hN using 1
|
| 60 |
+
unfold computedWidthEnvelope
|
| 61 |
+
rw [Real.exp_add, Real.exp_add]
|
| 62 |
+
have hp : Real.exp (2 * Real.log (inputHeight N : ℝ)) = (inputHeight N : ℝ) ^ 2 := by
|
| 63 |
+
simpa using (nat_pow_eq_exp_log (inputHeight N) 2 (Nat.two_pow_pos _)).symm
|
| 64 |
+
rw [hp]
|
| 65 |
+
ring
|
| 66 |
+
|
| 67 |
+
theorem computedWidthEnvelope_weighted_near_linear (C : ℕ)
|
| 68 |
+
(epsilon : ℝ) (hepsilon : 0 < epsilon) :
|
| 69 |
+
∀ᶠ N in atTop, computedWidthEnvelope N * (inputHeight N : ℝ) ^ C ≤
|
| 70 |
+
(N + 2 : ℝ) ^ (1 + epsilon) := by
|
| 71 |
+
have hlog : Tendsto (fun N => Real.log (inputHeight N : ℝ) / inputHeight N)
|
| 72 |
+
atTop (𝓝 0) :=
|
| 73 |
+
Real.isLittleO_log_id_atTop.tendsto_div_nhds_zero.comp inputHeight_real_tendsto
|
| 74 |
+
have hlimit := hlog.const_mul (C : ℝ)
|
| 75 |
+
simp only [mul_zero] at hlimit
|
| 76 |
+
have hf : Tendsto (fun N => ((C : ℝ) * Real.log (inputHeight N : ℝ)) / inputHeight N)
|
| 77 |
+
atTop (𝓝 0) := by convert hlimit using 1; ext N; ring
|
| 78 |
+
filter_upwards [computedWidthEnvelope_mul_exp_near_linear _ hf epsilon hepsilon] with N hN
|
| 79 |
+
rwa [← nat_pow_eq_exp_log (inputHeight N) C (Nat.two_pow_pos _)] at hN
|
| 80 |
+
|
| 81 |
+
theorem computedWidthEnvelope_coarse_near_linear (epsilon : ℝ) (hepsilon : 0 < epsilon) :
|
| 82 |
+
∀ᶠ N in atTop, computedWidthEnvelope N * computedCoarseWidthOverhead N ≤
|
| 83 |
+
(N + 2 : ℝ) ^ (1 + epsilon) := by
|
| 84 |
+
filter_upwards [computedWidthEnvelope_mul_exp_near_linear _
|
| 85 |
+
(computedCoarseOverheadExponent_tendsto 10) epsilon hepsilon, eventually_ge_atTop 1] with N hN hpos
|
| 86 |
+
exact (mul_le_mul_of_nonneg_left (computedCoarseWidthOverhead_exp_le N (by omega))
|
| 87 |
+
(computedWidthEnvelope_nonneg N)).trans hN
|
| 88 |
+
|
| 89 |
+
theorem computedWidthEnvelope_band_near_linear (C : ℕ)
|
| 90 |
+
(epsilon : ℝ) (hepsilon : 0 < epsilon) :
|
| 91 |
+
∀ᶠ N in atTop, computedWidthEnvelope N * computedActualBandBitBudget C N ≤
|
| 92 |
+
(N + 2 : ℝ) ^ (1 + epsilon) := by
|
| 93 |
+
filter_upwards [computedWidthEnvelope_mul_exp_near_linear _
|
| 94 |
+
(computedActualBandBitExponent_tendsto C) epsilon hepsilon, eventually_ge_atTop 1] with N hN hpos
|
| 95 |
+
exact (mul_le_mul_of_nonneg_left (computedActualBandBitBudget_exp_bound C N (by omega))
|
| 96 |
+
(computedWidthEnvelope_nonneg N)).trans hN
|
| 97 |
+
|
| 98 |
+
end EditApproximation
|
| 99 |
+
|
| 100 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryMass.lean
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Binary.BinaryWarmupAverage
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalRefinement
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The child mass is built from the actual gathered warmup words. The
|
| 7 |
+
mean and construction of its finite input list both contribute to work. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
def physicalWarmupMassWithWork {ny : ℕ} (T : ℕ)
|
| 12 |
+
(words : ℕ → TargetInterval ny → BinaryFraction) (query : TargetInterval ny) :
|
| 13 |
+
BinaryFraction × ℕ :=
|
| 14 |
+
let mean := BinaryFraction.warmupAverageWithWork (List.ofFn fun j : Fin T => words j.val query)
|
| 15 |
+
(mean.1, mean.2 + T + 1)
|
| 16 |
+
|
| 17 |
+
theorem physicalWarmupMassWithWork_value {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 18 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 19 |
+
(N P F T : ℕ) (A : ℚ) (node : PhysicalNode M J)
|
| 20 |
+
(words : ℕ → TargetInterval target.length → BinaryFraction)
|
| 21 |
+
(hwords : ∀ j < T, ∀ r, (words j r).value = physicalLocalWarmup source target U N P F A j (node, r))
|
| 22 |
+
(query : TargetInterval target.length) :
|
| 23 |
+
(physicalWarmupMassWithWork T words query).1.value =
|
| 24 |
+
physicalLocalWarmupMass source target U N P F A T (node, query) := by
|
| 25 |
+
rw [physicalWarmupMassWithWork, BinaryFraction.warmupAverageWithWork_ofFn_value]
|
| 26 |
+
unfold physicalLocalWarmupMass
|
| 27 |
+
congr 1
|
| 28 |
+
rw [← Fin.sum_univ_eq_sum_range (fun j =>
|
| 29 |
+
physicalLocalWarmup source target U N P F A j (node, query))]
|
| 30 |
+
apply Finset.sum_congr rfl
|
| 31 |
+
intro j _hj
|
| 32 |
+
exact hwords j.val j.isLt query
|
| 33 |
+
|
| 34 |
+
theorem physicalWarmupMassWithWork_bounds {ny : ℕ} (T B : ℕ)
|
| 35 |
+
(words : ℕ → TargetInterval ny → BinaryFraction)
|
| 36 |
+
(hwords : ∀ j < T, ∀ r, (words j r).width ≤ B) (query : TargetInterval ny) :
|
| 37 |
+
(physicalWarmupMassWithWork T words query).1.width ≤ BinaryFraction.warmupAverageWordBudget T B ∧
|
| 38 |
+
(physicalWarmupMassWithWork T words query).2 ≤ BinaryFraction.warmupAverageBitBudget T B + T + 1 := by
|
| 39 |
+
have hmean := BinaryFraction.warmupAverageWithWork_bounds
|
| 40 |
+
(List.ofFn fun j : Fin T => words j.val query) B (by
|
| 41 |
+
intro value hv
|
| 42 |
+
obtain ⟨j, rfl⟩ := List.mem_ofFn.mp hv
|
| 43 |
+
exact hwords j.val j.isLt query)
|
| 44 |
+
simp only [List.length_ofFn] at hmean
|
| 45 |
+
exact ⟨hmean.1, Nat.add_le_add_right (Nat.add_le_add_right hmean.2 T) 1⟩
|
| 46 |
+
|
| 47 |
+
theorem warmupAverageWordBudget_le_power (H T B : ℕ) (hH : 64 ≤ H)
|
| 48 |
+
(hT : T ≤ H ^ 2) (hB : B ≤ H ^ 3) :
|
| 49 |
+
BinaryFraction.warmupAverageWordBudget T B ≤ H ^ 8 := by
|
| 50 |
+
have hHp : 0 < H := by omega
|
| 51 |
+
have hHone : 1 ≤ H := by omega
|
| 52 |
+
have hsize : Nat.size T ≤ H ^ 2 := (Nat.size_le.mpr Nat.lt_two_pow_self).trans hT
|
| 53 |
+
have h23 : H ^ 2 ≤ H ^ 3 := Nat.pow_le_pow_right hHp (by decide)
|
| 54 |
+
have h35 : H ^ 3 ≤ H ^ 5 := Nat.pow_le_pow_right hHp (by decide)
|
| 55 |
+
have hone : 1 ≤ H ^ 3 := one_le_pow₀ hHone
|
| 56 |
+
have hproduct : T * (B + 1) ≤ 2 * H ^ 5 := by
|
| 57 |
+
calc
|
| 58 |
+
_ ≤ H ^ 2 * (2 * H ^ 3) := Nat.mul_le_mul hT (by omega)
|
| 59 |
+
_ = 2 * H ^ 5 := by ring
|
| 60 |
+
have hsmall : BinaryFraction.warmupAverageWordBudget T B ≤ 64 * H ^ 5 := by
|
| 61 |
+
unfold BinaryFraction.warmupAverageWordBudget BinaryFraction.bandMassTotalStorageBudget
|
| 62 |
+
nlinarith only [hsize, hB, h23, h35, hproduct, hone]
|
| 63 |
+
have h64 : 64 ≤ H ^ 3 := (by omega : 64 ≤ H).trans (Nat.le_pow (by decide))
|
| 64 |
+
exact hsmall.trans (by
|
| 65 |
+
calc
|
| 66 |
+
64 * H ^ 5 ≤ H ^ 3 * H ^ 5 := Nat.mul_le_mul_right _ h64
|
| 67 |
+
_ = H ^ 8 := by ring)
|
| 68 |
+
|
| 69 |
+
end EditApproximation
|
| 70 |
+
|
| 71 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBinaryStep.lean
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.PreparedCachedKernelWork
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCachedWords
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The Boolean refinement kernel at a physical node uses cached words
|
| 7 |
+
for its child and table requests. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
attribute [local irreducible] BinaryFraction.preparedLocalKernelWithWork
|
| 12 |
+
|
| 13 |
+
section Step
|
| 14 |
+
|
| 15 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 16 |
+
(source target : List α) (N P F exponent H Q eM eF : ℕ)
|
| 17 |
+
(hP : 0 < P) (hM : M = 2 ^ eM) (hF : F = 2 ^ eF)
|
| 18 |
+
(tauWord aWord etaWord kappaWord deltaWord : BinaryFraction)
|
| 19 |
+
(parentWords : TargetInterval target.length → BinaryFraction)
|
| 20 |
+
(massWords initialWords : Fin M → TargetInterval target.length → BinaryFraction)
|
| 21 |
+
(historyWords : ℕ → Fin M × TargetInterval target.length → BinaryFraction)
|
| 22 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 23 |
+
(integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 24 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ)
|
| 25 |
+
(query : TargetInterval target.length)
|
| 26 |
+
|
| 27 |
+
def physicalPreparedStepWithWork : BinaryFraction × ℕ :=
|
| 28 |
+
BinaryFraction.preparedLocalKernelWithWork source target (physicalSourceInterval source.length node)
|
| 29 |
+
N P F exponent H Q eM eF hP hM hF tauWord aWord etaWord kappaWord deltaWord
|
| 30 |
+
parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords t
|
| 31 |
+
(draw ⟨node, hbelow⟩ (t + 1)) (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query
|
| 32 |
+
|
| 33 |
+
omit [DecidableEq α] in
|
| 34 |
+
theorem physicalPreparedStepWithWork_bounds (B E S : ℕ) (hPdyadic : ∃ j : ℕ, P = 2 ^ j)
|
| 35 |
+
(hb : BinaryFraction.PreparedKernelInputBounds (nx := source.length)
|
| 36 |
+
N P F exponent H Q eM eF B E S t tauWord aWord etaWord kappaWord deltaWord
|
| 37 |
+
parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords
|
| 38 |
+
(integer ⟨node, hbelow⟩ (Fin.ofNat R t))) :
|
| 39 |
+
(physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 40 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 41 |
+
draw integer node hbelow t query).1.width ≤ BinaryFraction.preparedKernelWordBudget M B ∧
|
| 42 |
+
(physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 43 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 44 |
+
draw integer node hbelow t query).2 ≤ BinaryFraction.preparedKernelBitBudget N M P F exponent eM eF B S :=
|
| 45 |
+
BinaryFraction.preparedLocalKernelWithWork_bounds source target (physicalSourceInterval source.length node)
|
| 46 |
+
N P F exponent H Q eM eF B E S hP hM hF hPdyadic tauWord aWord etaWord kappaWord deltaWord
|
| 47 |
+
parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords t
|
| 48 |
+
(draw ⟨node, hbelow⟩ (t + 1)) (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query hb
|
| 49 |
+
|
| 50 |
+
variable (U : PhysicalEntry M J target.length → ℕ) (A tau eta kappa delta : ℚ) (T : ℕ)
|
| 51 |
+
(ha : aWord.value = refinementFactor A F) (htau : tauWord.value = tau)
|
| 52 |
+
(heta : etaWord.value = eta) (hkappa : kappaWord.value = kappa)
|
| 53 |
+
(hdelta : deltaWord.value = delta)
|
| 54 |
+
(hparent : ∀ r, (parentWords r).value = stageInitial source target U N P F A (node, r))
|
| 55 |
+
(hmass : ∀ i r, (massWords i r).value =
|
| 56 |
+
physicalLocalChildMass source target U N P F A T node hbelow i r)
|
| 57 |
+
(hinitial : ∀ i r, (initialWords i r).value =
|
| 58 |
+
stageInitial source target U N P F A (physicalChild node hbelow i, r))
|
| 59 |
+
(hhistory : ∀ s i r, (historyWords s (i, r)).value =
|
| 60 |
+
physicalLocalRefinement source target U N P F exponent Q A tau delta T draw
|
| 61 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 62 |
+
(physicalChild node hbelow i) s r)
|
| 63 |
+
(hwide : ¬ (physicalSourceInterval source.length node).hi -
|
| 64 |
+
(physicalSourceInterval source.length node).lo ≤ 1)
|
| 65 |
+
|
| 66 |
+
include ha htau heta hkappa hdelta hparent hmass hinitial hhistory hwide in
|
| 67 |
+
theorem physicalPreparedStepWithWork_value :
|
| 68 |
+
(physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 69 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 70 |
+
draw integer node hbelow t query).1.value =
|
| 71 |
+
physicalLocalRefinement source target U N P F exponent Q A tau delta T draw
|
| 72 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 73 |
+
node (t + 1) query := by
|
| 74 |
+
let children : PhysicalChildTables M target.length := fun i =>
|
| 75 |
+
physicalLocalRefinement source target U N P F exponent Q A tau delta T draw
|
| 76 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 77 |
+
(physicalChild node hbelow i)
|
| 78 |
+
have honline : physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer
|
| 79 |
+
node children (t + 1) query =
|
| 80 |
+
localOnlineCandidates source target (physicalSourceInterval source.length node)
|
| 81 |
+
N P F exponent H tau (refinementFactor A F) eta kappa
|
| 82 |
+
(fun r => stageInitial source target U N P F A (node, r))
|
| 83 |
+
(physicalLocalChildMass source target U N P F A T node hbelow)
|
| 84 |
+
(physicalBandChildInitial source target U N P F A node hbelow)
|
| 85 |
+
children t (integer ⟨node, hbelow⟩ (Fin.ofNat R t)) query := by
|
| 86 |
+
rw [physicalLocalOnline, dite_eq_left hbelow]
|
| 87 |
+
simp only [Nat.add_sub_cancel]
|
| 88 |
+
unfold physicalPreparedStepWithWork
|
| 89 |
+
rw [BinaryFraction.preparedLocalKernelWithWork_value]
|
| 90 |
+
simp_rw [ha, htau, heta, hkappa, hdelta, hparent, hmass, hinitial, hhistory]
|
| 91 |
+
conv_rhs => rw [physicalLocalRefinement]
|
| 92 |
+
rw [dite_eq_left hbelow, ite_eq_right hwide]
|
| 93 |
+
dsimp only
|
| 94 |
+
rw [honline]
|
| 95 |
+
rfl
|
| 96 |
+
|
| 97 |
+
include hparent hinitial hhistory in
|
| 98 |
+
theorem physicalPreparedStep_input_ranges (hd : 0 ≤ delta) :
|
| 99 |
+
(∀ r, 0 ≤ (parentWords r).value) ∧
|
| 100 |
+
(∀ s ≤ t + 1, ∀ i r, 0 ≤ (historyWords s (i, r)).value ∧
|
| 101 |
+
(historyWords s (i, r)).value ≤ (initialWords i r).value) := by
|
| 102 |
+
constructor
|
| 103 |
+
· intro r
|
| 104 |
+
rw [hparent]
|
| 105 |
+
exact stageInitial_nonneg_all_seeds source target U N P F A (node, r)
|
| 106 |
+
· intro s _hs i r
|
| 107 |
+
rw [hhistory, hinitial]
|
| 108 |
+
exact physicalLocalRefinement_bounds source target U N P F exponent Q A tau delta T hd draw
|
| 109 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 110 |
+
(physicalChild node hbelow i) s r
|
| 111 |
+
|
| 112 |
+
def physicalCachedStepWithWork (base : List Bool) (hbase : 0 < bitWordValue base) :
|
| 113 |
+
BinaryFraction × ℕ :=
|
| 114 |
+
BinaryFraction.finishCachedWithWork
|
| 115 |
+
(physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 116 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 117 |
+
draw integer node hbelow t query) base hbase (J - node.1.val)
|
| 118 |
+
|
| 119 |
+
omit [DecidableEq α] in
|
| 120 |
+
theorem physicalCachedStepWithWork_cost (base : List Bool) (hbase : 0 < bitWordValue base)
|
| 121 |
+
(B E S D : ℕ) (hbaseWidth : base.length ≤ D) (hPdyadic : ∃ j : ℕ, P = 2 ^ j)
|
| 122 |
+
(hb : BinaryFraction.PreparedKernelInputBounds (nx := source.length)
|
| 123 |
+
N P F exponent H Q eM eF B E S t tauWord aWord etaWord kappaWord deltaWord
|
| 124 |
+
parentWords massWords initialWords (historyWords t) (historyWords (t + 1)) historyWords
|
| 125 |
+
(integer ⟨node, hbelow⟩ (Fin.ofNat R t))) :
|
| 126 |
+
(physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 127 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 128 |
+
draw integer node hbelow t query base hbase).2 ≤
|
| 129 |
+
BinaryFraction.preparedKernelBitBudget N M P F exponent eM eF B S +
|
| 130 |
+
BinaryFraction.powerDenominatorBitBudget (J - node.1.val)
|
| 131 |
+
(BinaryFraction.preparedKernelWordBudget M B) D + 1 := by
|
| 132 |
+
have hk := physicalPreparedStepWithWork_bounds source target N P F exponent H Q eM eF hP hM hF
|
| 133 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 134 |
+
draw integer node hbelow t query B E S hPdyadic hb
|
| 135 |
+
have hc := BinaryFraction.powerDenominatorWithWork_cost
|
| 136 |
+
(physicalPreparedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 137 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 138 |
+
draw integer node hbelow t query).1 base hbase (J - node.1.val)
|
| 139 |
+
(BinaryFraction.preparedKernelWordBudget M B) D hk.1 hbaseWidth
|
| 140 |
+
exact Nat.add_le_add_right (Nat.add_le_add hk.2 hc) 1
|
| 141 |
+
|
| 142 |
+
include ha htau heta hkappa hdelta hparent hmass hinitial hhistory hwide in
|
| 143 |
+
theorem physicalCachedStepWithWork_value_width (ell : ℕ) (hell : 0 < ell)
|
| 144 |
+
(hdeltaExact : delta = 1 / (ell : ℚ) ^ 10)
|
| 145 |
+
(hsize : source.length + target.length ≤ N) (base : List Bool)
|
| 146 |
+
(hbase : bitWordValue base = ell ^ 10 + 1) :
|
| 147 |
+
(physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 148 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 149 |
+
draw integer node hbelow t query base (by rw [hbase]; omega)).1.value =
|
| 150 |
+
physicalLocalRefinement source target U N P F exponent Q A tau delta T draw
|
| 151 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 152 |
+
node (t + 1) query ∧
|
| 153 |
+
(physicalCachedStepWithWork source target N P F exponent H Q eM eF hP hM hF
|
| 154 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 155 |
+
draw integer node hbelow t query base (by rw [hbase]; omega)).1.width ≤
|
| 156 |
+
Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 := by
|
| 157 |
+
rcases hdeltaExact with rfl
|
| 158 |
+
have hraw := physicalPreparedStepWithWork_value source target N P F exponent H Q eM eF hP hM hF
|
| 159 |
+
tauWord aWord etaWord kappaWord deltaWord parentWords massWords initialWords historyWords
|
| 160 |
+
draw integer node hbelow t query U A tau eta kappa _ T ha htau heta hkappa hdelta
|
| 161 |
+
hparent hmass hinitial hhistory hwide
|
| 162 |
+
have hstored := physicalLocalOnlineRefinement_cached_word source target U N P F exponent H Q A tau eta kappa
|
| 163 |
+
hsize T ell hell draw integer node (t + 1) query _ hraw base hbase
|
| 164 |
+
exact ⟨hstored.1.trans hraw, hstored.2⟩
|
| 165 |
+
|
| 166 |
+
end Step
|
| 167 |
+
|
| 168 |
+
end EditApproximation
|
| 169 |
+
|
| 170 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundedQuery.lean
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalGlobalValue
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementReadWork
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Geometry.WarmupQueryKeys
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Geometry.RankedProgramRestriction
|
| 5 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRequestEncoding
|
| 6 |
+
|
| 7 |
+
namespace OAI
|
| 8 |
+
|
| 9 |
+
/-! The actual global read program stays within the bounded cache-key
|
| 10 |
+
domain. Restricting its type therefore preserves the complete local-pass
|
| 11 |
+
value and gives an injectively encoded memo evaluator. -/
|
| 12 |
+
|
| 13 |
+
namespace EditApproximation
|
| 14 |
+
|
| 15 |
+
instance PhysicalTableRequest.decidableBounded {M J ny : ℕ} (passes copies T S : ℕ) :
|
| 16 |
+
DecidablePred (PhysicalTableRequest.Bounded (M := M) (J := J) (ny := ny) passes copies T S) :=
|
| 17 |
+
fun request => inferInstanceAs (Decidable
|
| 18 |
+
(request.pass < passes ∧ request.copy < copies ∧ request.index ≤ T + S))
|
| 19 |
+
|
| 20 |
+
theorem globalSeedRead_keys_bounded {M J ny : ℕ} (N T S passes copies : ℕ)
|
| 21 |
+
(multiplier : ℕ → ℕ) (initial : PhysicalEntry M J ny → ℕ)
|
| 22 |
+
(parent : PhysicalTableRequest M J ny) (hparent : parent.Bounded passes copies T S)
|
| 23 |
+
(state : PhysicalEntry M J ny) (oracle) :
|
| 24 |
+
∀ key ∈ (globalSeedRead N T S copies multiplier initial parent state).keys oracle,
|
| 25 |
+
key.val.Bounded passes copies T S := by
|
| 26 |
+
unfold globalSeedRead
|
| 27 |
+
split_ifs with hnode hpass
|
| 28 |
+
· intro key hk
|
| 29 |
+
exact False.elim (List.not_mem_nil hk)
|
| 30 |
+
· unfold physicalMedianSeedQuery
|
| 31 |
+
apply FiniteQuery.keys_all_collect
|
| 32 |
+
· intro copy _ key hk
|
| 33 |
+
simp only [previousPassRead, FiniteQuery.keys, List.mem_singleton] at hk
|
| 34 |
+
subst key
|
| 35 |
+
exact ⟨Nat.lt_of_le_of_lt (Nat.sub_le _ _) hparent.1, copy.isLt, le_rfl⟩
|
| 36 |
+
· intro values key hk
|
| 37 |
+
exact False.elim (List.not_mem_nil hk)
|
| 38 |
+
· intro key hk
|
| 39 |
+
exact False.elim (List.not_mem_nil hk)
|
| 40 |
+
|
| 41 |
+
section Bounded
|
| 42 |
+
|
| 43 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 44 |
+
(source target : List α) (N P F exponent H Q T S passes copies : ℕ)
|
| 45 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 46 |
+
(group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
|
| 47 |
+
(integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 48 |
+
(initial : PhysicalEntry M J target.length → ℕ)
|
| 49 |
+
|
| 50 |
+
theorem physicalGlobalQuery_keys_bounded (request : PhysicalTableRequest M J target.length)
|
| 51 |
+
(hrequest : request.Bounded passes copies T S) (oracle) :
|
| 52 |
+
∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 53 |
+
tau eta kappa delta group integer initial request).keys oracle,
|
| 54 |
+
key.val.Bounded passes copies T S := by
|
| 55 |
+
rcases request with ⟨pass, copy, node, index, q⟩
|
| 56 |
+
obtain ⟨hpass, hcopy, hindex⟩ := hrequest
|
| 57 |
+
dsimp only at hpass hcopy hindex
|
| 58 |
+
by_cases hj : index ≤ T
|
| 59 |
+
· change ∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 60 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q)).keys oracle,
|
| 61 |
+
key.val.Bounded passes copies T S
|
| 62 |
+
rw [physicalGlobalQuery_warmup source target N P F exponent H Q T S copies factor multiplier
|
| 63 |
+
tau eta kappa delta group integer initial pass copy node index hj q]
|
| 64 |
+
apply physicalWarmupRequestQuery_keys_bounded source target N P F (factor pass)
|
| 65 |
+
passes copies pass copy T S index hpass hcopy hj node q _ oracle
|
| 66 |
+
intro r key hk
|
| 67 |
+
exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _
|
| 68 |
+
⟨hpass, hcopy, hindex⟩ _ oracle key hk
|
| 69 |
+
· obtain ⟨t, hi⟩ : ∃ t, index = T + t := ⟨index - T, by omega⟩
|
| 70 |
+
subst index
|
| 71 |
+
have ht : 0 < t := by omega
|
| 72 |
+
have htS : t ≤ S := by omega
|
| 73 |
+
change ∀ key ∈ (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 74 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q)).keys oracle,
|
| 75 |
+
key.val.Bounded passes copies T S
|
| 76 |
+
by_cases hbelow : node.1.val < J
|
| 77 |
+
· by_cases hshort : (physicalSourceInterval source.length node).hi -
|
| 78 |
+
(physicalSourceInterval source.length node).lo ≤ 1
|
| 79 |
+
· unfold physicalGlobalQuery
|
| 80 |
+
dsimp only
|
| 81 |
+
erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T
|
| 82 |
+
from hj), dite_eq_left hbelow, dite_eq_left hshort]
|
| 83 |
+
apply physicalInitialQuery_keys_all
|
| 84 |
+
intro r key hk
|
| 85 |
+
exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _
|
| 86 |
+
⟨hpass, hcopy, hindex⟩ _ oracle key hk
|
| 87 |
+
· unfold physicalGlobalQuery
|
| 88 |
+
dsimp only
|
| 89 |
+
erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T
|
| 90 |
+
from hj), dite_eq_left hbelow, dite_eq_right hshort]
|
| 91 |
+
erw [FiniteQuery.mapKeys_keys]
|
| 92 |
+
intro key hk
|
| 93 |
+
obtain ⟨child, hc, rfl⟩ := List.mem_map.mp hk
|
| 94 |
+
exact physicalRefinementDataRequest_keys_bounded source target N P F exponent H Q tau
|
| 95 |
+
(refinementFactor (factor pass) F) eta kappa delta passes copies pass copy T S
|
| 96 |
+
(T + t - T) (by omega) (by omega) hpass hcopy node hbelow _ _ q _ child hc
|
| 97 |
+
· unfold physicalGlobalQuery
|
| 98 |
+
dsimp only
|
| 99 |
+
erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T
|
| 100 |
+
from hj), dite_eq_right hbelow]
|
| 101 |
+
apply physicalInitialQuery_keys_all
|
| 102 |
+
intro r key hk
|
| 103 |
+
exact globalSeedRead_keys_bounded N T S passes copies multiplier initial _
|
| 104 |
+
⟨hpass, hcopy, hindex⟩ _ oracle key hk
|
| 105 |
+
|
| 106 |
+
def physicalBoundedQuery
|
| 107 |
+
(request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) :
|
| 108 |
+
FiniteQuery {child : {child : PhysicalTableRequest M J target.length // child.Bounded passes copies T S} //
|
| 109 |
+
child.val.combinedRank T S < request.val.combinedRank T S} :=
|
| 110 |
+
restrictRankedProgram (PhysicalTableRequest.combinedRank T S)
|
| 111 |
+
(physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 112 |
+
tau eta kappa delta group integer initial) (PhysicalTableRequest.Bounded passes copies T S) request
|
| 113 |
+
|
| 114 |
+
theorem physicalBoundedQuery_value
|
| 115 |
+
(request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) :
|
| 116 |
+
(physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier
|
| 117 |
+
tau eta kappa delta group integer initial request).value
|
| 118 |
+
(fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 119 |
+
tau eta kappa delta group integer initial child.val.val) =
|
| 120 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 121 |
+
tau eta kappa delta group integer initial request.val := by
|
| 122 |
+
unfold physicalBoundedQuery
|
| 123 |
+
rw [restrictRankedProgram_value _ _ _ _ request
|
| 124 |
+
(physicalGlobalQuery_keys_bounded source target N P F exponent H Q T S passes copies factor multiplier
|
| 125 |
+
tau eta kappa delta group integer initial request.val request.property _)]
|
| 126 |
+
exact physicalGlobalQuery_value source target N P F exponent H Q T S copies factor multiplier
|
| 127 |
+
tau eta kappa delta group integer initial request.val
|
| 128 |
+
|
| 129 |
+
def physicalMemoEvaluate
|
| 130 |
+
(request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) :=
|
| 131 |
+
rankedMemoEvaluate (fun request :
|
| 132 |
+
{request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S} =>
|
| 133 |
+
request.val.combinedRank T S)
|
| 134 |
+
(physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier
|
| 135 |
+
tau eta kappa delta group integer initial)
|
| 136 |
+
(PhysicalTableRequest.bits M J target.length passes copies T S)
|
| 137 |
+
(fun request => PhysicalTableRequest.code copies T S request.val) request .empty
|
| 138 |
+
|
| 139 |
+
theorem physicalMemoEvaluate_value (hM : 1 ≤ M)
|
| 140 |
+
(request : {request : PhysicalTableRequest M J target.length // request.Bounded passes copies T S}) :
|
| 141 |
+
(physicalMemoEvaluate source target N P F exponent H Q T S passes copies factor multiplier
|
| 142 |
+
tau eta kappa delta group integer initial request).value =
|
| 143 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 144 |
+
tau eta kappa delta group integer initial request.val := by
|
| 145 |
+
unfold physicalMemoEvaluate
|
| 146 |
+
exact rankedMemoEvaluate_specification
|
| 147 |
+
(fun request : {request : PhysicalTableRequest M J target.length //
|
| 148 |
+
request.Bounded passes copies T S} => request.val.combinedRank T S)
|
| 149 |
+
(physicalBoundedQuery source target N P F exponent H Q T S passes copies factor multiplier
|
| 150 |
+
tau eta kappa delta group integer initial)
|
| 151 |
+
(fun request => localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 152 |
+
tau eta kappa delta group integer initial request.val)
|
| 153 |
+
(physicalBoundedQuery_value source target N P F exponent H Q T S passes copies factor multiplier
|
| 154 |
+
tau eta kappa delta group integer initial)
|
| 155 |
+
_ _ (PhysicalTableRequest.code_injective hM passes copies T S)
|
| 156 |
+
(PhysicalTableRequest.code_fits hM passes copies T S) request
|
| 157 |
+
|
| 158 |
+
end Bounded
|
| 159 |
+
|
| 160 |
+
end EditApproximation
|
| 161 |
+
|
| 162 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalBoundsAllSeeds.lean
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementInvariants
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
/-! Nonnegativity and size bounds hold on every seed and every sample outcome. -/
|
| 6 |
+
|
| 7 |
+
namespace EditApproximation
|
| 8 |
+
|
| 9 |
+
open Finset
|
| 10 |
+
|
| 11 |
+
theorem rationalActualWideActions_connection_nonneg {nx ny M : ℕ} (parent : TargetInterval nx)
|
| 12 |
+
(representatives : List (ℕ × TargetInterval ny)) (P : ℕ)
|
| 13 |
+
(action : PhysicalRationalAction M ny)
|
| 14 |
+
(ha : action ∈ rationalActualWideActions parent representatives P) : 0 ≤ action.connection := by
|
| 15 |
+
obtain ⟨br, _, hmem⟩ := List.mem_flatMap.mp ha
|
| 16 |
+
obtain ⟨states, _, rfl⟩ := List.mem_map.mp hmem
|
| 17 |
+
exact Nat.cast_nonneg _
|
| 18 |
+
|
| 19 |
+
theorem localInitialConeTable_nonneg {α : Type*} (source target : List α)
|
| 20 |
+
(U : TargetInterval target.length → ℕ) (N P F : ℕ) (A a : ℚ) (q : TargetInterval target.length) :
|
| 21 |
+
0 ≤ localInitialConeTable source target U N P F A a q := by
|
| 22 |
+
unfold localInitialConeTable
|
| 23 |
+
split_ifs
|
| 24 |
+
· exact le_rfl
|
| 25 |
+
· apply (le_rationalMinimum_iff _ _ _).2
|
| 26 |
+
refine ⟨by positivity, ?_⟩
|
| 27 |
+
intro v hv
|
| 28 |
+
obtain ⟨r, _, rfl⟩ := List.mem_map.mp hv
|
| 29 |
+
unfold initialConeValue scaledSeedValue
|
| 30 |
+
positivity
|
| 31 |
+
|
| 32 |
+
theorem stageInitial_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 33 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 34 |
+
(N P F : ℕ) (A : ℚ) (state : PhysicalEntry M J target.length) :
|
| 35 |
+
0 ≤ stageInitial source target U N P F A state := by
|
| 36 |
+
unfold stageInitial physicalInitialTable
|
| 37 |
+
dsimp only
|
| 38 |
+
split_ifs
|
| 39 |
+
· exact Nat.cast_nonneg _
|
| 40 |
+
· exact localInitialConeTable_nonneg _ _ _ _ _ _ _ _ _
|
| 41 |
+
|
| 42 |
+
theorem stageInitial_upper_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 43 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 44 |
+
(N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N)
|
| 45 |
+
(state : PhysicalEntry M J target.length) :
|
| 46 |
+
stageInitial source target U N P F A state ≤ (32 * F + 1 : ℚ) * N := by
|
| 47 |
+
unfold stageInitial physicalInitialTable
|
| 48 |
+
dsimp only
|
| 49 |
+
split_ifs with hleaf
|
| 50 |
+
· rw [shortSourceCost_eq_edit _ _ hleaf]
|
| 51 |
+
have hcost : (stateEditCost (physicalSource source state.1) target state.2 : ℚ) ≤ N := by
|
| 52 |
+
exact_mod_cast physical_state_cost_le source target N hsize state
|
| 53 |
+
change (stateEditCost (physicalSource source state.1) target state.2 : ℚ) ≤ _
|
| 54 |
+
have hcoef : (1 : ℚ) ≤ 32 * F + 1 := by
|
| 55 |
+
have hF : (0 : ℚ) ≤ F := Nat.cast_nonneg _
|
| 56 |
+
linarith
|
| 57 |
+
exact hcost.trans (by simpa only [one_mul] using mul_le_mul_of_nonneg_right hcoef (Nat.cast_nonneg (α := ℚ) N))
|
| 58 |
+
· unfold localInitialConeTable
|
| 59 |
+
split_ifs
|
| 60 |
+
· positivity
|
| 61 |
+
· exact rationalMinimum_le_fallback _ _
|
| 62 |
+
|
| 63 |
+
theorem rationalPhysicalBellman_nonneg {α : Type*} {M J : ℕ} (source target : List α)
|
| 64 |
+
(P : ℕ) (L : ℚ) (hL : 0 ≤ L) (initial : PhysicalEntry M J target.length → ℚ)
|
| 65 |
+
(representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length))
|
| 66 |
+
(hinitial : ∀ state, 0 ≤ initial state)
|
| 67 |
+
(value : PhysicalEntry M J target.length → ℚ) (hvalue : ∀ state, 0 ≤ value state)
|
| 68 |
+
(state : PhysicalEntry M J target.length) :
|
| 69 |
+
0 ≤ rationalPhysicalBellman source target P L initial representatives value state := by
|
| 70 |
+
unfold rationalPhysicalBellman
|
| 71 |
+
dsimp only
|
| 72 |
+
split_ifs
|
| 73 |
+
· exact hinitial state
|
| 74 |
+
· apply (le_rationalMinimum_iff _ _ _).2
|
| 75 |
+
refine ⟨hinitial state, ?_⟩
|
| 76 |
+
intro v hv
|
| 77 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 78 |
+
unfold rationalActionValue
|
| 79 |
+
exact add_nonneg (add_nonneg (mul_nonneg hL (Nat.cast_nonneg _))
|
| 80 |
+
(rationalActualWideActions_connection_nonneg _ _ _ action ha)) (sum_nonneg fun i _ => hvalue _)
|
| 81 |
+
· exact hinitial state
|
| 82 |
+
|
| 83 |
+
theorem stageWarmup_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 84 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 85 |
+
(N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) :
|
| 86 |
+
0 ≤ stageWarmup source target U N P F A t state := by
|
| 87 |
+
induction t generalizing state with
|
| 88 |
+
| zero => exact stageInitial_nonneg_all_seeds source target U N P F A state
|
| 89 |
+
| succ t ih =>
|
| 90 |
+
exact rationalPhysicalBellman_nonneg source target P (128 * F) (by positivity) _ _
|
| 91 |
+
(stageInitial_nonneg_all_seeds source target U N P F A) _ ih state
|
| 92 |
+
|
| 93 |
+
theorem stageWarmup_le_initial_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 94 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 95 |
+
(N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) :
|
| 96 |
+
stageWarmup source target U N P F A t state ≤ stageInitial source target U N P F A state := by
|
| 97 |
+
cases t with
|
| 98 |
+
| zero => exact le_rfl
|
| 99 |
+
| succ t =>
|
| 100 |
+
change rationalPhysicalBellman source target P (128 * F) _ _ _ state ≤ _
|
| 101 |
+
unfold rationalPhysicalBellman
|
| 102 |
+
dsimp only
|
| 103 |
+
split_ifs
|
| 104 |
+
· exact le_rfl
|
| 105 |
+
· exact rationalMinimum_le_fallback _ _
|
| 106 |
+
· exact le_rfl
|
| 107 |
+
|
| 108 |
+
theorem physicalRefinement_upper_all_seeds {�� : Type*} [DecidableEq α] {M J : ℕ}
|
| 109 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 110 |
+
(N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N)
|
| 111 |
+
(T : ℕ) (delta : ℚ)
|
| 112 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 113 |
+
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ)
|
| 114 |
+
(q : TargetInterval target.length) :
|
| 115 |
+
physicalRefinement source target U N P F A T delta choices node t q ≤ (32 * F + 1 : ℚ) * N := by
|
| 116 |
+
exact (physicalRefinement_le_warmup source target U N P F A T delta choices node t q).trans
|
| 117 |
+
((stageWarmup_le_initial_all_seeds source target U N P F A T (node, q)).trans
|
| 118 |
+
(stageInitial_upper_all_seeds source target U N P F A hsize (node, q)))
|
| 119 |
+
|
| 120 |
+
theorem physicalRefinement_nonneg_all_seeds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 121 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 122 |
+
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
|
| 123 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 124 |
+
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ)
|
| 125 |
+
(q : TargetInterval target.length) :
|
| 126 |
+
0 ≤ physicalRefinement source target U N P F A T delta choices node t q := by
|
| 127 |
+
by_cases hbelow : node.1.val < J
|
| 128 |
+
· by_cases hleaf : (physicalSourceInterval source.length node).hi -
|
| 129 |
+
(physicalSourceInterval source.length node).lo ≤ 1
|
| 130 |
+
· rw [physicalRefinement_at_terminal source target U N P F A T delta choices node (Or.inr hleaf)]
|
| 131 |
+
exact stageInitial_nonneg_all_seeds source target U N P F A (node, q)
|
| 132 |
+
· have hpost := (physicalRefinement_bellman_invariants source target U N P F A T delta choices node t q).1
|
| 133 |
+
have hnonneg : 0 ≤ rationalPhysicalBellman source target P (128 * F)
|
| 134 |
+
(stageInitial source target U N P F A) (stageRepresentatives source target U N P F A)
|
| 135 |
+
(fun state => physicalRefinement source target U N P F A T delta choices state.1 t state.2) (node, q) := by
|
| 136 |
+
unfold rationalPhysicalBellman
|
| 137 |
+
dsimp only
|
| 138 |
+
rw [dite_eq_left hbelow, ite_eq_right hleaf]
|
| 139 |
+
apply (le_rationalMinimum_iff _ _ _).2
|
| 140 |
+
refine ⟨stageInitial_nonneg_all_seeds source target U N P F A (node, q), ?_⟩
|
| 141 |
+
intro v hv
|
| 142 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 143 |
+
unfold rationalActionValue
|
| 144 |
+
apply add_nonneg
|
| 145 |
+
· exact add_nonneg (mul_nonneg (by positivity) (Nat.cast_nonneg _))
|
| 146 |
+
(rationalActualWideActions_connection_nonneg _ _ _ action ha)
|
| 147 |
+
· apply sum_nonneg
|
| 148 |
+
intro i _
|
| 149 |
+
exact physicalRefinement_nonneg_all_seeds source target U N P F A T delta choices
|
| 150 |
+
(physicalChild node hbelow (action.childState i).1) t (action.childState i).2
|
| 151 |
+
exact hnonneg.trans hpost
|
| 152 |
+
· rw [physicalRefinement_at_terminal source target U N P F A T delta choices node (Or.inl hbelow)]
|
| 153 |
+
exact stageInitial_nonneg_all_seeds source target U N P F A (node, q)
|
| 154 |
+
termination_by J - node.1.val
|
| 155 |
+
decreasing_by
|
| 156 |
+
unfold physicalChild
|
| 157 |
+
dsimp only
|
| 158 |
+
omega
|
| 159 |
+
|
| 160 |
+
end EditApproximation
|
| 161 |
+
|
| 162 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCachedWords.lean
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Binary.BinaryPowerStorage
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalDenominator
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The cache normalization algorithm applied to the actual all-seed local
|
| 7 |
+
table invariants. These word bounds require neither a good-seed event nor a
|
| 8 |
+
bound on the temporary numerator and denominator before normalization. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
theorem physicalLocalRefinement_cached_word {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 13 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 14 |
+
(N P F exponent Q : ℕ) (A tau : ℚ) (hsize : source.length + target.length ≤ N)
|
| 15 |
+
(T ell : ℕ) (hell : 0 < ell)
|
| 16 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 17 |
+
(online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ →
|
| 18 |
+
TargetInterval target.length → List (PhysicalRationalAction M target.length))
|
| 19 |
+
(honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1)
|
| 20 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length)
|
| 21 |
+
(raw : BinaryFraction) (hraw : raw.value =
|
| 22 |
+
physicalLocalRefinement source target U N P F exponent Q A tau
|
| 23 |
+
(1 / (ell : ℚ) ^ 10) T draw online node t q)
|
| 24 |
+
(base : List Bool) (hbase : bitWordValue base = ell ^ 10 + 1) :
|
| 25 |
+
let result := BinaryFraction.powerDenominatorWithWork raw base
|
| 26 |
+
(by rw [hbase]; omega) (J - node.1.val)
|
| 27 |
+
result.1.value = raw.value ∧ result.1.width ≤
|
| 28 |
+
Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 := by
|
| 29 |
+
dsimp only
|
| 30 |
+
have hd : raw.value.den ∣ bitWordValue base ^ (J - node.1.val) := by
|
| 31 |
+
rw [hraw, hbase]
|
| 32 |
+
exact physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell
|
| 33 |
+
draw online honline node t q
|
| 34 |
+
have hb := physicalLocalRefinement_bounds source target U N P F exponent Q A tau
|
| 35 |
+
(1 / (ell : ℚ) ^ 10) T (by positivity) draw online node t q
|
| 36 |
+
have hv : |raw.value| ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by
|
| 37 |
+
rw [hraw, abs_of_nonneg hb.1]
|
| 38 |
+
simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using
|
| 39 |
+
hb.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize (node, q))
|
| 40 |
+
refine ⟨BinaryFraction.powerDenominatorWithWork_value raw base _ _ hd, ?_⟩
|
| 41 |
+
have hw := BinaryFraction.powerDenominatorWithWork_width raw base (by rw [hbase]; omega)
|
| 42 |
+
(J - node.1.val) ((32 * F + 1) * N) base.length le_rfl hd hv
|
| 43 |
+
simpa only [Nat.mul_add, Nat.mul_one, Nat.mul_assoc, Nat.add_assoc] using hw
|
| 44 |
+
|
| 45 |
+
theorem physicalLocalOnlineRefinement_cached_word {α : Type*} [DecidableEq α]
|
| 46 |
+
{M J R : ℕ} [NeZero R]
|
| 47 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 48 |
+
(N P F exponent H Q : ℕ) (A tau eta kappa : ℚ)
|
| 49 |
+
(hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell)
|
| 50 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 51 |
+
(integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 52 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length)
|
| 53 |
+
(raw : BinaryFraction) (hraw : raw.value =
|
| 54 |
+
physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10)
|
| 55 |
+
T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node t q)
|
| 56 |
+
(base : List Bool) (hbase : bitWordValue base = ell ^ 10 + 1) :
|
| 57 |
+
let result := BinaryFraction.powerDenominatorWithWork raw base
|
| 58 |
+
(by rw [hbase]; omega) (J - node.1.val)
|
| 59 |
+
result.1.value = raw.value ∧ result.1.width ≤
|
| 60 |
+
Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * base.length + 3 :=
|
| 61 |
+
physicalLocalRefinement_cached_word source target U N P F exponent Q A tau hsize T ell hell
|
| 62 |
+
draw _ (physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer)
|
| 63 |
+
node t q raw hraw base hbase
|
| 64 |
+
|
| 65 |
+
theorem physicalLocalWarmup_cached_word {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 66 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 67 |
+
(N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N)
|
| 68 |
+
(t : ℕ) (state : PhysicalEntry M J target.length)
|
| 69 |
+
(raw : BinaryFraction) (hraw : raw.value = physicalLocalWarmup source target U N P F A t state) :
|
| 70 |
+
let result := BinaryFraction.fixedDenominatorWithWork raw [true] (by decide)
|
| 71 |
+
result.1.value = raw.value ∧ result.1.width ≤ Nat.size ((32 * F + 1) * N) + 3 := by
|
| 72 |
+
dsimp only
|
| 73 |
+
have hd : raw.value.den ∣ bitWordValue [true] := by
|
| 74 |
+
rw [hraw, physicalLocalWarmup_den_one]
|
| 75 |
+
exact one_dvd _
|
| 76 |
+
have hb := physicalLocalWarmup_bounds source target U N P F A t state
|
| 77 |
+
have hv : |raw.value| ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by
|
| 78 |
+
rw [hraw, abs_of_nonneg hb.1]
|
| 79 |
+
simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using
|
| 80 |
+
hb.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize state)
|
| 81 |
+
exact ⟨BinaryFraction.fixedDenominatorWithWork_value raw [true] (by decide) hd,
|
| 82 |
+
BinaryFraction.fixedDenominatorWithWork_width raw [true] (by decide) hd
|
| 83 |
+
((32 * F + 1) * N) 1 hv (by decide)⟩
|
| 84 |
+
|
| 85 |
+
end EditApproximation
|
| 86 |
+
|
| 87 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseBitWork.lean
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseEntryCostSum
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWork
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
namespace EditApproximation
|
| 7 |
+
|
| 8 |
+
section Coarse
|
| 9 |
+
variable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B]
|
| 10 |
+
(source target : List ℕ) (N P H T S passes copies : ℕ)
|
| 11 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 12 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 13 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 14 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 15 |
+
|
| 16 |
+
local notation "ell" => inputSmallLog N
|
| 17 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 18 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 19 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 20 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 21 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 22 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 23 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 25 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 26 |
+
|
| 27 |
+
/-- Bit arithmetic is executed once for each fresh coarse source request. -/
|
| 28 |
+
noncomputable def physicalFamilyCoarseBitWork (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 29 |
+
(root : Table) (coarse : PhysicalCoarseDraw source target B depth) : ℝ :=
|
| 30 |
+
let initial := clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)
|
| 31 |
+
let result := chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80)
|
| 32 |
+
T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial
|
| 33 |
+
answer bits encode root
|
| 34 |
+
coarseEntryCostSum source target N depth coarse
|
| 35 |
+
(fun entry => Sum.inr (Sum.inl entry) ∈ result.freshKeys)
|
| 36 |
+
|
| 37 |
+
theorem physicalFamilyCoarseBitWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 38 |
+
(root : Table) (coarse : PhysicalCoarseDraw source target B depth) (C : ℝ)
|
| 39 |
+
(hc : ∀ entry : PhysicalEntry M J target.length,
|
| 40 |
+
(coarseEntryBinaryCost N B (depth entry) (physicalSource source entry.1)
|
| 41 |
+
(substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) ≤
|
| 42 |
+
C * ((coarseInitialArrayWork B (depth entry) (initialThresholdQ N) (initialLambda N)
|
| 43 |
+
(physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) +
|
| 44 |
+
((physicalSource source entry.1).length + 1 : ℕ))) :
|
| 45 |
+
physicalFamilyCoarseBitWork source target N P H T S passes copies factor multiplier
|
| 46 |
+
tau eta kappa delta draw depth bits encode root coarse ≤ C *
|
| 47 |
+
(physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier
|
| 48 |
+
tau eta kappa delta draw B depth bits encode root coarse +
|
| 49 |
+
physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier
|
| 50 |
+
tau eta kappa delta
|
| 51 |
+
(clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse))
|
| 52 |
+
draw bits encode root) := by
|
| 53 |
+
unfold physicalFamilyCoarseBitWork physicalFamilyMemoCoarseWork physicalFamilyCoarseInputWork
|
| 54 |
+
exact coarseEntryCostSum_bound source target N depth coarse _ C hc
|
| 55 |
+
|
| 56 |
+
end Coarse
|
| 57 |
+
end EditApproximation
|
| 58 |
+
|
| 59 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseExecution.lean
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLaw
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyRuntime
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
open MeasureTheory
|
| 10 |
+
|
| 11 |
+
section Execution
|
| 12 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 13 |
+
(source target : List α) (N P H B : ℕ)
|
| 14 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
variable [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 21 |
+
|
| 22 |
+
noncomputable def physicalCoarseExecutionLaw :
|
| 23 |
+
Measure (PhysicalCoarseExecution (R := R) source target N P H B depth) :=
|
| 24 |
+
(coarseFullSeedMeasure B depth
|
| 25 |
+
(fun entry => physicalSource source entry.1)
|
| 26 |
+
(fun entry => substring target entry.2.lo entry.2.hi)).prod
|
| 27 |
+
(rejectionRuntimeArrayLaw (physicalFamilyRange (M := M) (J := J) (R := R)
|
| 28 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H
|
| 29 |
+
(inputSmallLog N ^ 80) (computedSeedPassCount N) (H ^ 2)))
|
| 30 |
+
|
| 31 |
+
omit [NeZero M] [NeZero R] [NeZero B] in
|
| 32 |
+
theorem physicalCoarseExecutionProjection_measurable :
|
| 33 |
+
Measurable (physicalCoarseExecutionProjection (R := R) source target N P H B depth) := by
|
| 34 |
+
unfold physicalCoarseExecutionProjection
|
| 35 |
+
exact ((measurable_of_finite (physicalCoarseSeedTable source target N B depth)).comp
|
| 36 |
+
measurable_fst).prodMk measurable_snd
|
| 37 |
+
|
| 38 |
+
omit [NeZero R] in
|
| 39 |
+
theorem physicalCoarseExecutionProjection_law :
|
| 40 |
+
(physicalCoarseExecutionLaw (R := R) source target N P H B depth).map
|
| 41 |
+
(physicalCoarseExecutionProjection (R := R) source target N P H B depth) =
|
| 42 |
+
physicalFamilyRuntimeLaw (R := R) target N P H
|
| 43 |
+
(physicalCoarseSeedLaw source target N B depth) := by
|
| 44 |
+
unfold physicalCoarseExecutionLaw physicalCoarseExecutionProjection physicalFamilyRuntimeLaw
|
| 45 |
+
change ((_ : Measure (PhysicalCoarseDraw source target B depth)).prod _).map
|
| 46 |
+
(Prod.map (physicalCoarseSeedTable source target N B depth) id) = _
|
| 47 |
+
rw [← Measure.map_prod_map _ _ (measurable_of_finite _) measurable_id, Measure.map_id]
|
| 48 |
+
rfl
|
| 49 |
+
|
| 50 |
+
end Execution
|
| 51 |
+
end EditApproximation
|
| 52 |
+
|
| 53 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseInputWork.lean
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemoCoarse
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
namespace EditApproximation
|
| 6 |
+
|
| 7 |
+
section Coarse
|
| 8 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 9 |
+
(source target : List α) (N P H T S passes copies : ℕ)
|
| 10 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 11 |
+
(initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P)
|
| 12 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 13 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 14 |
+
|
| 15 |
+
local notation "ell" => inputSmallLog N
|
| 16 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 17 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 18 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 19 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 20 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 21 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 22 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 23 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 24 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 25 |
+
|
| 26 |
+
/-- Source scans and a constant setup charge for each first coarse request. -/
|
| 27 |
+
noncomputable def physicalFamilyCoarseInputWork (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 28 |
+
(root : Table) : ℝ :=
|
| 29 |
+
let result := chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80)
|
| 30 |
+
T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger initial
|
| 31 |
+
answer bits encode root
|
| 32 |
+
∑ entry, selectionIndicator (Sum.inr (Sum.inl entry) ∈ result.freshKeys) *
|
| 33 |
+
((physicalSource source entry.1).length + 1 : ℕ)
|
| 34 |
+
|
| 35 |
+
theorem physicalFamilyCoarseQuery_input_cost_le_width (root : Table) (hroot : root.depth = J) :
|
| 36 |
+
(physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier
|
| 37 |
+
tau eta kappa delta draw root).cost (fun entry => (initial entry : ℚ))
|
| 38 |
+
(fun entry => (physicalSource source entry.1).length + 1) ≤
|
| 39 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 40 |
+
tau eta kappa delta initial hP draw root).widthWork M source.length := by
|
| 41 |
+
apply (FiniteQuery.cost_mono_weights _ _ _ _ ?_).trans
|
| 42 |
+
(chargedRandomCoarseQuery_width_cost_le source target N P H T S (passes + 1) copies
|
| 43 |
+
factor multiplier tau eta kappa delta readGroup readInteger answer initial
|
| 44 |
+
(physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies draw)
|
| 45 |
+
(physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 46 |
+
factor multiplier tau eta kappa delta hP draw initial)
|
| 47 |
+
(physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 48 |
+
factor multiplier tau eta kappa delta initial hP draw) root hroot)
|
| 49 |
+
intro entry
|
| 50 |
+
rw [physicalSource_length_eq]
|
| 51 |
+
simpa only [physicalSourceInterval, Nat.add_comm] using Nat.add_le_add_right
|
| 52 |
+
(sourceIntervalAt_width M source.length entry.1.1.val (Nat.pos_of_neZero M) entry.1.2) 1
|
| 53 |
+
|
| 54 |
+
theorem physicalFamilyCoarseInputWork_le (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 55 |
+
(hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits)
|
| 56 |
+
(root : Table) (hroot : root.depth = J) :
|
| 57 |
+
physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier
|
| 58 |
+
tau eta kappa delta initial draw bits encode root ≤
|
| 59 |
+
((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 60 |
+
tau eta kappa delta initial hP draw root).widthWork M source.length : ℝ) := by
|
| 61 |
+
classical
|
| 62 |
+
let query := physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier
|
| 63 |
+
tau eta kappa delta draw root
|
| 64 |
+
have hkey (entry : PhysicalEntry M J target.length) :=
|
| 65 |
+
chargedRandomMemo_coarse_key source target N P ell exponent H (ell ^ 80) T S
|
| 66 |
+
(passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial
|
| 67 |
+
(physicalFamilyRequestValue source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 68 |
+
factor multiplier tau eta kappa delta initial hP draw)
|
| 69 |
+
(physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 70 |
+
factor multiplier tau eta kappa delta initial hP draw)
|
| 71 |
+
bits encode hinjective hbounded root entry
|
| 72 |
+
have hs := sum_selected_nat_weights_le (query.keys (fun entry => (initial entry : ℚ)))
|
| 73 |
+
(fun entry => (physicalSource source entry.1).length + 1)
|
| 74 |
+
have hc := physicalFamilyCoarseQuery_input_cost_le_width source target N P H T S passes copies
|
| 75 |
+
factor multiplier tau eta kappa delta initial hP draw root hroot
|
| 76 |
+
change query.cost (fun entry => (initial entry : ℚ))
|
| 77 |
+
(fun entry => (physicalSource source entry.1).length + 1) ≤ _ at hc
|
| 78 |
+
rw [FiniteQuery.cost_eq_sum] at hc
|
| 79 |
+
apply le_trans (b := ∑ entry, selectionIndicator (entry ∈ query.keys
|
| 80 |
+
(fun entry => (initial entry : ℚ))) * ((physicalSource source entry.1).length + 1 : ℕ))
|
| 81 |
+
· unfold physicalFamilyCoarseInputWork
|
| 82 |
+
apply Finset.sum_le_sum
|
| 83 |
+
intro entry _
|
| 84 |
+
apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _)
|
| 85 |
+
by_cases he : Sum.inr (Sum.inl entry) ∈
|
| 86 |
+
(chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1)
|
| 87 |
+
copies factor multiplier tau eta kappa delta readGroup readInteger initial answer
|
| 88 |
+
bits encode root).freshKeys
|
| 89 |
+
· have hq := hkey entry he
|
| 90 |
+
change entry ∈ query.keys (fun entry => (initial entry : ℚ)) at hq
|
| 91 |
+
simp only [selectionIndicator, he, hq, ite_true, le_refl]
|
| 92 |
+
· simp only [selectionIndicator, he, ite_false]
|
| 93 |
+
split <;> norm_num
|
| 94 |
+
· exact hs.trans (by exact_mod_cast hc)
|
| 95 |
+
|
| 96 |
+
end Coarse
|
| 97 |
+
end EditApproximation
|
| 98 |
+
|
| 99 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarsePreparation.lean
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseInputPreparation
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWork
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
theorem physicalCoarsePreparationCost_bound {M J : ℕ} (source target : List ℕ) (H : ℕ)
|
| 13 |
+
(hH : 100 ≤ H) (hs : Nat.size source.length ≤ H ^ 3) (ht : Nat.size target.length ≤ H ^ 3)
|
| 14 |
+
(hsymbol : ∀ a ∈ source ++ target, Nat.size a ≤ H ^ 3)
|
| 15 |
+
(entry : PhysicalEntry M J target.length) :
|
| 16 |
+
physicalCoarsePreparationCost source target entry ≤ H ^ 6 * ((physicalSource source entry.1).length + 1) := by
|
| 17 |
+
unfold physicalCoarsePreparationCost
|
| 18 |
+
rw [physicalSource_length_eq]
|
| 19 |
+
exact coarsePreparedSlicesWithWork_height_bound source target
|
| 20 |
+
(physicalSourceInterval source.length entry.1).lo (physicalSourceInterval source.length entry.1).hi
|
| 21 |
+
entry.2.lo entry.2.hi H (physicalSourceInterval source.length entry.1).ordered
|
| 22 |
+
(physicalSourceInterval source.length entry.1).valid entry.2.ordered entry.2.valid hH hs ht hsymbol
|
| 23 |
+
|
| 24 |
+
section Coarse
|
| 25 |
+
variable {M J R : ℕ} [NeZero M] [NeZero R]
|
| 26 |
+
(source target : List ℕ) (N P H T S passes copies : ℕ)
|
| 27 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 28 |
+
(initial : PhysicalEntry M J target.length → ℕ)
|
| 29 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 30 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 31 |
+
|
| 32 |
+
local notation "ell" => inputSmallLog N
|
| 33 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 34 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 35 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 36 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 37 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 38 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 39 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 40 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 41 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
theorem physicalFamilyCoarsePreparationWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 46 |
+
(root : Table) (hH : 100 ≤ H) (hs : Nat.size source.length ≤ H ^ 3)
|
| 47 |
+
(ht : Nat.size target.length ≤ H ^ 3)
|
| 48 |
+
(hsymbol : ∀ a ∈ source ++ target, Nat.size a ≤ H ^ 3) :
|
| 49 |
+
physicalFamilyCoarsePreparationWork source target N P H T S passes copies factor multiplier
|
| 50 |
+
tau eta kappa delta initial draw bits encode root ≤
|
| 51 |
+
(H : ℝ) ^ 6 * physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier
|
| 52 |
+
tau eta kappa delta initial draw bits encode root := by
|
| 53 |
+
classical
|
| 54 |
+
unfold physicalFamilyCoarsePreparationWork physicalFamilyCoarseInputWork
|
| 55 |
+
rw [Finset.mul_sum]
|
| 56 |
+
apply Finset.sum_le_sum
|
| 57 |
+
intro entry _
|
| 58 |
+
have hc : (physicalCoarsePreparationCost source target entry : ℝ) ≤
|
| 59 |
+
(H : ℝ) ^ 6 * ((physicalSource source entry.1).length + 1 : ℕ) := by
|
| 60 |
+
exact_mod_cast physicalCoarsePreparationCost_bound source target H hH hs ht hsymbol entry
|
| 61 |
+
have hp := mul_le_mul_of_nonneg_left hc
|
| 62 |
+
(show 0 ≤ selectionIndicator (Sum.inr (Sum.inl entry) ∈
|
| 63 |
+
(chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1)
|
| 64 |
+
copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root).freshKeys) by
|
| 65 |
+
unfold selectionIndicator; split <;> norm_num)
|
| 66 |
+
exact hp.trans_eq (by ring)
|
| 67 |
+
|
| 68 |
+
end Coarse
|
| 69 |
+
end EditApproximation
|
| 70 |
+
|
| 71 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSamplingWork.lean
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseInitialLabels
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWork
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
section Coarse
|
| 11 |
+
variable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B]
|
| 12 |
+
(source target : List ℕ) (N P H T S passes copies : ℕ)
|
| 13 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 14 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 15 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 16 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 17 |
+
|
| 18 |
+
local notation "ell" => inputSmallLog N
|
| 19 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 20 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 21 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 22 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 23 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 25 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 26 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 27 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 28 |
+
|
| 29 |
+
/- One binary word is consumed for every threshold label actually exposed. -/
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
omit [NeZero B] in
|
| 33 |
+
theorem physicalFamilyCoarseSamplingWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 34 |
+
(root : Table) (coarse : PhysicalCoarseDraw source target B depth) :
|
| 35 |
+
physicalFamilyCoarseSamplingWork source target N P H T S passes copies factor multiplier
|
| 36 |
+
tau eta kappa delta draw depth bits encode root coarse ≤ (Nat.size B : ℝ) *
|
| 37 |
+
physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier
|
| 38 |
+
tau eta kappa delta draw B depth bits encode root coarse := by
|
| 39 |
+
classical
|
| 40 |
+
unfold physicalFamilyCoarseSamplingWork physicalFamilyMemoCoarseWork
|
| 41 |
+
rw [Finset.mul_sum]
|
| 42 |
+
apply Finset.sum_le_sum
|
| 43 |
+
intro entry _
|
| 44 |
+
have h := coarseInitialLabelCount_le_arrayWork B (depth entry) (initialThresholdQ N) (initialLambda N)
|
| 45 |
+
(physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry)
|
| 46 |
+
have hs : 0 ≤ selectionIndicator (Sum.inr (Sum.inl entry) ∈
|
| 47 |
+
(chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80)
|
| 48 |
+
T S (passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger
|
| 49 |
+
(clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse))
|
| 50 |
+
answer bits encode root).freshKeys) := by
|
| 51 |
+
unfold selectionIndicator
|
| 52 |
+
split <;> norm_num
|
| 53 |
+
push_cast
|
| 54 |
+
exact (mul_le_mul_of_nonneg_left
|
| 55 |
+
(mul_le_mul_of_nonneg_left (Nat.cast_le.mpr h) (Nat.cast_nonneg (Nat.size B))) hs).trans_eq (by ring)
|
| 56 |
+
|
| 57 |
+
end Coarse
|
| 58 |
+
end EditApproximation
|
| 59 |
+
|
| 60 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCoarseSeedLaw.lean
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalSeedTables
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseGlobalSeed
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Geometry.StateDomain
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
namespace OAI
|
| 8 |
+
|
| 9 |
+
/-! The clamped incoming seed table is the image of the actual complete
|
| 10 |
+
coarse sampler. Its simultaneous initial accuracy is a derived fact. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
open MeasureTheory ProbabilityTheory
|
| 15 |
+
|
| 16 |
+
section CoarseLaw
|
| 17 |
+
|
| 18 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 19 |
+
(source target : List α) (N B : ℕ)
|
| 20 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
variable [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 27 |
+
|
| 28 |
+
noncomputable def physicalCoarseSeedLaw : Measure (ClampedPhysicalSeed M J target.length N) := by
|
| 29 |
+
classical
|
| 30 |
+
exact (coarseFullSeedMeasure B depth
|
| 31 |
+
(fun state : PhysicalEntry M J target.length => physicalSource source state.1)
|
| 32 |
+
(fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi)).map
|
| 33 |
+
(physicalCoarseSeedTable source target N B depth)
|
| 34 |
+
|
| 35 |
+
instance physicalCoarseSeedLaw_probability :
|
| 36 |
+
IsProbabilityMeasure (physicalCoarseSeedLaw source target N B depth) := by
|
| 37 |
+
unfold physicalCoarseSeedLaw
|
| 38 |
+
infer_instance
|
| 39 |
+
|
| 40 |
+
theorem physicalCoarseSeedLaw_failure (hN : 0 < N)
|
| 41 |
+
(hsize : source.length + target.length ≤ N) (hell : 200 ≤ inputSmallLog N)
|
| 42 |
+
(hB : B = (integerParameters N).B) (hM : M = (integerParameters N).M)
|
| 43 |
+
(hJ : J = intervalTreeDepth M source.length)
|
| 44 |
+
(hdepth : ∀ state, depth state = computedCoarseDepth N
|
| 45 |
+
(coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi)))
|
| 46 |
+
(bernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B =>
|
| 47 |
+
(PMF.uniformOfFintype (Fin B)).toMeasure)) :
|
| 48 |
+
(physicalCoarseSeedLaw source target N B depth).real
|
| 49 |
+
{seed | ¬ physicalSeedGood source target ((integerParameters N).initialFactor : ℚ) seed} < 1 / 100 := by
|
| 50 |
+
classical
|
| 51 |
+
have hwidth (state : PhysicalEntry M J target.length) :
|
| 52 |
+
coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi) ≤ N := by
|
| 53 |
+
apply max_le
|
| 54 |
+
· exact (physicalSource_length_le source state.1).trans (by omega)
|
| 55 |
+
· have hlen : (substring target state.2.lo state.2.hi).length ≤ target.length := by
|
| 56 |
+
simp only [substring, List.length_drop, List.length_take]
|
| 57 |
+
exact (Nat.sub_le _ _).trans (min_le_right _ _)
|
| 58 |
+
exact hlen.trans (by omega)
|
| 59 |
+
have hcount : Fintype.card (PhysicalEntry M J target.length) ≤ 2 ^ (5 * inputHeight N) := by
|
| 60 |
+
rw [hJ, hM]
|
| 61 |
+
exact computed_labeledEntry_card_le N source.length target.length hN (by omega) (by omega) hell
|
| 62 |
+
have h := computed_fullSeedTable_accuracy N B depth
|
| 63 |
+
(fun state : PhysicalEntry M J target.length => physicalSource source state.1)
|
| 64 |
+
(fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi)
|
| 65 |
+
hB hdepth hN hwidth hcount hell bernstein
|
| 66 |
+
rw [physicalCoarseSeedLaw, map_measureReal_apply (measurable_of_finite _) (Set.toFinite _).measurableSet]
|
| 67 |
+
have hevents : (physicalCoarseSeedTable source target N B depth) ⁻¹'
|
| 68 |
+
{seed | ¬ physicalSeedGood source target ((integerParameters N).initialFactor : ℚ) seed} =
|
| 69 |
+
{draw : PhysicalCoarseDraw source target B depth | ¬ ∀ state : PhysicalEntry M J target.length,
|
| 70 |
+
stateEditCost (physicalSource source state.1) target state.2 ≤
|
| 71 |
+
coarseFullSeedTable N B depth
|
| 72 |
+
(fun state : PhysicalEntry M J target.length => physicalSource source state.1)
|
| 73 |
+
(fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi) draw state ∧
|
| 74 |
+
coarseFullSeedTable N B depth
|
| 75 |
+
(fun state : PhysicalEntry M J target.length => physicalSource source state.1)
|
| 76 |
+
(fun state : PhysicalEntry M J target.length => substring target state.2.lo state.2.hi) draw state ≤
|
| 77 |
+
(integerParameters N).initialFactor * stateEditCost (physicalSource source state.1) target state.2} := by
|
| 78 |
+
ext draw
|
| 79 |
+
apply not_congr
|
| 80 |
+
unfold physicalSeedGood clampedSeedNat physicalCoarseSeedTable
|
| 81 |
+
constructor
|
| 82 |
+
· intro hg state
|
| 83 |
+
exact ⟨(hg state).1, by exact_mod_cast (hg state).2⟩
|
| 84 |
+
· intro hg state
|
| 85 |
+
exact ⟨(hg state).1, by exact_mod_cast (hg state).2⟩
|
| 86 |
+
rw [hevents]
|
| 87 |
+
exact h
|
| 88 |
+
|
| 89 |
+
end CoarseLaw
|
| 90 |
+
|
| 91 |
+
end EditApproximation
|
| 92 |
+
|
| 93 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalCommonSource.lean
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.CommonRangeSource
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalProgramLaw
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! The actual bounded physical program can share one source universe
|
| 9 |
+
across incoming seed tables. Online coordinates include their requested
|
| 10 |
+
range; group coordinates share whole-cell arrays. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
open MeasureTheory ProbabilityTheory
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
abbrev PhysicalCommonCoordinate (M J N n exponent F Q R B : ℕ)
|
| 19 |
+
(key : PhysicalCommonKey M J N n exponent B) : Type :=
|
| 20 |
+
match key with
|
| 21 |
+
| .inl online => Fin R → Fin online.2.val.val
|
| 22 |
+
| .inr group => PhysicalLocalGroupArray M J N n exponent F Q R group
|
| 23 |
+
|
| 24 |
+
section Source
|
| 25 |
+
|
| 26 |
+
variable (M J N n exponent F Q R B : ℕ)
|
| 27 |
+
[NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 28 |
+
|
| 29 |
+
instance physicalCommonCoordinateFintype (key : PhysicalCommonKey M J N n exponent B) :
|
| 30 |
+
Fintype (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by
|
| 31 |
+
cases key <;> dsimp only [PhysicalCommonCoordinate] <;> infer_instance
|
| 32 |
+
|
| 33 |
+
instance physicalCommonCoordinateMeasurable (key : PhysicalCommonKey M J N n exponent B) :
|
| 34 |
+
MeasurableSpace (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by
|
| 35 |
+
cases key <;> dsimp only [PhysicalCommonCoordinate] <;> infer_instance
|
| 36 |
+
|
| 37 |
+
instance physicalCommonCoordinateSingleton (key : PhysicalCommonKey M J N n exponent B) :
|
| 38 |
+
MeasurableSingletonClass (PhysicalCommonCoordinate M J N n exponent F Q R B key) := by
|
| 39 |
+
cases key <;> dsimp only [PhysicalCommonCoordinate, physicalCommonCoordinateMeasurable] <;> infer_instance
|
| 40 |
+
|
| 41 |
+
noncomputable def physicalCommonCoordinateLaw (key : PhysicalCommonKey M J N n exponent B) :
|
| 42 |
+
Measure (PhysicalCommonCoordinate M J N n exponent F Q R B key) :=
|
| 43 |
+
match key with
|
| 44 |
+
| .inl online => Measure.pi fun _ : Fin R =>
|
| 45 |
+
(PMF.uniformOfFintype (Fin online.2.val.val)).toMeasure
|
| 46 |
+
| .inr group => physicalLocalGroupArrayLaw M J N n exponent F Q R group
|
| 47 |
+
|
| 48 |
+
instance physicalCommonCoordinateLaw_probability (key : PhysicalCommonKey M J N n exponent B) :
|
| 49 |
+
IsProbabilityMeasure (physicalCommonCoordinateLaw M J N n exponent F Q R B key) := by
|
| 50 |
+
cases key <;> dsimp only [physicalCommonCoordinateLaw, PhysicalCommonCoordinate,
|
| 51 |
+
physicalCommonCoordinateMeasurable] <;> infer_instance
|
| 52 |
+
|
| 53 |
+
abbrev PhysicalCommonDraw := ∀ key : PhysicalCommonKey M J N n exponent B,
|
| 54 |
+
PhysicalCommonCoordinate M J N n exponent F Q R B key
|
| 55 |
+
|
| 56 |
+
noncomputable def physicalCommonLaw : Measure (PhysicalCommonDraw M J N n exponent F Q R B) :=
|
| 57 |
+
Measure.pi (physicalCommonCoordinateLaw M J N n exponent F Q R B)
|
| 58 |
+
|
| 59 |
+
instance physicalCommonLaw_probability : IsProbabilityMeasure
|
| 60 |
+
(physicalCommonLaw M J N n exponent F Q R B) := by
|
| 61 |
+
unfold physicalCommonLaw
|
| 62 |
+
infer_instance
|
| 63 |
+
|
| 64 |
+
end Source
|
| 65 |
+
|
| 66 |
+
section Selection
|
| 67 |
+
|
| 68 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 69 |
+
[NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 70 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 71 |
+
(N P F : ℕ) (A : ℚ) (T exponent H Q R B : ℕ) (tau : ℚ)
|
| 72 |
+
(hbound : ∀ key, physicalLocalOnlineMass source target U N P F A T exponent H tau key ≤ B)
|
| 73 |
+
|
| 74 |
+
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] in
|
| 75 |
+
theorem physicalCommonMass_positive (key : PhysicalLocalOnlineKey M J N target.length) :
|
| 76 |
+
0 < physicalLocalOnlineMass source target U N P F A T exponent H tau key :=
|
| 77 |
+
optimizerTriangularMass_positive _
|
| 78 |
+
(pow_pos (physicalLocalOnlineBandG_positive source target U N P F A T exponent H tau key) 80)
|
| 79 |
+
|
| 80 |
+
def physicalCommonSelectedOnlineKey (online : PhysicalLocalOnlineKey M J N target.length) :
|
| 81 |
+
CommonRangeKey (PhysicalLocalOnlineKey M J N target.length) B :=
|
| 82 |
+
(online, positiveDrawRangeOfLE B
|
| 83 |
+
(physicalLocalOnlineMass source target U N P F A T exponent H tau online)
|
| 84 |
+
(physicalCommonMass_positive source target U N P F A T exponent H tau online) (hbound online))
|
| 85 |
+
|
| 86 |
+
def physicalCommonSelectedKey (key : PhysicalLocalProgramKey M J N target.length exponent) :
|
| 87 |
+
PhysicalCommonKey M J N target.length exponent B :=
|
| 88 |
+
match key with
|
| 89 |
+
| .inl online => .inl (physicalCommonSelectedOnlineKey source target U N P F A T exponent H B tau hbound online)
|
| 90 |
+
| .inr group => .inr group
|
| 91 |
+
|
| 92 |
+
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] in
|
| 93 |
+
theorem physicalCommonSelectedKey_injective : Function.Injective
|
| 94 |
+
(physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound) := by
|
| 95 |
+
intro left right heq
|
| 96 |
+
cases left with
|
| 97 |
+
| inl left =>
|
| 98 |
+
cases right with
|
| 99 |
+
| inl right => exact congrArg Sum.inl (congrArg Prod.fst (Sum.inl.inj heq))
|
| 100 |
+
| inr right => exact False.elim (Sum.inl_ne_inr heq)
|
| 101 |
+
| inr left =>
|
| 102 |
+
cases right with
|
| 103 |
+
| inl right => exact False.elim (Sum.inr_ne_inl heq)
|
| 104 |
+
| inr right => exact congrArg Sum.inr (Sum.inr.inj heq)
|
| 105 |
+
|
| 106 |
+
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] in
|
| 107 |
+
theorem physicalCommonSelectedOnlineKey_range (online : PhysicalLocalOnlineKey M J N target.length) :
|
| 108 |
+
(physicalCommonSelectedOnlineKey source target U N P F A T exponent H B tau hbound online).2.val.val =
|
| 109 |
+
physicalLocalOnlineMass source target U N P F A T exponent H tau online := by
|
| 110 |
+
exact positiveDrawRangeOfLE_val B _
|
| 111 |
+
(physicalCommonMass_positive source target U N P F A T exponent H tau online) (hbound online)
|
| 112 |
+
|
| 113 |
+
def physicalCommonCoordinateImage (key : PhysicalLocalProgramKey M J N target.length exponent) :
|
| 114 |
+
PhysicalCommonCoordinate M J N target.length exponent F Q R B
|
| 115 |
+
(physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound key) →
|
| 116 |
+
PhysicalLocalProgramCoordinate (R := R) source target U N P F A T exponent H Q tau key :=
|
| 117 |
+
match key with
|
| 118 |
+
| .inl online => fun array time => Fin.cast
|
| 119 |
+
(physicalCommonSelectedOnlineKey_range source target U N P F A T exponent H B tau hbound online)
|
| 120 |
+
(array time)
|
| 121 |
+
| .inr _ => id
|
| 122 |
+
|
| 123 |
+
def physicalCommonSample
|
| 124 |
+
(draw : PhysicalCommonDraw M J N target.length exponent F Q R B) :
|
| 125 |
+
PhysicalLocalProgramDraw (R := R) source target U N P F A T exponent H Q tau :=
|
| 126 |
+
fun key => physicalCommonCoordinateImage source target U N P F A T exponent H Q R B tau hbound key
|
| 127 |
+
(draw (physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound key))
|
| 128 |
+
|
| 129 |
+
theorem physicalCommonSample_law :
|
| 130 |
+
(physicalCommonLaw M J N target.length exponent F Q R B).map
|
| 131 |
+
(physicalCommonSample source target U N P F A T exponent H Q R B tau hbound) =
|
| 132 |
+
physicalLocalProgramDrawLaw (R := R) source target U N P F A T exponent H Q tau := by
|
| 133 |
+
have h := finite_pi_restrict_image_map
|
| 134 |
+
(physicalCommonCoordinateLaw M J N target.length exponent F Q R B)
|
| 135 |
+
(physicalCommonSelectedKey source target U N P F A T exponent H B tau hbound)
|
| 136 |
+
(physicalCommonSelectedKey_injective source target U N P F A T exponent H B tau hbound)
|
| 137 |
+
(physicalCommonCoordinateImage source target U N P F A T exponent H Q R B tau hbound)
|
| 138 |
+
(fun _ => measurable_of_finite _)
|
| 139 |
+
refine h.trans ?_
|
| 140 |
+
unfold physicalLocalProgramDrawLaw
|
| 141 |
+
congr 1
|
| 142 |
+
funext key
|
| 143 |
+
cases key with
|
| 144 |
+
| inl online =>
|
| 145 |
+
exact finite_uniform_array_cast R _ _
|
| 146 |
+
(physicalCommonSelectedOnlineKey_range source target U N P F A T exponent H B tau hbound online)
|
| 147 |
+
| inr group => exact Measure.map_id
|
| 148 |
+
|
| 149 |
+
end Selection
|
| 150 |
+
|
| 151 |
+
end EditApproximation
|
| 152 |
+
|
| 153 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalComparisonBand.lean
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalUnskippedComparison
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegret
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Refinement.StageComparisonEnergy
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedBandSpacing
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! Non-bad, low-velocity comparison children belong to an actual unskipped cell band. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open Finset
|
| 13 |
+
|
| 14 |
+
section Node
|
| 15 |
+
|
| 16 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 17 |
+
(source target : List α) (hM : 0 < M)
|
| 18 |
+
(U : PhysicalEntry M J target.length → ℕ) (N P : ℕ) (A : ℚ)
|
| 19 |
+
(hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N)
|
| 20 |
+
(hMeq : M = (integerParameters N).M) (hPeq : P = (integerParameters N).P)
|
| 21 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A)
|
| 22 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 23 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 24 |
+
(T : ℕ) (hT : 0 < T) (node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 25 |
+
(q : TargetInterval target.length) (hc : 0 < stateEditCost (physicalSource source node) target q)
|
| 26 |
+
|
| 27 |
+
local notation "F" => inputSmallLog N
|
| 28 |
+
local notation "parent" => physicalSourceInterval source.length node
|
| 29 |
+
local notation "b" => (2 ^ Nat.log 2 (stateEditCost (physicalSource source node) target q) : ℕ)
|
| 30 |
+
local notation "r" => roundInterval (seedGridSpacing b P) q
|
| 31 |
+
local notation "action" => comparisonChildren source target hM P hP parent q hc
|
| 32 |
+
local notation "child" => physicalBandChildMassTable source target U N P F A T node hbelow
|
| 33 |
+
local notation "childR" => fun i s => (child i s : ℝ)
|
| 34 |
+
local notation "initial" => physicalBandChildInitial source target U N P F A node hbelow
|
| 35 |
+
local notation "tau" => RationalParameters.tau (rationalParameters (inputSmallLog N))
|
| 36 |
+
local notation "theta" => RationalParameters.theta (rationalParameters (inputSmallLog N))
|
| 37 |
+
local notation "thetaExponent" => 40 * smallLogExponent N
|
| 38 |
+
|
| 39 |
+
include hN hell hMeq hPeq hsize hA hseed hT in
|
| 40 |
+
theorem physicalComparison_unskipped
|
| 41 |
+
(hscale : 2 * (refinementFactor A F : ℝ) ≤ P) (hMP : 4 * (M : ℝ) / P ≤ 1)
|
| 42 |
+
(hnonempty : wideActionList M parent r b P ≠ [])
|
| 43 |
+
(hvelocity : |rationalStateGap (physicalSource source node) target r /
|
| 44 |
+
rationalWideActionMinimum parent r b P hnonempty child| ≤ 1 - tau)
|
| 45 |
+
(hKsmall : comparisonActionCurvature source target parent r action childR ≤ b / heightQuarterRoot N)
|
| 46 |
+
(hGsmall : comparisonActionMass action childR - wideActionMinimum parent r b P hnonempty childR ≤
|
| 47 |
+
b / heightQuarterRoot N) :
|
| 48 |
+
∃ member : UnskippedBand source target parent b P thetaExponent tau F child initial,
|
| 49 |
+
member ∈ physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent tau
|
| 50 |
+
(targetCell (theta * b) r) ∧ member.center = r ∧ action ∈ member.actions := by
|
| 51 |
+
have hF : 1 ≤ F := Nat.one_le_two_pow
|
| 52 |
+
have hell2 : 2 ≤ F := by
|
| 53 |
+
have h : 2 ≤ (2 : ℕ) ^ 1000 := by
|
| 54 |
+
simpa only [pow_one] using pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (by decide : 1 ≤ 1000)
|
| 55 |
+
exact h.trans hell
|
| 56 |
+
have hspec := comparisonChildren_spec source target hM P hP parent q hc
|
| 57 |
+
have hrep := stageRounded_representative_mem source target U N P F A hsize hP hF hA hseed node q hc
|
| 58 |
+
have hdyadic := cost_dyadicScale _ _ hc le_rfl
|
| 59 |
+
have hcR : (stateEditCost (physicalSource source node) target q : ℝ) ≤ 2 * (b : ℝ) := by
|
| 60 |
+
exact_mod_cast hdyadic.2.2.le
|
| 61 |
+
have hcost := comparisonChildren_cost_bound source target hM P hP parent q hc
|
| 62 |
+
change (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤
|
| 63 |
+
(1 + 4 * (M : ℝ) / P) * stateEditCost (physicalSource source node) target q at hcost
|
| 64 |
+
have hcostSum : (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤
|
| 65 |
+
4 * b := by
|
| 66 |
+
have h := mul_le_mul_of_nonneg_right hMP
|
| 67 |
+
(Nat.cast_nonneg (α := ℝ) (stateEditCost (physicalSource source node) target q))
|
| 68 |
+
nlinarith only [hcost, hcR, h]
|
| 69 |
+
have ha : (1 : ℝ) ≤ refinementFactor A F := by
|
| 70 |
+
simpa only [Rat.cast_one] using (Rat.cast_le (K := ℝ)).mpr (refinementFactor_spec A F (by omega)).1
|
| 71 |
+
have hlower := stageWarmupMass_child_lower source target hM U N P F A hsize hP hF hA hseed T hT node hbelow
|
| 72 |
+
have hupper (i : Fin M) : (child i (action i) : ℝ) ≤
|
| 73 |
+
2 * F * stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) := by
|
| 74 |
+
dsimp only [physicalBandChildMassTable]
|
| 75 |
+
have h := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT
|
| 76 |
+
(physicalChild node hbelow i, action i)
|
| 77 |
+
simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using
|
| 78 |
+
(Rat.cast_le (K := ℝ)).mpr (h.2.2.1.trans h.2.2.2)
|
| 79 |
+
have hpositive := (stageComparison_positive_movement source target hM U N P F A hsize hP hF hA hseed
|
| 80 |
+
T hT node q hc hscale).1
|
| 81 |
+
have hband := computed_comparison_band_mem source target N hN hell hM hMeq parent r action
|
| 82 |
+
hspec.1 hnonempty child (refinementFactor A F : ℝ) ha hlower hupper hcostSum hpositive
|
| 83 |
+
hspec.2.1 hspec.2.2.2.1 hvelocity hKsmall hGsmall
|
| 84 |
+
have hnum := computed_band_basic_constants N hell2
|
| 85 |
+
have hspacing := computed_band_spacing_dominates N hN hell
|
| 86 |
+
rw [← hMeq, ← hPeq, computed_theta_dyadic] at hspacing
|
| 87 |
+
rw [computed_theta_dyadic] at hnum
|
| 88 |
+
have hmember := physical_comparison_unskipped source target hM U N P F A hsize hP hF hA hseed
|
| 89 |
+
T node hbelow b thetaExponent (Nat.two_pow_pos _) ⟨_, rfl⟩
|
| 90 |
+
⟨_, hPeq.trans (computed_P_dyadic N)⟩ tau hnum.1 hnum.2.2.1 hnum.2.2.2.1 hnum.2.2.2.2 hspacing
|
| 91 |
+
r hrep action (by simpa only [← computed_theta_dyadic, physicalSource] using hband)
|
| 92 |
+
(by exact_mod_cast hcostSum)
|
| 93 |
+
simpa only [physicalNodeCellBands, computed_theta_dyadic] using hmember
|
| 94 |
+
|
| 95 |
+
end Node
|
| 96 |
+
|
| 97 |
+
end EditApproximation
|
| 98 |
+
|
| 99 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalAccuracy.lean
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFinalAccuracy
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLaw
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! Conditional accuracy of coarse sampling, adaptive median passes and the final fresh query. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open MeasureTheory ProbabilityTheory
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
section Conditional
|
| 17 |
+
|
| 18 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ}
|
| 19 |
+
[NeZero M] [NeZero R] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 20 |
+
(source target : List α) (N P T S H B : ℕ)
|
| 21 |
+
[NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 22 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 23 |
+
|
| 24 |
+
noncomputable def wholeFinalAnswer
|
| 25 |
+
(pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : ℕ :=
|
| 26 |
+
finalProgramAnswer (R := R) source target N P T S H (finalTargetState target.length) pair
|
| 27 |
+
|
| 28 |
+
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] in
|
| 29 |
+
theorem wholeFinalAnswer_equal (heq : source = target)
|
| 30 |
+
(pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) :
|
| 31 |
+
wholeFinalAnswer (R := R) source target N P T S H pair = 0 := by
|
| 32 |
+
apply finalProgramAnswer_equal
|
| 33 |
+
simpa only [finalTargetState, substring, List.take_length, List.drop_zero] using heq
|
| 34 |
+
|
| 35 |
+
theorem physical_conditional_accuracy (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N)
|
| 36 |
+
(hsize : source.length + target.length ≤ N)
|
| 37 |
+
(hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length)
|
| 38 |
+
(hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T)
|
| 39 |
+
(hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N)
|
| 40 |
+
(hB : B = (integerParameters N).B)
|
| 41 |
+
(hdepth : ∀ state, depth state = computedCoarseDepth N
|
| 42 |
+
(coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi)))
|
| 43 |
+
(coarseBernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B =>
|
| 44 |
+
(PMF.uniformOfFintype (Fin B)).toMeasure))
|
| 45 |
+
(groupBernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length,
|
| 46 |
+
FiniteBernsteinInput (Measure.pi fun _ : Fin
|
| 47 |
+
(groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) =>
|
| 48 |
+
(PMF.uniformOfFintype (Fin M)).toMeasure))
|
| 49 |
+
(epsilon : ℝ) (hepsilon : 0 < epsilon) (haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) :
|
| 50 |
+
(2 / 3 : ℝ) ≤ (finalProgramLaw (R := R) source target N P T S H
|
| 51 |
+
(physicalCoarseSeedLaw source target N B depth)).real
|
| 52 |
+
{pair | EditDistortion.edit source target ≤ wholeFinalAnswer (R := R) source target N P T S H pair ∧
|
| 53 |
+
(wholeFinalAnswer (R := R) source target N P T S H pair : ℝ) ≤
|
| 54 |
+
(1 + epsilon) * EditDistortion.edit source target} := by
|
| 55 |
+
classical
|
| 56 |
+
have hsmall : 256 ≤ (2 : ℕ) ^ 1000 := by
|
| 57 |
+
have h := pow_le_pow_right₀ (by decide : 1 ≤ (2 : ℕ)) (by decide : 8 ≤ 1000)
|
| 58 |
+
norm_num only [show (2 : ℕ) ^ 8 = 256 by norm_num] at h
|
| 59 |
+
exact h
|
| 60 |
+
have hcut : 200 ≤ inputSmallLog N := by omega
|
| 61 |
+
have hinitial := physicalCoarseSeedLaw_failure source target N B depth hN hsize hcut
|
| 62 |
+
hB hMeq hJeq hdepth coarseBernstein
|
| 63 |
+
have h := finalProgram_accuracy (R := R) source target N P T S H hN hell hMeq hJeq hPeq
|
| 64 |
+
hTeq hSeq hHeq hsize groupBernstein (physicalCoarseSeedLaw source target N B depth)
|
| 65 |
+
hinitial.le (finalTargetState target.length) epsilon hepsilon haccuracy
|
| 66 |
+
apply (by norm_num : (2 / 3 : ℝ) ≤ 4 / 5).trans
|
| 67 |
+
simpa only [wholeFinalAnswer, stateEditCost, finalTargetState, substring,
|
| 68 |
+
List.take_length, List.drop_zero] using h
|
| 69 |
+
|
| 70 |
+
end Conditional
|
| 71 |
+
|
| 72 |
+
end EditApproximation
|
| 73 |
+
|
| 74 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalConditionalNode.lean
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalParentDraw
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalResampledRegret
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-!
|
| 7 |
+
# Conditional expected regret in a fixed child environment
|
| 8 |
+
|
| 9 |
+
Finite Bernstein bounds control the parent product draws. Agreement of
|
| 10 |
+
deeper selection functions fixes all child histories by locality, and
|
| 11 |
+
list membership connects the sampled actions to the refinement recurrence.
|
| 12 |
+
-/
|
| 13 |
+
|
| 14 |
+
namespace EditApproximation
|
| 15 |
+
|
| 16 |
+
open Finset MeasureTheory ProbabilityTheory
|
| 17 |
+
|
| 18 |
+
abbrev BandParentSpace (R M b F Q K : ℕ) :=
|
| 19 |
+
ParentRandomSpace R (optimizerTriangularMass K) M (groupDyadicScales M b F).length
|
| 20 |
+
(fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))
|
| 21 |
+
|
| 22 |
+
noncomputable def bandParentLaw (R M b F Q K : ℕ) [NeZero M] [NeZero (optimizerTriangularMass K)]
|
| 23 |
+
[MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] : Measure (BandParentSpace R M b F Q K) :=
|
| 24 |
+
parentDrawLaw R (optimizerTriangularMass K) M (groupDyadicScales M b F).length
|
| 25 |
+
(fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale))
|
| 26 |
+
|
| 27 |
+
theorem physical_conditional_node_regret {α : Type*} [DecidableEq α]
|
| 28 |
+
(source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N)
|
| 29 |
+
{M J P F b Q thetaExponent R H G K : ℕ}
|
| 30 |
+
[NeZero M] [NeZero R] [NeZero (optimizerTriangularMass K)]
|
| 31 |
+
[MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 32 |
+
(hM : 0 < M) (hMeq : M = (integerParameters N).M)
|
| 33 |
+
(hPeq : P = (integerParameters N).P) (hFeq : F = inputSmallLog N)
|
| 34 |
+
(eb : ℕ) (hbeq : b = 2 ^ eb) (hQeq : Q = inputSmallLog N ^ 80)
|
| 35 |
+
(hthetaeq : thetaExponent = 40 * smallLogExponent N) (hHeq : H = inputHeight N) (hH : 4 ≤ H)
|
| 36 |
+
(U : PhysicalEntry M J target.length → ℕ) (A : ℚ)
|
| 37 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 38 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 39 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 40 |
+
(T : ℕ) (hT : 0 < T) (delta η κ : ℚ)
|
| 41 |
+
(hdelta : 0 < delta) (hη : 0 < η) (hκ : 0 ≤ κ) (hκhalf : κ ≤ 1 / 2)
|
| 42 |
+
(reference : PhysicalSelections M J source.length target.length P
|
| 43 |
+
(stageRepresentatives source target U N P F A))
|
| 44 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 45 |
+
(hleaf : ¬ (physicalSourceInterval source.length node).hi -
|
| 46 |
+
(physicalSourceInterval source.length node).lo ≤ 1)
|
| 47 |
+
(cell : ℕ × ℕ)
|
| 48 |
+
(hnonempty : physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent
|
| 49 |
+
(rationalParameters F).tau cell ≠ [])
|
| 50 |
+
(specified : UnskippedBand source target (physicalSourceInterval source.length node)
|
| 51 |
+
b P thetaExponent (rationalParameters F).tau F
|
| 52 |
+
(physicalBandChildMassTable source target U N P F A T node hbelow)
|
| 53 |
+
(physicalBandChildInitial source target U N P F A node hbelow))
|
| 54 |
+
(hspecified : specified ∈ physicalNodeCellBands source target U N P F A T node hbelow b thetaExponent
|
| 55 |
+
(rationalParameters F).tau cell)
|
| 56 |
+
(hrep : (b, specified.center) ∈ stageRepresentatives source target U N P F A node)
|
| 57 |
+
(q : TargetInterval target.length)
|
| 58 |
+
(hb : (b : ℝ) ≤ stateEditCost (physicalSource source node) target q)
|
| 59 |
+
(comparison : Fin M → TargetInterval target.length) (hc : comparison ∈ specified.actions)
|
| 60 |
+
(hG : G = H + (bandCoordinates specified.actions.toFinset).card + 2) (hK : K = G ^ 80)
|
| 61 |
+
(htau : 0 < (rationalParameters F).tau)
|
| 62 |
+
(hηrange : (η : ℝ) * (2 * (delta : ℝ) + 8 * ((128 * F : ℚ) : ℝ) *
|
| 63 |
+
(((2 : ℚ) ^ (-(thetaExponent : ℤ))) : ℝ)) ≤ (κ : ℝ))
|
| 64 |
+
(herror : 2 * (rationalParameters F).gamma +
|
| 65 |
+
512 * (128 * F : ℚ) * F * (2 : ℚ) ^ (-(thetaExponent : ℤ)) ≤ κ * delta)
|
| 66 |
+
(realizations : BandParentSpace R M b F Q K → PhysicalSelections M J source.length target.length P
|
| 67 |
+
(stageRepresentatives source target U N P F A))
|
| 68 |
+
(hgroupsFixed : ∀ ω label, node.1.val < label.1.val →
|
| 69 |
+
(realizations ω).groups label = reference.groups label)
|
| 70 |
+
(honlineFixed : ∀ ω label, node.1.val < label.1.val →
|
| 71 |
+
(realizations ω).online label = reference.online label)
|
| 72 |
+
(honlineWire : ∀ ω t, sharedBandRationalAction specified.center
|
| 73 |
+
(physicalBandOnlineDraw source target U N P F A T delta reference node hbelow
|
| 74 |
+
b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t
|
| 75 |
+
(parentOnlineDraw ω t)) ∈
|
| 76 |
+
physicalNodeOnline source target U N P F A T delta (realizations ω) node hbelow t q)
|
| 77 |
+
(hgroupWire : ∀ ω t,
|
| 78 |
+
(physicalNodeSelectedGroup source target U N P F A T delta reference node hbelow
|
| 79 |
+
b thetaExponent Q (rationalParameters F).tau cell hnonempty t (parentGroupDraw ω t)).rationalAction ∈
|
| 80 |
+
physicalNodeGroups source target U N P F A T delta (realizations ω) node hbelow t)
|
| 81 |
+
(bernstein : ∀ scale : Fin (groupDyadicScales M b F).length, FiniteBernsteinInput
|
| 82 |
+
(Measure.pi fun _ : Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) =>
|
| 83 |
+
(PMF.uniformOfFintype (Fin M)).toMeasure)) (S : ℕ) :
|
| 84 |
+
let c : ℝ := stateEditCost (physicalSource source node) target q
|
| 85 |
+
let charge : ℝ := ((128 * F : ℚ) : ℝ) * targetEndpointDistance q specified.center
|
| 86 |
+
let clipped := physicalComparisonClipped source target U N P F A T delta reference node hbelow comparison
|
| 87 |
+
(∫ ω, (∑ t ∈ range S,
|
| 88 |
+
(max c (physicalRefinement source target U N P F A T delta (realizations ω) node (t + 1) q : ℝ) -
|
| 89 |
+
charge - clipped (t + 1))) ∂bandParentLaw R M b F Q K) ≤
|
| 90 |
+
((∑ child, specified.envelope child : ℚ) : ℝ) *
|
| 91 |
+
(Real.log (bandCoordinates specified.actions.toFinset).card / (η : ℝ) + 2 * (κ : ℝ) +
|
| 92 |
+
(S : ℝ) / (H : ℝ) ^ 3) +
|
| 93 |
+
2 * (delta : ℝ) * c + 2 * S * (1 / (H : ℝ) ^ 4) * F * c := by
|
| 94 |
+
let c : ℝ := stateEditCost (physicalSource source node) target q
|
| 95 |
+
let charge : ℝ := ((128 * F : ℚ) : ℝ) * targetEndpointDistance q specified.center
|
| 96 |
+
let history := physicalBandHistory source target U N P F A T delta reference node hbelow
|
| 97 |
+
let clipped := physicalComparisonClipped source target U N P F A T delta reference node hbelow comparison
|
| 98 |
+
let sample := fun t integer => physicalBandOnlineDraw source target U N P F A T delta reference node hbelow
|
| 99 |
+
b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t integer
|
| 100 |
+
let failure := fun t draw => physicalNodeGroupFailure source target U N P F A T delta reference node hbelow
|
| 101 |
+
b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma
|
| 102 |
+
let crossing := firstCrossing specified.actions.toFinset S
|
| 103 |
+
(fun t => bandActionCost charge (fun t coordinate => (history t coordinate : ℝ)) (t + 1)) c
|
| 104 |
+
let prefixPayoff := fun t integer => sampledPrefixRegret charge (κ : ℝ)
|
| 105 |
+
(fun t coordinate => (history t coordinate : ℝ)) clipped (fun j => sample j integer) t
|
| 106 |
+
let regret := fun ω t => max c
|
| 107 |
+
(physicalRefinement source target U N P F A T delta (realizations ω) node (t + 1) q : ℝ) - charge - clipped (t + 1)
|
| 108 |
+
let budget := ((∑ child, specified.envelope child : ℚ) : ℝ) *
|
| 109 |
+
(Real.log (bandCoordinates specified.actions.toFinset).card / (η : ℝ) + 2 * (κ : ℝ) + (S : ℝ) / (H : ℝ) ^ 3)
|
| 110 |
+
have hpoint (ω : BandParentSpace R M b F Q K) : (∑ t ∈ range S, regret ω t) ≤
|
| 111 |
+
(∑ t ∈ range crossing, prefixPayoff t (parentOnlineDraw ω t)) + 2 * (delta : ℝ) * c +
|
| 112 |
+
(2 * (F : ℝ) * c) * ∑ t ∈ range S, (if failure t (parentGroupDraw ω t) then (1 : ℝ) else 0) := by
|
| 113 |
+
have hdet := physicalNode_resampled_regret source target U N P F A T delta
|
| 114 |
+
reference (realizations ω) node hbelow hM hsize hP hF hA hseed hT
|
| 115 |
+
(hgroupsFixed ω) (honlineFixed ω) hleaf b thetaExponent Q (rationalParameters F).tau
|
| 116 |
+
(rationalParameters F).gamma κ htau hdelta hκ hκhalf cell hnonempty specified hspecified hrep q hb comparison hc
|
| 117 |
+
(fun t => sample t (parentOnlineDraw ω t))
|
| 118 |
+
(fun t => physicalBandOnlineDraw_mem source target U N P F A T delta reference node hbelow
|
| 119 |
+
b thetaExponent (rationalParameters F).tau specified.center specified.nonempty η κ G K t (parentOnlineDraw ω t))
|
| 120 |
+
(fun t => parentGroupDraw ω t) (honlineWire ω) (hgroupWire ω) herror S
|
| 121 |
+
have hprefixEq : (∑ t ∈ range crossing, sampledPrefixRegret charge (κ : ℝ)
|
| 122 |
+
(fun t coordinate => (history t coordinate : ℝ)) clipped
|
| 123 |
+
(fun j => sample j (parentOnlineDraw ω j)) t) =
|
| 124 |
+
∑ t ∈ range crossing, prefixPayoff t (parentOnlineDraw ω t) := by
|
| 125 |
+
apply sum_congr rfl
|
| 126 |
+
intro t _
|
| 127 |
+
exact sampledPrefixRegret_current_sample_congr charge (κ : ℝ)
|
| 128 |
+
(fun t coordinate => (history t coordinate : ℝ)) clipped
|
| 129 |
+
(fun j => sample j (parentOnlineDraw ω j))
|
| 130 |
+
(fun j => sample j (parentOnlineDraw ω t)) t rfl
|
| 131 |
+
change (∑ t ∈ range S, regret ω t) ≤
|
| 132 |
+
(∑ t ∈ range crossing, sampledPrefixRegret charge (κ : ℝ)
|
| 133 |
+
(fun t coordinate => (history t coordinate : ℝ)) clipped
|
| 134 |
+
(fun j => sample j (parentOnlineDraw ω j)) t) + 2 * (delta : ℝ) * c +
|
| 135 |
+
(2 * (F : ℝ) * c) * ∑ t ∈ range S,
|
| 136 |
+
(if failure t (parentGroupDraw ω t) then (1 : ℝ) else 0) at hdet
|
| 137 |
+
rw [hprefixEq] at hdet
|
| 138 |
+
exact hdet
|
| 139 |
+
have hprefix : (∑ t ∈ range crossing, uniformMean (prefixPayoff t)) ≤ budget := by
|
| 140 |
+
exact physicalBand_prefix_expected_regret source target U N P F A T delta reference node hbelow
|
| 141 |
+
b thetaExponent (rationalParameters F).tau specified.center hM hsize hP hF hA hseed hT htau hdelta.le
|
| 142 |
+
specified.nonempty crossing S H G K (firstCrossing_le _ _ _ _) η κ hG hK comparison hc hH hη hκ hκhalf hηrange charge
|
| 143 |
+
have hfailure t (_ht : t < S) :
|
| 144 |
+
(groupSharedDrawLaw (M := M) (fun scale : Fin (groupDyadicScales M b F).length =>
|
| 145 |
+
groupSampleCount M Q b (groupDyadicScaleAt M b F scale))).real {draw | failure t draw = true} ≤
|
| 146 |
+
1 / (H : ℝ) ^ 4 := by
|
| 147 |
+
rw [hHeq]
|
| 148 |
+
exact physicalNode_groupFailure_probability source target N hN hell hM hMeq hPeq hFeq eb hbeq hQeq hthetaeq
|
| 149 |
+
U A hsize hP hA hseed T hT delta reference node hbelow t cell bernstein
|
| 150 |
+
have hbound := parentDrawLaw_firstCrossing_bound R (optimizerTriangularMass K) M
|
| 151 |
+
(groupDyadicScales M b F).length
|
| 152 |
+
(fun scale => groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) S crossing regret prefixPayoff failure
|
| 153 |
+
budget (2 * (delta : ℝ) * c) (2 * (F : ℝ) * c) (1 / (H : ℝ) ^ 4)
|
| 154 |
+
(mul_nonneg (mul_nonneg (by norm_num : (0 : ℝ) ≤ 2) (Nat.cast_nonneg F))
|
| 155 |
+
(Nat.cast_nonneg _)) hpoint hprefix hfailure
|
| 156 |
+
dsimp only
|
| 157 |
+
change (∫ ω, (∑ t ∈ range S, regret ω t) ∂bandParentLaw R M b F Q K) ≤
|
| 158 |
+
budget + 2 * (delta : ℝ) * c + 2 * S * (1 / (H : ℝ) ^ 4) * F * c
|
| 159 |
+
have hchargeEq : (2 * (F : ℝ) * c) * (S : ℝ) * (1 / (H : ℝ) ^ 4) =
|
| 160 |
+
2 * S * (1 / (H : ℝ) ^ 4) * F * c := by ring
|
| 161 |
+
exact hbound.trans_eq (by rw [hchargeEq])
|
| 162 |
+
|
| 163 |
+
end EditApproximation
|
| 164 |
+
|
| 165 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDenominator.lean
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalBoundsAllSeeds
|
| 2 |
+
import Mathlib.Data.Rat.Lemmas
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The actual returned values have one additional fixed denominator per tree level. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open Finset
|
| 11 |
+
|
| 12 |
+
theorem rat_den_add_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) :
|
| 13 |
+
(x + y).den ∣ D := (Rat.add_den_dvd_lcm x y).trans (Nat.lcm_dvd hx hy)
|
| 14 |
+
|
| 15 |
+
theorem rat_den_min_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) :
|
| 16 |
+
(min x y).den ∣ D := by
|
| 17 |
+
by_cases h : x ≤ y
|
| 18 |
+
· simpa only [min_eq_left h] using hx
|
| 19 |
+
· simpa only [min_eq_right (le_of_not_ge h)] using hy
|
| 20 |
+
|
| 21 |
+
theorem rat_den_max_dvd {D : ℕ} {x y : ℚ} (hx : x.den ∣ D) (hy : y.den ∣ D) :
|
| 22 |
+
(max x y).den ∣ D := by
|
| 23 |
+
by_cases h : x ≤ y
|
| 24 |
+
· simpa only [max_eq_right h] using hy
|
| 25 |
+
· simpa only [max_eq_left (le_of_not_ge h)] using hx
|
| 26 |
+
|
| 27 |
+
theorem rat_den_sum_dvd {ι : Type*} (s : Finset ι) (f : ι → ℚ) (D : ℕ)
|
| 28 |
+
(hf : ∀ i ∈ s, (f i).den ∣ D) : (∑ i ∈ s, f i).den ∣ D := by
|
| 29 |
+
classical
|
| 30 |
+
induction s using Finset.induction_on with
|
| 31 |
+
| empty => simp only [sum_empty, Rat.den_zero, one_dvd]
|
| 32 |
+
| @insert i s hi ih =>
|
| 33 |
+
rw [sum_insert hi]
|
| 34 |
+
exact rat_den_add_dvd (hf i (mem_insert_self _ _))
|
| 35 |
+
(ih fun j hj => hf j (mem_insert_of_mem hj))
|
| 36 |
+
|
| 37 |
+
theorem rationalMinimum_den_dvd (fallback : ℚ) (values : List ℚ) (D : ℕ)
|
| 38 |
+
(hfallback : fallback.den ∣ D) (hvalues : ∀ v ∈ values, v.den ∣ D) :
|
| 39 |
+
(rationalMinimum fallback values).den ∣ D := by
|
| 40 |
+
induction values with
|
| 41 |
+
| nil => exact hfallback
|
| 42 |
+
| cons v rest ih =>
|
| 43 |
+
exact rat_den_min_dvd (hvalues v (by simp)) (ih fun w hw => hvalues w (by simp [hw]))
|
| 44 |
+
|
| 45 |
+
theorem rationalActualWideActions_connection_den {nx ny M : ℕ} (parent : TargetInterval nx)
|
| 46 |
+
(representatives : List (ℕ × TargetInterval ny)) (P : ℕ)
|
| 47 |
+
(action : PhysicalRationalAction M ny)
|
| 48 |
+
(ha : action ∈ rationalActualWideActions parent representatives P) : action.connection.den = 1 := by
|
| 49 |
+
obtain ⟨br, _, hmem⟩ := List.mem_flatMap.mp ha
|
| 50 |
+
obtain ⟨states, _, rfl⟩ := List.mem_map.mp hmem
|
| 51 |
+
exact Rat.den_natCast _
|
| 52 |
+
|
| 53 |
+
theorem rationalActionValue_den_dvd {Parent Child : Type*} {M D : ℕ}
|
| 54 |
+
(distance : Parent → Parent → ℚ) (L : ℚ) (child : Child → ℚ)
|
| 55 |
+
(q : Parent) (action : RationalBellmanAction Parent Child M)
|
| 56 |
+
(hdistance : (distance q action.center).den = 1) (hL : L.den = 1)
|
| 57 |
+
(ha : action.connection.den = 1) (hchild : ∀ i, (child (action.childState i)).den ∣ D) :
|
| 58 |
+
(rationalActionValue distance L child q action).den ∣ D := by
|
| 59 |
+
unfold rationalActionValue
|
| 60 |
+
apply rat_den_add_dvd
|
| 61 |
+
· apply rat_den_add_dvd
|
| 62 |
+
· have h := Rat.mul_den_dvd L (distance q action.center)
|
| 63 |
+
rw [hL, hdistance, one_mul] at h
|
| 64 |
+
exact h.trans (one_dvd D)
|
| 65 |
+
· rw [ha]
|
| 66 |
+
exact one_dvd D
|
| 67 |
+
· exact rat_den_sum_dvd univ _ D (fun i _ => hchild i)
|
| 68 |
+
|
| 69 |
+
theorem stageInitial_den_one {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 70 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 71 |
+
(N P F : ℕ) (A : ℚ) (state : PhysicalEntry M J target.length) :
|
| 72 |
+
(stageInitial source target U N P F A state).den = 1 := by
|
| 73 |
+
have hmin (fallback : ℚ) (values : List ℚ) (hf : fallback.den = 1)
|
| 74 |
+
(hv : ∀ v ∈ values, v.den = 1) : (rationalMinimum fallback values).den = 1 :=
|
| 75 |
+
Nat.eq_one_of_dvd_one (rationalMinimum_den_dvd fallback values 1 (by rw [hf])
|
| 76 |
+
(fun v h => by rw [hv v h]))
|
| 77 |
+
unfold stageInitial physicalInitialTable
|
| 78 |
+
dsimp only
|
| 79 |
+
split_ifs
|
| 80 |
+
· exact Rat.den_natCast _
|
| 81 |
+
· unfold localInitialConeTable
|
| 82 |
+
split_ifs
|
| 83 |
+
· exact Rat.den_zero
|
| 84 |
+
· apply hmin
|
| 85 |
+
· simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using
|
| 86 |
+
Rat.den_natCast ((32 * F + 1) * N)
|
| 87 |
+
· intro v hv
|
| 88 |
+
obtain ⟨r, _, rfl⟩ := List.mem_map.mp hv
|
| 89 |
+
unfold initialConeValue scaledSeedValue
|
| 90 |
+
apply Nat.eq_one_of_dvd_one
|
| 91 |
+
apply rat_den_add_dvd
|
| 92 |
+
· apply rat_den_max_dvd
|
| 93 |
+
· simp only [Rat.den_natCast, dvd_refl]
|
| 94 |
+
· have heq : rationalStateGap (physicalSource source state.1) target r =
|
| 95 |
+
(((r.hi : ℤ) - r.lo - (physicalSource source state.1).length : ℤ) : ℚ) := by
|
| 96 |
+
simp only [rationalStateGap, Int.cast_sub, Int.cast_natCast]
|
| 97 |
+
rw [heq, ← Int.cast_abs]
|
| 98 |
+
simp only [Rat.den_intCast, dvd_refl]
|
| 99 |
+
· have heq : (32 * F : ℚ) * targetEndpointDistance state.2 r =
|
| 100 |
+
((32 * F * targetEndpointDistance state.2 r : ℕ) : ℚ) := by push_cast; rfl
|
| 101 |
+
rw [heq, Rat.den_natCast]
|
| 102 |
+
|
| 103 |
+
theorem rationalPhysicalBellman_den_dvd {α : Type*} {M J D : ℕ}
|
| 104 |
+
(source target : List α) (P F : ℕ)
|
| 105 |
+
(initial : PhysicalEntry M J target.length → ℚ)
|
| 106 |
+
(representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length))
|
| 107 |
+
(hinitial : ∀ state, (initial state).den ∣ D)
|
| 108 |
+
(value : PhysicalEntry M J target.length → ℚ)
|
| 109 |
+
(hvalue : ∀ state, (value state).den ∣ D) (state : PhysicalEntry M J target.length) :
|
| 110 |
+
(rationalPhysicalBellman source target P (128 * F) initial representatives value state).den ∣ D := by
|
| 111 |
+
unfold rationalPhysicalBellman
|
| 112 |
+
dsimp only
|
| 113 |
+
split_ifs
|
| 114 |
+
· exact hinitial state
|
| 115 |
+
· apply rationalMinimum_den_dvd _ _ D (hinitial state)
|
| 116 |
+
intro v hv
|
| 117 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 118 |
+
exact rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _)
|
| 119 |
+
(by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F))
|
| 120 |
+
(rationalActualWideActions_connection_den _ _ _ action ha) (fun i => hvalue _)
|
| 121 |
+
· exact hinitial state
|
| 122 |
+
|
| 123 |
+
theorem stageWarmup_den_one {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 124 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 125 |
+
(N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) :
|
| 126 |
+
(stageWarmup source target U N P F A t state).den = 1 := by
|
| 127 |
+
induction t generalizing state with
|
| 128 |
+
| zero => exact stageInitial_den_one source target U N P F A state
|
| 129 |
+
| succ t ih =>
|
| 130 |
+
apply Nat.eq_one_of_dvd_one
|
| 131 |
+
exact rationalPhysicalBellman_den_dvd source target P F _ _
|
| 132 |
+
(fun s => by rw [stageInitial_den_one source target U N P F A s]) _ (fun s => by
|
| 133 |
+
change (stageWarmup source target U N P F A t s).den ∣ 1
|
| 134 |
+
rw [ih s]) state
|
| 135 |
+
|
| 136 |
+
theorem rat_inverse_shift_den_dvd (m : ℕ) (hm : 0 < m) :
|
| 137 |
+
(1 / (1 + 1 / (m : ℚ))).den ∣ m + 1 := by
|
| 138 |
+
have hmp : (0 : ℚ) < m := by exact_mod_cast hm
|
| 139 |
+
have heq : (1 / (1 + 1 / (m : ℚ))) = (m : ℚ) / (m + 1 : ℕ) := by
|
| 140 |
+
push_cast
|
| 141 |
+
field_simp
|
| 142 |
+
rw [heq]
|
| 143 |
+
have h : (((m : ℚ) / (m + 1 : ℕ)).den : ℤ) ∣ (m + 1 : ℕ) := by
|
| 144 |
+
simpa only [Rat.divInt_eq_div, Int.cast_natCast] using Rat.den_dvd (m : ℤ) (m + 1 : ℕ)
|
| 145 |
+
exact Int.natCast_dvd_natCast.mp h
|
| 146 |
+
|
| 147 |
+
theorem rationalRefinementUpdate_den_dvd (m D : ℕ) (hm : 0 < m)
|
| 148 |
+
(cone : ℚ) (online : Option ℚ) (hcone : cone.den ∣ D)
|
| 149 |
+
(honline : ∀ v, online = some v → v.den ∣ D) :
|
| 150 |
+
(rationalRefinementUpdate (1 / (m : ℚ)) cone online).den ∣ D * (m + 1) := by
|
| 151 |
+
have hstep : D ∣ D * (m + 1) := dvd_mul_right _ _
|
| 152 |
+
cases online with
|
| 153 |
+
| none => exact hcone.trans hstep
|
| 154 |
+
| some v =>
|
| 155 |
+
apply rat_den_min_dvd (hcone.trans hstep)
|
| 156 |
+
apply rat_den_max_dvd _ ((honline v rfl).trans hstep)
|
| 157 |
+
rw [div_eq_mul_one_div]
|
| 158 |
+
exact (Rat.mul_den_dvd cone _).trans (Nat.mul_dvd_mul hcone (rat_inverse_shift_den_dvd m hm))
|
| 159 |
+
|
| 160 |
+
theorem rationalOnlineMinimum_den_dvd (values : List ℚ) (D : ℕ)
|
| 161 |
+
(hvalues : ∀ v ∈ values, v.den ∣ D) (v : ℚ)
|
| 162 |
+
(heq : rationalOnlineMinimum values = some v) : v.den ∣ D := by
|
| 163 |
+
cases values with
|
| 164 |
+
| nil => cases heq
|
| 165 |
+
| cons first rest =>
|
| 166 |
+
have hv : rationalMinimum first rest = v := Option.some.inj heq
|
| 167 |
+
rw [← hv]
|
| 168 |
+
exact rationalMinimum_den_dvd first rest D (hvalues first (by simp))
|
| 169 |
+
(fun w hw => hvalues w (by simp [hw]))
|
| 170 |
+
|
| 171 |
+
theorem rationalWideStep_den_dvd {nx ny M D : ℕ} (parent : TargetInterval nx)
|
| 172 |
+
(representatives : List (ℕ × TargetInterval ny)) (P F m : ℕ) (hm : 0 < m)
|
| 173 |
+
(initial : TargetInterval ny → ℚ) (hinitial : ∀ q, (initial q).den ∣ D)
|
| 174 |
+
(old current : Fin M × TargetInterval ny → ℚ)
|
| 175 |
+
(hold : ∀ is, (old is).den ∣ D) (hcurrent : ∀ is, (current is).den ∣ D)
|
| 176 |
+
(groups online : List (PhysicalRationalAction M ny))
|
| 177 |
+
(hgroups : ∀ a ∈ groups, a ∈ rationalActualWideActions parent representatives P)
|
| 178 |
+
(honline : ∀ a ∈ online, a ∈ rationalActualWideActions parent representatives P)
|
| 179 |
+
(q : TargetInterval ny) :
|
| 180 |
+
(rationalWideStep parent representatives P initial (128 * F) (1 / (m : ℚ))
|
| 181 |
+
old current groups online q).den ∣ D * (m + 1) := by
|
| 182 |
+
have hvalue (child : Fin M × TargetInterval ny → ℚ) (hchild : ∀ is, (child is).den ∣ D)
|
| 183 |
+
(action : PhysicalRationalAction M ny) (ha : action ∈ rationalActualWideActions parent representatives P) :
|
| 184 |
+
(rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F) child q action).den ∣ D :=
|
| 185 |
+
rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _)
|
| 186 |
+
(by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F))
|
| 187 |
+
(rationalActualWideActions_connection_den _ _ _ action ha) (fun i => hchild _)
|
| 188 |
+
unfold rationalWideStep
|
| 189 |
+
apply rationalRefinementUpdate_den_dvd m D hm
|
| 190 |
+
· unfold rationalWideStepCone rationalBellman
|
| 191 |
+
apply rationalMinimum_den_dvd
|
| 192 |
+
· apply rationalMinimum_den_dvd _ _ D (hinitial q)
|
| 193 |
+
intro v hv
|
| 194 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 195 |
+
exact hvalue old hold action ha
|
| 196 |
+
· intro v hv
|
| 197 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 198 |
+
exact hvalue current hcurrent action (hgroups action ha)
|
| 199 |
+
· intro v hv
|
| 200 |
+
apply rationalOnlineMinimum_den_dvd _ D _ v hv
|
| 201 |
+
intro w hw
|
| 202 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hw
|
| 203 |
+
exact hvalue current hcurrent action (honline action ha)
|
| 204 |
+
|
| 205 |
+
theorem physicalRefinement_den_dvd {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 206 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 207 |
+
(N P F : ℕ) (A : ℚ) (T ell : ℕ) (hell : 0 < ell)
|
| 208 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 209 |
+
(stageRepresentatives source target U N P F A)) (node : PhysicalNode M J) (t : ℕ)
|
| 210 |
+
(q : TargetInterval target.length) :
|
| 211 |
+
(physicalRefinement source target U N P F A T (1 / (ell : ℚ) ^ 10) choices node t q).den ∣
|
| 212 |
+
(ell ^ 10 + 1) ^ (J - node.1.val) := by
|
| 213 |
+
have hdelta : (1 / (ell : ℚ) ^ 10) = 1 / ((ell ^ 10 : ℕ) : ℚ) := by rw [Nat.cast_pow]
|
| 214 |
+
by_cases hbelow : node.1.val < J
|
| 215 |
+
· by_cases hleaf : (physicalSourceInterval source.length node).hi -
|
| 216 |
+
(physicalSourceInterval source.length node).lo ≤ 1
|
| 217 |
+
· rw [physicalRefinement_at_terminal source target U N P F A T _ choices node (Or.inr hleaf),
|
| 218 |
+
stageInitial_den_one source target U N P F A]
|
| 219 |
+
exact one_dvd _
|
| 220 |
+
· cases t with
|
| 221 |
+
| zero =>
|
| 222 |
+
rw [physicalRefinement_zero source target U N P F A T _ choices node q,
|
| 223 |
+
stageWarmup_den_one source target U N P F A]
|
| 224 |
+
exact one_dvd _
|
| 225 |
+
| succ t =>
|
| 226 |
+
rw [physicalRefinement_succ source target U N P F A T _ choices node hbelow hleaf]
|
| 227 |
+
dsimp only
|
| 228 |
+
have hheight : J - node.1.val = (J - (node.1.val + 1)) + 1 := by omega
|
| 229 |
+
rw [hheight]
|
| 230 |
+
conv_rhs => rw [pow_succ]
|
| 231 |
+
rw [hdelta]
|
| 232 |
+
apply rationalWideStep_den_dvd _ _ P F (ell ^ 10) (pow_pos hell 10)
|
| 233 |
+
· intro r
|
| 234 |
+
rw [stageInitial_den_one source target U N P F A]
|
| 235 |
+
exact one_dvd _
|
| 236 |
+
· intro is
|
| 237 |
+
simpa only [Nat.cast_pow, physicalChild] using physicalRefinement_den_dvd source target U N P F A T ell hell choices
|
| 238 |
+
(physicalChild node hbelow is.1) t is.2
|
| 239 |
+
· intro is
|
| 240 |
+
simpa only [Nat.cast_pow, physicalChild] using physicalRefinement_den_dvd source target U N P F A T ell hell choices
|
| 241 |
+
(physicalChild node hbelow is.1) (t + 1) is.2
|
| 242 |
+
· exact choices.groups_mem node _ (t + 1)
|
| 243 |
+
· exact choices.online_mem node _ (t + 1) q
|
| 244 |
+
· rw [physicalRefinement_at_terminal source target U N P F A T _ choices node (Or.inl hbelow),
|
| 245 |
+
stageInitial_den_one source target U N P F A]
|
| 246 |
+
exact one_dvd _
|
| 247 |
+
termination_by J - node.1.val
|
| 248 |
+
decreasing_by
|
| 249 |
+
all_goals
|
| 250 |
+
unfold physicalChild
|
| 251 |
+
dsimp only
|
| 252 |
+
omega
|
| 253 |
+
|
| 254 |
+
end EditApproximation
|
| 255 |
+
|
| 256 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalDependencyRank.lean
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalWarmup
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.DependencyExpansion
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! Concrete table requests and their dependency order. A single table
|
| 9 |
+
index identifies the end of warmup with refinement time zero. Copy labels
|
| 10 |
+
remain part of a request but do not reset its dependency rank. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
namespace PhysicalTableRequest
|
| 19 |
+
|
| 20 |
+
variable {M J ny : ℕ}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
theorem refinement_zero_eq_warmup (pass copy : ℕ) (node : PhysicalNode M J)
|
| 33 |
+
(T : ℕ) (state : TargetInterval ny) :
|
| 34 |
+
refinement pass copy node T 0 state = warmup pass copy node T state := by
|
| 35 |
+
simp only [refinement, warmup, Nat.add_zero]
|
| 36 |
+
|
| 37 |
+
def changeCopy (request : PhysicalTableRequest M J ny) (copy : ℕ) :
|
| 38 |
+
PhysicalTableRequest M J ny := { request with copy := copy }
|
| 39 |
+
|
| 40 |
+
@[simp] theorem rank_changeCopy (T S : ℕ) (request : PhysicalTableRequest M J ny) (copy : ℕ) :
|
| 41 |
+
rank T S (changeCopy request copy) = rank T S request := rfl
|
| 42 |
+
|
| 43 |
+
@[simp] theorem remainingDepth_changeCopy (request : PhysicalTableRequest M J ny) (copy : ℕ) :
|
| 44 |
+
remainingDepth (changeCopy request copy) = remainingDepth request := rfl
|
| 45 |
+
|
| 46 |
+
@[simp] theorem warmup_rank (pass copy : ℕ) (node : PhysicalNode M J)
|
| 47 |
+
(T S j : ℕ) (state : TargetInterval ny) :
|
| 48 |
+
rank T S (warmup pass copy node j state) = pass * (T + S + 1) + j := rfl
|
| 49 |
+
|
| 50 |
+
@[simp] theorem refinement_rank (pass copy : ℕ) (node : PhysicalNode M J)
|
| 51 |
+
(T S t : ℕ) (state : TargetInterval ny) :
|
| 52 |
+
rank T S (refinement pass copy node T t state) = pass * (T + S + 1) + (T + t) := rfl
|
| 53 |
+
|
| 54 |
+
theorem remainingDepth_le_of_no_ancestor (first second : PhysicalTableRequest M J ny)
|
| 55 |
+
(hnode : first.node.1.val ≤ second.node.1.val) :
|
| 56 |
+
second.remainingDepth ≤ first.remainingDepth :=
|
| 57 |
+
Nat.sub_le_sub_left hnode J
|
| 58 |
+
|
| 59 |
+
theorem remainingDepth_lt_of_descendant (first second : PhysicalTableRequest M J ny)
|
| 60 |
+
(hnode : first.node.1.val < second.node.1.val) :
|
| 61 |
+
second.remainingDepth < first.remainingDepth := by
|
| 62 |
+
have hsecond : second.node.1.val ≤ J := Nat.le_of_lt_succ second.node.1.isLt
|
| 63 |
+
unfold remainingDepth
|
| 64 |
+
omega
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
theorem sameIndexChild_progress (T S : ℕ) (request : PhysicalTableRequest M J ny)
|
| 69 |
+
(hbelow : request.node.1.val < J) (i : Fin M) (state : TargetInterval ny) :
|
| 70 |
+
(sameIndexChild request hbelow i state).remainingDepth < request.remainingDepth ∧
|
| 71 |
+
rank T S (sameIndexChild request hbelow i state) ≤ rank T S request := by
|
| 72 |
+
constructor
|
| 73 |
+
· unfold remainingDepth sameIndexChild physicalChild
|
| 74 |
+
dsimp only
|
| 75 |
+
omega
|
| 76 |
+
· exact le_rfl
|
| 77 |
+
|
| 78 |
+
theorem rank_lt_same_pass (T S : ℕ) (first second : PhysicalTableRequest M J ny)
|
| 79 |
+
(hpass : second.pass = first.pass) (hindex : second.index < first.index) :
|
| 80 |
+
rank T S second < rank T S first := by
|
| 81 |
+
unfold rank
|
| 82 |
+
rw [hpass]
|
| 83 |
+
exact Nat.add_lt_add_left hindex _
|
| 84 |
+
|
| 85 |
+
/-- A warmup predecessor lies at the physical child and at the preceding
|
| 86 |
+
unified table index. -/
|
| 87 |
+
theorem warmup_previous_child_progress (pass copy T S j : ℕ)
|
| 88 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J) (i : Fin M)
|
| 89 |
+
(state previousState : TargetInterval ny) (hj : 0 < j) :
|
| 90 |
+
(warmup pass copy (physicalChild node hbelow i) (j - 1) previousState).remainingDepth <
|
| 91 |
+
(warmup pass copy node j state).remainingDepth ∧
|
| 92 |
+
rank T S (warmup pass copy (physicalChild node hbelow i) (j - 1) previousState) <
|
| 93 |
+
rank T S (warmup pass copy node j state) := by
|
| 94 |
+
constructor
|
| 95 |
+
· unfold remainingDepth warmup physicalChild
|
| 96 |
+
dsimp only
|
| 97 |
+
omega
|
| 98 |
+
· dsimp only [rank, warmup]
|
| 99 |
+
omega
|
| 100 |
+
|
| 101 |
+
/-- Old refinement values and all optimistic-history values have
|
| 102 |
+
strictly smaller rank, even if their copy label changes. -/
|
| 103 |
+
theorem refinement_history_progress (pass copy previousCopy T S t s : ℕ)
|
| 104 |
+
(node previousNode : PhysicalNode M J) (state previousState : TargetInterval ny)
|
| 105 |
+
(hnode : node.1.val ≤ previousNode.1.val) (hs : s < t) :
|
| 106 |
+
(refinement pass previousCopy previousNode T s previousState).remainingDepth ≤
|
| 107 |
+
(refinement pass copy node T t state).remainingDepth ∧
|
| 108 |
+
rank T S (refinement pass previousCopy previousNode T s previousState) <
|
| 109 |
+
rank T S (refinement pass copy node T t state) := by
|
| 110 |
+
constructor
|
| 111 |
+
· exact Nat.sub_le_sub_left hnode J
|
| 112 |
+
· simp only [refinement_rank]
|
| 113 |
+
omega
|
| 114 |
+
|
| 115 |
+
theorem refinement_history_child_progress (pass copy T S t s : ℕ)
|
| 116 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J) (i : Fin M)
|
| 117 |
+
(state previousState : TargetInterval ny) (hs : s < t) :
|
| 118 |
+
(refinement pass copy (physicalChild node hbelow i) T s previousState).remainingDepth <
|
| 119 |
+
(refinement pass copy node T t state).remainingDepth ∧
|
| 120 |
+
rank T S (refinement pass copy (physicalChild node hbelow i) T s previousState) <
|
| 121 |
+
rank T S (refinement pass copy node T t state) := by
|
| 122 |
+
constructor
|
| 123 |
+
· unfold remainingDepth refinement physicalChild
|
| 124 |
+
dsimp only
|
| 125 |
+
omega
|
| 126 |
+
· dsimp only [rank, refinement]
|
| 127 |
+
omega
|
| 128 |
+
|
| 129 |
+
/-- A previous pass can request any of its warmup/refinement indices.
|
| 130 |
+
The added one in the pass stride makes its last index strictly earlier
|
| 131 |
+
than the next pass's first index. -/
|
| 132 |
+
theorem rank_lt_previous_pass (T S : ℕ) (first second : PhysicalTableRequest M J ny)
|
| 133 |
+
(hpass : second.pass < first.pass) (hindex : second.index ≤ T + S) :
|
| 134 |
+
rank T S second < rank T S first := by
|
| 135 |
+
have hblock : second.pass * (T + S + 1) + second.index <
|
| 136 |
+
(second.pass + 1) * (T + S + 1) := by
|
| 137 |
+
nlinarith only [hindex]
|
| 138 |
+
have hnext := Nat.mul_le_mul_right (T + S + 1) (Nat.succ_le_of_lt hpass)
|
| 139 |
+
exact hblock.trans_le (hnext.trans (Nat.le_add_right _ _))
|
| 140 |
+
|
| 141 |
+
theorem previous_pass_progress (T S : ℕ) (first second : PhysicalTableRequest M J ny)
|
| 142 |
+
(hpass : second.pass < first.pass) (hindex : second.index ≤ T + S)
|
| 143 |
+
(hnode : first.node.1.val ≤ second.node.1.val) :
|
| 144 |
+
second.remainingDepth ≤ first.remainingDepth ∧ rank T S second < rank T S first :=
|
| 145 |
+
⟨remainingDepth_le_of_no_ancestor first second hnode,
|
| 146 |
+
rank_lt_previous_pass T S first second hpass hindex⟩
|
| 147 |
+
|
| 148 |
+
theorem rank_lt_pass_bound (T S passes : ℕ) (request : PhysicalTableRequest M J ny)
|
| 149 |
+
(hpass : request.pass < passes) (hindex : request.index ≤ T + S) :
|
| 150 |
+
rank T S request < passes * (T + S + 1) := by
|
| 151 |
+
have hblock : request.pass * (T + S + 1) + request.index <
|
| 152 |
+
(request.pass + 1) * (T + S + 1) := by
|
| 153 |
+
nlinarith only [hindex]
|
| 154 |
+
exact hblock.trans_le (Nat.mul_le_mul_right (T + S + 1) (Nat.succ_le_of_lt hpass))
|
| 155 |
+
|
| 156 |
+
theorem warmup_index_bound (pass copy : ℕ) (node : PhysicalNode M J)
|
| 157 |
+
(T S j : ℕ) (state : TargetInterval ny) (hj : j ≤ T) :
|
| 158 |
+
(warmup pass copy node j state).index ≤ T + S := by
|
| 159 |
+
change j ≤ T + S
|
| 160 |
+
omega
|
| 161 |
+
|
| 162 |
+
theorem refinement_index_bound (pass copy : ℕ) (node : PhysicalNode M J)
|
| 163 |
+
(T S t : ℕ) (state : TargetInterval ny) (ht : t ≤ S) :
|
| 164 |
+
(refinement pass copy node T t state).index ≤ T + S := by
|
| 165 |
+
change T + t ≤ T + S
|
| 166 |
+
omega
|
| 167 |
+
|
| 168 |
+
theorem warmup_bounded (passes copies pass copy : ℕ) (node : PhysicalNode M J)
|
| 169 |
+
(T S j : ℕ) (state : TargetInterval ny)
|
| 170 |
+
(hpass : pass < passes) (hcopy : copy < copies) (hj : j ≤ T) :
|
| 171 |
+
Bounded passes copies T S (warmup pass copy node j state) :=
|
| 172 |
+
⟨hpass, hcopy, warmup_index_bound pass copy node T S j state hj⟩
|
| 173 |
+
|
| 174 |
+
theorem refinement_bounded (passes copies pass copy : ℕ) (node : PhysicalNode M J)
|
| 175 |
+
(T S t : ℕ) (state : TargetInterval ny)
|
| 176 |
+
(hpass : pass < passes) (hcopy : copy < copies) (ht : t ≤ S) :
|
| 177 |
+
Bounded passes copies T S (refinement pass copy node T t state) :=
|
| 178 |
+
⟨hpass, hcopy, refinement_index_bound pass copy node T S t state ht⟩
|
| 179 |
+
|
| 180 |
+
theorem bounded_changeCopy (passes copies T S : ℕ) (request : PhysicalTableRequest M J ny)
|
| 181 |
+
(hrequest : Bounded passes copies T S request) (copy : ℕ) (hcopy : copy < copies) :
|
| 182 |
+
Bounded passes copies T S (changeCopy request copy) :=
|
| 183 |
+
⟨hrequest.1, hcopy, hrequest.2.2⟩
|
| 184 |
+
|
| 185 |
+
theorem bounded_sameIndexChild (passes copies T S : ℕ) (request : PhysicalTableRequest M J ny)
|
| 186 |
+
(hrequest : Bounded passes copies T S request)
|
| 187 |
+
(hbelow : request.node.1.val < J) (i : Fin M) (state : TargetInterval ny) :
|
| 188 |
+
Bounded passes copies T S (sameIndexChild request hbelow i state) := hrequest
|
| 189 |
+
|
| 190 |
+
theorem bounded_of_earlier_same_pass (passes copies T S : ℕ)
|
| 191 |
+
(first second : PhysicalTableRequest M J ny) (hfirst : Bounded passes copies T S first)
|
| 192 |
+
(hpass : second.pass = first.pass) (hcopy : second.copy < copies)
|
| 193 |
+
(hindex : second.index ≤ first.index) : Bounded passes copies T S second := by
|
| 194 |
+
exact ⟨hpass.symm ▸ hfirst.1, hcopy, hindex.trans hfirst.2.2⟩
|
| 195 |
+
|
| 196 |
+
theorem bounded_of_previous_pass (passes copies T S : ℕ)
|
| 197 |
+
(first second : PhysicalTableRequest M J ny) (hfirst : Bounded passes copies T S first)
|
| 198 |
+
(hpass : second.pass < first.pass) (hcopy : second.copy < copies)
|
| 199 |
+
(hindex : second.index ≤ T + S) : Bounded passes copies T S second :=
|
| 200 |
+
⟨hpass.trans hfirst.1, hcopy, hindex⟩
|
| 201 |
+
|
| 202 |
+
/-- Bounded requests have an explicit finite coordinate representation;
|
| 203 |
+
the copy coordinate is retained even though the progress rank ignores it. -/
|
| 204 |
+
def boundedTuple (passes copies T S : ℕ)
|
| 205 |
+
(request : {r : PhysicalTableRequest M J ny // Bounded passes copies T S r}) :
|
| 206 |
+
Fin passes × Fin copies × PhysicalNode M J × Fin (T + S + 1) × TargetInterval ny :=
|
| 207 |
+
(⟨request.1.pass, request.2.1⟩, ⟨request.1.copy, request.2.2.1⟩, request.1.node,
|
| 208 |
+
⟨request.1.index, Nat.lt_succ_of_le request.2.2.2⟩, request.1.state)
|
| 209 |
+
|
| 210 |
+
theorem boundedTuple_injective (passes copies T S : ℕ) :
|
| 211 |
+
Function.Injective (@boundedTuple M J ny passes copies T S) := by
|
| 212 |
+
intro first second heq
|
| 213 |
+
apply Subtype.ext
|
| 214 |
+
have hpass := congrArg (fun t => t.1.val) heq
|
| 215 |
+
have hcopy := congrArg (fun t => t.2.1.val) heq
|
| 216 |
+
have hnode := congrArg (fun t => t.2.2.1) heq
|
| 217 |
+
have hindex := congrArg (fun t => t.2.2.2.1.val) heq
|
| 218 |
+
have hstate := congrArg (fun t => t.2.2.2.2) heq
|
| 219 |
+
cases first with
|
| 220 |
+
| mk first hf =>
|
| 221 |
+
cases second with
|
| 222 |
+
| mk second hs =>
|
| 223 |
+
cases first
|
| 224 |
+
cases second
|
| 225 |
+
simp only [boundedTuple] at hpass hcopy hnode hindex hstate
|
| 226 |
+
cases hpass
|
| 227 |
+
cases hcopy
|
| 228 |
+
cases hnode
|
| 229 |
+
cases hindex
|
| 230 |
+
cases hstate
|
| 231 |
+
rfl
|
| 232 |
+
|
| 233 |
+
instance boundedRequestFinite (passes copies T S : ℕ) :
|
| 234 |
+
Finite {r : PhysicalTableRequest M J ny // Bounded passes copies T S r} :=
|
| 235 |
+
Finite.of_injective (boundedTuple passes copies T S) (boundedTuple_injective passes copies T S)
|
| 236 |
+
|
| 237 |
+
end PhysicalTableRequest
|
| 238 |
+
end EditApproximation
|
| 239 |
+
|
| 240 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalExpectedRegret.lean
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegret
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalGroupAccuracy
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! Conditional prefix regret from the exact physical-band sampler. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open Finset MeasureTheory ProbabilityTheory
|
| 11 |
+
|
| 12 |
+
theorem uniformMean_sub {Ω : Type*} [Fintype Ω] (f g : Ω → ℝ) :
|
| 13 |
+
uniformMean (fun ω => f ω - g ω) = uniformMean f - uniformMean g := by
|
| 14 |
+
simp only [uniformMean, sum_sub_distrib, sub_div]
|
| 15 |
+
|
| 16 |
+
theorem sampledPrefixRegret_child_identity {β σ : Type*} [Fintype β]
|
| 17 |
+
(charge κ : ℝ) (table : ℕ → β × σ → ℝ)
|
| 18 |
+
(clipped : ℕ → ℝ) (sample : ℕ → β → σ) (t : ℕ) :
|
| 19 |
+
sampledPrefixRegret charge κ table clipped sample t =
|
| 20 |
+
(∑ child, table (t + 1) (child, sample t child)) +
|
| 21 |
+
κ * ((∑ child, table t (child, sample t child)) -
|
| 22 |
+
∑ child, table (t + 1) (child, sample t child)) - clipped (t + 1) := by
|
| 23 |
+
unfold sampledPrefixRegret bandActionCost
|
| 24 |
+
ring
|
| 25 |
+
|
| 26 |
+
section PhysicalPrefix
|
| 27 |
+
|
| 28 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 29 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 30 |
+
(N P F : ℕ) (A : ℚ) (T : ℕ) (delta : ℚ)
|
| 31 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 32 |
+
(stageRepresentatives source target U N P F A))
|
| 33 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 34 |
+
(b thetaExponent : ℕ) (tau : ℚ) (r : TargetInterval target.length)
|
| 35 |
+
|
| 36 |
+
local notation "band" => physicalBandActions source target U N P F A T node hbelow b thetaExponent tau r
|
| 37 |
+
local notation "mass" => physicalBandEnvelope source target U N P F A T node hbelow b thetaExponent tau r
|
| 38 |
+
local notation "history" => physicalBandHistory source target U N P F A T delta choices node hbelow
|
| 39 |
+
local notation "theta" => (2 : ℚ) ^ (-(thetaExponent : ℤ))
|
| 40 |
+
|
| 41 |
+
variable (hM : 0 < M) (hsize : source.length + target.length ≤ N)
|
| 42 |
+
(hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 43 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 44 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 45 |
+
(hT : 0 < T)
|
| 46 |
+
|
| 47 |
+
include hM hsize hP hF hA hseed hT in
|
| 48 |
+
/-- Every deterministic prefix uses the same actual computed online mixtures.
|
| 49 |
+
Clipping comparison children only decreases the prefix regret. -/
|
| 50 |
+
theorem physicalBand_prefix_expected_regret (htau : 0 < tau) (hdelta : 0 ≤ delta)
|
| 51 |
+
(hband : band ≠ []) (C S H G K : ℕ) (hCS : C ≤ S) (η κ : ℚ)
|
| 52 |
+
(hG : G = H + (bandCoordinates (band).toFinset).card + 2) (hK : K = G ^ 80)
|
| 53 |
+
(comparison : Fin M → TargetInterval target.length) (hc : comparison ∈ band)
|
| 54 |
+
(hH : 4 ≤ H) (hη : 0 < η) (hκ : 0 ≤ κ) (hκhalf : κ ≤ 1 / 2)
|
| 55 |
+
(hηrange : (η : ℝ) *
|
| 56 |
+
(2 * (delta : ℝ) + 8 * ((128 * F : ℚ) : ℝ) * (theta : ℝ)) ≤ (κ : ℝ)) (charge : ℝ) :
|
| 57 |
+
(∑ t ∈ range C, uniformMean (fun integer : Fin (optimizerTriangularMass K) =>
|
| 58 |
+
sampledPrefixRegret charge (κ : ℝ) (fun t coordinate => (history t coordinate : ℝ))
|
| 59 |
+
(physicalComparisonClipped source target U N P F A T delta choices node hbelow comparison)
|
| 60 |
+
(fun j => physicalBandOnlineDraw source target U N P F A T delta choices node hbelow
|
| 61 |
+
b thetaExponent tau r hband η κ G K j integer) t)) ≤
|
| 62 |
+
((∑ child, mass child : ℚ) : ℝ) *
|
| 63 |
+
(Real.log (bandCoordinates (band).toFinset).card / (η : ℝ) + 2 * (κ : ℝ) +
|
| 64 |
+
(S : ℝ) / (H : ℝ) ^ 3) := by
|
| 65 |
+
have hGpos : 0 < G := by omega
|
| 66 |
+
have hKpos : 0 < K := by rw [hK]; exact pow_pos hGpos 80
|
| 67 |
+
let : NeZero (optimizerTriangularMass K) := ⟨Nat.ne_of_gt (optimizerTriangularMass_positive K hKpos)⟩
|
| 68 |
+
have hcost := physicalBandOnlineDraw_cost_regret source target U N P F A T delta choices node hbelow
|
| 69 |
+
b thetaExponent tau r hM hsize hP hF hA hseed hT htau hdelta hband C H G K η κ hG hK
|
| 70 |
+
hc hH hη hκ hκhalf hηrange
|
| 71 |
+
have hcomparison : (∑ t ∈ range C, ∑ child, (history (t + 1) (child, comparison child) : ℝ)) ≤
|
| 72 |
+
∑ t ∈ range C,
|
| 73 |
+
physicalComparisonClipped source target U N P F A T delta choices node hbelow comparison (t + 1) := by
|
| 74 |
+
apply sum_le_sum
|
| 75 |
+
intro t _
|
| 76 |
+
exact sum_le_sum fun i _ => le_max_right _ _
|
| 77 |
+
have hmass : (0 : ℝ) ≤ ((∑ child, mass child : ℚ) : ℝ) :=
|
| 78 |
+
(Rat.cast_nonneg (K := ℝ)).mpr (sum_nonneg fun i _ =>
|
| 79 |
+
(physicalBandEnvelope_pos source target U N P F A T node hbelow b thetaExponent tau r i).le)
|
| 80 |
+
have hprefix : (C : ℝ) / (H : ℝ) ^ 3 ≤ (S : ℝ) / (H : ℝ) ^ 3 :=
|
| 81 |
+
div_le_div_of_nonneg_right (by exact_mod_cast hCS) (pow_nonneg (Nat.cast_nonneg H) 3)
|
| 82 |
+
have hbudget := mul_le_mul_of_nonneg_left hprefix hmass
|
| 83 |
+
simp_rw [sampledPrefixRegret_child_identity, uniformMean_sub, uniformMean_const]
|
| 84 |
+
rw [sum_sub_distrib]
|
| 85 |
+
nlinarith only [hcost, hcomparison, hbudget]
|
| 86 |
+
|
| 87 |
+
end PhysicalPrefix
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
theorem unskippedGroupFailure_true {α : Type*} (source target : List α) {M : ℕ}
|
| 91 |
+
(parent : TargetInterval source.length) (b P thetaExponent : ℕ) (tau F : ℚ)
|
| 92 |
+
(child initial value : Fin M → TargetInterval target.length → ℚ) (Q : ℕ)
|
| 93 |
+
(members : List (UnskippedBand source target parent b P thetaExponent tau F child initial))
|
| 94 |
+
(draw : ∀ scale : Fin (groupDyadicScales M b F).length,
|
| 95 |
+
Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) → Fin M) (gamma : ℚ) :
|
| 96 |
+
unskippedGroupFailure source target parent b P thetaExponent tau F child initial value Q members draw gamma = true ↔
|
| 97 |
+
∃ member ∈ members, gamma * b < |dyadicUnskippedGroupEstimate Q value member draw -
|
| 98 |
+
rationalEndpointActionValue member.center member.rounded value| := by
|
| 99 |
+
simp only [unskippedGroupFailure, List.any_eq_true, decide_eq_true_eq]
|
| 100 |
+
|
| 101 |
+
/-- Per-scale finite Bernstein bounds imply the whole-cell failure probability. -/
|
| 102 |
+
theorem physicalNode_groupFailure_probability {α : Type*} [DecidableEq α]
|
| 103 |
+
(source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N)
|
| 104 |
+
{M J P F b Q thetaExponent : ℕ} [NeZero M]
|
| 105 |
+
[MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 106 |
+
(hM : 0 < M) (hMeq : M = (integerParameters N).M)
|
| 107 |
+
(hPeq : P = (integerParameters N).P) (hFeq : F = inputSmallLog N)
|
| 108 |
+
(eb : ℕ) (hbeq : b = 2 ^ eb) (hQeq : Q = inputSmallLog N ^ 80)
|
| 109 |
+
(hthetaeq : thetaExponent = 40 * smallLogExponent N)
|
| 110 |
+
(U : PhysicalEntry M J target.length → ℕ) (A : ℚ)
|
| 111 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A)
|
| 112 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 113 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 114 |
+
(T : ℕ) (hT : 0 < T) (delta : ℚ)
|
| 115 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 116 |
+
(stageRepresentatives source target U N P F A))
|
| 117 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ) (cell : ℕ × ℕ)
|
| 118 |
+
(bernstein : ∀ scale : Fin (groupDyadicScales M b F).length, FiniteBernsteinInput
|
| 119 |
+
(Measure.pi fun _ : Fin (groupSampleCount M Q b (groupDyadicScaleAt M b F scale)) =>
|
| 120 |
+
(PMF.uniformOfFintype (Fin M)).toMeasure)) :
|
| 121 |
+
(groupSharedDrawLaw (fun scale : Fin (groupDyadicScales M b F).length =>
|
| 122 |
+
groupSampleCount M Q b (groupDyadicScaleAt M b F scale))).real
|
| 123 |
+
{draw | physicalNodeGroupFailure source target U N P F A T delta choices node hbelow
|
| 124 |
+
b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma = true} ≤
|
| 125 |
+
1 / (inputHeight N : ℝ) ^ 4 := by
|
| 126 |
+
subst F
|
| 127 |
+
let F := inputSmallLog N
|
| 128 |
+
let scales := groupDyadicScaleAt M b (F : ℚ)
|
| 129 |
+
let count := fun scale : Fin (groupDyadicScales M b F).length => groupSampleCount M Q b (scales scale)
|
| 130 |
+
have hscales : List.ofFn scales = groupDyadicScales M b F := List.ofFn_get _
|
| 131 |
+
have hprob := physical_cellGroupEstimate_failure source target N hN hell hM hMeq hPeq eb hbeq hQeq hthetaeq
|
| 132 |
+
U A hsize hP hA hseed T hT delta choices node hbelow (t + 1) cell scales count hscales (fun _ => rfl) bernstein
|
| 133 |
+
dsimp only at hprob
|
| 134 |
+
let members := physicalNodeCellBands source target U N P F A T node hbelow
|
| 135 |
+
b thetaExponent (rationalParameters F).tau cell
|
| 136 |
+
let value := fun i s => physicalBandHistory source target U N P F A T delta choices node hbelow (t + 1) (i, s)
|
| 137 |
+
have hevent : {draw | physicalNodeGroupFailure source target U N P F A T delta choices node hbelow
|
| 138 |
+
b thetaExponent Q (rationalParameters F).tau cell t draw (rationalParameters F).gamma = true} =
|
| 139 |
+
{draw | ∃ member ∈ members, ((rationalParameters F).gamma : ℝ) * b <
|
| 140 |
+
|((dyadicUnskippedGroupEstimate Q value member draw -
|
| 141 |
+
rationalEndpointActionValue member.center member.rounded value : ℚ) : ℝ)|} := by
|
| 142 |
+
ext draw
|
| 143 |
+
simp only [Set.mem_ofPred_eq, physicalNodeGroupFailure, unskippedGroupFailure_true]
|
| 144 |
+
change (∃ member ∈ members, (rationalParameters F).gamma * b <
|
| 145 |
+
|dyadicUnskippedGroupEstimate Q value member draw -
|
| 146 |
+
rationalEndpointActionValue member.center member.rounded value|) ↔ _
|
| 147 |
+
constructor
|
| 148 |
+
· rintro ⟨member, hm, he⟩
|
| 149 |
+
refine ⟨member, hm, ?_⟩
|
| 150 |
+
exact_mod_cast he
|
| 151 |
+
· rintro ⟨member, hm, he⟩
|
| 152 |
+
refine ⟨member, hm, ?_⟩
|
| 153 |
+
exact_mod_cast he
|
| 154 |
+
rw [hevent]
|
| 155 |
+
exact hprob
|
| 156 |
+
|
| 157 |
+
end EditApproximation
|
| 158 |
+
|
| 159 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyAccuracy.lean
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemo
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalFinalAccuracy
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The finite family is consumed through actual source reads in the shared
|
| 7 |
+
memo evaluator. Its final value and law agree with the proved local answer. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
open MeasureTheory ProbabilityTheory
|
| 12 |
+
|
| 13 |
+
section Accuracy
|
| 14 |
+
|
| 15 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 16 |
+
(source target : List α) (N P T S H : ℕ)
|
| 17 |
+
|
| 18 |
+
local notation "Seed" => ClampedPhysicalSeed M J target.length N
|
| 19 |
+
local notation "ell" => inputSmallLog N
|
| 20 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 21 |
+
local notation "passes" => computedSeedPassCount N
|
| 22 |
+
local notation "tau" => RationalParameters.tau (rationalParameters ell)
|
| 23 |
+
local notation "eta" => RationalParameters.eta (rationalParameters ell)
|
| 24 |
+
local notation "kappa" => RationalParameters.kappa (rationalParameters ell)
|
| 25 |
+
local notation "delta" => RationalParameters.delta (rationalParameters ell)
|
| 26 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 27 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 28 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 29 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 30 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
theorem physicalFamilyMemoAnswer_event (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 34 |
+
(encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 35 |
+
(hbounded : ∀ key, encode key < 2 ^ bits) (incoming : Measure Seed)
|
| 36 |
+
[IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) (event : Set ℕ) :
|
| 37 |
+
(incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 38 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2))).real
|
| 39 |
+
{input | physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ input ∈ event} =
|
| 40 |
+
(localFinalProgramLaw (R := R) source target N P T S H incoming).real
|
| 41 |
+
{input | localFinalProgramAnswer (R := R) source target N P T S H rootQ input ∈ event} := by
|
| 42 |
+
classical
|
| 43 |
+
have h := congrArg (fun law : Measure ℕ => law.real event)
|
| 44 |
+
(physicalFamilyMemoAnswer_law source target N P T S H hP hH bits encode hinjective hbounded incoming rootQ)
|
| 45 |
+
simpa only [map_measureReal_apply (measurable_of_finite _) (Set.to_countable _).measurableSet,
|
| 46 |
+
Set.preimage] using h
|
| 47 |
+
|
| 48 |
+
variable (B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 49 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 50 |
+
|
| 51 |
+
/-- Accuracy of the shared source/table memo evaluator under finite Bernstein bounds. -/
|
| 52 |
+
theorem physicalFamilyMemoAnswer_conditional_accuracy (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 53 |
+
(encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 54 |
+
(hbounded : ∀ key, encode key < 2 ^ bits)
|
| 55 |
+
(hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N)
|
| 56 |
+
(hsize : source.length + target.length ≤ N)
|
| 57 |
+
(hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length)
|
| 58 |
+
(hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T)
|
| 59 |
+
(hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N)
|
| 60 |
+
(hB : B = (integerParameters N).B)
|
| 61 |
+
(hdepth : ∀ state, depth state = computedCoarseDepth N
|
| 62 |
+
(coarseEntryWidth (physicalSource source state.1) (substring target state.2.lo state.2.hi)))
|
| 63 |
+
(coarseBernstein : FiniteBernsteinInput (Measure.pi fun _ : Fin B =>
|
| 64 |
+
(PMF.uniformOfFintype (Fin B)).toMeasure))
|
| 65 |
+
(groupBernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length,
|
| 66 |
+
FiniteBernsteinInput (Measure.pi fun _ : Fin
|
| 67 |
+
(groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) =>
|
| 68 |
+
(PMF.uniformOfFintype (Fin M)).toMeasure))
|
| 69 |
+
(epsilon : ℝ) (hepsilon : 0 < epsilon) (haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) :
|
| 70 |
+
(2 / 3 : ℝ) ≤ ((physicalCoarseSeedLaw source target N B depth).prod
|
| 71 |
+
(physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 72 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2))).real
|
| 73 |
+
{input | EditDistortion.edit source target ≤ physicalFamilyMemoAnswer source target N P T S H
|
| 74 |
+
hH bits encode (finalTargetState target.length) input ∧
|
| 75 |
+
(physicalFamilyMemoAnswer source target N P T S H hH bits encode
|
| 76 |
+
(finalTargetState target.length) input : ℝ) ≤
|
| 77 |
+
(1 + epsilon) * EditDistortion.edit source target} := by
|
| 78 |
+
have hevent := physicalFamilyMemoAnswer_event source target N P T S H hP hH bits encode hinjective hbounded
|
| 79 |
+
(physicalCoarseSeedLaw source target N B depth) (finalTargetState target.length)
|
| 80 |
+
{answer | EditDistortion.edit source target ≤ answer ∧
|
| 81 |
+
(answer : ℝ) ≤ (1 + epsilon) * EditDistortion.edit source target}
|
| 82 |
+
simp only [Set.mem_ofPred_eq] at hevent
|
| 83 |
+
rw [hevent]
|
| 84 |
+
exact local_physical_conditional_accuracy source target N P T S H B depth hN hell hsize
|
| 85 |
+
hMeq hJeq hPeq hTeq hSeq hHeq hB hdepth coarseBernstein groupBernstein epsilon hepsilon haccuracy
|
| 86 |
+
|
| 87 |
+
end Accuracy
|
| 88 |
+
|
| 89 |
+
end EditApproximation
|
| 90 |
+
|
| 91 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyCoarseWork.lean
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyWork
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomCoarseWork
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseFirstRequestCost
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Geometry.BalancedWidths
|
| 5 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseSeedLaw
|
| 6 |
+
|
| 7 |
+
namespace OAI
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
section Coarse
|
| 12 |
+
|
| 13 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 14 |
+
(source target : List α) (N P H T S passes copies : ℕ)
|
| 15 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 16 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 17 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 18 |
+
|
| 19 |
+
local notation "ell" => inputSmallLog N
|
| 20 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 21 |
+
local notation "group" => physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies draw
|
| 22 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 23 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 24 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 25 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 26 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 27 |
+
|
| 28 |
+
noncomputable def physicalFamilyCoarseQuery
|
| 29 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 30 |
+
FiniteQuery (PhysicalEntry M J target.length) :=
|
| 31 |
+
chargedRandomCoarseQuery source target N P ell exponent H (ell ^ 80) T S (passes + 1)
|
| 32 |
+
copies factor multiplier tau eta kappa delta readGroup readInteger answer root
|
| 33 |
+
|
| 34 |
+
theorem physicalFamilyCoarseQuery_cost_le_width
|
| 35 |
+
(initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P)
|
| 36 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S)
|
| 37 |
+
(hroot : root.depth = J) :
|
| 38 |
+
(physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier
|
| 39 |
+
tau eta kappa delta draw root).cost (fun entry => (initial entry : ℚ))
|
| 40 |
+
(fun entry => (physicalSource source entry.1).length) ≤
|
| 41 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 42 |
+
tau eta kappa delta initial hP draw root).widthWork M source.length := by
|
| 43 |
+
apply (FiniteQuery.cost_mono_weights _ _ _ _ ?_).trans
|
| 44 |
+
(chargedRandomCoarseQuery_width_cost_le source target N P H T S (passes + 1) copies
|
| 45 |
+
factor multiplier tau eta kappa delta readGroup readInteger answer initial group
|
| 46 |
+
(physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 47 |
+
factor multiplier tau eta kappa delta hP draw initial)
|
| 48 |
+
(physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 49 |
+
factor multiplier tau eta kappa delta initial hP draw) root hroot)
|
| 50 |
+
intro entry
|
| 51 |
+
rw [physicalSource_length_eq]
|
| 52 |
+
exact (sourceIntervalAt_width M source.length entry.1.1.val (Nat.pos_of_neZero M) entry.1.2).trans
|
| 53 |
+
(Nat.le_add_left _ 1)
|
| 54 |
+
|
| 55 |
+
variable (B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 56 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 57 |
+
|
| 58 |
+
noncomputable def physicalFamilyCoarseWork
|
| 59 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S)
|
| 60 |
+
(coarse : PhysicalCoarseDraw source target B depth) : ℝ :=
|
| 61 |
+
coarseFirstRequestWork N B depth
|
| 62 |
+
(fun entry => physicalSource source entry.1)
|
| 63 |
+
(fun entry => substring target entry.2.lo entry.2.hi)
|
| 64 |
+
(physicalFamilyCoarseQuery source target N P H T S passes copies factor multiplier
|
| 65 |
+
tau eta kappa delta draw root) coarse
|
| 66 |
+
|
| 67 |
+
theorem physicalFamilyCoarseWork_expected_le
|
| 68 |
+
(hP : 0 < P) (hN : 0 < N) (hell : 200 ≤ ell)
|
| 69 |
+
(hB : B = (integerParameters N).B) (hsize : source.length + target.length ≤ N)
|
| 70 |
+
(hdepth : ∀ entry, depth entry = computedCoarseDepth N
|
| 71 |
+
(coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi)))
|
| 72 |
+
(hinverse : coarseInverseAllowanceFactor B (initialThresholdQ N) (initialLambda N) ≤
|
| 73 |
+
(inputHeight N : ℝ) ^ 8)
|
| 74 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S)
|
| 75 |
+
(hroot : root.depth = J) (budget : ℝ)
|
| 76 |
+
(hwidth : ∀ coarse : PhysicalCoarseDraw source target B depth,
|
| 77 |
+
((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 78 |
+
tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse))
|
| 79 |
+
hP draw root).widthWork M source.length : ℝ) ≤ budget) :
|
| 80 |
+
(∫ coarse, physicalFamilyCoarseWork source target N P H T S passes copies factor multiplier
|
| 81 |
+
tau eta kappa delta draw B depth root coarse
|
| 82 |
+
∂coarseFullSeedMeasure B depth
|
| 83 |
+
(fun entry => physicalSource source entry.1)
|
| 84 |
+
(fun entry => substring target entry.2.lo entry.2.hi)) ≤
|
| 85 |
+
budget * computedCoarseWidthOverhead N := by
|
| 86 |
+
have hentries (entry : PhysicalEntry M J target.length) :
|
| 87 |
+
coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) ≤ N := by
|
| 88 |
+
apply max_le
|
| 89 |
+
· exact (physicalSource_length_le source entry.1).trans (by omega)
|
| 90 |
+
· have hl : (substring target entry.2.lo entry.2.hi).length ≤ target.length := by
|
| 91 |
+
simp only [substring, List.length_drop, List.length_take]
|
| 92 |
+
exact (Nat.sub_le _ _).trans (min_le_right _ _)
|
| 93 |
+
exact hl.trans (by omega)
|
| 94 |
+
apply coarseFirstRequestWork_expected_le N B depth _ _ _ hB hN hell hdepth hentries hinverse budget
|
| 95 |
+
intro coarse
|
| 96 |
+
have hc := physicalFamilyCoarseQuery_cost_le_width source target N P H T S passes copies
|
| 97 |
+
factor multiplier tau eta kappa delta draw
|
| 98 |
+
(clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)) hP root hroot
|
| 99 |
+
exact ((Nat.cast_le (α := ℝ)).mpr hc).trans (hwidth coarse)
|
| 100 |
+
|
| 101 |
+
end Coarse
|
| 102 |
+
|
| 103 |
+
end EditApproximation
|
| 104 |
+
|
| 105 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyEncoding.lean
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarCodeBits
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamily
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
section Encoding
|
| 11 |
+
|
| 12 |
+
variable {α : Type*} {M J R : ℕ} (target : List α) (N P F exponent H Q passes copies : ℕ)
|
| 13 |
+
|
| 14 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 15 |
+
target N P F exponent H Q passes copies
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
theorem physicalFamilyCode_injective (hM : 1 ≤ M) :
|
| 20 |
+
Function.Injective (physicalFamilyCode (M := M) (J := J) (R := R)
|
| 21 |
+
target N P F exponent H Q passes copies) := by
|
| 22 |
+
intro first second h
|
| 23 |
+
obtain ⟨hp, h⟩ := Nat.pair_eq_pair.mp h
|
| 24 |
+
obtain ⟨hc, hs⟩ := Nat.pair_eq_pair.mp h
|
| 25 |
+
exact Prod.ext (Fin.ext hp) (Prod.ext (Fin.ext hc) (physicalScalarCode_injective hM hs))
|
| 26 |
+
|
| 27 |
+
theorem physicalFamilyCode_bound (k : ℕ)
|
| 28 |
+
(hpass : passes + 1 ≤ 2 ^ k) (hcopy : copies + 1 ≤ 2 ^ k)
|
| 29 |
+
(hscalar : ∀ key : PhysicalScalarKey M J N target.length exponent F Q R
|
| 30 |
+
(localOnlineMassBound M P H), physicalScalarCode key < 2 ^ (64 * k + 1))
|
| 31 |
+
(key : Key) : physicalFamilyCode target N P F exponent H Q passes copies key <
|
| 32 |
+
2 ^ (256 * k + 4) := by
|
| 33 |
+
have hk : k ≤ 64 * k + 1 := by omega
|
| 34 |
+
have hp := key.1.isLt.trans_le (hpass.trans (Nat.pow_le_pow_right (by decide) hk))
|
| 35 |
+
have hc := key.2.1.isLt.trans_le (hcopy.trans (Nat.pow_le_pow_right (by decide) hk))
|
| 36 |
+
have hi := natPair_lt_two_pow hc (hscalar key.2.2)
|
| 37 |
+
have ho := natPair_lt_two_pow_scaled hp hi (by decide : 1 ≤ 2)
|
| 38 |
+
change Nat.pair _ (Nat.pair _ _) < _
|
| 39 |
+
convert ho using 1
|
| 40 |
+
congr 1
|
| 41 |
+
omega
|
| 42 |
+
|
| 43 |
+
end Encoding
|
| 44 |
+
|
| 45 |
+
end EditApproximation
|
| 46 |
+
|
| 47 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemo.lean
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyOutput
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemo
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! The finite family is consumed through actual source reads in the shared
|
| 9 |
+
memo evaluator. Its final value and law agree with the proved local answer. -/
|
| 10 |
+
|
| 11 |
+
namespace EditApproximation
|
| 12 |
+
|
| 13 |
+
open MeasureTheory ProbabilityTheory
|
| 14 |
+
|
| 15 |
+
section Memo
|
| 16 |
+
|
| 17 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 18 |
+
(source target : List α) (N P T S H : ℕ)
|
| 19 |
+
|
| 20 |
+
local notation "Seed" => ClampedPhysicalSeed M J target.length N
|
| 21 |
+
local notation "ell" => inputSmallLog N
|
| 22 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 23 |
+
local notation "passes" => computedSeedPassCount N
|
| 24 |
+
local notation "tau" => RationalParameters.tau (rationalParameters ell)
|
| 25 |
+
local notation "eta" => RationalParameters.eta (rationalParameters ell)
|
| 26 |
+
local notation "kappa" => RationalParameters.kappa (rationalParameters ell)
|
| 27 |
+
local notation "delta" => RationalParameters.delta (rationalParameters ell)
|
| 28 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 29 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 30 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 31 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 32 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
theorem physicalFamilyMemoResult_value (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 37 |
+
(encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 38 |
+
(hbounded : ∀ key, encode key < 2 ^ bits) (rootQ : TargetInterval target.length)
|
| 39 |
+
(input : Seed × Family) :
|
| 40 |
+
((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ input).value : ℝ) =
|
| 41 |
+
physicalFamilyFinalValue source target N P T S H hP rootQ input := by
|
| 42 |
+
unfold physicalFamilyMemoResult
|
| 43 |
+
rw [chargedRandomMemoEvaluate_value source target N P ell exponent H (ell ^ 80) T S
|
| 44 |
+
(passes + 1) (H ^ 2) (scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta
|
| 45 |
+
(physicalFamilyGroupRead target N P ell exponent H (ell ^ 80) passes (H ^ 2))
|
| 46 |
+
(physicalFamilyOnlineRead target N P ell exponent H (ell ^ 80) passes (H ^ 2))
|
| 47 |
+
(clampedSeedNat input.1)
|
| 48 |
+
(physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2)
|
| 49 |
+
(physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2)
|
| 50 |
+
(physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 51 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2
|
| 52 |
+
(clampedSeedNat input.1))]
|
| 53 |
+
· rfl
|
| 54 |
+
· exact physicalFamilyGroupRead_value target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2
|
| 55 |
+
· exact physicalFamilyOnlineRead_value source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 56 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2
|
| 57 |
+
(clampedSeedNat input.1)
|
| 58 |
+
· exact hinjective
|
| 59 |
+
· exact hbounded
|
| 60 |
+
|
| 61 |
+
noncomputable def physicalFamilyMemoAnswer (hH : 0 < H) (bits : ℕ)
|
| 62 |
+
(encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (input : Seed × Family) : ℕ :=
|
| 63 |
+
if source = substring target rootQ.lo rootQ.hi then 0 else
|
| 64 |
+
integerAnswer N ((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ input).value : ℝ)
|
| 65 |
+
|
| 66 |
+
theorem physicalFamilyMemoAnswer_eq (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 67 |
+
(encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 68 |
+
(hbounded : ∀ key, encode key < 2 ^ bits) (rootQ : TargetInterval target.length)
|
| 69 |
+
(input : Seed × Family) :
|
| 70 |
+
physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ input =
|
| 71 |
+
physicalFamilyFinalAnswer source target N P T S H hP rootQ input := by
|
| 72 |
+
unfold physicalFamilyMemoAnswer physicalFamilyFinalAnswer
|
| 73 |
+
rw [physicalFamilyMemoResult_value source target N P T S H hP hH bits encode hinjective hbounded]
|
| 74 |
+
|
| 75 |
+
theorem physicalFamilyMemoAnswer_law (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 76 |
+
(encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 77 |
+
(hbounded : ∀ key, encode key < 2 ^ bits) (incoming : Measure Seed)
|
| 78 |
+
[IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) :
|
| 79 |
+
(incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 80 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map
|
| 81 |
+
(physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ) =
|
| 82 |
+
(localFinalProgramLaw (R := R) source target N P T S H incoming).map
|
| 83 |
+
(localFinalProgramAnswer (R := R) source target N P T S H rootQ) := by
|
| 84 |
+
have heq : physicalFamilyMemoAnswer (R := R) source target N P T S H hH bits encode rootQ =
|
| 85 |
+
physicalFamilyFinalAnswer source target N P T S H hP rootQ := by
|
| 86 |
+
funext input
|
| 87 |
+
exact physicalFamilyMemoAnswer_eq source target N P T S H hP hH bits encode hinjective hbounded rootQ input
|
| 88 |
+
rw [heq]
|
| 89 |
+
exact physicalFamilyFinalAnswer_law source target N P T S H hP hH incoming rootQ
|
| 90 |
+
|
| 91 |
+
end Memo
|
| 92 |
+
|
| 93 |
+
end EditApproximation
|
| 94 |
+
|
| 95 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyMemoCoarse.lean
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyCoarseWork
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomCoarseKeys
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open MeasureTheory
|
| 11 |
+
|
| 12 |
+
private theorem selectionIndicator_le {p q : Prop} (h : p → q) :
|
| 13 |
+
selectionIndicator p ≤ selectionIndicator q := by
|
| 14 |
+
classical
|
| 15 |
+
by_cases hp : p
|
| 16 |
+
· have hq := h hp
|
| 17 |
+
simp only [selectionIndicator, hp, hq, ite_true, le_refl]
|
| 18 |
+
· simp only [selectionIndicator, hp, ite_false]
|
| 19 |
+
split <;> norm_num
|
| 20 |
+
|
| 21 |
+
section Coarse
|
| 22 |
+
|
| 23 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 24 |
+
(source target : List α) (N P H T S passes copies : ℕ)
|
| 25 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 26 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 27 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 28 |
+
(B : ℕ) [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)]
|
| 29 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 30 |
+
|
| 31 |
+
local notation "ell" => inputSmallLog N
|
| 32 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 33 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 34 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 35 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 36 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 37 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 38 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 39 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 40 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
omit [NeZero B] [MeasurableSpace (Fin B)] [MeasurableSingletonClass (Fin B)] in
|
| 45 |
+
theorem physicalFamilyMemoCoarseWork_le (hP : 0 < P) (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 46 |
+
(hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits)
|
| 47 |
+
(root : Table) (coarse : PhysicalCoarseDraw source target B depth) :
|
| 48 |
+
physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier
|
| 49 |
+
tau eta kappa delta draw B depth bits encode root coarse ≤
|
| 50 |
+
physicalFamilyCoarseWork source target N P H T S passes copies factor multiplier
|
| 51 |
+
tau eta kappa delta draw B depth root coarse := by
|
| 52 |
+
classical
|
| 53 |
+
let initial := clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse)
|
| 54 |
+
have hkey (entry : PhysicalEntry M J target.length) :=
|
| 55 |
+
chargedRandomMemo_coarse_key source target N P ell exponent H (ell ^ 80) T S
|
| 56 |
+
(passes + 1) copies factor multiplier tau eta kappa delta readGroup readInteger answer initial
|
| 57 |
+
(physicalFamilyRequestValue source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 58 |
+
factor multiplier tau eta kappa delta initial hP draw)
|
| 59 |
+
(physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80) T S passes copies
|
| 60 |
+
factor multiplier tau eta kappa delta initial hP draw)
|
| 61 |
+
bits encode hinjective hbounded root entry
|
| 62 |
+
unfold physicalFamilyMemoCoarseWork physicalFamilyCoarseWork coarseFirstRequestWork
|
| 63 |
+
apply Finset.sum_le_sum
|
| 64 |
+
intro entry _
|
| 65 |
+
apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg _)
|
| 66 |
+
exact selectionIndicator_le (hkey entry)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
theorem physicalFamilyMemoCoarseWork_expected_le (hP : 0 < P) (hN : 0 < N)
|
| 70 |
+
(hell : 200 ≤ ell) (hB : B = (integerParameters N).B)
|
| 71 |
+
(hsize : source.length + target.length ≤ N)
|
| 72 |
+
(hdepth : ∀ entry, depth entry = computedCoarseDepth N
|
| 73 |
+
(coarseEntryWidth (physicalSource source entry.1) (substring target entry.2.lo entry.2.hi)))
|
| 74 |
+
(hinverse : coarseInverseAllowanceFactor B (initialThresholdQ N) (initialLambda N) ≤
|
| 75 |
+
(inputHeight N : ℝ) ^ 8)
|
| 76 |
+
(bits : ℕ) (encode : Sum Key Table → ℕ) (hinjective : Function.Injective encode)
|
| 77 |
+
(hbounded : ∀ key, encode key < 2 ^ bits) (root : Table) (hroot : root.depth = J)
|
| 78 |
+
(budget : ℝ)
|
| 79 |
+
(hwidth : ∀ coarse : PhysicalCoarseDraw source target B depth,
|
| 80 |
+
((physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 81 |
+
tau eta kappa delta (clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse))
|
| 82 |
+
hP draw root).widthWork M source.length : ℝ) ≤ budget) :
|
| 83 |
+
(∫ coarse, physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier
|
| 84 |
+
tau eta kappa delta draw B depth bits encode root coarse
|
| 85 |
+
∂coarseFullSeedMeasure B depth
|
| 86 |
+
(fun entry => physicalSource source entry.1)
|
| 87 |
+
(fun entry => substring target entry.2.lo entry.2.hi)) ≤
|
| 88 |
+
budget * computedCoarseWidthOverhead N := by
|
| 89 |
+
classical
|
| 90 |
+
apply (integral_mono Integrable.of_finite Integrable.of_finite (fun coarse =>
|
| 91 |
+
physicalFamilyMemoCoarseWork_le source target N P H T S passes copies factor multiplier
|
| 92 |
+
tau eta kappa delta draw B depth hP bits encode hinjective hbounded root coarse)).trans
|
| 93 |
+
exact physicalFamilyCoarseWork_expected_le source target N P H T S passes copies factor multiplier
|
| 94 |
+
tau eta kappa delta draw B depth hP hN hell hB hsize hdepth hinverse root hroot budget hwidth
|
| 95 |
+
|
| 96 |
+
end Coarse
|
| 97 |
+
|
| 98 |
+
end EditApproximation
|
| 99 |
+
|
| 100 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyOutput.lean
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySeedTrace
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalCommonOutput
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
namespace EditApproximation
|
| 7 |
+
|
| 8 |
+
open MeasureTheory ProbabilityTheory
|
| 9 |
+
|
| 10 |
+
section Output
|
| 11 |
+
|
| 12 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 13 |
+
(source target : List α) (N P T S H : ℕ) (hP : 0 < P)
|
| 14 |
+
|
| 15 |
+
local notation "SeedState" => ClampedPhysicalSeed M J target.length N
|
| 16 |
+
local notation "ell" => inputSmallLog N
|
| 17 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 18 |
+
local notation "passes" => computedSeedPassCount N
|
| 19 |
+
local notation "tau" => RationalParameters.tau (rationalParameters ell)
|
| 20 |
+
local notation "eta" => RationalParameters.eta (rationalParameters ell)
|
| 21 |
+
local notation "kappa" => RationalParameters.kappa (rationalParameters ell)
|
| 22 |
+
local notation "delta" => RationalParameters.delta (rationalParameters ell)
|
| 23 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 25 |
+
|
| 26 |
+
noncomputable def physicalFamilyFinalValue (rootQ : TargetInterval target.length)
|
| 27 |
+
(input : SeedState × Family) : ℝ :=
|
| 28 |
+
localRequestValue source target N P ell exponent H (ell ^ 80) T S (H ^ 2)
|
| 29 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta
|
| 30 |
+
(physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) input.2)
|
| 31 |
+
(physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 32 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP input.2
|
| 33 |
+
(clampedSeedNat input.1))
|
| 34 |
+
(clampedSeedNat input.1)
|
| 35 |
+
(PhysicalTableRequest.refinement passes 0
|
| 36 |
+
(Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit) T S rootQ)
|
| 37 |
+
|
| 38 |
+
noncomputable def physicalFamilyFinalAnswer (rootQ : TargetInterval target.length)
|
| 39 |
+
(input : SeedState × Family) : ℕ :=
|
| 40 |
+
if source = substring target rootQ.lo rootQ.hi then 0 else
|
| 41 |
+
integerAnswer N (physicalFamilyFinalValue source target N P T S H hP rootQ input)
|
| 42 |
+
|
| 43 |
+
theorem physicalFamily_localPassValue (seed : SeedState) (draw : Family) (pass copy : ℕ)
|
| 44 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) :
|
| 45 |
+
localPassValue source target N P ell exponent H (ell ^ 80) T
|
| 46 |
+
(scheduledSeedFactor N) tau eta kappa delta
|
| 47 |
+
(physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw)
|
| 48 |
+
(physicalFamilyInteger source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 49 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw
|
| 50 |
+
(clampedSeedNat seed))
|
| 51 |
+
(physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 52 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw
|
| 53 |
+
(clampedSeedNat seed) pass) pass copy node t q =
|
| 54 |
+
physicalLocalJointValue source target
|
| 55 |
+
(physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 56 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw
|
| 57 |
+
(clampedSeedNat seed) pass)
|
| 58 |
+
N P ell (scheduledSeedFactor N pass) T exponent H (ell ^ 80) tau eta kappa delta
|
| 59 |
+
(physicalFamilySample source target N P ell exponent H (ell ^ 80) T passes (H ^ 2)
|
| 60 |
+
(scheduledSeedFactor N) tau hP draw
|
| 61 |
+
(physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 62 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw
|
| 63 |
+
(clampedSeedNat seed) pass) pass copy) node t q := rfl
|
| 64 |
+
|
| 65 |
+
theorem physicalFamilyFinalValue_eq (rootQ : TargetInterval target.length) (input : SeedState × Family) :
|
| 66 |
+
physicalFamilyFinalValue source target N P T S H hP rootQ input =
|
| 67 |
+
let outcome := physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) input
|
| 68 |
+
localFinalProgramValue source target N P T S H rootQ
|
| 69 |
+
(localCommonSeed source target N P T S H hP passes outcome.1)
|
| 70 |
+
(localCommonTerminalSample source target N P T H hP
|
| 71 |
+
(localCommonSeed source target N P T S H hP passes outcome.1) outcome.2) := by
|
| 72 |
+
rcases input with ⟨seed, draw⟩
|
| 73 |
+
dsimp only
|
| 74 |
+
rw [physicalFamilyToTrace_fst, physicalFamilyToTrace_snd]
|
| 75 |
+
unfold physicalFamilyFinalValue
|
| 76 |
+
rw [localRequestValue_refinement, physicalFamilySeed_eq, physicalFamily_localPassValue]
|
| 77 |
+
have hseed := physicalFamilySeed_prefix source target N P T S H passes hP draw seed passes le_rfl
|
| 78 |
+
rw [hseed]
|
| 79 |
+
unfold localFinalProgramValue localCommonTerminalSample
|
| 80 |
+
dsimp only [Prod.snd]
|
| 81 |
+
have hs := physicalFamilySample_fin source target N P T H passes hP draw
|
| 82 |
+
(localCommonSeed source target N P T S H hP passes
|
| 83 |
+
(physicalFamilyPrefix target N P H passes draw seed passes le_rfl)) (Fin.last passes) 0
|
| 84 |
+
simp only [Fin.val_last, Fin.val_zero] at hs
|
| 85 |
+
rw [hs]
|
| 86 |
+
|
| 87 |
+
theorem physicalFamilyFinalAnswer_eq (hH : 0 < H) (rootQ : TargetInterval target.length)
|
| 88 |
+
(input : SeedState × Family) :
|
| 89 |
+
physicalFamilyFinalAnswer source target N P T S H hP rootQ input =
|
| 90 |
+
localCommonMemoAnswer (M := M) (J := J) (R := R) source target N P T S H hP hH rootQ
|
| 91 |
+
(physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) input) := by
|
| 92 |
+
rw [localCommonMemoAnswer_eq]
|
| 93 |
+
unfold physicalFamilyFinalAnswer localFinalProgramAnswer freshSeedValue
|
| 94 |
+
rw [physicalFamilyFinalValue_eq]
|
| 95 |
+
|
| 96 |
+
theorem physicalFamilyFinalAnswer_law (hH : 0 < H) (incoming : Measure SeedState)
|
| 97 |
+
[IsProbabilityMeasure incoming] (rootQ : TargetInterval target.length) :
|
| 98 |
+
(incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 99 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map
|
| 100 |
+
(physicalFamilyFinalAnswer source target N P T S H hP rootQ) =
|
| 101 |
+
(localFinalProgramLaw (R := R) source target N P T S H incoming).map
|
| 102 |
+
(localFinalProgramAnswer (R := R) source target N P T S H rootQ) := by
|
| 103 |
+
classical
|
| 104 |
+
let : MeasurableSingletonClass (PhysicalCommonDraw M J N target.length exponent ell
|
| 105 |
+
(ell ^ 80) R (localOnlineMassBound M P H)) := inferInstance
|
| 106 |
+
let := commonSeedTraceFintype SeedState
|
| 107 |
+
(fun _ => LocalCommonDraw (M := M) (J := J) (R := R) target N P H) passes
|
| 108 |
+
let := commonSeedTraceSingleton SeedState
|
| 109 |
+
(fun _ => LocalCommonDraw (M := M) (J := J) (R := R) target N P H) passes
|
| 110 |
+
have heq : physicalFamilyFinalAnswer (R := R) source target N P T S H hP rootQ =
|
| 111 |
+
localCommonMemoAnswer (M := M) (J := J) (R := R) source target N P T S H hP hH rootQ ∘
|
| 112 |
+
physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2) := by
|
| 113 |
+
funext input
|
| 114 |
+
exact physicalFamilyFinalAnswer_eq source target N P T S H hP hH rootQ input
|
| 115 |
+
have htrace : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 116 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2))).map
|
| 117 |
+
(physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2)) =
|
| 118 |
+
localCommonFinalLaw (M := M) (J := J) (R := R) target N P H incoming := by
|
| 119 |
+
exact physicalFamilyToTrace_law (Seed := SeedState) (M := M) (J := J) (R := R)
|
| 120 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2) incoming
|
| 121 |
+
rw [heq, ← Measure.map_map (measurable_of_finite _) (measurable_of_finite _), htrace]
|
| 122 |
+
exact localCommonMemoAnswer_law source target N P T S H hP hH incoming rootQ
|
| 123 |
+
|
| 124 |
+
end Output
|
| 125 |
+
|
| 126 |
+
end EditApproximation
|
| 127 |
+
|
| 128 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyProgram.lean
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarReadCost
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemo
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedChargedRandomSourceCost
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
namespace OAI
|
| 8 |
+
|
| 9 |
+
/-! The actual scalar family supplies the body-value and source-read
|
| 10 |
+
bounds required by the mixed source/table dependency analysis. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
section Program
|
| 15 |
+
|
| 16 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 17 |
+
(source target : List α) (N P F exponent H Q T S passes copies : ℕ)
|
| 18 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 19 |
+
(initial : PhysicalEntry M J target.length → ℕ)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
variable (hP : 0 < P)
|
| 24 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 25 |
+
target N P F exponent H Q passes copies)
|
| 26 |
+
|
| 27 |
+
noncomputable def physicalFamilyRequestValue :=
|
| 28 |
+
chargedRequestValue source target N P F exponent H Q T S (passes + 1) copies
|
| 29 |
+
factor multiplier tau eta kappa delta
|
| 30 |
+
(physicalFamilyGroup target N P F exponent H Q passes copies draw)
|
| 31 |
+
(physicalFamilyInteger source target N P F exponent H Q T S passes copies
|
| 32 |
+
factor multiplier tau eta kappa delta hP draw initial) initial
|
| 33 |
+
|
| 34 |
+
theorem physicalFamilyProgram_value
|
| 35 |
+
(request : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 36 |
+
(physicalFamilyProgram source target N P F exponent H Q T S passes copies factor multiplier
|
| 37 |
+
tau eta kappa delta initial request).value
|
| 38 |
+
(Sum.elim (physicalFamilyAnswer target N P F exponent H Q passes copies draw)
|
| 39 |
+
(fun child => physicalFamilyRequestValue source target N P F exponent H Q T S passes copies
|
| 40 |
+
factor multiplier tau eta kappa delta initial hP draw child.val)) =
|
| 41 |
+
physicalFamilyRequestValue source target N P F exponent H Q T S passes copies
|
| 42 |
+
factor multiplier tau eta kappa delta initial hP draw request := by
|
| 43 |
+
exact chargedRandomGlobalQuery_value source target N P F exponent H Q T S (passes + 1)
|
| 44 |
+
copies factor multiplier tau eta kappa delta _ _ initial _ _ _
|
| 45 |
+
(physicalRandomBoundedQuery_localValue source target N P F exponent H Q T S (passes + 1)
|
| 46 |
+
copies factor multiplier tau eta kappa delta _ _ initial _ _ _
|
| 47 |
+
(physicalFamilyGroupRead_value target N P F exponent H Q passes copies draw)
|
| 48 |
+
(physicalFamilyOnlineRead_value source target N P F exponent H Q T S passes copies
|
| 49 |
+
factor multiplier tau eta kappa delta hP draw initial)) request
|
| 50 |
+
|
| 51 |
+
end Program
|
| 52 |
+
|
| 53 |
+
section ComputedCost
|
| 54 |
+
|
| 55 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 56 |
+
(source target : List α) (N P H T S passes copies : ℕ)
|
| 57 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 58 |
+
(initial : PhysicalEntry M J target.length → ℕ) (hP : 0 < P)
|
| 59 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 60 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H
|
| 61 |
+
(inputSmallLog N ^ 80) passes copies)
|
| 62 |
+
|
| 63 |
+
theorem computed_physicalFamilyProgram_source_cost
|
| 64 |
+
(hN : 0 < N) (hell : 200 ≤ inputSmallLog N) (hM : M = (integerParameters N).M)
|
| 65 |
+
(hA : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ))
|
| 66 |
+
(request : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 67 |
+
(physicalFamilyProgram source target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 68 |
+
H (inputSmallLog N ^ 80) T S passes copies factor multiplier tau eta kappa delta initial request).cost
|
| 69 |
+
(Sum.elim (physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 70 |
+
H (inputSmallLog N ^ 80) passes copies draw)
|
| 71 |
+
(fun child => physicalFamilyRequestValue source target N P (inputSmallLog N)
|
| 72 |
+
(40 * smallLogExponent N) H (inputSmallLog N ^ 80) T S passes copies factor multiplier
|
| 73 |
+
tau eta kappa delta initial hP draw child.val))
|
| 74 |
+
(Sum.elim (fun _ => 1) (fun _ => 0)) ≤ inputHeight N ^ 91 := by
|
| 75 |
+
have hg := physicalFamilyGroupRead_cost_le target N P (inputSmallLog N)
|
| 76 |
+
(40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies
|
| 77 |
+
(physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 78 |
+
H (inputSmallLog N ^ 80) passes copies draw) (fun _ => 1) 1 (fun _ => le_rfl)
|
| 79 |
+
have ho := physicalFamilyOnlineRead_cost_le target N P (inputSmallLog N)
|
| 80 |
+
(40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies
|
| 81 |
+
(physicalFamilyAnswer target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 82 |
+
H (inputSmallLog N ^ 80) passes copies draw) (fun _ => 1) 1 (fun _ => le_rfl)
|
| 83 |
+
simpa only [physicalFamilyProgram, physicalFamilyRequestValue, Nat.mul_one] using
|
| 84 |
+
(computed_chargedRandomGlobalQuery_source_cost source target N P H T S (passes + 1) copies
|
| 85 |
+
factor multiplier tau eta kappa delta
|
| 86 |
+
(physicalFamilyGroup target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 87 |
+
H (inputSmallLog N ^ 80) passes copies draw)
|
| 88 |
+
(physicalFamilyInteger source target N P (inputSmallLog N) (40 * smallLogExponent N)
|
| 89 |
+
H (inputSmallLog N ^ 80) T S passes copies factor multiplier tau eta kappa delta hP draw initial)
|
| 90 |
+
initial _ _ _ (fun _ => 1) 1 hN hell hM hA hg ho request)
|
| 91 |
+
|
| 92 |
+
end ComputedCost
|
| 93 |
+
|
| 94 |
+
end EditApproximation
|
| 95 |
+
|
| 96 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRejectionWork.lean
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyMemo
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySampling
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Probability.RejectionMemoCost
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedFamilyEncoding
|
| 5 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
namespace OAI
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open MeasureTheory ProbabilityTheory
|
| 13 |
+
|
| 14 |
+
section Work
|
| 15 |
+
|
| 16 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 17 |
+
(source target : List α) (N P T S H : ℕ)
|
| 18 |
+
|
| 19 |
+
local notation "SeedState" => ClampedPhysicalSeed M J target.length N
|
| 20 |
+
local notation "ell" => inputSmallLog N
|
| 21 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 22 |
+
local notation "passes" => computedSeedPassCount N
|
| 23 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 25 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
|
| 26 |
+
local notation "FamilyRange" => physicalFamilyRange (M := M) (J := J) (R := R)
|
| 27 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
theorem physicalFamilyMemoBits_integrable (hH : 0 < H) (bits : ℕ)
|
| 32 |
+
(encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (seed : SeedState) :
|
| 33 |
+
Integrable (physicalFamilyMemoBits source target N P T S H hH bits encode rootQ seed)
|
| 34 |
+
(rejectionRuntimeArrayLaw FamilyRange) := rejectionSelectedBits_integrable _ _
|
| 35 |
+
|
| 36 |
+
theorem physicalFamilyMemoBits_expected_le (hH : 0 < H) (bits sourceBits : ℕ)
|
| 37 |
+
(encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length) (seed : SeedState)
|
| 38 |
+
(budget : ℝ)
|
| 39 |
+
(hrequests : ∀ draw, ((physicalFamilyMemoResult source target N P T S H hH bits encode rootQ
|
| 40 |
+
(seed, draw)).requests : ℝ) ≤ budget)
|
| 41 |
+
(hbits : ∀ key, rejectionBitCount (FamilyRange key) ≤ sourceBits) :
|
| 42 |
+
(∫ execution, physicalFamilyMemoBits source target N P T S H hH bits encode rootQ seed execution
|
| 43 |
+
∂rejectionRuntimeArrayLaw FamilyRange) ≤ 2 * (budget * sourceBits) := by
|
| 44 |
+
classical
|
| 45 |
+
let : Fintype Table := Fintype.ofInjective
|
| 46 |
+
(fun key : Table => (⟨ChargedPhysicalRequest.code key,
|
| 47 |
+
ChargedPhysicalRequest.code_bound (Nat.one_le_iff_ne_zero.mpr (NeZero.ne M)) key⟩ :
|
| 48 |
+
Fin (ChargedPhysicalRequest.capacity M J target.length (passes + 1) (H ^ 2) T S)))
|
| 49 |
+
(fun _ _ h => ChargedPhysicalRequest.code_injective
|
| 50 |
+
(Nat.one_le_iff_ne_zero.mpr (NeZero.ne M)) (congrArg Fin.val h))
|
| 51 |
+
apply memo_rejectionBits_expected_le_real FamilyRange _ budget sourceBits _ hbits
|
| 52 |
+
intro draw
|
| 53 |
+
have hf : (physicalFamilyMemoResult source target N P T S H hH bits encode rootQ
|
| 54 |
+
(seed, draw)).freshKeys.length ≤
|
| 55 |
+
(physicalFamilyMemoResult source target N P T S H hH bits encode rootQ (seed, draw)).requests :=
|
| 56 |
+
(rankedMemoEvaluate_resource_bounds _ _ _ _ _ _).1
|
| 57 |
+
exact (Nat.cast_le (α := ℝ)).mpr hf |>.trans (hrequests draw)
|
| 58 |
+
|
| 59 |
+
theorem physicalFamilyMemo_nodes_polynomial (hH : 0 < H)
|
| 60 |
+
(encode : Sum Key Table → ℕ) (rootQ : TargetInterval target.length)
|
| 61 |
+
(input : SeedState × PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 62 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)) :
|
| 63 |
+
(physicalFamilyMemoResult source target N P T S H hH (16384 * inputHeight N + 5)
|
| 64 |
+
encode rootQ input).memory.nodes + 1 ≤ (N + 2) ^ 65542 :=
|
| 65 |
+
computed_mixed_cache_nodes N _ _ encode _
|
| 66 |
+
|
| 67 |
+
end Work
|
| 68 |
+
|
| 69 |
+
end EditApproximation
|
| 70 |
+
|
| 71 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyRuntime.lean
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyAccuracy
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilySampling
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! The source family is the projection of terminating rejection-sampling executions. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open MeasureTheory ProbabilityTheory
|
| 13 |
+
|
| 14 |
+
section Runtime
|
| 15 |
+
|
| 16 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 17 |
+
(source target : List α) (N P T S H : ℕ)
|
| 18 |
+
|
| 19 |
+
local notation "SeedState" => ClampedPhysicalSeed M J target.length N
|
| 20 |
+
local notation "ell" => inputSmallLog N
|
| 21 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 22 |
+
local notation "passes" => computedSeedPassCount N
|
| 23 |
+
local notation "FamilyRange" => physicalFamilyRange (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 25 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 26 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 27 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) (H ^ 2) T S
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
noncomputable def physicalFamilyRuntimeLaw (incoming : Measure SeedState) :
|
| 32 |
+
Measure (PhysicalFamilyRuntimeOutcome (M := M) (J := J) (R := R) target N P H) :=
|
| 33 |
+
incoming.prod (rejectionRuntimeArrayLaw FamilyRange)
|
| 34 |
+
|
| 35 |
+
instance physicalFamilyRuntimeLaw_probability (incoming : Measure SeedState)
|
| 36 |
+
[IsProbabilityMeasure incoming] :
|
| 37 |
+
IsProbabilityMeasure (physicalFamilyRuntimeLaw (R := R) target N P H incoming) := by
|
| 38 |
+
unfold physicalFamilyRuntimeLaw
|
| 39 |
+
infer_instance
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
omit [DecidableEq α] [NeZero R] in
|
| 44 |
+
theorem physicalFamilyRuntimeAccepted_law (incoming : Measure SeedState) [IsProbabilityMeasure incoming] :
|
| 45 |
+
(physicalFamilyRuntimeLaw (R := R) target N P H incoming).map
|
| 46 |
+
(physicalFamilyRuntimeAccepted (R := R) target N P H) =
|
| 47 |
+
incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 48 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)) := by
|
| 49 |
+
change (incoming.prod (rejectionRuntimeArrayLaw FamilyRange)).map
|
| 50 |
+
(Prod.map id Prod.snd) = _
|
| 51 |
+
rw [← Measure.map_prod_map _ _ measurable_id measurable_snd, Measure.map_id,
|
| 52 |
+
physicalFamily_rejection_runtime_law]
|
| 53 |
+
|
| 54 |
+
noncomputable def physicalFamilyRuntimeAnswer (hH : 0 < H) (bits : ℕ)
|
| 55 |
+
(encode : Sum (PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 56 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)) Table → ℕ)
|
| 57 |
+
(rootQ : TargetInterval target.length)
|
| 58 |
+
(execution : PhysicalFamilyRuntimeOutcome (M := M) (J := J) (R := R) target N P H) : ℕ :=
|
| 59 |
+
physicalFamilyMemoAnswer source target N P T S H hH bits encode rootQ
|
| 60 |
+
(physicalFamilyRuntimeAccepted target N P H execution)
|
| 61 |
+
|
| 62 |
+
theorem physicalFamilyRuntimeAnswer_event (hP : 0 < P) (hH : 0 < H) (bits : ℕ)
|
| 63 |
+
(encode : Sum (PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 64 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)) Table → ℕ)
|
| 65 |
+
(hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits)
|
| 66 |
+
(incoming : Measure SeedState) [IsProbabilityMeasure incoming]
|
| 67 |
+
(rootQ : TargetInterval target.length) (event : Set ℕ) :
|
| 68 |
+
(physicalFamilyRuntimeLaw (R := R) target N P H incoming).real
|
| 69 |
+
{execution | physicalFamilyRuntimeAnswer source target N P T S H hH bits encode rootQ execution ∈ event} =
|
| 70 |
+
(localFinalProgramLaw (R := R) source target N P T S H incoming).real
|
| 71 |
+
{input | localFinalProgramAnswer (R := R) source target N P T S H rootQ input ∈ event} := by
|
| 72 |
+
rw [← physicalFamilyMemoAnswer_event source target N P T S H hP hH bits encode hinjective hbounded
|
| 73 |
+
incoming rootQ event, ← physicalFamilyRuntimeAccepted_law target N P H incoming,
|
| 74 |
+
map_measureReal_apply (by unfold physicalFamilyRuntimeAccepted; fun_prop) (by exact (Set.toFinite _).measurableSet)]
|
| 75 |
+
rfl
|
| 76 |
+
|
| 77 |
+
end Runtime
|
| 78 |
+
|
| 79 |
+
end EditApproximation
|
| 80 |
+
|
| 81 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySampling.lean
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamilyLaw
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Probability.RejectionSelectedLaw
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
/-! The finite scalar family is exactly the accepted output of the
|
| 9 |
+
independent literal rejection samplers. Only requested coordinates need
|
| 10 |
+
be generated; their failure counts have a product law. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
open MeasureTheory ProbabilityTheory
|
| 15 |
+
|
| 16 |
+
section Family
|
| 17 |
+
|
| 18 |
+
variable {α : Type*} {M J R : ℕ} [NeZero M]
|
| 19 |
+
(target : List α) (N P F exponent H Q passes copies : ℕ)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
theorem physicalFamilyLaw_eq_rejectionAcceptedLaw :
|
| 26 |
+
physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies =
|
| 27 |
+
rejectionAcceptedLaw (physicalFamilyRange (M := M) (J := J) (R := R)
|
| 28 |
+
target N P F exponent H Q passes copies) := rfl
|
| 29 |
+
|
| 30 |
+
theorem physicalFamily_rejection_runtime_law :
|
| 31 |
+
(rejectionRuntimeArrayLaw (physicalFamilyRange (M := M) (J := J) (R := R)
|
| 32 |
+
target N P F exponent H Q passes copies)).map Prod.snd =
|
| 33 |
+
physicalFamilyLaw (M := M) (J := J) (R := R) target N P F exponent H Q passes copies :=
|
| 34 |
+
rejectionRuntimeArrayLaw_accepted _
|
| 35 |
+
|
| 36 |
+
omit [NeZero M] in
|
| 37 |
+
theorem physicalFamilyRange_bits_le (bits : ℕ)
|
| 38 |
+
(hM : M ≤ 2 ^ bits) (hB : localOnlineMassBound M P H ≤ 2 ^ bits)
|
| 39 |
+
(key : PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 40 |
+
target N P F exponent H Q passes copies) :
|
| 41 |
+
rejectionBitCount (physicalFamilyRange target N P F exponent H Q passes copies key) ≤ bits := by
|
| 42 |
+
apply (Nat.clog_le_iff_le_pow (by decide : 1 < (2 : ℕ))).2
|
| 43 |
+
rcases key with ⟨pass, copy, scalar, index⟩
|
| 44 |
+
cases scalar with
|
| 45 |
+
| inl online =>
|
| 46 |
+
change online.2.val.val ≤ 2 ^ bits
|
| 47 |
+
exact (Nat.le_of_lt_succ online.2.val.isLt).trans hB
|
| 48 |
+
| inr group => exact hM
|
| 49 |
+
|
| 50 |
+
end Family
|
| 51 |
+
|
| 52 |
+
end EditApproximation
|
| 53 |
+
|
| 54 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilySeedTrace.lean
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyTrace
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalCommonTrace
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
namespace EditApproximation
|
| 7 |
+
|
| 8 |
+
section SourceFamily
|
| 9 |
+
|
| 10 |
+
variable {α : Type} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 11 |
+
(source target : List α) (N P T S H passes : ℕ) (hP : 0 < P)
|
| 12 |
+
|
| 13 |
+
local notation "SeedState" => ClampedPhysicalSeed M J target.length N
|
| 14 |
+
local notation "ell" => inputSmallLog N
|
| 15 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 16 |
+
local notation "tau" => RationalParameters.tau (rationalParameters ell)
|
| 17 |
+
local notation "eta" => RationalParameters.eta (rationalParameters ell)
|
| 18 |
+
local notation "kappa" => RationalParameters.kappa (rationalParameters ell)
|
| 19 |
+
local notation "delta" => RationalParameters.delta (rationalParameters ell)
|
| 20 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 21 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 22 |
+
|
| 23 |
+
variable (draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 24 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H ((inputSmallLog N) ^ 80) passes (H ^ 2))
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
noncomputable def physicalFamilyPrefix (seed : SeedState) (n : ℕ) (hn : n ≤ passes) :
|
| 28 |
+
LocalCommonTrace (M := M) (J := J) (R := R) target N P H n :=
|
| 29 |
+
let rows : Fin n → LocalCommonDraw (M := M) (J := J) (R := R) target N P H :=
|
| 30 |
+
fun p copy => physicalFamilyPack (M := M) (J := J) (R := R)
|
| 31 |
+
target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw
|
| 32 |
+
⟨p.val, Nat.lt_succ_of_le (p.isLt.le.trans hn)⟩ copy.castSucc
|
| 33 |
+
commonArrayToTrace (Seed := SeedState)
|
| 34 |
+
(Ω := LocalCommonDraw (M := M) (J := J) (R := R) target N P H) n (seed, rows)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
omit [DecidableEq α] [NeZero M] [NeZero R] in
|
| 38 |
+
theorem physicalFamilyDraw_fin (pass : Fin (passes + 1)) (copy : Fin (H ^ 2 + 1)) :
|
| 39 |
+
physicalFamilyDraw (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass.val copy.val =
|
| 40 |
+
physicalFamilyCurry (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass copy := by
|
| 41 |
+
funext key
|
| 42 |
+
unfold physicalFamilyDraw physicalFamilyCurry
|
| 43 |
+
have hp : Fin.ofNat (passes + 1) pass.val = pass := Fin.ext (Nat.mod_eq_of_lt pass.isLt)
|
| 44 |
+
have hc : Fin.ofNat (H ^ 2 + 1) copy.val = copy := Fin.ext (Nat.mod_eq_of_lt copy.isLt)
|
| 45 |
+
rw [hp, hc]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
omit [DecidableEq α] [NeZero M] [NeZero R] in
|
| 49 |
+
theorem physicalFamilyPrefix_succ (seed : SeedState) (n : ℕ) (hn : n + 1 ≤ passes) :
|
| 50 |
+
physicalFamilyPrefix target N P H passes draw seed (n + 1) hn =
|
| 51 |
+
(physicalFamilyPrefix target N P H passes draw seed n (by omega),
|
| 52 |
+
fun copy : Fin (H ^ 2) => physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80)
|
| 53 |
+
passes (H ^ 2) draw ⟨n, by omega⟩ copy.castSucc) := rfl
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
omit [DecidableEq α] [NeZero M] [NeZero R] in
|
| 57 |
+
theorem physicalFamilyToTrace_fst (seed : SeedState) :
|
| 58 |
+
(physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 59 |
+
(seed, draw)).1 = physicalFamilyPrefix target N P H passes draw seed passes le_rfl := by
|
| 60 |
+
unfold physicalFamilyToTrace commonArrayFinal
|
| 61 |
+
dsimp only
|
| 62 |
+
rw [mapCommonTrace_array]
|
| 63 |
+
rfl
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
omit [DecidableEq α] [NeZero M] [NeZero R] in
|
| 67 |
+
theorem physicalFamilyToTrace_snd (seed : SeedState) :
|
| 68 |
+
(physicalFamilyToTrace target N P ell exponent H (ell ^ 80) passes (H ^ 2)
|
| 69 |
+
(seed, draw)).2 =
|
| 70 |
+
physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw
|
| 71 |
+
(Fin.last passes) 0 := rfl
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
omit [NeZero M] [NeZero R] in
|
| 75 |
+
theorem physicalFamilySample_fin
|
| 76 |
+
(seed : SeedState) (pass : Fin (passes + 1)) (copy : Fin (H ^ 2 + 1)) :
|
| 77 |
+
physicalFamilySample source target N P ell exponent H (ell ^ 80) T passes (H ^ 2)
|
| 78 |
+
(scheduledSeedFactor N) tau hP draw (clampedSeedNat seed) pass.val copy.val =
|
| 79 |
+
physicalCommonSample source target (clampedSeedNat seed) N P ell
|
| 80 |
+
(scheduledSeedFactor N pass.val) T exponent H (ell ^ 80) R
|
| 81 |
+
(localOnlineMassBound M P H) tau
|
| 82 |
+
(physicalLocalOnlineMass_le source target (clampedSeedNat seed) N P ell
|
| 83 |
+
(scheduledSeedFactor N pass.val) T exponent H tau hP)
|
| 84 |
+
(physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H (ell ^ 80) passes (H ^ 2) draw pass copy) := by
|
| 85 |
+
unfold physicalFamilySample physicalFamilyPack
|
| 86 |
+
rw [physicalFamilyDraw_fin]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
theorem localScheduledSeedNext_nat_value (pass : ℕ) (previous : SeedState)
|
| 90 |
+
(samples : LocalScheduledSeedDraw (R := R) source target N P T H pass previous) :
|
| 91 |
+
clampedSeedNat (localScheduledSeedNext source target N P T S H pass previous samples) =
|
| 92 |
+
fun state => min N (upperMedian (List.ofFn fun copy : Fin (H ^ 2) =>
|
| 93 |
+
⌈(scheduledSeedMultiplier N pass : ℚ) * physicalLocalJointValue source target
|
| 94 |
+
(clampedSeedNat previous) N P ell (scheduledSeedFactor N pass) T exponent H (ell ^ 80)
|
| 95 |
+
tau eta kappa delta (samples copy) state.1 S state.2⌉₊)) := rfl
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
theorem physicalFamilySeed_prefix [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 99 |
+
(seed : SeedState) : ∀ (n : ℕ) (hn : n ≤ passes),
|
| 100 |
+
physicalFamilySeed source target N P ell exponent H (ell ^ 80) T S passes (H ^ 2)
|
| 101 |
+
(scheduledSeedFactor N) (scheduledSeedMultiplier N) tau eta kappa delta hP draw
|
| 102 |
+
(clampedSeedNat seed) n =
|
| 103 |
+
clampedSeedNat (localCommonSeed source target N P T S H hP n
|
| 104 |
+
(physicalFamilyPrefix target N P H passes draw seed n hn)) := by
|
| 105 |
+
intro n
|
| 106 |
+
induction n with
|
| 107 |
+
| zero => intro hn; rfl
|
| 108 |
+
| succ n ih =>
|
| 109 |
+
intro hn
|
| 110 |
+
let previous := localCommonSeed source target N P T S H hP n
|
| 111 |
+
(physicalFamilyPrefix target N P H passes draw seed n (by omega))
|
| 112 |
+
let row := fun copy : Fin (H ^ 2) => physicalFamilyPack (M := M) (J := J) (R := R) target N P ell exponent H
|
| 113 |
+
(ell ^ 80) passes (H ^ 2) draw ⟨n, by omega⟩ copy.castSucc
|
| 114 |
+
have hnext : localCommonSeed source target N P T S H hP (n + 1)
|
| 115 |
+
(physicalFamilyPrefix target N P H passes draw seed (n + 1) hn) =
|
| 116 |
+
localScheduledSeedNext source target N P T S H n previous
|
| 117 |
+
(localCommonSample source target N P T H hP n previous row) := rfl
|
| 118 |
+
have hsamples :
|
| 119 |
+
(fun copy : Fin (H ^ 2) => physicalFamilySample source target N P ell exponent H
|
| 120 |
+
(ell ^ 80) T passes (H ^ 2) (scheduledSeedFactor N) tau hP draw
|
| 121 |
+
(clampedSeedNat previous) n copy.val) =
|
| 122 |
+
localCommonSample source target N P T H hP n previous row := by
|
| 123 |
+
funext copy
|
| 124 |
+
exact physicalFamilySample_fin source target N P T H passes hP draw previous
|
| 125 |
+
⟨n, by omega⟩ copy.castSucc
|
| 126 |
+
rw [hnext, localScheduledSeedNext_nat_value, physicalFamilySeed, ih (by omega)]
|
| 127 |
+
rw [← hsamples]
|
| 128 |
+
|
| 129 |
+
end SourceFamily
|
| 130 |
+
|
| 131 |
+
end EditApproximation
|
| 132 |
+
|
| 133 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyTrace.lean
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalScalarFamilyLaw
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Probability.FiniteArrayMarginal
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The literal finite scalar family supplies the independent common
|
| 7 |
+
source trace and its final draw, after removing unused extra copies. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
open MeasureTheory ProbabilityTheory
|
| 12 |
+
|
| 13 |
+
section SourceFamily
|
| 14 |
+
|
| 15 |
+
variable {Seed α : Type} {M J R : ℕ} [NeZero M]
|
| 16 |
+
(target : List α) (N P F exponent H Q passes copies : ℕ)
|
| 17 |
+
|
| 18 |
+
local notation "Draw" => PhysicalCommonDraw M J N target.length exponent F Q R (localOnlineMassBound M P H)
|
| 19 |
+
local notation "Family" => PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 20 |
+
target N P F exponent H Q passes copies
|
| 21 |
+
local notation "μ" => physicalCommonLaw M J N target.length exponent F Q R (localOnlineMassBound M P H)
|
| 22 |
+
|
| 23 |
+
def physicalFamilyToTrace (input : Seed × Family) :
|
| 24 |
+
CommonSeedTrace Seed (fun _ => Fin copies → Draw) passes × Draw :=
|
| 25 |
+
let packed := physicalFamilyPack target N P F exponent H Q passes copies input.2
|
| 26 |
+
let rows := commonArrayFinal passes (input.1, packed)
|
| 27 |
+
(mapCommonTrace (fun row (copy : Fin copies) => row copy.castSucc) passes rows.1,
|
| 28 |
+
rows.2 0)
|
| 29 |
+
|
| 30 |
+
variable [Fintype Seed] [MeasurableSpace Seed] [MeasurableSingletonClass Seed]
|
| 31 |
+
(incoming : Measure Seed)
|
| 32 |
+
|
| 33 |
+
theorem physicalFamilyToTrace_law :
|
| 34 |
+
(incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 35 |
+
target N P F exponent H Q passes copies)).map
|
| 36 |
+
(physicalFamilyToTrace (Seed := Seed) target N P F exponent H Q passes copies) =
|
| 37 |
+
(commonTraceLaw (fun _ => Measure.pi fun _ : Fin copies => μ) incoming passes).prod μ := by
|
| 38 |
+
classical
|
| 39 |
+
let : MeasurableSingletonClass Draw := inferInstance
|
| 40 |
+
let : MeasurableSingletonClass (Fin (copies + 1) → Draw) := inferInstance
|
| 41 |
+
let : MeasurableSingletonClass (Fin (passes + 1) → Fin (copies + 1) → Draw) := inferInstance
|
| 42 |
+
let := commonSeedTraceFintype Seed (fun _ => Fin (copies + 1) → Draw) passes
|
| 43 |
+
let := commonSeedTraceSingleton Seed (fun _ => Fin (copies + 1) → Draw) passes
|
| 44 |
+
let rowLaw : Measure (Fin (copies + 1) → Draw) := Measure.pi fun _ => μ
|
| 45 |
+
let trim : (Fin (copies + 1) → Draw) → (Fin copies → Draw) := fun row copy => row copy.castSucc
|
| 46 |
+
let finish : (Fin (copies + 1) → Draw) → Draw := fun row => row 0
|
| 47 |
+
let pack : Seed × Family → Seed × (Fin (passes + 1) → Fin (copies + 1) → Draw) :=
|
| 48 |
+
Prod.map (id : Seed → Seed)
|
| 49 |
+
(physicalFamilyPack target N P F exponent H Q passes copies)
|
| 50 |
+
let finalMap := Prod.map (mapCommonTrace (Seed := Seed) trim passes) finish
|
| 51 |
+
have hpack : (incoming.prod (physicalFamilyLaw (M := M) (J := J) (R := R)
|
| 52 |
+
target N P F exponent H Q passes copies)).map pack =
|
| 53 |
+
incoming.prod (Measure.pi fun _ : Fin (passes + 1) => rowLaw) := by
|
| 54 |
+
dsimp only [pack, rowLaw]
|
| 55 |
+
rw [← Measure.map_prod_map _ _ measurable_id (measurable_of_finite _), Measure.map_id,
|
| 56 |
+
physicalFamilyPack_law]
|
| 57 |
+
have hrow : rowLaw.map trim = Measure.pi fun _ : Fin copies => μ :=
|
| 58 |
+
finite_init_law μ copies
|
| 59 |
+
have hlast : rowLaw.map finish = μ := by
|
| 60 |
+
simpa only [measure_univ, Finset.prod_const_one, one_smul] using
|
| 61 |
+
(Measure.pi_map_eval (fun _ : Fin (copies + 1) => μ) 0)
|
| 62 |
+
have hmap : ((commonTraceLaw (fun _ => rowLaw) incoming passes).prod rowLaw).map finalMap =
|
| 63 |
+
(commonTraceLaw (fun _ => Measure.pi fun _ : Fin copies => μ) incoming passes).prod μ := by
|
| 64 |
+
dsimp only [finalMap]
|
| 65 |
+
rw [← Measure.map_prod_map _ _ (measurable_of_finite _) (measurable_of_finite _),
|
| 66 |
+
mapCommonTrace_law incoming rowLaw trim passes, hrow, hlast]
|
| 67 |
+
have heq : physicalFamilyToTrace (Seed := Seed) target N P F exponent H Q passes copies =
|
| 68 |
+
finalMap ∘ commonArrayFinal passes ∘ pack := rfl
|
| 69 |
+
rw [heq, ← Measure.map_map (measurable_of_finite _) (measurable_of_finite _),
|
| 70 |
+
← Measure.map_map (measurable_of_finite _) (measurable_of_finite _), hpack,
|
| 71 |
+
commonArrayFinal_law incoming rowLaw passes]
|
| 72 |
+
exact hmap
|
| 73 |
+
|
| 74 |
+
end SourceFamily
|
| 75 |
+
|
| 76 |
+
end EditApproximation
|
| 77 |
+
|
| 78 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFamilyWork.lean
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalFamilyProgram
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ChargedRandomMemoWork
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
namespace EditApproximation
|
| 7 |
+
|
| 8 |
+
section Work
|
| 9 |
+
|
| 10 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 11 |
+
(source target : List α) (N P H T S passes copies : ℕ)
|
| 12 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 13 |
+
(initial : PhysicalEntry M J target.length → ℕ) (hPpos : 0 < P)
|
| 14 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 15 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 16 |
+
|
| 17 |
+
local notation "ell" => inputSmallLog N
|
| 18 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 19 |
+
local notation "group" => physicalFamilyGroup target N P ell exponent H (ell ^ 80) passes copies draw
|
| 20 |
+
local notation "integer" => physicalFamilyInteger source target N P ell exponent H (ell ^ 80)
|
| 21 |
+
T S passes copies factor multiplier tau eta kappa delta hPpos draw initial
|
| 22 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 23 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 24 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 25 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 26 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 27 |
+
local notation "bodyValue" => physicalFamilyProgram_value source target N P ell exponent H (ell ^ 80)
|
| 28 |
+
T S passes copies factor multiplier tau eta kappa delta initial hPpos draw
|
| 29 |
+
|
| 30 |
+
noncomputable def physicalFamilyDependencyTree
|
| 31 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) : DependencyExpansion :=
|
| 32 |
+
chargedRandomDependencyTree source target N P H T S (passes + 1) copies factor multiplier
|
| 33 |
+
tau eta kappa delta group integer initial readGroup readInteger answer bodyValue root
|
| 34 |
+
|
| 35 |
+
theorem physicalFamilyDependencyTree_depth
|
| 36 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 37 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 38 |
+
tau eta kappa delta initial hPpos draw root).depth = root.depth := by
|
| 39 |
+
exact queryDependencyExpansion_depth _ _ _
|
| 40 |
+
(chargedRandomRequestList_progress source target N P H T S (passes + 1) copies factor multiplier
|
| 41 |
+
tau eta kappa delta group integer initial readGroup readInteger answer bodyValue) root
|
| 42 |
+
|
| 43 |
+
theorem physicalFamilyDependencyTree_rank
|
| 44 |
+
(hpasses : passes = computedSeedPassCount N) (hT : T = (integerParameters N).T)
|
| 45 |
+
(hS : S = (integerParameters N).S)
|
| 46 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 47 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 48 |
+
tau eta kappa delta initial hPpos draw root).rank ≤ computedDependencyIndexCount N := by
|
| 49 |
+
have heq : (physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 50 |
+
tau eta kappa delta initial hPpos draw root).rank = root.index :=
|
| 51 |
+
queryDependencyExpansion_index _ _ _
|
| 52 |
+
(chargedRandomRequestList_progress source target N P H T S (passes + 1) copies factor multiplier
|
| 53 |
+
tau eta kappa delta group integer initial readGroup readInteger answer bodyValue) root
|
| 54 |
+
rw [heq]
|
| 55 |
+
apply (chargedRequest_index_le root).trans_eq
|
| 56 |
+
simp only [computedDependencyIndexCount, hpasses, hT, hS]
|
| 57 |
+
|
| 58 |
+
theorem physicalFamilyDependencyTree_valid
|
| 59 |
+
(hN : 0 < N) (hell : 200 ≤ ell) (hM : M = (integerParameters N).M)
|
| 60 |
+
(hP : P = (integerParameters N).P) (hT : T = (integerParameters N).T)
|
| 61 |
+
(hS : S = (integerParameters N).S) (hcopies : copies ≤ inputHeight N ^ 2)
|
| 62 |
+
(hAmin : ∀ pass, 1 ≤ factor pass)
|
| 63 |
+
(hAmax : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ))
|
| 64 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 65 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 66 |
+
tau eta kappa delta initial hPpos draw root).Valid
|
| 67 |
+
(M * ell ^ 257) (inputHeight N ^ (512 * (coarseExponent ell + 1))) :=
|
| 68 |
+
chargedRandomDependencyTree_valid source target N P H T S (passes + 1) copies factor multiplier
|
| 69 |
+
tau eta kappa delta group integer initial readGroup readInteger answer bodyValue
|
| 70 |
+
hN hell hM hP hT hS hcopies hAmin hAmax root
|
| 71 |
+
|
| 72 |
+
theorem physicalFamilyMemo_requests_le_width
|
| 73 |
+
(hN : 0 < N) (hell : 200 ≤ ell) (hM : M = (integerParameters N).M)
|
| 74 |
+
(hAmax : ∀ pass, factor pass ≤ ((integerParameters N).initialFactor : ℚ))
|
| 75 |
+
(bits : ℕ) (encode : Sum
|
| 76 |
+
(PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 77 |
+
target N P ell exponent H (ell ^ 80) passes copies)
|
| 78 |
+
(ChargedPhysicalRequest M J target.length (passes + 1) copies T S) → ℕ)
|
| 79 |
+
(hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits)
|
| 80 |
+
(root : ChargedPhysicalRequest M J target.length (passes + 1) copies T S) :
|
| 81 |
+
(chargedRandomMemoEvaluate source target N P ell exponent H (ell ^ 80) T S (passes + 1)
|
| 82 |
+
copies factor multiplier tau eta kappa delta readGroup readInteger initial answer bits encode root).requests ≤
|
| 83 |
+
(inputHeight N ^ 91 + 1) *
|
| 84 |
+
(physicalFamilyDependencyTree source target N P H T S passes copies factor multiplier
|
| 85 |
+
tau eta kappa delta initial hPpos draw root).widthWork M source.length :=
|
| 86 |
+
chargedRandomMemoEvaluate_requests_le_widthWork source target N P H T S (passes + 1)
|
| 87 |
+
copies factor multiplier tau eta kappa delta group integer initial readGroup readInteger answer
|
| 88 |
+
bodyValue (inputHeight N ^ 91) bits encode hinjective hbounded
|
| 89 |
+
(computed_physicalFamilyProgram_source_cost source target N P H T S passes copies factor multiplier
|
| 90 |
+
tau eta kappa delta initial hPpos draw hN hell hM hAmax) root
|
| 91 |
+
|
| 92 |
+
end Work
|
| 93 |
+
|
| 94 |
+
end EditApproximation
|
| 95 |
+
|
| 96 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalFinalAccuracy.lean
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalSeedSchedule
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Probability.FiniteSeedFinal
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! Accuracy of the final fresh refinement after adaptive median seed passes,
|
| 7 |
+
under finite Bernstein bounds and an explicit incoming seed failure bound. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
open MeasureTheory ProbabilityTheory
|
| 12 |
+
|
| 13 |
+
section Final
|
| 14 |
+
|
| 15 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ}
|
| 16 |
+
[NeZero M] [NeZero R] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 17 |
+
(source target : List α) (N P T S H : ℕ)
|
| 18 |
+
|
| 19 |
+
local notation "Seed" => ClampedPhysicalSeed M J target.length N
|
| 20 |
+
local notation "ell" => inputSmallLog N
|
| 21 |
+
local notation "terminalFactor" => scheduledSeedFactor N (computedSeedPassCount N)
|
| 22 |
+
local notation "thetaExponent" => (40 * smallLogExponent N : ℕ)
|
| 23 |
+
local notation "eta" => RationalParameters.eta (rationalParameters ell)
|
| 24 |
+
local notation "kappa" => RationalParameters.kappa (rationalParameters ell)
|
| 25 |
+
local notation "delta" => RationalParameters.delta (rationalParameters ell)
|
| 26 |
+
local notation "tau" => RationalParameters.tau (rationalParameters ell)
|
| 27 |
+
|
| 28 |
+
abbrev FinalProgramDraw (seed : Seed) :=
|
| 29 |
+
PhysicalProgramDraw (R := R) source target (clampedSeedNat seed) N P ell terminalFactor
|
| 30 |
+
T thetaExponent H (ell ^ 80) tau
|
| 31 |
+
|
| 32 |
+
noncomputable def finalProgramDrawLaw (seed : Seed) :
|
| 33 |
+
Measure (FinalProgramDraw (R := R) source target N P T H seed) :=
|
| 34 |
+
physicalProgramDrawLaw (R := R) source target (clampedSeedNat seed) N P ell terminalFactor
|
| 35 |
+
T thetaExponent H (ell ^ 80) tau
|
| 36 |
+
|
| 37 |
+
instance finalProgramDrawLaw_probability (seed : Seed) :
|
| 38 |
+
IsProbabilityMeasure (finalProgramDrawLaw (R := R) source target N P T H seed) := by
|
| 39 |
+
unfold finalProgramDrawLaw
|
| 40 |
+
infer_instance
|
| 41 |
+
|
| 42 |
+
noncomputable def finalProgramValue (rootQ : TargetInterval target.length) (seed : Seed)
|
| 43 |
+
(draw : FinalProgramDraw (R := R) source target N P T H seed) : ℝ :=
|
| 44 |
+
physicalRefinement source target (clampedSeedNat seed) N P ell terminalFactor T delta
|
| 45 |
+
(physicalProgramDrawSelections source target (clampedSeedNat seed) N P ell terminalFactor
|
| 46 |
+
T thetaExponent H (ell ^ 80) tau eta kappa draw)
|
| 47 |
+
(Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J) S rootQ
|
| 48 |
+
|
| 49 |
+
abbrev FinalProgramOutcome := Seed × (∀ seed : Seed, FinalProgramDraw (R := R) source target N P T H seed)
|
| 50 |
+
|
| 51 |
+
noncomputable def finalProgramLaw (incoming : Measure Seed) :
|
| 52 |
+
Measure (FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) := by
|
| 53 |
+
classical
|
| 54 |
+
exact (scheduledSeedLaw (R := R) source target N P T S H incoming (computedSeedPassCount N)).prod
|
| 55 |
+
(Measure.pi (finalProgramDrawLaw (R := R) source target N P T H))
|
| 56 |
+
|
| 57 |
+
instance finalProgramLaw_probability (incoming : Measure Seed) [IsProbabilityMeasure incoming] :
|
| 58 |
+
IsProbabilityMeasure (finalProgramLaw (R := R) source target N P T S H incoming) := by
|
| 59 |
+
unfold finalProgramLaw
|
| 60 |
+
infer_instance
|
| 61 |
+
|
| 62 |
+
/-- Equality is tested before the final query, so equal strings return zero
|
| 63 |
+
on every execution, including executions with a bad seed. -/
|
| 64 |
+
noncomputable def finalProgramAnswer (rootQ : TargetInterval target.length)
|
| 65 |
+
(pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) : ℕ :=
|
| 66 |
+
if source = substring target rootQ.lo rootQ.hi then 0 else
|
| 67 |
+
integerAnswer N (freshSeedValue (finalProgramValue (M := M) (J := J) (R := R) source target N P T S H rootQ) pair)
|
| 68 |
+
|
| 69 |
+
omit [NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)] in
|
| 70 |
+
theorem finalProgramAnswer_equal (rootQ : TargetInterval target.length)
|
| 71 |
+
(heq : source = substring target rootQ.lo rootQ.hi)
|
| 72 |
+
(pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) :
|
| 73 |
+
finalProgramAnswer (R := R) source target N P T S H rootQ pair = 0 := by
|
| 74 |
+
simp only [finalProgramAnswer, heq, ite_true]
|
| 75 |
+
|
| 76 |
+
variable (hN : 0 < N) (hell : 2 ^ 1000 ≤ inputSmallLog N)
|
| 77 |
+
(hMeq : M = (integerParameters N).M) (hJeq : J = intervalTreeDepth M source.length)
|
| 78 |
+
(hPeq : P = (integerParameters N).P) (hTeq : T = (integerParameters N).T)
|
| 79 |
+
(hSeq : S = (integerParameters N).S) (hHeq : H = inputHeight N)
|
| 80 |
+
(hsize : source.length + target.length ≤ N)
|
| 81 |
+
(bernstein : ∀ b : ℕ, ∀ h : Fin (groupDyadicScales M b (inputSmallLog N)).length,
|
| 82 |
+
FiniteBernsteinInput (Measure.pi fun _ : Fin
|
| 83 |
+
(groupSampleCount M (inputSmallLog N ^ 80) b (groupDyadicScaleAt M b (inputSmallLog N) h)) =>
|
| 84 |
+
(PMF.uniformOfFintype (Fin M)).toMeasure))
|
| 85 |
+
|
| 86 |
+
include hN hell hMeq hJeq hPeq hTeq hSeq hHeq hsize bernstein in
|
| 87 |
+
theorem finalProgram_accuracy (incoming : Measure Seed) [IsProbabilityMeasure incoming]
|
| 88 |
+
(hinitial : incoming.real {seed | ¬ physicalSeedGood source target
|
| 89 |
+
((integerParameters N).initialFactor : ℚ) seed} ≤ 1 / 100)
|
| 90 |
+
(rootQ : TargetInterval target.length) (epsilon : ℝ) (hepsilon : 0 < epsilon)
|
| 91 |
+
(haccuracy : 10 ≤ (inputSmallLog N : ℝ) * epsilon) :
|
| 92 |
+
(4 / 5 : ℝ) ≤ (finalProgramLaw (R := R) source target N P T S H incoming).real
|
| 93 |
+
{pair | stateEditCost source target rootQ ≤
|
| 94 |
+
finalProgramAnswer (R := R) source target N P T S H rootQ pair ∧
|
| 95 |
+
(finalProgramAnswer (R := R) source target N P T S H rootQ pair : ℝ) ≤
|
| 96 |
+
(1 + epsilon) * stateEditCost source target rootQ} := by
|
| 97 |
+
classical
|
| 98 |
+
by_cases heq : source = substring target rootQ.lo rootQ.hi
|
| 99 |
+
· have hcost : stateEditCost source target rootQ = 0 :=
|
| 100 |
+
(EditDistortion.cost_eq_zero_iff (s := true)).mpr heq
|
| 101 |
+
have hans (pair : FinalProgramOutcome (M := M) (J := J) (R := R) source target N P T H) :
|
| 102 |
+
finalProgramAnswer (R := R) source target N P T S H rootQ pair = 0 :=
|
| 103 |
+
finalProgramAnswer_equal source target N P T S H rootQ heq pair
|
| 104 |
+
simp only [hans, hcost, Nat.cast_zero, mul_zero, le_refl, and_self, Set.ofPred_true, probReal_univ]
|
| 105 |
+
norm_num
|
| 106 |
+
have hD : 0 < stateEditCost source target rootQ :=
|
| 107 |
+
Nat.pos_of_ne_zero (fun h => heq ((EditDistortion.cost_eq_zero_iff (s := true)).mp h))
|
| 108 |
+
have hf : 3 ≤ smallLogExponent N := by
|
| 109 |
+
have h := (Nat.pow_le_pow_iff_right (by decide : 1 < (2 : ℕ))).mp hell
|
| 110 |
+
omega
|
| 111 |
+
have hA : (1 : ℚ) ≤ terminalFactor := by
|
| 112 |
+
unfold scheduledSeedFactor
|
| 113 |
+
exact one_le_pow₀ (by norm_num)
|
| 114 |
+
have hAupper : terminalFactor ≤ ((integerParameters N).initialFactor : ℚ) := by
|
| 115 |
+
unfold scheduledSeedFactor
|
| 116 |
+
rw [← computedSeed_initial_factor]
|
| 117 |
+
exact dyadicSeedFactor_bound _ _ _
|
| 118 |
+
have ha := scheduledSeedFactor_terminal_refinement N hf
|
| 119 |
+
have hbranch : 0 < M := Nat.pos_of_ne_zero (NeZero.ne M)
|
| 120 |
+
have hP := computed_program_grid_lower N P hN hPeq
|
| 121 |
+
have hF : 1 ≤ ell := Nat.one_le_two_pow
|
| 122 |
+
have hT : 0 < T := by rw [hTeq]; exact (computed_stage_positive_counts N hN hell).1
|
| 123 |
+
have hEll : (0 : ℝ) < ell := Nat.cast_pos.2 (Nat.two_pow_pos _)
|
| 124 |
+
let terminalLaw := scheduledSeedLaw (R := R) source target N P T S H incoming (computedSeedPassCount N)
|
| 125 |
+
let good : Seed → Prop := physicalSeedGood source target terminalFactor
|
| 126 |
+
let value := finalProgramValue (M := M) (J := J) (R := R) source target N P T S H rootQ
|
| 127 |
+
have hseed : terminalLaw.real {seed | ¬ good seed} ≤ 1 / 10 :=
|
| 128 |
+
(scheduledSeedLaw_failure_lt (R := R) source target N P T S H hN hell hMeq hJeq hPeq
|
| 129 |
+
hTeq hSeq hHeq hsize bernstein incoming hinitial).le
|
| 130 |
+
have hlower (seed : Seed) (hg : good seed) (draw : FinalProgramDraw (R := R) source target N P T H seed) :
|
| 131 |
+
(stateEditCost source target rootQ : ℝ) ≤ value seed draw := by
|
| 132 |
+
have h := (physicalRefinement_stage_bounds source target hbranch (clampedSeedNat seed) N P ell
|
| 133 |
+
terminalFactor hsize hP hF hA hg T hT delta
|
| 134 |
+
(physicalProgramDrawSelections source target (clampedSeedNat seed) N P ell terminalFactor
|
| 135 |
+
T thetaExponent H (ell ^ 80) tau eta kappa draw)
|
| 136 |
+
(Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J) S rootQ).1
|
| 137 |
+
have hleft := (le_max_left _ _).trans h
|
| 138 |
+
simpa only [value, finalProgramValue, ha, Rat.cast_one, div_one, physicalSource, physicalSourceInterval,
|
| 139 |
+
sourceIntervalAt, substring, List.take_length, List.drop_zero] using hleft
|
| 140 |
+
have hmoment (seed : Seed) (hg : good seed) :
|
| 141 |
+
(∫ draw, max (value seed draw - stateEditCost source target rootQ) 0
|
| 142 |
+
∂finalProgramDrawLaw (R := R) source target N P T H seed) ≤
|
| 143 |
+
(stateEditCost source target rootQ : ℝ) / ell := by
|
| 144 |
+
have h := physicalProgram_expected_root_excess (R := R) source target N hN hell hMeq hJeq
|
| 145 |
+
(clampedSeedNat seed) P hPeq terminalFactor hA hAupper hsize hg T S hTeq hSeq hHeq bernstein rootQ
|
| 146 |
+
simpa only [value, finalProgramValue, finalProgramDrawLaw, one_div_mul_eq_div] using h
|
| 147 |
+
have hDN : stateEditCost source target rootQ ≤ N := by
|
| 148 |
+
have h := physical_state_cost_le (M := M) (J := J) source target N hsize
|
| 149 |
+
((Sigma.mk (Fin.mk 0 (Nat.zero_lt_succ J)) PUnit.unit : PhysicalNode M J), rootQ)
|
| 150 |
+
simpa only [physicalSource, physicalSourceInterval, sourceIntervalAt, substring,
|
| 151 |
+
List.take_length, List.drop_zero] using h
|
| 152 |
+
have h := freshSeed_answer_accuracy (finalProgramDrawLaw (R := R) source target N P T H)
|
| 153 |
+
terminalLaw good value hDN hD hEll hepsilon haccuracy hseed hlower hmoment
|
| 154 |
+
simpa only [finalProgramLaw, finalProgramAnswer, heq, ite_false, terminalLaw, value] using h
|
| 155 |
+
|
| 156 |
+
end Final
|
| 157 |
+
|
| 158 |
+
end EditApproximation
|
| 159 |
+
|
| 160 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGenericRegret.lean
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalNodeRegret
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.StageComparisonEnergy
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The generic regret bound for the actual complete physical recurrence. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open Finset
|
| 11 |
+
|
| 12 |
+
section Node
|
| 13 |
+
|
| 14 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 15 |
+
(source target : List α) (hM : 0 < M)
|
| 16 |
+
(U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ)
|
| 17 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 18 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 19 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 20 |
+
(T : ℕ) (hT : 0 < T) (delta : ℚ)
|
| 21 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 22 |
+
(stageRepresentatives source target U N P F A))
|
| 23 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 24 |
+
(hleaf : ¬ (physicalSourceInterval source.length node).hi -
|
| 25 |
+
(physicalSourceInterval source.length node).lo ≤ 1)
|
| 26 |
+
(q : TargetInterval target.length)
|
| 27 |
+
(hc : 0 < stateEditCost (physicalSource source node) target q)
|
| 28 |
+
|
| 29 |
+
local notation "parent" => physicalSourceInterval source.length node
|
| 30 |
+
local notation "b" => 2 ^ Nat.log 2 (stateEditCost (physicalSource source node) target q)
|
| 31 |
+
local notation "r" => roundInterval (seedGridSpacing b P) q
|
| 32 |
+
local notation "action" => comparisonChildren source target hM P hP parent q hc
|
| 33 |
+
local notation "mass" => fun i s => (stageWarmupMass source target U N P F A T (physicalChild node hbelow i, s) : ℝ)
|
| 34 |
+
local notation "W" => comparisonActionMass action mass
|
| 35 |
+
local notation "value" => fun t (s : PhysicalEntry M J target.length) =>
|
| 36 |
+
(physicalRefinement source target U N P F A T delta choices (Prod.fst s) t (Prod.snd s) : ℝ)
|
| 37 |
+
local notation "regret" => fun t =>
|
| 38 |
+
max (stateEditCost (physicalSource source node) target q : ℝ) (value (t + 1) (node, q)) -
|
| 39 |
+
(128 * (F : ℝ)) * targetEndpointDistance q r -
|
| 40 |
+
physicalComparisonClipped source target U N P F A T delta choices node hbelow action (t + 1)
|
| 41 |
+
|
| 42 |
+
include hsize hF hA hseed hT hleaf in
|
| 43 |
+
theorem physicalNode_generic_regret (S : ℕ) :
|
| 44 |
+
(∑ t ∈ range S, regret t) ≤ W - |stateLengthGap (physicalSource source node) target r| := by
|
| 45 |
+
have hspec := comparisonChildren_spec source target hM P hP parent q hc
|
| 46 |
+
have hzero : endpointActionConnection r action = 0 := hspec.2.1
|
| 47 |
+
have hrep := stageRounded_representative_mem source target U N P F A hsize hP hF hA hseed node q hc
|
| 48 |
+
have hL : (1 : ℝ) ≤ 128 * F := by
|
| 49 |
+
have hFR : (1 : ℝ) ≤ F := by exact_mod_cast hF
|
| 50 |
+
linarith only [hFR]
|
| 51 |
+
have hsplit : (stateEditCost (physicalSource source node) target q : ℝ) ≤
|
| 52 |
+
(128 * (F : ℝ)) * targetEndpointDistance q r +
|
| 53 |
+
∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ) := by
|
| 54 |
+
have h := comparisonChildren_lower source target hM P hP parent q hc
|
| 55 |
+
have he := mul_le_mul_of_nonneg_right hL (Nat.cast_nonneg (α := ℝ) (targetEndpointDistance q r))
|
| 56 |
+
change (stateEditCost (physicalSource source node) target q : ℝ) ≤
|
| 57 |
+
(∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) +
|
| 58 |
+
targetEndpointDistance q r at h
|
| 59 |
+
simp only [one_mul] at he
|
| 60 |
+
linarith only [h, he]
|
| 61 |
+
have hbellman (t : ℕ) (_ht : t < S) :
|
| 62 |
+
value (t + 1) (node, q) ≤ (128 * (F : ℝ)) * targetEndpointDistance q r +
|
| 63 |
+
∑ i, value t (physicalChild node hbelow i, action i) := by
|
| 64 |
+
have hQ := (physicalRefinement_bellman_invariants source target U N P F A T delta choices node t q).2
|
| 65 |
+
have hR := (Rat.cast_le (K := ℝ)).mpr hQ
|
| 66 |
+
rw [rationalPhysicalBellman_cast] at hR
|
| 67 |
+
have h := physicalBellman_le_action source target P ((128 * F : ℚ) : ℝ)
|
| 68 |
+
(fun s => (stageInitial source target U N P F A s : ℝ))
|
| 69 |
+
(stageRepresentatives source target U N P F A) (value t) node hbelow hleaf q r b hrep action hspec.1
|
| 70 |
+
rw [hzero, Nat.cast_zero, add_zero] at h
|
| 71 |
+
simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using hR.trans h
|
| 72 |
+
have hmono (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) :
|
| 73 |
+
value S (physicalChild node hbelow i, action i) ≤ value 0 (physicalChild node hbelow i, action i) := by
|
| 74 |
+
apply Rat.cast_le.mpr
|
| 75 |
+
have hantitone : Antitone (fun t => physicalRefinement source target U N P F A T delta choices
|
| 76 |
+
(physicalChild node hbelow i) t (action i)) :=
|
| 77 |
+
antitone_nat_of_succ_le (fun t => physicalRefinement_nonincreasing source target U N P F A T delta choices
|
| 78 |
+
(physicalChild node hbelow i) t (action i))
|
| 79 |
+
exact hantitone (Nat.zero_le S)
|
| 80 |
+
have hinv (i : Fin M) := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed
|
| 81 |
+
T hT (physicalChild node hbelow i, action i)
|
| 82 |
+
have hinit (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) :
|
| 83 |
+
value 0 (physicalChild node hbelow i, action i) ≤ mass i (action i) := by
|
| 84 |
+
dsimp only
|
| 85 |
+
rw [physicalRefinement_zero]
|
| 86 |
+
exact Rat.cast_le.mpr (hinv i).2.1
|
| 87 |
+
have hgapMass (i : Fin M) (_hi : i ∈ (univ : Finset (Fin M))) :
|
| 88 |
+
|stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)| ≤ mass i (action i) :=
|
| 89 |
+
((le_max_right _ _).trans (hinv i).1).trans (Rat.cast_le.mpr (hinv i).2.1)
|
| 90 |
+
have h := generic_regret_mass_bound univ S
|
| 91 |
+
(stateEditCost (physicalSource source node) target q : ℝ)
|
| 92 |
+
((128 * (F : ℝ)) * targetEndpointDistance q r)
|
| 93 |
+
(fun i => (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ))
|
| 94 |
+
(fun i => mass i (action i))
|
| 95 |
+
(fun i => stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i))
|
| 96 |
+
(fun t => value t (node, q)) (fun t i => value t (physicalChild node hbelow i, action i))
|
| 97 |
+
hsplit hbellman hmono hinit
|
| 98 |
+
(fun i _ => stateEditCost_length_lower _ _ _) hgapMass
|
| 99 |
+
apply h.trans
|
| 100 |
+
have hsum := sum_mass_sub_abs_le univ (fun i => mass i (action i))
|
| 101 |
+
(fun i => stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i))
|
| 102 |
+
have hgapSum : (∑ i, stateLengthGap (physicalSource source (physicalChild node hbelow i)) target (action i)) =
|
| 103 |
+
stateLengthGap (physicalSource source node) target r :=
|
| 104 |
+
zero_connection_gap_sum source target hM parent r action hzero
|
| 105 |
+
rw [hgapSum] at hsum
|
| 106 |
+
exact hsum
|
| 107 |
+
|
| 108 |
+
include hsize hF hA hseed hT in
|
| 109 |
+
theorem physicalComparison_mass_upper (hMP : 4 * (M : ℝ) / P ≤ 1) :
|
| 110 |
+
W ≤ 4 * F * stateEditCost (physicalSource source node) target q := by
|
| 111 |
+
have hcost := comparisonChildren_cost_bound source target hM P hP parent q hc
|
| 112 |
+
change (∑ i, (stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ)) ≤
|
| 113 |
+
(1 + 4 * (M : ℝ) / P) * stateEditCost (physicalSource source node) target q at hcost
|
| 114 |
+
have hsum : W ≤ 2 * (F : ℝ) * ∑ i,
|
| 115 |
+
(stateEditCost (physicalSource source (physicalChild node hbelow i)) target (action i) : ℝ) := by
|
| 116 |
+
change (∑ i, mass i (action i)) ≤ _
|
| 117 |
+
rw [mul_sum]
|
| 118 |
+
apply sum_le_sum
|
| 119 |
+
intro i _
|
| 120 |
+
have h := stageWarmup_invariants source target hM U N P F A hsize hP hF hA hseed T hT
|
| 121 |
+
(physicalChild node hbelow i, action i)
|
| 122 |
+
have hQ := h.2.2.1.trans h.2.2.2
|
| 123 |
+
simpa only [Rat.cast_mul, Rat.cast_ofNat, Rat.cast_natCast] using (Rat.cast_le (K := ℝ)).mpr hQ
|
| 124 |
+
have hfactor := mul_le_mul_of_nonneg_left hcost (show (0 : ℝ) ≤ 2 * F by positivity)
|
| 125 |
+
have hcost0 : (0 : ℝ) ≤ stateEditCost (physicalSource source node) target q := Nat.cast_nonneg _
|
| 126 |
+
have hfactor2 := mul_le_mul_of_nonneg_right hMP hcost0
|
| 127 |
+
have hfactor3 := mul_le_mul_of_nonneg_left hfactor2 (show (0 : ℝ) ≤ 2 * F by positivity)
|
| 128 |
+
nlinarith only [hsum, hfactor, hfactor3]
|
| 129 |
+
|
| 130 |
+
include hsize hF hA hseed hT hleaf in
|
| 131 |
+
theorem physicalNode_generic_regret_upper (hMP : 4 * (M : ℝ) / P ≤ 1) (S : ℕ) :
|
| 132 |
+
(∑ t ∈ range S, regret t) ≤ 4 * F * stateEditCost (physicalSource source node) target q := by
|
| 133 |
+
exact (physicalNode_generic_regret source target hM U N P F A hsize hP hF hA hseed T hT delta choices node
|
| 134 |
+
hbelow hleaf q hc S).trans ((sub_le_self _ (abs_nonneg _)).trans
|
| 135 |
+
(physicalComparison_mass_upper source target hM U N P F A hsize hP hF hA hseed T hT node hbelow q hc hMP))
|
| 136 |
+
|
| 137 |
+
include hsize hF hA hseed hT hleaf in
|
| 138 |
+
theorem physicalNode_near_length_gap_regret
|
| 139 |
+
(hscale : 2 * (refinementFactor A F : ℝ) ≤ P) (hMP : 4 * (M : ℝ) / P ≤ 1)
|
| 140 |
+
(hnonempty : wideActionList M parent r b P ≠ []) (tau : ℚ) (htau : 0 ≤ tau)
|
| 141 |
+
(hprediction : 1 - tau < |rationalStateGap (physicalSource source node) target r /
|
| 142 |
+
rationalWideActionMinimum parent r b P hnonempty
|
| 143 |
+
(physicalBandChildMassTable source target U N P F A T node hbelow)|)
|
| 144 |
+
(ratio : ℝ)
|
| 145 |
+
(hdiscrepancy : W - wideActionMinimum parent r b P hnonempty mass ≤
|
| 146 |
+
ratio * stateEditCost (physicalSource source node) target q) (S : ℕ) :
|
| 147 |
+
(∑ t ∈ range S, regret t) ≤
|
| 148 |
+
(ratio + 4 * (tau : ℝ) * F) * stateEditCost (physicalSource source node) target q := by
|
| 149 |
+
let Z := wideActionMinimum parent r b P hnonempty mass
|
| 150 |
+
have hspec := comparisonChildren_spec source target hM P hP parent q hc
|
| 151 |
+
have ha : (1 : ℝ) ≤ refinementFactor A F := by
|
| 152 |
+
simpa only [Rat.cast_one] using (Rat.cast_le (K := ℝ)).mpr (refinementFactor_spec A F (by omega)).1
|
| 153 |
+
have hlower := wideActionMinimum_lower source target hM parent r b P hnonempty
|
| 154 |
+
(refinementFactor A F : ℝ) ha mass
|
| 155 |
+
(stageWarmupMass_child_lower source target hM U N P F A hsize hP hF hA hseed T hT node hbelow)
|
| 156 |
+
have hpositive := (stageComparison_positive_movement source target hM U N P F A hsize hP hF hA hseed
|
| 157 |
+
T hT node q hc hscale).1
|
| 158 |
+
have hcostPos : (0 : ℝ) < stateEditCost (physicalSource source node) target r := by exact_mod_cast hpositive
|
| 159 |
+
have hZ : 0 < Z := (div_pos hcostPos (by linarith only [ha])).trans_le ((le_max_left _ _).trans hlower)
|
| 160 |
+
have hZW : Z ≤ W := by
|
| 161 |
+
have h := wideActionMinimum_le_member parent r hnonempty mass action hspec.1
|
| 162 |
+
have hzero : endpointActionConnection r action = 0 := hspec.2.1
|
| 163 |
+
simpa only [Z, endpointActionValue, hzero, Nat.cast_zero, zero_add, comparisonActionMass] using h
|
| 164 |
+
have hpred : 1 - (tau : ℝ) < |stateLengthGap (physicalSource source node) target r| / Z := by
|
| 165 |
+
have h := (Rat.cast_lt (K := ℝ)).mpr hprediction
|
| 166 |
+
simp only [Rat.cast_sub, Rat.cast_one, Rat.cast_abs, Rat.cast_div, rationalStateGap_cast,
|
| 167 |
+
rationalWideActionMinimum_cast, abs_div] at h
|
| 168 |
+
change 1 - (tau : ℝ) < |stateLengthGap (physicalSource source node) target r| / |Z| at h
|
| 169 |
+
rwa [abs_of_pos hZ] at h
|
| 170 |
+
have hnear := near_length_gap_regret_bound W Z (stateLengthGap (physicalSource source node) target r)
|
| 171 |
+
(tau : ℝ) ratio F (stateEditCost (physicalSource source node) target q) hZ hZW
|
| 172 |
+
((Rat.cast_nonneg (K := ℝ)).mpr htau) hpred hdiscrepancy
|
| 173 |
+
(physicalComparison_mass_upper source target hM U N P F A hsize hP hF hA hseed T hT node hbelow q hc hMP)
|
| 174 |
+
exact (physicalNode_generic_regret source target hM U N P F A hsize hP hF hA hseed T hT delta choices
|
| 175 |
+
node hbelow hleaf q hc S).trans hnear
|
| 176 |
+
|
| 177 |
+
end Node
|
| 178 |
+
|
| 179 |
+
end EditApproximation
|
| 180 |
+
|
| 181 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalQuery.lean
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Probability.FiniteQueryRestriction
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementDataRequest
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalMedianQuery
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalSeedSequence
|
| 5 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
namespace OAI
|
| 9 |
+
|
| 10 |
+
/-! The global query body. A seed read at pass zero evaluates the coarse
|
| 11 |
+
seed entry; every later pass reads the preceding pass's copy medians.
|
| 12 |
+
All warmup and refinement dependencies carry strict physical ranks. -/
|
| 13 |
+
|
| 14 |
+
namespace EditApproximation
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
section Program
|
| 19 |
+
|
| 20 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 21 |
+
(source target : List α) (N P F exponent H Q T S copies : ℕ)
|
| 22 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 23 |
+
(group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
|
| 24 |
+
(integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 25 |
+
(initial : PhysicalEntry M J target.length → ℕ)
|
| 26 |
+
|
| 27 |
+
def physicalGlobalQuery (request : PhysicalTableRequest M J target.length) :
|
| 28 |
+
FiniteQuery {child : PhysicalTableRequest M J target.length //
|
| 29 |
+
child.combinedRank T S < request.combinedRank T S} := by
|
| 30 |
+
let seedRead := globalSeedRead N T S copies multiplier initial request
|
| 31 |
+
by_cases hwarmup : request.index ≤ T
|
| 32 |
+
· exact physicalWarmupRequestQuery source target N P F (factor request.pass)
|
| 33 |
+
request.pass request.copy T S request.index request.node request.state seedRead
|
| 34 |
+
· by_cases hbelow : request.node.1.val < J
|
| 35 |
+
· by_cases hshort : (physicalSourceInterval source.length request.node).hi -
|
| 36 |
+
(physicalSourceInterval source.length request.node).lo ≤ 1
|
| 37 |
+
· exact physicalInitialQuery source target N P F (factor request.pass) seedRead
|
| 38 |
+
(request.node, request.state)
|
| 39 |
+
· have ht : 0 < request.index - T := by omega
|
| 40 |
+
have hrequest : PhysicalTableRequest.refinement request.pass request.copy request.node
|
| 41 |
+
T (request.index - T) request.state = request := by
|
| 42 |
+
have hi : T + (request.index - T) = request.index := by omega
|
| 43 |
+
unfold PhysicalTableRequest.refinement
|
| 44 |
+
rw [hi]
|
| 45 |
+
have program := physicalRefinementDataRequestQuery source target N P F exponent H Q
|
| 46 |
+
tau (refinementFactor (factor request.pass) F) eta kappa delta
|
| 47 |
+
request.pass request.copy T S (request.index - T) ht request.node hbelow
|
| 48 |
+
(group request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1)))
|
| 49 |
+
(integer request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1)))
|
| 50 |
+
request.state
|
| 51 |
+
exact FiniteQuery.mapKeys
|
| 52 |
+
(fun child => ⟨child.val, by simpa only [hrequest] using child.property⟩) program
|
| 53 |
+
· exact physicalInitialQuery source target N P F (factor request.pass) seedRead
|
| 54 |
+
(request.node, request.state)
|
| 55 |
+
|
| 56 |
+
end Program
|
| 57 |
+
|
| 58 |
+
end EditApproximation
|
| 59 |
+
|
| 60 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGlobalValue.lean
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalGlobalQuery
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.RankedMemoSimulation
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The global query body computes the local pass recurrence on every seed and draw. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
section Value
|
| 11 |
+
|
| 12 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 13 |
+
(source target : List α) (N P F exponent H Q T S copies : ℕ)
|
| 14 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 15 |
+
(group : ℕ → ℕ → PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
|
| 16 |
+
(integer : ℕ → ℕ → PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 17 |
+
(initial : PhysicalEntry M J target.length → ℕ)
|
| 18 |
+
|
| 19 |
+
theorem physicalGlobalQuery_warmup (pass copy : ℕ) (node : PhysicalNode M J)
|
| 20 |
+
(j : ℕ) (hj : j ≤ T) (q : TargetInterval target.length) :
|
| 21 |
+
physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 22 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node j q) =
|
| 23 |
+
physicalWarmupRequestQuery source target N P F (factor pass) pass copy T S j node q
|
| 24 |
+
(globalSeedRead N T S copies multiplier initial (PhysicalTableRequest.warmup pass copy node j q)) := by
|
| 25 |
+
unfold physicalGlobalQuery
|
| 26 |
+
dsimp only
|
| 27 |
+
erw [dite_eq_left (show (PhysicalTableRequest.warmup pass copy node j q).index ≤ T from hj)]
|
| 28 |
+
rfl
|
| 29 |
+
|
| 30 |
+
theorem physicalGlobalQuery_refinement_value (request : PhysicalTableRequest M J target.length)
|
| 31 |
+
(hindex : T < request.index) (hbelow : request.node.1.val < J)
|
| 32 |
+
(hshort : ¬ (physicalSourceInterval source.length request.node).hi -
|
| 33 |
+
(physicalSourceInterval source.length request.node).lo ≤ 1)
|
| 34 |
+
(values : PhysicalTableRequest M J target.length → ℚ) :
|
| 35 |
+
(physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 36 |
+
tau eta kappa delta group integer initial request).value (fun child => values child.val) =
|
| 37 |
+
(physicalRefinementDataRequestQuery source target N P F exponent H Q tau
|
| 38 |
+
(refinementFactor (factor request.pass) F) eta kappa delta request.pass request.copy T S
|
| 39 |
+
(request.index - T) (Nat.sub_pos_of_lt hindex) request.node hbelow
|
| 40 |
+
(group request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1)))
|
| 41 |
+
(integer request.pass request.copy ⟨request.node, hbelow⟩ (Fin.ofNat R (request.index - T - 1)))
|
| 42 |
+
request.state).value (fun child => values child.val) := by
|
| 43 |
+
unfold physicalGlobalQuery
|
| 44 |
+
dsimp only
|
| 45 |
+
erw [dite_eq_right (Nat.not_le.mpr hindex), dite_eq_left hbelow, dite_eq_right hshort]
|
| 46 |
+
rw [FiniteQuery.mapKeys_value]
|
| 47 |
+
rfl
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
theorem globalSeedRead_value (parent : PhysicalTableRequest M J target.length)
|
| 51 |
+
(q : TargetInterval target.length) :
|
| 52 |
+
(globalSeedRead N T S copies multiplier initial parent (parent.node, q)).value
|
| 53 |
+
(fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 54 |
+
tau eta kappa delta group integer initial child.val) =
|
| 55 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 56 |
+
tau eta kappa delta group integer initial parent.pass (parent.node, q) : ℚ) := by
|
| 57 |
+
by_cases hp : parent.pass = 0
|
| 58 |
+
· rw [globalSeedRead, ite_eq_left rfl, dite_eq_left hp]
|
| 59 |
+
change (initial (parent.node, q) : ℚ) = _
|
| 60 |
+
rw [hp]
|
| 61 |
+
rfl
|
| 62 |
+
· simp only [globalSeedRead, ite_true, dite_eq_right hp]
|
| 63 |
+
rw [physicalMedianSeedQuery_value]
|
| 64 |
+
have hprev (copy : Fin copies) :
|
| 65 |
+
previousPassRequest T S copy.val parent q =
|
| 66 |
+
PhysicalTableRequest.refinement (parent.pass - 1) copy.val parent.node T S q := rfl
|
| 67 |
+
simp only [hprev, localRequestValue_refinement]
|
| 68 |
+
obtain ⟨pass, hpass⟩ := Nat.exists_eq_succ_of_ne_zero hp
|
| 69 |
+
simp only [hpass, Nat.succ_eq_add_one, Nat.add_sub_cancel, localSeedSequence]
|
| 70 |
+
|
| 71 |
+
theorem localRequestValue_initial (pass copy : ℕ) (node : PhysicalNode M J)
|
| 72 |
+
(q : TargetInterval target.length) :
|
| 73 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 74 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node 0 q) =
|
| 75 |
+
stageInitial source target
|
| 76 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 77 |
+
tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by
|
| 78 |
+
rw [localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier
|
| 79 |
+
tau eta kappa delta group integer initial pass copy node 0 (Nat.zero_le T)]
|
| 80 |
+
rfl
|
| 81 |
+
|
| 82 |
+
theorem localRequestValue_mass (pass copy : ℕ) (node : PhysicalNode M J)
|
| 83 |
+
(q : TargetInterval target.length) :
|
| 84 |
+
(∑ j : Fin T, localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 85 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node j.val q)) / T =
|
| 86 |
+
physicalLocalWarmupMass source target
|
| 87 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 88 |
+
tau eta kappa delta group integer initial pass) N P F (factor pass) T (node, q) := by
|
| 89 |
+
unfold physicalLocalWarmupMass
|
| 90 |
+
rw [← Fin.sum_univ_eq_sum_range]
|
| 91 |
+
congr 1
|
| 92 |
+
exact Finset.sum_congr rfl (fun j _ => localRequestValue_warmup source target N P F exponent H Q
|
| 93 |
+
T S copies factor multiplier tau eta kappa delta group integer initial pass copy node j.val
|
| 94 |
+
(Nat.le_of_lt j.isLt) q)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
theorem localPassValue_step (seed : PhysicalEntry M J target.length → ℕ)
|
| 98 |
+
(pass copy : ℕ) (node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 99 |
+
(hshort : ¬ (physicalSourceInterval source.length node).hi -
|
| 100 |
+
(physicalSourceInterval source.length node).lo ≤ 1)
|
| 101 |
+
(t : ℕ) (ht : 0 < t) (q : TargetInterval target.length) :
|
| 102 |
+
let children := fun i s r => localPassValue source target N P F exponent H Q T factor
|
| 103 |
+
tau eta kappa delta group integer seed pass copy (physicalChild node hbelow i) s r
|
| 104 |
+
localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer
|
| 105 |
+
seed pass copy node t q =
|
| 106 |
+
rationalLocalWideStep source target (physicalSourceInterval source.length node)
|
| 107 |
+
N P F exponent Q tau (refinementFactor (factor pass) F) delta
|
| 108 |
+
(fun r => stageInitial source target seed N P F (factor pass) (node, r))
|
| 109 |
+
(physicalLocalChildMass source target seed N P F (factor pass) T node hbelow)
|
| 110 |
+
(fun i r => stageInitial source target seed N P F (factor pass) (physicalChild node hbelow i, r))
|
| 111 |
+
(fun i r => children i (t - 1) r) (fun i r => children i t r)
|
| 112 |
+
(group pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1)))
|
| 113 |
+
(localOnlineCandidates source target (physicalSourceInterval source.length node)
|
| 114 |
+
N P F exponent H tau (refinementFactor (factor pass) F) eta kappa
|
| 115 |
+
(fun r => stageInitial source target seed N P F (factor pass) (node, r))
|
| 116 |
+
(physicalLocalChildMass source target seed N P F (factor pass) T node hbelow)
|
| 117 |
+
(fun i r => stageInitial source target seed N P F (factor pass) (physicalChild node hbelow i, r))
|
| 118 |
+
children (t - 1) (integer pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q) q := by
|
| 119 |
+
dsimp only
|
| 120 |
+
cases t with
|
| 121 |
+
| zero => omega
|
| 122 |
+
| succ t =>
|
| 123 |
+
unfold localPassValue
|
| 124 |
+
rw [physicalLocalRefinement]
|
| 125 |
+
simp only [dite_eq_left hbelow, ite_eq_right hshort, Nat.add_sub_cancel,
|
| 126 |
+
physicalLocalOnline]
|
| 127 |
+
rfl
|
| 128 |
+
|
| 129 |
+
theorem physicalRefinementDataRequestQuery_localValue (pass copy : ℕ) (node : PhysicalNode M J)
|
| 130 |
+
(hbelow : node.1.val < J)
|
| 131 |
+
(hshort : ¬ (physicalSourceInterval source.length node).hi -
|
| 132 |
+
(physicalSourceInterval source.length node).lo ≤ 1)
|
| 133 |
+
(t : ℕ) (ht : 0 < t) (q : TargetInterval target.length) :
|
| 134 |
+
(physicalRefinementDataRequestQuery source target N P F exponent H Q tau
|
| 135 |
+
(refinementFactor (factor pass) F) eta kappa delta pass copy T S t ht node hbelow
|
| 136 |
+
(group pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1)))
|
| 137 |
+
(integer pass copy ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q).value
|
| 138 |
+
(fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 139 |
+
tau eta kappa delta group integer initial child.val) =
|
| 140 |
+
localPassValue source target N P F exponent H Q T factor tau eta kappa delta group integer
|
| 141 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 142 |
+
tau eta kappa delta group integer initial pass) pass copy node t q := by
|
| 143 |
+
rw [physicalRefinementDataRequestQuery_value]
|
| 144 |
+
dsimp only
|
| 145 |
+
simp_rw [localRequestValue_initial source target N P F exponent H Q T S copies factor multiplier
|
| 146 |
+
tau eta kappa delta group integer initial,
|
| 147 |
+
localRequestValue_mass source target N P F exponent H Q T S copies factor multiplier
|
| 148 |
+
tau eta kappa delta group integer initial,
|
| 149 |
+
localRequestValue_refinement source target N P F exponent H Q T S copies factor multiplier
|
| 150 |
+
tau eta kappa delta group integer initial]
|
| 151 |
+
exact (localPassValue_step source target N P F exponent H Q T factor tau eta kappa delta
|
| 152 |
+
group integer _ pass copy node hbelow hshort t ht q).symm
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
theorem physicalGlobalQuery_value (request : PhysicalTableRequest M J target.length) :
|
| 156 |
+
(physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 157 |
+
tau eta kappa delta group integer initial request).value
|
| 158 |
+
(fun child => localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 159 |
+
tau eta kappa delta group integer initial child.val) =
|
| 160 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 161 |
+
tau eta kappa delta group integer initial request := by
|
| 162 |
+
rcases request with ⟨pass, copy, node, index, q⟩
|
| 163 |
+
by_cases hj : index ≤ T
|
| 164 |
+
· change (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 165 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q)).value _ = _
|
| 166 |
+
rw [physicalGlobalQuery_warmup source target N P F exponent H Q T S copies factor multiplier
|
| 167 |
+
tau eta kappa delta group integer initial pass copy node index hj q]
|
| 168 |
+
change _ = localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 169 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.warmup pass copy node index q)
|
| 170 |
+
rw [localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier
|
| 171 |
+
tau eta kappa delta group integer initial pass copy node index hj q]
|
| 172 |
+
apply physicalWarmupRequestQuery_value_local
|
| 173 |
+
· intro r
|
| 174 |
+
exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier
|
| 175 |
+
tau eta kappa delta group integer initial _ r
|
| 176 |
+
· intro hbelow input
|
| 177 |
+
exact localRequestValue_warmup source target N P F exponent H Q T S copies factor multiplier
|
| 178 |
+
tau eta kappa delta group integer initial pass copy (physicalChild node hbelow input.1)
|
| 179 |
+
(index - 1) (by omega) input.2
|
| 180 |
+
· obtain ⟨t, hi⟩ : ∃ t, index = T + t := ⟨index - T, by omega⟩
|
| 181 |
+
subst index
|
| 182 |
+
have ht : 0 < t := by omega
|
| 183 |
+
change (physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 184 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q)).value _ =
|
| 185 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 186 |
+
tau eta kappa delta group integer initial (PhysicalTableRequest.refinement pass copy node T t q)
|
| 187 |
+
rw [localRequestValue_refinement source target N P F exponent H Q T S copies factor multiplier
|
| 188 |
+
tau eta kappa delta group integer initial pass copy node t q]
|
| 189 |
+
by_cases hbelow : node.1.val < J
|
| 190 |
+
· by_cases hshort : (physicalSourceInterval source.length node).hi -
|
| 191 |
+
(physicalSourceInterval source.length node).lo ≤ 1
|
| 192 |
+
· have hterminal : localPassValue source target N P F exponent H Q T factor tau eta kappa delta
|
| 193 |
+
group integer (localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 194 |
+
tau eta kappa delta group integer initial pass) pass copy node t q =
|
| 195 |
+
stageInitial source target
|
| 196 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 197 |
+
tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by
|
| 198 |
+
unfold localPassValue
|
| 199 |
+
rw [physicalLocalRefinement, dite_eq_left hbelow, ite_eq_left hshort]
|
| 200 |
+
rw [hterminal]
|
| 201 |
+
unfold physicalGlobalQuery
|
| 202 |
+
dsimp only
|
| 203 |
+
erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T
|
| 204 |
+
from hj), dite_eq_left hbelow, dite_eq_left hshort]
|
| 205 |
+
apply physicalInitialQuery_value_local
|
| 206 |
+
intro r
|
| 207 |
+
exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier
|
| 208 |
+
tau eta kappa delta group integer initial _ r
|
| 209 |
+
· erw [physicalGlobalQuery_refinement_value source target N P F exponent H Q T S copies
|
| 210 |
+
factor multiplier tau eta kappa delta group integer initial
|
| 211 |
+
(PhysicalTableRequest.refinement pass copy node T t q) (by change T < T + t; omega)
|
| 212 |
+
hbelow hshort]
|
| 213 |
+
refine (physicalRefinementDataRequestQuery_localValue source target N P F exponent H Q T S copies
|
| 214 |
+
factor multiplier tau eta kappa delta group integer initial pass copy node hbelow hshort
|
| 215 |
+
(T + t - T) (by omega) q).trans ?_
|
| 216 |
+
rw [Nat.add_sub_cancel_left]
|
| 217 |
+
· have hterminal : localPassValue source target N P F exponent H Q T factor tau eta kappa delta
|
| 218 |
+
group integer (localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 219 |
+
tau eta kappa delta group integer initial pass) pass copy node t q =
|
| 220 |
+
stageInitial source target
|
| 221 |
+
(localSeedSequence source target N P F exponent H Q T S copies factor multiplier
|
| 222 |
+
tau eta kappa delta group integer initial pass) N P F (factor pass) (node, q) := by
|
| 223 |
+
unfold localPassValue
|
| 224 |
+
rw [physicalLocalRefinement, dite_eq_right hbelow]
|
| 225 |
+
rw [hterminal]
|
| 226 |
+
unfold physicalGlobalQuery
|
| 227 |
+
dsimp only
|
| 228 |
+
erw [dite_eq_right (show ¬ (PhysicalTableRequest.refinement pass copy node T t q).index ≤ T
|
| 229 |
+
from hj), dite_eq_right hbelow]
|
| 230 |
+
apply physicalInitialQuery_value_local
|
| 231 |
+
intro r
|
| 232 |
+
exact globalSeedRead_value source target N P F exponent H Q T S copies factor multiplier
|
| 233 |
+
tau eta kappa delta group integer initial _ r
|
| 234 |
+
|
| 235 |
+
theorem physicalGlobalProgramValue (request : PhysicalTableRequest M J target.length) :
|
| 236 |
+
rankedProgramValue (PhysicalTableRequest.combinedRank T S)
|
| 237 |
+
(physicalGlobalQuery source target N P F exponent H Q T S copies factor multiplier
|
| 238 |
+
tau eta kappa delta group integer initial) request =
|
| 239 |
+
localRequestValue source target N P F exponent H Q T S copies factor multiplier
|
| 240 |
+
tau eta kappa delta group integer initial request :=
|
| 241 |
+
rankedProgramValue_eq _ _ _
|
| 242 |
+
(physicalGlobalQuery_value source target N P F exponent H Q T S copies factor multiplier
|
| 243 |
+
tau eta kappa delta group integer initial) request
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
end Value
|
| 247 |
+
|
| 248 |
+
end EditApproximation
|
| 249 |
+
|
| 250 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalGroupAccuracy.lean
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.ComputedGroupAccuracy
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRefinementSpatial
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! Group concentration specialized to the actual stage and complete child histories. -/
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
open MeasureTheory ProbabilityTheory
|
| 11 |
+
|
| 12 |
+
theorem physical_cellGroupEstimate_failure {α : Type*} [DecidableEq α]
|
| 13 |
+
(source target : List α) (N : ℕ) (hN : 0 < N) (hell : 1764 ≤ inputSmallLog N)
|
| 14 |
+
{M J P b Q thetaExponent K : ℕ} [NeZero M]
|
| 15 |
+
[MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 16 |
+
(hM : 0 < M) (hMeq : M = (integerParameters N).M)
|
| 17 |
+
(hPeq : P = (integerParameters N).P) (eb : ℕ) (hbeq : b = 2 ^ eb)
|
| 18 |
+
(hQeq : Q = inputSmallLog N ^ 80) (hthetaeq : thetaExponent = 40 * smallLogExponent N)
|
| 19 |
+
(U : PhysicalEntry M J target.length → ℕ) (A : ℚ)
|
| 20 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hA : 1 ≤ A)
|
| 21 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 22 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 23 |
+
(T : ℕ) (hT : 0 < T) (delta : ℚ)
|
| 24 |
+
(choices : PhysicalSelections M J source.length target.length P
|
| 25 |
+
(stageRepresentatives source target U N P (inputSmallLog N) A))
|
| 26 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J) (t : ℕ) (cell : ℕ × ℕ)
|
| 27 |
+
(scales : Fin K → ℚ) (count : Fin K → ℕ)
|
| 28 |
+
(hscales : List.ofFn scales = groupDyadicScales M b (inputSmallLog N))
|
| 29 |
+
(hcount : ∀ scale, count scale = groupSampleCount M Q b (scales scale))
|
| 30 |
+
(bernstein : ∀ scale : Fin K, FiniteBernsteinInput
|
| 31 |
+
(Measure.pi fun _ : Fin (count scale) => (PMF.uniformOfFintype (Fin M)).toMeasure)) :
|
| 32 |
+
let F := inputSmallLog N
|
| 33 |
+
let initial := fun i s => stageInitial source target U N P F A (physicalChild node hbelow i, s)
|
| 34 |
+
let child := fun i s => stageWarmupMass source target U N P F A T (physicalChild node hbelow i, s)
|
| 35 |
+
let value := fun i s => physicalRefinement source target U N P F A T delta choices
|
| 36 |
+
(physicalChild node hbelow i) t s
|
| 37 |
+
let members := cellUnskippedBands source target (physicalSourceInterval source.length node)
|
| 38 |
+
b P F thetaExponent (rationalParameters F).tau (refinementFactor A F)
|
| 39 |
+
(fun s => stageInitial source target U N P F A (node, s)) child initial cell
|
| 40 |
+
(groupSharedDrawLaw count).real
|
| 41 |
+
{draw | ∃ member ∈ members, ((rationalParameters F).gamma : ℝ) * b <
|
| 42 |
+
|((unskippedGroupEstimate scales count value member draw -
|
| 43 |
+
rationalEndpointActionValue member.center member.rounded value : ℚ) : ℝ)|} ≤
|
| 44 |
+
1 / (inputHeight N : ℝ) ^ 4 := by
|
| 45 |
+
have hF : 1 ≤ inputSmallLog N := Nat.one_le_two_pow
|
| 46 |
+
apply computed_cellGroupEstimate_failure source target N hN hell hM hMeq hPeq eb hbeq hQeq hthetaeq
|
| 47 |
+
(physicalSourceInterval source.length node) (refinementFactor A (inputSmallLog N))
|
| 48 |
+
(fun s => stageInitial source target U N P (inputSmallLog N) A (node, s))
|
| 49 |
+
(fun i s => stageWarmupMass source target U N P (inputSmallLog N) A T (physicalChild node hbelow i, s))
|
| 50 |
+
(fun i s => stageInitial source target U N P (inputSmallLog N) A (physicalChild node hbelow i, s))
|
| 51 |
+
(fun i s => physicalRefinement source target U N P (inputSmallLog N) A T delta choices
|
| 52 |
+
(physicalChild node hbelow i) t s) cell scales count hscales hcount
|
| 53 |
+
· intro i s r
|
| 54 |
+
have hf := refinementFactor_spec A (inputSmallLog N) (by omega)
|
| 55 |
+
exact physicalInitialTable_spatial source target U N P (inputSmallLog N) A
|
| 56 |
+
(refinementFactor A (inputSmallLog N)) hsize hP hF hA hf.1 hf.2 hseed
|
| 57 |
+
(physicalChild node hbelow i) s r
|
| 58 |
+
· intro i s
|
| 59 |
+
have h := physicalRefinement_stage_bounds source target hM U N P (inputSmallLog N) A
|
| 60 |
+
hsize hP hF hA hseed T hT delta choices (physicalChild node hbelow i) t s
|
| 61 |
+
exact ⟨physicalRefinement_nonneg source target hM U N P (inputSmallLog N) A
|
| 62 |
+
hsize hP hF hA hseed T hT delta choices (physicalChild node hbelow i) t s,
|
| 63 |
+
h.2.1.trans (h.2.2.1.trans h.2.2.2.1)⟩
|
| 64 |
+
· exact bernstein
|
| 65 |
+
|
| 66 |
+
end EditApproximation
|
| 67 |
+
|
| 68 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalIndexedCoarseWork.lean
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Coarse.CoarseIndexedEntryCost
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalCoarseInputWork
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
namespace OAI
|
| 7 |
+
|
| 8 |
+
namespace EditApproximation
|
| 9 |
+
|
| 10 |
+
section Coarse
|
| 11 |
+
variable {M J R B : ℕ} [NeZero M] [NeZero R] [NeZero B]
|
| 12 |
+
(source target : List ℕ) (N P H T S passes copies : ℕ)
|
| 13 |
+
(factor : ℕ → ℚ) (multiplier : ℕ → ℕ) (tau eta kappa delta : ℚ)
|
| 14 |
+
(draw : PhysicalFamilyScalarDraw (M := M) (J := J) (R := R)
|
| 15 |
+
target N P (inputSmallLog N) (40 * smallLogExponent N) H (inputSmallLog N ^ 80) passes copies)
|
| 16 |
+
(depth : PhysicalEntry M J target.length → ℕ)
|
| 17 |
+
|
| 18 |
+
local notation "ell" => inputSmallLog N
|
| 19 |
+
local notation "exponent" => (40 * smallLogExponent N : ℕ)
|
| 20 |
+
local notation "Key" => PhysicalFamilyScalarKey (M := M) (J := J) (R := R)
|
| 21 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 22 |
+
local notation "Table" => ChargedPhysicalRequest M J target.length (passes + 1) copies T S
|
| 23 |
+
local notation "readGroup" => physicalFamilyGroupRead (M := M) (J := J) (R := R)
|
| 24 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 25 |
+
local notation "readInteger" => physicalFamilyOnlineRead (M := M) (J := J) (R := R)
|
| 26 |
+
target N P ell exponent H (ell ^ 80) passes copies
|
| 27 |
+
local notation "answer" => physicalFamilyAnswer target N P ell exponent H (ell ^ 80) passes copies draw
|
| 28 |
+
|
| 29 |
+
/-- Bit arithmetic is executed once for each fresh coarse source request. -/
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
theorem physicalFamilyIndexedCoarseWork_bound (bits : ℕ) (encode : Sum Key Table → ℕ)
|
| 33 |
+
(root : Table) (coarse : PhysicalCoarseDraw source target B depth) (C : ℝ)
|
| 34 |
+
(hc : ∀ entry : PhysicalEntry M J target.length,
|
| 35 |
+
(coarseIndexedEntryBinaryCost N B (depth entry) (physicalSource source entry.1)
|
| 36 |
+
(substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) ≤
|
| 37 |
+
C * ((coarseInitialArrayWork B (depth entry) (initialThresholdQ N) (initialLambda N)
|
| 38 |
+
(physicalSource source entry.1) (substring target entry.2.lo entry.2.hi) (coarse entry) : ℝ) +
|
| 39 |
+
((physicalSource source entry.1).length + 1 : ℕ))) :
|
| 40 |
+
physicalFamilyIndexedCoarseWork source target N P H T S passes copies factor multiplier
|
| 41 |
+
tau eta kappa delta draw depth bits encode root coarse ≤ C *
|
| 42 |
+
(physicalFamilyMemoCoarseWork source target N P H T S passes copies factor multiplier
|
| 43 |
+
tau eta kappa delta draw B depth bits encode root coarse +
|
| 44 |
+
physicalFamilyCoarseInputWork source target N P H T S passes copies factor multiplier
|
| 45 |
+
tau eta kappa delta
|
| 46 |
+
(clampedSeedNat (physicalCoarseSeedTable source target N B depth coarse))
|
| 47 |
+
draw bits encode root) := by
|
| 48 |
+
unfold physicalFamilyIndexedCoarseWork physicalFamilyMemoCoarseWork physicalFamilyCoarseInputWork
|
| 49 |
+
exact coarseIndexedEntryCostSum_bound source target N depth coarse _ C hc
|
| 50 |
+
|
| 51 |
+
end Coarse
|
| 52 |
+
end EditApproximation
|
| 53 |
+
|
| 54 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInitial.lean
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalWarmup
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalInitialCones
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Geometry.Leaves
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Probability.Exact
|
| 5 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
namespace OAI
|
| 9 |
+
|
| 10 |
+
/-! The actual initial table uses exact empty/singleton leaves and local cones elsewhere. -/
|
| 11 |
+
|
| 12 |
+
namespace EditApproximation
|
| 13 |
+
|
| 14 |
+
open EditDistortion
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
theorem shortSourceCost_eq_edit {α : Type*} [DecidableEq α] (source target : List α)
|
| 19 |
+
(hsource : source.length ≤ 1) : shortSourceCost source target = edit source target := by
|
| 20 |
+
cases source with
|
| 21 |
+
| nil =>
|
| 22 |
+
exact (edit_nil_left target).symm
|
| 23 |
+
| cons a rest =>
|
| 24 |
+
have hrest : rest = [] := List.length_eq_zero_iff.mp (by
|
| 25 |
+
simp only [List.length_cons] at hsource
|
| 26 |
+
omega)
|
| 27 |
+
subst rest
|
| 28 |
+
exact singletonCost_eq_edit a target
|
| 29 |
+
|
| 30 |
+
def physicalInitialTable {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α)
|
| 31 |
+
(U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A a : ℚ)
|
| 32 |
+
(state : PhysicalEntry M J target.length) : ℚ :=
|
| 33 |
+
let piece := physicalSource source state.1
|
| 34 |
+
if piece.length ≤ 1 then shortSourceCost piece (substring target state.2.lo state.2.hi)
|
| 35 |
+
else localInitialConeTable piece target (fun q => U (state.1, q)) N P F A a state.2
|
| 36 |
+
|
| 37 |
+
theorem physicalSource_length_le {α : Type*} {M J : ℕ} (source : List α)
|
| 38 |
+
(node : PhysicalNode M J) : (physicalSource source node).length ≤ source.length := by
|
| 39 |
+
simp only [physicalSource, substring, List.length_drop, List.length_take]
|
| 40 |
+
exact (Nat.sub_le _ _).trans (min_le_right _ _)
|
| 41 |
+
|
| 42 |
+
theorem physical_state_cost_le {α : Type*} {M J : ℕ} (source target : List α)
|
| 43 |
+
(N : ℕ) (hsize : source.length + target.length ≤ N)
|
| 44 |
+
(state : PhysicalEntry M J target.length) :
|
| 45 |
+
stateEditCost (physicalSource source state.1) target state.2 ≤ N := by
|
| 46 |
+
apply (edit_le_max_length _ _).trans
|
| 47 |
+
apply max_le
|
| 48 |
+
· exact (physicalSource_length_le source state.1).trans (by omega)
|
| 49 |
+
· have hlen : (substring target state.2.lo state.2.hi).length ≤ target.length := by
|
| 50 |
+
simp only [substring, List.length_drop, List.length_take]
|
| 51 |
+
exact (Nat.sub_le _ _).trans (min_le_right _ _)
|
| 52 |
+
exact hlen.trans (by omega)
|
| 53 |
+
|
| 54 |
+
theorem physicalInitialTable_bounds {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 55 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 56 |
+
(N P F : ℕ) (A a : ℚ) (hsize : source.length + target.length ≤ N)
|
| 57 |
+
(hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (ha : 1 ≤ a) (hfactor : A ≤ a * F)
|
| 58 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 59 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 60 |
+
(state : PhysicalEntry M J target.length) :
|
| 61 |
+
max ((stateEditCost (physicalSource source state.1) target state.2 : ℚ) / a)
|
| 62 |
+
|rationalStateGap (physicalSource source state.1) target state.2| ≤
|
| 63 |
+
physicalInitialTable source target U N P F A a state ∧
|
| 64 |
+
physicalInitialTable source target U N P F A a state ≤
|
| 65 |
+
2 * F * stateEditCost (physicalSource source state.1) target state.2 := by
|
| 66 |
+
unfold physicalInitialTable
|
| 67 |
+
dsimp only
|
| 68 |
+
split_ifs with hleaf
|
| 69 |
+
· rw [shortSourceCost_eq_edit _ _ hleaf]
|
| 70 |
+
change max ((stateEditCost _ _ _ : ℚ) / a) |rationalStateGap _ _ _| ≤
|
| 71 |
+
stateEditCost _ _ _ ∧ (stateEditCost _ _ _ : ℚ) ≤ 2 * F * stateEditCost _ _ _
|
| 72 |
+
have hc : (0 : ℚ) ≤ stateEditCost (physicalSource source state.1) target state.2 := Nat.cast_nonneg _
|
| 73 |
+
have hFQ : (1 : ℚ) ≤ F := by exact_mod_cast hF
|
| 74 |
+
have hgap := stateEditCost_length_lower (physicalSource source state.1) target state.2
|
| 75 |
+
rw [← rationalStateGap_cast] at hgap
|
| 76 |
+
constructor
|
| 77 |
+
· apply max_le
|
| 78 |
+
· apply (div_le_iff₀ (by linarith : 0 < a)).2
|
| 79 |
+
nlinarith
|
| 80 |
+
· exact_mod_cast hgap
|
| 81 |
+
· nlinarith
|
| 82 |
+
· rw [localInitialConeTable_eq_global _ _ _ N P F A a hP hF hA ha hfactor
|
| 83 |
+
(fun q => physical_state_cost_le source target N hsize (state.1, q))
|
| 84 |
+
(fun q => hseed (state.1, q))]
|
| 85 |
+
exact globalInitialConeTable_bounds _ _ _ N P F A a hP hF hA ha hfactor
|
| 86 |
+
(fun q => physical_state_cost_le source target N hsize (state.1, q))
|
| 87 |
+
(fun q => hseed (state.1, q)) state.2
|
| 88 |
+
|
| 89 |
+
theorem physicalInitialTable_real_lower {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 90 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 91 |
+
(N P F : ℕ) (A a : ℚ) (hsize : source.length + target.length ≤ N)
|
| 92 |
+
(hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A) (ha : 1 ≤ a) (hfactor : A ≤ a * F)
|
| 93 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 94 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2) :
|
| 95 |
+
physicalLower source target (a : ℝ) ≤
|
| 96 |
+
fun state => (physicalInitialTable source target U N P F A a state : ℝ) := by
|
| 97 |
+
intro state
|
| 98 |
+
have h := (physicalInitialTable_bounds source target U N P F A a hsize hP hF hA ha hfactor hseed state).1
|
| 99 |
+
have hR : ((max ((stateEditCost (physicalSource source state.1) target state.2 : ℚ) / a)
|
| 100 |
+
|rationalStateGap (physicalSource source state.1) target state.2| : ℚ) : ℝ) ≤
|
| 101 |
+
(physicalInitialTable source target U N P F A a state : ℝ) := Rat.cast_le.mpr h
|
| 102 |
+
simpa only [Rat.cast_max, Rat.cast_div, Rat.cast_natCast, Rat.cast_abs,
|
| 103 |
+
rationalStateGap_cast, physicalLower] using hR
|
| 104 |
+
|
| 105 |
+
end EditApproximation
|
| 106 |
+
|
| 107 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputEncoding.lean
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.GatheredLocalStep
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
namespace OAI
|
| 6 |
+
|
| 7 |
+
/-! Fixed-width binary keys for gathered child states. The encoding uses
|
| 8 |
+
mixed radix arithmetic on the child label and the two state endpoints. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
theorem mixedRadix_injective {radix lo lo' hi hi' : ℕ}
|
| 13 |
+
(hlo : lo < radix) (hlo' : lo' < radix)
|
| 14 |
+
(heq : lo + radix * hi = lo' + radix * hi') : lo = lo' ∧ hi = hi' := by
|
| 15 |
+
have hmod := congrArg (fun n => n % radix) heq
|
| 16 |
+
simp only [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt hlo, Nat.mod_eq_of_lt hlo'] at hmod
|
| 17 |
+
refine ⟨hmod, ?_⟩
|
| 18 |
+
apply Nat.mul_left_cancel (by omega : 0 < radix)
|
| 19 |
+
omega
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
theorem childInputCode_injective (M n : ℕ) :
|
| 24 |
+
Function.Injective (@childInputCode M n) := by
|
| 25 |
+
rintro ⟨i, q⟩ ⟨i', q'⟩ heq
|
| 26 |
+
obtain ⟨hi, hq⟩ := mixedRadix_injective i.isLt i'.isLt heq
|
| 27 |
+
have hqlo : q.lo < n + 1 := by have := q.ordered.trans q.valid; omega
|
| 28 |
+
have hqlo' : q'.lo < n + 1 := by have := q'.ordered.trans q'.valid; omega
|
| 29 |
+
obtain ⟨hlo, hhi⟩ := mixedRadix_injective hqlo hqlo' hq
|
| 30 |
+
have hqeq : q = q' := by cases q; cases q'; cases hlo; cases hhi; rfl
|
| 31 |
+
exact Prod.ext (Fin.ext hi) hqeq
|
| 32 |
+
|
| 33 |
+
theorem childInputCode_bound {M n : ℕ} (input : Fin M × TargetInterval n) :
|
| 34 |
+
childInputCode input < M * (n + 1) ^ 2 := by
|
| 35 |
+
have hlow := input.2.ordered.trans input.2.valid
|
| 36 |
+
have hhigh := input.2.valid
|
| 37 |
+
have hlabel := input.1.isLt
|
| 38 |
+
have hM : 0 < M := by omega
|
| 39 |
+
have hinner : input.2.lo + (n + 1) * input.2.hi < (n + 1) ^ 2 := by
|
| 40 |
+
nlinarith only [hlow, hhigh]
|
| 41 |
+
unfold childInputCode
|
| 42 |
+
nlinarith only [hlabel, Nat.mul_le_mul_left M (Nat.succ_le_of_lt hinner)]
|
| 43 |
+
|
| 44 |
+
def childInputBits (M n : ℕ) : ℕ := Nat.clog 2 (M * (n + 1) ^ 2 + 1)
|
| 45 |
+
|
| 46 |
+
theorem childInputCode_fits {M n : ℕ} (input : Fin M × TargetInterval n) :
|
| 47 |
+
childInputCode input < 2 ^ childInputBits M n := by
|
| 48 |
+
exact (childInputCode_bound input).trans_le
|
| 49 |
+
((Nat.le_succ _).trans (Nat.le_pow_clog (by decide : 1 < 2) _))
|
| 50 |
+
|
| 51 |
+
theorem childInputBinaryKey_injective (M n : ℕ) :
|
| 52 |
+
Function.Injective (fun input : Fin M × TargetInterval n =>
|
| 53 |
+
binaryMemoKey (childInputBits M n) (childInputCode input)) := by
|
| 54 |
+
intro input other heq
|
| 55 |
+
apply childInputCode_injective M n
|
| 56 |
+
exact binaryMemoKey_injective _ (childInputCode_fits input) (childInputCode_fits other) heq
|
| 57 |
+
|
| 58 |
+
theorem childInputBits_le (M n H : ℕ) (hM : M ≤ 2 ^ H) (hn : n + 1 ≤ 2 ^ H) :
|
| 59 |
+
childInputBits M n ≤ 3 * H + 1 := by
|
| 60 |
+
apply (Nat.clog_le_iff_le_pow (by decide : 1 < 2)).2
|
| 61 |
+
have hproduct : M * (n + 1) ^ 2 ≤ 2 ^ (3 * H) := by
|
| 62 |
+
calc
|
| 63 |
+
_ ≤ 2 ^ H * (2 ^ H) ^ 2 := Nat.mul_le_mul hM (Nat.pow_le_pow_left hn 2)
|
| 64 |
+
_ = _ := by rw [← pow_mul, ← pow_add]; congr 1; omega
|
| 65 |
+
have hone : 1 ≤ 2 ^ (3 * H) := one_le_pow₀ (by decide : 1 ≤ (2 : ℕ))
|
| 66 |
+
calc
|
| 67 |
+
_ ≤ 2 ^ (3 * H) + 2 ^ (3 * H) := Nat.add_le_add hproduct hone
|
| 68 |
+
_ = 2 ^ (3 * H + 1) := by rw [pow_succ]; omega
|
| 69 |
+
|
| 70 |
+
end EditApproximation
|
| 71 |
+
|
| 72 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalInputGuard.lean
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.ParameterNumericalConstruction
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Binary.BinaryAffineGuard
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalUniformAccuracy
|
| 4 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
namespace OAI
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
/-- Prefix rejection precedes arithmetic involving the accuracy word. -/
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
theorem physicalLargeInputWithWork_value (N : ℕ) (epsilon : BinaryFraction) :
|
| 15 |
+
(physicalLargeInputWithWork N epsilon).1 = decide (physicalLargeInput N epsilon) := by
|
| 16 |
+
apply Bool.eq_iff_iff.mpr
|
| 17 |
+
by_cases hi : (inspectAccuracyWithWork (inputHeight N) epsilon).1.isSome = true
|
| 18 |
+
· have hc : (binaryNaturalCompareWithWork (inputSmallLog N) (2 ^ 1000)).1 ≠ .lt ↔
|
| 19 |
+
2 ^ 1000 ≤ inputSmallLog N := by
|
| 20 |
+
rw [ne_eq, binaryNaturalCompareWithWork_lt, not_lt]
|
| 21 |
+
have ha : (BinaryFraction.ltWithWork
|
| 22 |
+
(BinaryFraction.canonicalMulWithWork (BinaryFraction.nat (inputSmallLog N)) epsilon).1
|
| 23 |
+
(BinaryFraction.nat 10)).1 ≠ true ↔ 10 ≤ (inputSmallLog N : ℚ) * epsilon.value := by
|
| 24 |
+
rw [ne_eq, BinaryFraction.ltWithWork_value, BinaryFraction.canonicalMulWithWork_value,
|
| 25 |
+
BinaryFraction.nat_value, BinaryFraction.nat_value, not_lt]
|
| 26 |
+
norm_num
|
| 27 |
+
have hm : (binaryNaturalCompareWithWork (inputHeight N)
|
| 28 |
+
(inputBitLengthWithWork
|
| 29 |
+
(onlineMassWithWork (integerParameters N).M (integerParameters N).P (inputHeight N)).1).1).1 ≠ .lt ↔
|
| 30 |
+
Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P
|
| 31 |
+
(inputHeight N)) ≤ inputHeight N := by
|
| 32 |
+
rw [ne_eq, binaryNaturalCompareWithWork_lt, inputBitLengthWithWork_spec,
|
| 33 |
+
onlineMassWithWork_value, not_lt]
|
| 34 |
+
simp only [physicalLargeInputWithWork, hi, ite_true, decide_eq_true_eq,
|
| 35 |
+
physicalLargeInput, largeAccuracyInput, hc, ha, hm, true_and, and_assoc]
|
| 36 |
+
· simp only [physicalLargeInputWithWork, hi, ite_false, Bool.false_eq_true, decide_eq_true_eq,
|
| 37 |
+
physicalLargeInput, false_and]
|
| 38 |
+
|
| 39 |
+
theorem physicalLargeInputWithWork_cost (N : ℕ) (epsilon : BinaryFraction)
|
| 40 |
+
(hmass : Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P
|
| 41 |
+
(inputHeight N)) ≤ inputHeight N) :
|
| 42 |
+
(physicalLargeInputWithWork N epsilon).2 ≤ 100000 * (inputHeight N + 1005) ^ 2 := by
|
| 43 |
+
let B := (inputHeight N) + 1005
|
| 44 |
+
have hi := inspectAccuracyWithWork_cost (inputHeight N) epsilon
|
| 45 |
+
by_cases haccepted : (inspectAccuracyWithWork (inputHeight N) epsilon).1.isSome = true
|
| 46 |
+
· have hepsilon : epsilon.width ≤ (inputHeight N) := by
|
| 47 |
+
rw [inspectAccuracyWithWork_spec] at haccepted
|
| 48 |
+
split_ifs at haccepted with he
|
| 49 |
+
· exact he
|
| 50 |
+
· cases haccepted
|
| 51 |
+
have hell : Nat.size (inputSmallLog N) + 2 ≤ B := by
|
| 52 |
+
have hs := Nat.size_le_size (computed_smallLog_le_height N)
|
| 53 |
+
have hh : Nat.size (inputHeight N) ≤ (inputHeight N) + 1 := by
|
| 54 |
+
apply Nat.size_le.mpr
|
| 55 |
+
exact Nat.lt_two_pow_self.trans_le (Nat.pow_le_pow_right (by decide) (Nat.le_succ (inputHeight N)))
|
| 56 |
+
dsimp only [B]
|
| 57 |
+
omega
|
| 58 |
+
have hleft : (BinaryFraction.nat (inputSmallLog N)).width ≤ B :=
|
| 59 |
+
(BinaryFraction.nat_width_le _).trans hell
|
| 60 |
+
have hright : epsilon.width ≤ B := hepsilon.trans (by dsimp [B]; omega)
|
| 61 |
+
have hten : (BinaryFraction.nat 10).width ≤ 4 * B + 2 := by
|
| 62 |
+
have ht := BinaryFraction.nat_width_le 10
|
| 63 |
+
rw [show Nat.size 10 = 4 from by decide] at ht
|
| 64 |
+
dsimp only [B]
|
| 65 |
+
omega
|
| 66 |
+
have hp := BinaryFraction.canonicalMulWithWork_cost
|
| 67 |
+
(BinaryFraction.nat (inputSmallLog N)) epsilon B hleft hright
|
| 68 |
+
have hpw := BinaryFraction.canonicalMulWithWork_width
|
| 69 |
+
(BinaryFraction.nat (inputSmallLog N)) epsilon B hleft hright
|
| 70 |
+
have ha := BinaryFraction.ltWithWork_cost
|
| 71 |
+
(BinaryFraction.canonicalMulWithWork (BinaryFraction.nat (inputSmallLog N)) epsilon).1
|
| 72 |
+
(BinaryFraction.nat 10) (4 * B + 2) hpw hten
|
| 73 |
+
have ht := binaryNaturalCompareWithWork_cost (inputSmallLog N) (2 ^ 1000)
|
| 74 |
+
have hc := binaryNaturalCompareWithWork_cost (inputHeight N)
|
| 75 |
+
(Nat.size (localOnlineMassBound (integerParameters N).M (integerParameters N).P (inputHeight N)))
|
| 76 |
+
have hHsize : Nat.size (inputHeight N) ≤ (inputHeight N) + 1 := by
|
| 77 |
+
apply Nat.size_le.mpr
|
| 78 |
+
exact Nat.lt_two_pow_self.trans_le (Nat.pow_le_pow_right (by decide) (Nat.le_succ (inputHeight N)))
|
| 79 |
+
have hmsize : Nat.size (Nat.size (localOnlineMassBound (integerParameters N).M
|
| 80 |
+
(integerParameters N).P (inputHeight N))) ≤ (inputHeight N) + 1 := (Nat.size_le_size hmass).trans hHsize
|
| 81 |
+
simp only [Nat.size_pow] at ht
|
| 82 |
+
simp only [physicalLargeInputWithWork, haccepted, ite_true, inputBitLengthWithWork_spec,
|
| 83 |
+
onlineMassWithWork_value, onlineMassWithWork_cost]
|
| 84 |
+
change _ ≤ 100000 * B ^ 2
|
| 85 |
+
dsimp only [B] at hp ha hell ⊢
|
| 86 |
+
nlinarith only [hp, ha, ht, hi, hc, hHsize, hmsize, hmass, hell]
|
| 87 |
+
· simp only [physicalLargeInputWithWork, haccepted, Bool.false_eq_true, ite_false]
|
| 88 |
+
nlinarith only [hi, Nat.zero_le (inputHeight N)]
|
| 89 |
+
|
| 90 |
+
end EditApproximation
|
| 91 |
+
|
| 92 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLeaves.lean
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.StageWarmup
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
/-! Exact source leaves remain exact throughout the actual physical warmup. -/
|
| 6 |
+
|
| 7 |
+
namespace EditApproximation
|
| 8 |
+
|
| 9 |
+
open Finset
|
| 10 |
+
|
| 11 |
+
theorem physicalSource_length_eq {α : Type*} {M J : ℕ} (source : List α)
|
| 12 |
+
(node : PhysicalNode M J) : (physicalSource source node).length =
|
| 13 |
+
(physicalSourceInterval source.length node).hi - (physicalSourceInterval source.length node).lo := by
|
| 14 |
+
simp only [physicalSource, substring, List.length_drop, List.length_take,
|
| 15 |
+
Nat.min_eq_left (physicalSourceInterval source.length node).valid]
|
| 16 |
+
|
| 17 |
+
theorem physicalBellman_at_leaf {α : Type*} {M J : ℕ} (source target : List α)
|
| 18 |
+
(P : ℕ) (L : ℝ) (initial : PhysicalEntry M J target.length → ℝ)
|
| 19 |
+
(representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length))
|
| 20 |
+
(value : PhysicalEntry M J target.length → ℝ) (node : PhysicalNode M J)
|
| 21 |
+
(hleaf : (physicalSourceInterval source.length node).hi -
|
| 22 |
+
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
|
| 23 |
+
physicalBellman source target P L initial representatives value (node, q) = initial (node, q) := by
|
| 24 |
+
classical
|
| 25 |
+
unfold physicalBellman
|
| 26 |
+
dsimp only
|
| 27 |
+
split_ifs <;> rfl
|
| 28 |
+
|
| 29 |
+
theorem physicalWarmup_at_leaf {α : Type*} {M J : ℕ} (source target : List α)
|
| 30 |
+
(P : ℕ) (L : ℝ) (initial : PhysicalEntry M J target.length → ℝ)
|
| 31 |
+
(representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length))
|
| 32 |
+
(t : ℕ) (node : PhysicalNode M J)
|
| 33 |
+
(hleaf : (physicalSourceInterval source.length node).hi -
|
| 34 |
+
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
|
| 35 |
+
physicalWarmup source target P L initial representatives t (node, q) = initial (node, q) := by
|
| 36 |
+
cases t with
|
| 37 |
+
| zero => rfl
|
| 38 |
+
| succ t => exact physicalBellman_at_leaf source target P L initial representatives _ node hleaf q
|
| 39 |
+
|
| 40 |
+
theorem rationalPhysicalWarmup_at_leaf {α : Type*} {M J : ℕ} (source target : List α)
|
| 41 |
+
(P : ℕ) (L : ℚ) (initial : PhysicalEntry M J target.length → ℚ)
|
| 42 |
+
(representatives : PhysicalNode M J → List (ℕ × TargetInterval target.length))
|
| 43 |
+
(t : ℕ) (node : PhysicalNode M J)
|
| 44 |
+
(hleaf : (physicalSourceInterval source.length node).hi -
|
| 45 |
+
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
|
| 46 |
+
rationalPhysicalWarmup source target P L initial representatives t (node, q) = initial (node, q) := by
|
| 47 |
+
apply (Rat.cast_inj (α := ℝ)).mp
|
| 48 |
+
rw [rationalPhysicalWarmup_cast]
|
| 49 |
+
exact physicalWarmup_at_leaf source target P (L : ℝ) (fun s => (initial s : ℝ)) representatives t node hleaf q
|
| 50 |
+
|
| 51 |
+
theorem stageWarmup_at_leaf {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α)
|
| 52 |
+
(U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ)
|
| 53 |
+
(t : ℕ) (node : PhysicalNode M J)
|
| 54 |
+
(hleaf : (physicalSourceInterval source.length node).hi -
|
| 55 |
+
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
|
| 56 |
+
stageWarmup source target U N P F A t (node, q) =
|
| 57 |
+
stateEditCost (physicalSource source node) target q := by
|
| 58 |
+
unfold stageWarmup
|
| 59 |
+
rw [rationalPhysicalWarmup_at_leaf source target P (128 * F) _ _ t node hleaf q]
|
| 60 |
+
have hlength : (physicalSource source node).length ≤ 1 := (physicalSource_length_eq source node).trans_le hleaf
|
| 61 |
+
simp only [stageInitial, physicalInitialTable, ite_eq_left hlength]
|
| 62 |
+
rw [shortSourceCost_eq_edit _ _ hlength]
|
| 63 |
+
rfl
|
| 64 |
+
|
| 65 |
+
theorem stageWarmupMass_at_leaf {α : Type*} [DecidableEq α] {M J : ℕ} (source target : List α)
|
| 66 |
+
(U : PhysicalEntry M J target.length → ℕ) (N P F : ℕ) (A : ℚ)
|
| 67 |
+
(T : ℕ) (hT : 0 < T) (node : PhysicalNode M J)
|
| 68 |
+
(hleaf : (physicalSourceInterval source.length node).hi -
|
| 69 |
+
(physicalSourceInterval source.length node).lo ≤ 1) (q : TargetInterval target.length) :
|
| 70 |
+
stageWarmupMass source target U N P F A T (node, q) =
|
| 71 |
+
stateEditCost (physicalSource source node) target q := by
|
| 72 |
+
change (∑ t ∈ range T, stageWarmup source target U N P F A t (node, q)) / T = _
|
| 73 |
+
simp_rw [stageWarmup_at_leaf source target U N P F A _ node hleaf q]
|
| 74 |
+
simp only [sum_const, card_range, nsmul_eq_mul]
|
| 75 |
+
have hTr : (T : ℚ) ≠ 0 := by exact_mod_cast hT.ne'
|
| 76 |
+
exact mul_div_cancel_left₀ _ hTr
|
| 77 |
+
|
| 78 |
+
end EditApproximation
|
| 79 |
+
|
| 80 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalDenominator.lean
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalValueBits
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalOnlineProgram
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! Denominator and bit bounds for the local evaluator on every incoming
|
| 7 |
+
seed. The proofs use the literal local candidates and do not pass through
|
| 8 |
+
the good-seed equality with the complete evaluator. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open Finset
|
| 13 |
+
|
| 14 |
+
theorem physicalLocalWarmup_den_one {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 15 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 16 |
+
(N P F : ℕ) (A : ℚ) (t : ℕ) (state : PhysicalEntry M J target.length) :
|
| 17 |
+
(physicalLocalWarmup source target U N P F A t state).den = 1 := by
|
| 18 |
+
induction t generalizing state with
|
| 19 |
+
| zero => exact stageInitial_den_one source target U N P F A state
|
| 20 |
+
| succ t ih =>
|
| 21 |
+
rw [physicalLocalWarmup]
|
| 22 |
+
split_ifs
|
| 23 |
+
· exact stageInitial_den_one source target U N P F A state
|
| 24 |
+
· apply Nat.eq_one_of_dvd_one
|
| 25 |
+
apply rationalMinimum_den_dvd
|
| 26 |
+
· rw [stageInitial_den_one source target U N P F A]
|
| 27 |
+
· intro v hv
|
| 28 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 29 |
+
exact rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _)
|
| 30 |
+
(by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F))
|
| 31 |
+
(rationalActualWideActions_connection_den _ _ _ action ha)
|
| 32 |
+
(fun i => by rw [ih])
|
| 33 |
+
· exact stageInitial_den_one source target U N P F A state
|
| 34 |
+
|
| 35 |
+
theorem rationalLocalWideStep_den_dvd {α : Type*} (source target : List α) {M D : ℕ}
|
| 36 |
+
(parent : TargetInterval source.length) (N P F exponent Q m : ℕ) (hm : 0 < m)
|
| 37 |
+
(tau a : ℚ) (parentInitial : TargetInterval target.length → ℚ)
|
| 38 |
+
(childMass childInitial old current : Fin M → TargetInterval target.length → ℚ)
|
| 39 |
+
(draw : CellGroupDraws M F Q) (online : List (PhysicalRationalAction M target.length))
|
| 40 |
+
(hinitial : ∀ q, (parentInitial q).den ∣ D)
|
| 41 |
+
(hold : ∀ i r, (old i r).den ∣ D) (hcurrent : ∀ i r, (current i r).den ∣ D)
|
| 42 |
+
(honline : ∀ action ∈ online, action.connection.den = 1)
|
| 43 |
+
(q : TargetInterval target.length) :
|
| 44 |
+
(rationalLocalWideStep source target parent N P F exponent Q tau a (1 / (m : ℚ))
|
| 45 |
+
parentInitial childMass childInitial old current draw online q).den ∣ D * (m + 1) := by
|
| 46 |
+
have hvalue (child : Fin M → TargetInterval target.length → ℚ)
|
| 47 |
+
(hchild : ∀ i r, (child i r).den ∣ D)
|
| 48 |
+
(action : PhysicalRationalAction M target.length) (hconn : action.connection.den = 1) :
|
| 49 |
+
(rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F)
|
| 50 |
+
(fun is => child is.1 is.2) q action).den ∣ D :=
|
| 51 |
+
rationalActionValue_den_dvd _ _ _ _ _ (Rat.den_natCast _)
|
| 52 |
+
(by simpa only [Nat.cast_mul, Nat.cast_ofNat] using Rat.den_natCast (128 * F))
|
| 53 |
+
hconn (fun i => hchild _ _)
|
| 54 |
+
unfold rationalLocalWideStep
|
| 55 |
+
apply rationalRefinementUpdate_den_dvd m D hm
|
| 56 |
+
· apply rationalMinimum_den_dvd
|
| 57 |
+
· apply rationalMinimum_den_dvd _ _ D (hinitial q)
|
| 58 |
+
intro v hv
|
| 59 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 60 |
+
exact hvalue old hold action (rationalActualWideActions_connection_den _ _ _ action ha)
|
| 61 |
+
· intro v hv
|
| 62 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hv
|
| 63 |
+
have hwide := completeCellGroupActions_wide source target parent N P F exponent Q tau a
|
| 64 |
+
parentInitial childMass childInitial current draw action
|
| 65 |
+
(localCellGroupActions_subset source target parent N P F exponent Q tau a parentInitial
|
| 66 |
+
childMass childInitial current draw q action ha)
|
| 67 |
+
exact hvalue current hcurrent action (rationalActualWideActions_connection_den _ _ _ action hwide)
|
| 68 |
+
· intro v hv
|
| 69 |
+
apply rationalOnlineMinimum_den_dvd _ D _ v hv
|
| 70 |
+
intro value hvalueMem
|
| 71 |
+
obtain ⟨action, ha, rfl⟩ := List.mem_map.mp hvalueMem
|
| 72 |
+
exact hvalue current hcurrent action (honline action ha)
|
| 73 |
+
|
| 74 |
+
theorem keyedOnlineCandidate_connection_den {α : Type*} (source target : List α) {M : ℕ}
|
| 75 |
+
(parent : TargetInterval source.length) (P F exponent H b : ℕ) (tau eta kappa : ℚ)
|
| 76 |
+
(child initial : Fin M → TargetInterval target.length → ℚ)
|
| 77 |
+
(children : PhysicalChildTables M target.length) (t : ℕ)
|
| 78 |
+
(r : TargetInterval target.length) (integer : ℕ) (action : PhysicalRationalAction M target.length)
|
| 79 |
+
(h : keyedOnlineCandidate source target parent P F exponent H b tau eta kappa
|
| 80 |
+
child initial children t r integer = some action) : action.connection.den = 1 := by
|
| 81 |
+
unfold keyedOnlineCandidate at h
|
| 82 |
+
dsimp only at h
|
| 83 |
+
split_ifs at h
|
| 84 |
+
split at h
|
| 85 |
+
· cases h
|
| 86 |
+
· cases Option.some.inj h
|
| 87 |
+
exact Rat.den_zero
|
| 88 |
+
|
| 89 |
+
theorem localOnlineCandidates_connection_den {α : Type*} (source target : List α) {M : ℕ}
|
| 90 |
+
(parent : TargetInterval source.length) (N P F exponent H : ℕ) (tau a eta kappa : ℚ)
|
| 91 |
+
(parentInitial : TargetInterval target.length → ℚ)
|
| 92 |
+
(child initial : Fin M → TargetInterval target.length → ℚ)
|
| 93 |
+
(children : PhysicalChildTables M target.length) (t : ℕ)
|
| 94 |
+
(integer : ℕ → TargetInterval target.length → ℕ) (q : TargetInterval target.length)
|
| 95 |
+
(action : PhysicalRationalAction M target.length)
|
| 96 |
+
(ha : action ∈ localOnlineCandidates source target parent N P F exponent H tau a eta kappa
|
| 97 |
+
parentInitial child initial children t integer q) : action.connection.den = 1 := by
|
| 98 |
+
obtain ⟨b, _, _, hcandidate⟩ :=
|
| 99 |
+
(localOnlineCandidates_mem source target parent N P F exponent H tau a eta kappa
|
| 100 |
+
parentInitial child initial children t integer q action).mp ha
|
| 101 |
+
exact keyedOnlineCandidate_connection_den source target parent P F exponent H b tau eta kappa
|
| 102 |
+
child initial children t _ _ action hcandidate
|
| 103 |
+
|
| 104 |
+
theorem physicalLocalOnline_connection_den {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 105 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 106 |
+
(N P F exponent H T : ℕ) (A tau eta kappa : ℚ)
|
| 107 |
+
(integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 108 |
+
(node : PhysicalNode M J) (children : PhysicalChildTables M target.length)
|
| 109 |
+
(t : ℕ) (q : TargetInterval target.length) (action : PhysicalRationalAction M target.length)
|
| 110 |
+
(ha : action ∈ physicalLocalOnline source target U N P F exponent H T A tau eta kappa
|
| 111 |
+
integer node children t q) : action.connection.den = 1 := by
|
| 112 |
+
unfold physicalLocalOnline at ha
|
| 113 |
+
split_ifs at ha with hbelow
|
| 114 |
+
· exact localOnlineCandidates_connection_den source target (physicalSourceInterval source.length node)
|
| 115 |
+
N P F exponent H tau (refinementFactor A F) eta kappa _ _ _ children (t - 1) _ q action ha
|
| 116 |
+
· exact False.elim (List.not_mem_nil ha)
|
| 117 |
+
|
| 118 |
+
theorem physicalLocalRefinement_den_dvd {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 119 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 120 |
+
(N P F exponent Q : ℕ) (A tau : ℚ) (T ell : ℕ) (hell : 0 < ell)
|
| 121 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 122 |
+
(online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ →
|
| 123 |
+
TargetInterval target.length → List (PhysicalRationalAction M target.length))
|
| 124 |
+
(honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1)
|
| 125 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) :
|
| 126 |
+
(physicalLocalRefinement source target U N P F exponent Q A tau
|
| 127 |
+
(1 / (ell : ℚ) ^ 10) T draw online node t q).den ∣ (ell ^ 10 + 1) ^ (J - node.1.val) := by
|
| 128 |
+
rw [physicalLocalRefinement]
|
| 129 |
+
split_ifs with hbelow hleaf
|
| 130 |
+
· rw [stageInitial_den_one source target U N P F A]
|
| 131 |
+
exact one_dvd _
|
| 132 |
+
· dsimp only
|
| 133 |
+
cases t with
|
| 134 |
+
| zero =>
|
| 135 |
+
rw [physicalLocalWarmup_den_one source target U N P F A]
|
| 136 |
+
exact one_dvd _
|
| 137 |
+
| succ t =>
|
| 138 |
+
have hheight : J - node.1.val = (J - (node.1.val + 1)) + 1 := by omega
|
| 139 |
+
rw [hheight]
|
| 140 |
+
conv_rhs => rw [pow_succ]
|
| 141 |
+
have hdelta : (1 / (ell : ℚ) ^ 10) = 1 / ((ell ^ 10 : ℕ) : ℚ) := by rw [Nat.cast_pow]
|
| 142 |
+
rw [hdelta]
|
| 143 |
+
apply rationalLocalWideStep_den_dvd source target _ N P F exponent Q (ell ^ 10)
|
| 144 |
+
(pow_pos hell 10) tau (refinementFactor A F)
|
| 145 |
+
· intro r
|
| 146 |
+
rw [stageInitial_den_one source target U N P F A]
|
| 147 |
+
exact one_dvd _
|
| 148 |
+
· intro i r
|
| 149 |
+
simpa only [Nat.cast_pow, physicalChild] using
|
| 150 |
+
physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell
|
| 151 |
+
draw online honline (physicalChild node hbelow i) t r
|
| 152 |
+
· intro i r
|
| 153 |
+
simpa only [Nat.cast_pow, physicalChild] using
|
| 154 |
+
physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell
|
| 155 |
+
draw online honline (physicalChild node hbelow i) (t + 1) r
|
| 156 |
+
· exact honline _ _ _ _
|
| 157 |
+
· rw [stageInitial_den_one source target U N P F A]
|
| 158 |
+
exact one_dvd _
|
| 159 |
+
termination_by J - node.1.val
|
| 160 |
+
decreasing_by
|
| 161 |
+
all_goals
|
| 162 |
+
unfold physicalChild
|
| 163 |
+
dsimp only
|
| 164 |
+
omega
|
| 165 |
+
|
| 166 |
+
theorem physicalLocalRefinement_encoding_bits {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 167 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 168 |
+
(N P F exponent Q : ℕ) (A tau : ℚ) (hsize : source.length + target.length ≤ N)
|
| 169 |
+
(T ell : ℕ) (hell : 0 < ell)
|
| 170 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 171 |
+
(online : PhysicalNode M J → PhysicalChildTables M target.length → ℕ →
|
| 172 |
+
TargetInterval target.length → List (PhysicalRationalAction M target.length))
|
| 173 |
+
(honline : ∀ node children t q action, action ∈ online node children t q → action.connection.den = 1)
|
| 174 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) :
|
| 175 |
+
rationalEncodingBits (physicalLocalRefinement source target U N P F exponent Q A tau
|
| 176 |
+
(1 / (ell : ℚ) ^ 10) T draw online node t q) ≤
|
| 177 |
+
Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * Nat.size (ell ^ 10 + 1) + 3 := by
|
| 178 |
+
let value := physicalLocalRefinement source target U N P F exponent Q A tau
|
| 179 |
+
(1 / (ell : ℚ) ^ 10) T draw online node t q
|
| 180 |
+
have hbounds := physicalLocalRefinement_bounds source target U N P F exponent Q A tau
|
| 181 |
+
(1 / (ell : ℚ) ^ 10) T (by positivity) draw online node t q
|
| 182 |
+
have hupper : value ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by
|
| 183 |
+
simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using
|
| 184 |
+
hbounds.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize (node, q))
|
| 185 |
+
have h := rationalEncodingBits_of_den_dvd value ((32 * F + 1) * N)
|
| 186 |
+
((ell ^ 10 + 1) ^ (J - node.1.val)) (by rw [abs_of_nonneg hbounds.1]; exact hupper)
|
| 187 |
+
(pow_pos (by omega) _) (physicalLocalRefinement_den_dvd source target U N P F exponent Q
|
| 188 |
+
A tau T ell hell draw online honline node t q)
|
| 189 |
+
have hpower := natural_power_bit_length (ell ^ 10 + 1) (J - node.1.val)
|
| 190 |
+
have hpowerTwice := Nat.mul_le_mul_left 2 hpower
|
| 191 |
+
simp only [Nat.mul_add, Nat.mul_one, ← Nat.mul_assoc] at hpowerTwice
|
| 192 |
+
change rationalEncodingBits value ≤ _
|
| 193 |
+
omega
|
| 194 |
+
|
| 195 |
+
theorem physicalLocalOnlineRefinement_den_dvd {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 196 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 197 |
+
(N P F exponent H Q : ℕ) (A tau eta kappa : ℚ) (T ell : ℕ) (hell : 0 < ell)
|
| 198 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 199 |
+
(integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 200 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) :
|
| 201 |
+
(physicalLocalRefinement source target U N P F exponent Q A tau (1 / (ell : ℚ) ^ 10)
|
| 202 |
+
T draw (physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer)
|
| 203 |
+
node t q).den ∣ (ell ^ 10 + 1) ^ (J - node.1.val) :=
|
| 204 |
+
physicalLocalRefinement_den_dvd source target U N P F exponent Q A tau T ell hell draw _
|
| 205 |
+
(physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer) node t q
|
| 206 |
+
|
| 207 |
+
theorem physicalLocalWarmup_encoding_bits {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 208 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 209 |
+
(N P F : ℕ) (A : ℚ) (hsize : source.length + target.length ≤ N)
|
| 210 |
+
(t : ℕ) (state : PhysicalEntry M J target.length) :
|
| 211 |
+
rationalEncodingBits (physicalLocalWarmup source target U N P F A t state) ≤
|
| 212 |
+
Nat.size ((32 * F + 1) * N) + 3 := by
|
| 213 |
+
let value := physicalLocalWarmup source target U N P F A t state
|
| 214 |
+
have hbounds := physicalLocalWarmup_bounds source target U N P F A t state
|
| 215 |
+
have hupper : value ≤ (((32 * F + 1) * N : ℕ) : ℚ) := by
|
| 216 |
+
simpa only [Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using
|
| 217 |
+
hbounds.2.trans (stageInitial_upper_all_seeds source target U N P F A hsize state)
|
| 218 |
+
have hden : value.den ∣ 1 := by
|
| 219 |
+
rw [physicalLocalWarmup_den_one source target U N P F A]
|
| 220 |
+
have h := rationalEncodingBits_of_den_dvd value ((32 * F + 1) * N) 1
|
| 221 |
+
(by rw [abs_of_nonneg hbounds.1]; exact hupper) (by decide) hden
|
| 222 |
+
simpa only [Nat.size_one, Nat.mul_one, Nat.add_assoc] using h
|
| 223 |
+
|
| 224 |
+
theorem physicalLocalOnlineRefinement_encoding_bits {α : Type*} [DecidableEq α]
|
| 225 |
+
{M J R : ℕ} [NeZero R]
|
| 226 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 227 |
+
(N P F exponent H Q : ℕ) (A tau eta kappa : ℚ)
|
| 228 |
+
(hsize : source.length + target.length ≤ N) (T ell : ℕ) (hell : 0 < ell)
|
| 229 |
+
(draw : PhysicalInternalNode M J → ℕ → CellGroupDraws M F Q)
|
| 230 |
+
(integer : PhysicalInternalNode M J → Fin R → ℕ → TargetInterval target.length → ℕ)
|
| 231 |
+
(node : PhysicalNode M J) (t : ℕ) (q : TargetInterval target.length) :
|
| 232 |
+
rationalEncodingBits (physicalLocalRefinement source target U N P F exponent Q A tau
|
| 233 |
+
(1 / (ell : ℚ) ^ 10) T draw
|
| 234 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa integer) node t q) ≤
|
| 235 |
+
Nat.size ((32 * F + 1) * N) + 2 * (J - node.1.val) * Nat.size (ell ^ 10 + 1) + 3 :=
|
| 236 |
+
physicalLocalRefinement_encoding_bits source target U N P F exponent Q A tau hsize T ell hell draw _
|
| 237 |
+
(physicalLocalOnline_connection_den source target U N P F exponent H T A tau eta kappa integer) node t q
|
| 238 |
+
|
| 239 |
+
end EditApproximation
|
| 240 |
+
|
| 241 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupKeys.lean
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalOnlineKeys
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Definitions
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
namespace OAI
|
| 6 |
+
|
| 7 |
+
/-! Every whole-cell stream used by the complete program has a bounded
|
| 8 |
+
physical key. Its two cell coordinates are at most n*2^exponent. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
open MeasureTheory ProbabilityTheory
|
| 13 |
+
|
| 14 |
+
theorem list_eraseDups_nodup {α : Type*} [BEq α] [LawfulBEq α] (items : List α) :
|
| 15 |
+
items.eraseDups.Nodup := by
|
| 16 |
+
cases items with
|
| 17 |
+
| nil => simp
|
| 18 |
+
| cons first rest =>
|
| 19 |
+
rw [List.eraseDups_cons, List.nodup_cons]
|
| 20 |
+
refine ⟨?_, list_eraseDups_nodup _⟩
|
| 21 |
+
intro hmem
|
| 22 |
+
have hfalse := (List.mem_filter.mp (List.mem_eraseDups.mp hmem)).2
|
| 23 |
+
simp at hfalse
|
| 24 |
+
termination_by items.length
|
| 25 |
+
decreasing_by
|
| 26 |
+
simpa only [List.length_cons] using
|
| 27 |
+
Nat.lt_succ_of_le (List.length_filter_le (fun item => !(item == first)) rest)
|
| 28 |
+
|
| 29 |
+
theorem targetCell_coordinate_bound {n : ℕ} (exponent b : ℕ) (hb : 1 ≤ b)
|
| 30 |
+
(q : TargetInterval n) :
|
| 31 |
+
(targetCell ((2 : ℚ) ^ (-(exponent : ℤ)) * b) q).1 ≤ n * 2 ^ exponent ∧
|
| 32 |
+
(targetCell ((2 : ℚ) ^ (-(exponent : ℤ)) * b) q).2 ≤ n * 2 ^ exponent := by
|
| 33 |
+
have hside : (0 : ℚ) < (2 : ℚ) ^ (-(exponent : ℤ)) * b := by positivity
|
| 34 |
+
have hcoordinate (p : ℕ) (hp : p ≤ n) :
|
| 35 |
+
⌊(p : ℚ) / ((2 : ℚ) ^ (-(exponent : ℤ)) * b)⌋₊ ≤ n * 2 ^ exponent := by
|
| 36 |
+
have hcancel : ((n * 2 ^ exponent : ℕ) : ℚ) *
|
| 37 |
+
((2 : ℚ) ^ (-(exponent : ℤ)) * b) = n * b := by
|
| 38 |
+
push_cast
|
| 39 |
+
rw [zpow_neg, zpow_natCast]
|
| 40 |
+
field_simp
|
| 41 |
+
have hmul : (p : ℚ) ≤ ((n * 2 ^ exponent : ℕ) : ℚ) *
|
| 42 |
+
((2 : ℚ) ^ (-(exponent : ℤ)) * b) := by
|
| 43 |
+
rw [hcancel]
|
| 44 |
+
exact_mod_cast hp.trans (Nat.le_mul_of_pos_right n (by omega))
|
| 45 |
+
have h := Nat.floor_le_floor ((div_le_iff₀ hside).2 hmul)
|
| 46 |
+
simpa only [Nat.floor_natCast] using h
|
| 47 |
+
exact ⟨hcoordinate q.lo (q.ordered.trans q.valid), hcoordinate q.hi q.valid⟩
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
section Keys
|
| 52 |
+
|
| 53 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 54 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 55 |
+
(N P F exponent : ℕ) (A : ℚ)
|
| 56 |
+
|
| 57 |
+
theorem physicalProgramCells_bounds (node : PhysicalNode M J)
|
| 58 |
+
(b : ℕ) (hb : 1 ≤ b) (cell : ℕ × ℕ)
|
| 59 |
+
(hcell : cell ∈ physicalProgramCells source target U N P F A exponent node b) :
|
| 60 |
+
cell.1 ≤ target.length * 2 ^ exponent ∧ cell.2 ≤ target.length * 2 ^ exponent := by
|
| 61 |
+
obtain ⟨br, _, rfl⟩ := List.mem_map.mp (List.mem_eraseDups.mp hcell)
|
| 62 |
+
exact targetCell_coordinate_bound exponent b hb br.2
|
| 63 |
+
|
| 64 |
+
theorem physicalGroupScale_positive
|
| 65 |
+
(key : PhysicalGroupKey source target U N P F A exponent) :
|
| 66 |
+
1 ≤ (dyadicScales N).get key.2.1 := by
|
| 67 |
+
have hm := List.get_mem (dyadicScales N) key.2.1
|
| 68 |
+
obtain ⟨e, _, heq⟩ := List.mem_map.mp hm
|
| 69 |
+
exact heq ▸ Nat.one_le_two_pow
|
| 70 |
+
|
| 71 |
+
def physicalGroupRawKey (key : PhysicalGroupKey source target U N P F A exponent) :
|
| 72 |
+
PhysicalLocalGroupKey M J N target.length exponent :=
|
| 73 |
+
let cell := (physicalProgramCells source target U N P F A exponent key.1.1
|
| 74 |
+
((dyadicScales N).get key.2.1)).get key.2.2
|
| 75 |
+
let bounds := physicalProgramCells_bounds source target U N P F exponent A key.1.1
|
| 76 |
+
((dyadicScales N).get key.2.1) (physicalGroupScale_positive source target U N P F exponent A key)
|
| 77 |
+
cell (List.get_mem _ key.2.2)
|
| 78 |
+
(key.1, key.2.1, ⟨cell.1, Nat.lt_succ_of_le bounds.1⟩, ⟨cell.2, Nat.lt_succ_of_le bounds.2⟩)
|
| 79 |
+
|
| 80 |
+
theorem physicalGroupRawKey_injective :
|
| 81 |
+
Function.Injective (physicalGroupRawKey source target U N P F exponent A) := by
|
| 82 |
+
rintro ⟨node, scale, cell⟩ ⟨node', scale', cell'⟩ heq
|
| 83 |
+
have hn := congrArg Prod.fst heq
|
| 84 |
+
change node = node' at hn
|
| 85 |
+
subst node'
|
| 86 |
+
have hs := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.1) heq
|
| 87 |
+
change scale = scale' at hs
|
| 88 |
+
subst scale'
|
| 89 |
+
have hlo := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.2.1.val) heq
|
| 90 |
+
have hhi := congrArg (fun key : PhysicalLocalGroupKey M J N target.length exponent => key.2.2.2.val) heq
|
| 91 |
+
simp only [physicalGroupRawKey] at hlo hhi
|
| 92 |
+
have hnodup : (physicalProgramCells source target U N P F A exponent node.1
|
| 93 |
+
((dyadicScales N).get scale)).Nodup := list_eraseDups_nodup _
|
| 94 |
+
have hcell := hnodup.injective_get (Prod.ext hlo hhi)
|
| 95 |
+
cases hcell
|
| 96 |
+
rfl
|
| 97 |
+
|
| 98 |
+
end Keys
|
| 99 |
+
|
| 100 |
+
abbrev PhysicalLocalGroupArray (M J N n exponent F Q R : ℕ)
|
| 101 |
+
(key : PhysicalLocalGroupKey M J N n exponent) :=
|
| 102 |
+
Fin R → ParentGroupDraw M (groupDyadicScales M ((dyadicScales N).get key.2.1) F).length
|
| 103 |
+
(fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1)
|
| 104 |
+
(groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h))
|
| 105 |
+
|
| 106 |
+
noncomputable def physicalLocalGroupArrayLaw (M J N n exponent F Q R : ℕ)
|
| 107 |
+
[NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 108 |
+
(key : PhysicalLocalGroupKey M J N n exponent) :
|
| 109 |
+
Measure (PhysicalLocalGroupArray M J N n exponent F Q R key) :=
|
| 110 |
+
Measure.pi fun _ : Fin R => groupSharedDrawLaw (M := M)
|
| 111 |
+
(fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1)
|
| 112 |
+
(groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h))
|
| 113 |
+
|
| 114 |
+
instance physicalLocalGroupArrayLaw_probability (M J N n exponent F Q R : ℕ)
|
| 115 |
+
[NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 116 |
+
(key : PhysicalLocalGroupKey M J N n exponent) :
|
| 117 |
+
IsProbabilityMeasure (physicalLocalGroupArrayLaw M J N n exponent F Q R key) := by
|
| 118 |
+
unfold physicalLocalGroupArrayLaw
|
| 119 |
+
infer_instance
|
| 120 |
+
|
| 121 |
+
theorem physicalLocalGroupDrawLaw_restrict {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 122 |
+
[NeZero M] [MeasurableSpace (Fin M)] [MeasurableSingletonClass (Fin M)]
|
| 123 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 124 |
+
(N P F exponent Q R : ℕ) (A : ℚ) :
|
| 125 |
+
(Measure.pi (physicalLocalGroupArrayLaw M J N target.length exponent F Q R)).map
|
| 126 |
+
(fun draw (key : PhysicalGroupKey source target U N P F A exponent) =>
|
| 127 |
+
draw (physicalGroupRawKey source target U N P F exponent A key)) =
|
| 128 |
+
Measure.pi (fun key : PhysicalGroupKey source target U N P F A exponent =>
|
| 129 |
+
Measure.pi (fun _ : Fin R => groupSharedDrawLaw (M := M)
|
| 130 |
+
(fun h => groupSampleCount M Q ((dyadicScales N).get key.2.1)
|
| 131 |
+
(groupDyadicScaleAt M ((dyadicScales N).get key.2.1) F h)))) :=
|
| 132 |
+
finite_pi_restrict_map _ _ (physicalGroupRawKey_injective source target U N P F exponent A)
|
| 133 |
+
|
| 134 |
+
end EditApproximation
|
| 135 |
+
|
| 136 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalGroupProgram.lean
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalGroupCones
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalSelectionProgram
|
| 3 |
+
|
| 4 |
+
namespace OAI
|
| 5 |
+
|
| 6 |
+
/-! The finite indexed group program has an equivalent cell-keyed
|
| 7 |
+
realization. Good initial seeds permit its whole cone to be evaluated
|
| 8 |
+
using only the directly enumerated query cells. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
section Program
|
| 13 |
+
|
| 14 |
+
variable {α : Type*} [DecidableEq α] {M J : ℕ}
|
| 15 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 16 |
+
(N P F exponent Q : ℕ) (A : ℚ)
|
| 17 |
+
|
| 18 |
+
def physicalGroupStreamsOfKeys {R : ℕ}
|
| 19 |
+
(draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q) :
|
| 20 |
+
PhysicalGroupStreams source target U N P F A exponent Q R :=
|
| 21 |
+
fun node scale cell time => draw node time ((dyadicScales N).get scale)
|
| 22 |
+
((physicalProgramCells source target U N P F A exponent node.1
|
| 23 |
+
((dyadicScales N).get scale)).get cell)
|
| 24 |
+
|
| 25 |
+
theorem physicalProgramCells_keyed (node : PhysicalNode M J) (b : ℕ) :
|
| 26 |
+
physicalProgramCells source target U N P F A exponent node b =
|
| 27 |
+
representativeCells N P F b (refinementFactor A F) ((2 : ℚ) ^ (-(exponent : ℤ)))
|
| 28 |
+
(fun q => stageInitial source target U N P F A (node, q)) := rfl
|
| 29 |
+
|
| 30 |
+
theorem physicalProgramGroups_keyed (T : ℕ) (tau : ℚ) {R : ℕ} [NeZero R]
|
| 31 |
+
(draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
|
| 32 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 33 |
+
(children : PhysicalChildTables M target.length) (t : ℕ) :
|
| 34 |
+
physicalProgramGroups source target U N P F A T exponent Q tau
|
| 35 |
+
(physicalGroupStreamsOfKeys source target U N P F exponent Q A draw) node children t =
|
| 36 |
+
completeCellGroupActions source target (physicalSourceInterval source.length node)
|
| 37 |
+
N P F exponent Q tau (refinementFactor A F)
|
| 38 |
+
(fun q => stageInitial source target U N P F A (node, q))
|
| 39 |
+
(physicalBandChildMassTable source target U N P F A T node hbelow)
|
| 40 |
+
(physicalBandChildInitial source target U N P F A node hbelow)
|
| 41 |
+
(fun i q => children i t q) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) := by
|
| 42 |
+
unfold physicalProgramGroups
|
| 43 |
+
rw [dite_eq_left hbelow]
|
| 44 |
+
unfold completeCellGroupActions
|
| 45 |
+
conv_rhs => rw [← List.map_get_finRange (dyadicScales N)]
|
| 46 |
+
rw [List.flatMap_map]
|
| 47 |
+
apply List.flatMap_congr
|
| 48 |
+
intro scale _
|
| 49 |
+
rw [← physicalProgramCells_keyed source target U N P F exponent A node]
|
| 50 |
+
conv_rhs => rw [← List.map_get_finRange (physicalProgramCells source target U N P F A exponent node
|
| 51 |
+
((dyadicScales N).get scale))]
|
| 52 |
+
simp only [List.filterMap_map, Function.comp_def, physicalGroupStreamsOfKeys]
|
| 53 |
+
|
| 54 |
+
/-- Actual chosen-group cone at one node, evaluated by bounded query
|
| 55 |
+
cell loops. The old-child fallback is arbitrary provided it is at most
|
| 56 |
+
the literal initial value. -/
|
| 57 |
+
theorem physicalProgramGroups_local_minimum (T : ℕ) (tau : ℚ) {R : ℕ} [NeZero R]
|
| 58 |
+
(draw : PhysicalInternalNode M J → Fin R → CellGroupDraws M F Q)
|
| 59 |
+
(node : PhysicalNode M J) (hbelow : node.1.val < J)
|
| 60 |
+
(children : PhysicalChildTables M target.length) (t : ℕ)
|
| 61 |
+
(q : TargetInterval target.length) (fallback : ℚ)
|
| 62 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 63 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 64 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 65 |
+
(hfallback : fallback ≤ stageInitial source target U N P F A (node, q))
|
| 66 |
+
(hchild : ∀ i r, 0 ≤ children i t r) :
|
| 67 |
+
rationalMinimum fallback
|
| 68 |
+
((localCellGroupActions source target (physicalSourceInterval source.length node)
|
| 69 |
+
N P F exponent Q tau (refinementFactor A F)
|
| 70 |
+
(fun r => stageInitial source target U N P F A (node, r))
|
| 71 |
+
(physicalBandChildMassTable source target U N P F A T node hbelow)
|
| 72 |
+
(physicalBandChildInitial source target U N P F A node hbelow)
|
| 73 |
+
(fun i r => children i t r) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q).map
|
| 74 |
+
(rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F)
|
| 75 |
+
(fun is => children is.1 t is.2) q)) =
|
| 76 |
+
rationalMinimum fallback
|
| 77 |
+
((physicalProgramGroups source target U N P F A T exponent Q tau
|
| 78 |
+
(physicalGroupStreamsOfKeys source target U N P F exponent Q A draw) node children t).map
|
| 79 |
+
(rationalActionValue (fun q r => targetEndpointDistance q r) (128 * F)
|
| 80 |
+
(fun is => children is.1 t is.2) q)) := by
|
| 81 |
+
rw [physicalProgramGroups_keyed source target U N P F exponent Q A T tau draw node hbelow children t]
|
| 82 |
+
have hfactor := refinementFactor_spec A F (by omega : 0 < F)
|
| 83 |
+
have hspatial : ∀ r, |stageInitial source target U N P F A (node, q) -
|
| 84 |
+
stageInitial source target U N P F A (node, r)| ≤ 32 * F * targetEndpointDistance q r := by
|
| 85 |
+
intro r
|
| 86 |
+
have hqr := physicalInitialTable_spatial source target U N P F A (refinementFactor A F)
|
| 87 |
+
hsize hP hF hA hfactor.1 hfactor.2 hseed node q r
|
| 88 |
+
have hrq := physicalInitialTable_spatial source target U N P F A (refinementFactor A F)
|
| 89 |
+
hsize hP hF hA hfactor.1 hfactor.2 hseed node r q
|
| 90 |
+
have hsym : targetEndpointDistance r q = targetEndpointDistance q r := by
|
| 91 |
+
exact congrArg₂ (· + ·) (Nat.dist_comm _ _) (Nat.dist_comm _ _)
|
| 92 |
+
rw [hsym] at hrq
|
| 93 |
+
apply abs_le.mpr
|
| 94 |
+
constructor <;> dsimp only [stageInitial] <;> linarith only [hqr, hrq]
|
| 95 |
+
exact localCellGroupMinimum_eq source target (physicalSourceInterval source.length node)
|
| 96 |
+
N P F exponent Q tau (refinementFactor A F)
|
| 97 |
+
(fun r => stageInitial source target U N P F A (node, r))
|
| 98 |
+
(physicalBandChildMassTable source target U N P F A T node hbelow)
|
| 99 |
+
(physicalBandChildInitial source target U N P F A node hbelow)
|
| 100 |
+
(fun i r => children i t r) (draw ⟨node, hbelow⟩ (Fin.ofNat R (t - 1))) q fallback
|
| 101 |
+
hfactor.1 hF hfallback hchild hspatial
|
| 102 |
+
|
| 103 |
+
end Program
|
| 104 |
+
|
| 105 |
+
end EditApproximation
|
| 106 |
+
|
| 107 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalJointProgram.lean
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalLocalProgramLaw
|
| 2 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRawOnlineProgram
|
| 3 |
+
import OAI.Combinatorics.EditApproximation.Refinement.PhysicalRawGroupProgram
|
| 4 |
+
|
| 5 |
+
namespace OAI
|
| 6 |
+
|
| 7 |
+
/-! Direct evaluation from the bounded joint random source agrees with
|
| 8 |
+
complete refinement. All complete-table indexing occurs in the proof. -/
|
| 9 |
+
|
| 10 |
+
namespace EditApproximation
|
| 11 |
+
|
| 12 |
+
section Joint
|
| 13 |
+
|
| 14 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero M] [NeZero R]
|
| 15 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 16 |
+
(N P F : ℕ) (A : ℚ) (T exponent H Q : ℕ) (tau eta kappa delta : ℚ)
|
| 17 |
+
(draw : PhysicalLocalProgramDraw (R := R) source target U N P F A T exponent H Q tau)
|
| 18 |
+
|
| 19 |
+
def physicalLocalJointValue (node : PhysicalNode M J) (t : ℕ)
|
| 20 |
+
(q : TargetInterval target.length) : ℚ :=
|
| 21 |
+
physicalLocalRefinement source target U N P F exponent Q A tau delta T
|
| 22 |
+
(fun label s => physicalRawGroupDraws M J N target.length exponent F Q R
|
| 23 |
+
(fun key => draw (.inr key)) label (Fin.ofNat R (s - 1)))
|
| 24 |
+
(physicalLocalOnline source target U N P F exponent H T A tau eta kappa
|
| 25 |
+
(physicalRawOnlineIntegers source target U N P F A T exponent H tau
|
| 26 |
+
(fun key => draw (.inl key)))) node t q
|
| 27 |
+
|
| 28 |
+
variable (hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 29 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 30 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 31 |
+
|
| 32 |
+
theorem physicalLocalJointValue_eq (node : PhysicalNode M J) (t : ℕ)
|
| 33 |
+
(q : TargetInterval target.length) :
|
| 34 |
+
physicalLocalJointValue source target U N P F A T exponent H Q tau eta kappa delta draw node t q =
|
| 35 |
+
physicalRefinement source target U N P F A T delta
|
| 36 |
+
(physicalProgramDrawSelections source target U N P F A T exponent H Q tau eta kappa
|
| 37 |
+
(physicalLocalProgramToComplete source target U N P F A T exponent H Q tau
|
| 38 |
+
hsize hP hF hA hseed draw)) node t q := by
|
| 39 |
+
unfold physicalLocalJointValue
|
| 40 |
+
rw [physicalRawOnlineProgram_eq source target U N P F A T exponent H tau eta kappa
|
| 41 |
+
(fun key => draw (.inl key)) hsize hP hF hA hseed]
|
| 42 |
+
rw [physicalGroupStreamsOfRaw]
|
| 43 |
+
rfl
|
| 44 |
+
|
| 45 |
+
end Joint
|
| 46 |
+
|
| 47 |
+
end EditApproximation
|
| 48 |
+
|
| 49 |
+
end OAI
|
lean/OAI/Combinatorics/EditApproximation/Refinement/PhysicalLocalOnlineEquality.lean
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import OAI.Combinatorics.EditApproximation.Geometry.LocalOnlineProgram
|
| 2 |
+
|
| 3 |
+
namespace OAI
|
| 4 |
+
|
| 5 |
+
/-! A proof adapter couples the bounded online query loop to the original
|
| 6 |
+
finite product slots. The adapter is used only to compare laws: local
|
| 7 |
+
execution uses scale/center keys and never searches a complete table. -/
|
| 8 |
+
|
| 9 |
+
namespace EditApproximation
|
| 10 |
+
|
| 11 |
+
section Program
|
| 12 |
+
|
| 13 |
+
variable {α : Type*} [DecidableEq α] {M J R : ℕ} [NeZero R]
|
| 14 |
+
(source target : List α) (U : PhysicalEntry M J target.length → ℕ)
|
| 15 |
+
(N P F exponent H T : ℕ) (A tau eta kappa : ℚ)
|
| 16 |
+
(online : PhysicalOnlineStreams source target U N P F A T exponent H tau R)
|
| 17 |
+
|
| 18 |
+
local notation "representatives" => stageRepresentatives source target U N P F A
|
| 19 |
+
|
| 20 |
+
noncomputable def physicalRepresentativeFin (node : PhysicalNode M J)
|
| 21 |
+
(br : ℕ × TargetInterval target.length) (hbr : br ∈ representatives node) :
|
| 22 |
+
Fin (representatives node).length := Classical.choose (List.mem_iff_get.mp hbr)
|
| 23 |
+
|
| 24 |
+
theorem physicalRepresentativeFin_get (node : PhysicalNode M J)
|
| 25 |
+
(br : ℕ × TargetInterval target.length) (hbr : br ∈ representatives node) :
|
| 26 |
+
(representatives node).get (physicalRepresentativeFin source target U N P F A node br hbr) = br :=
|
| 27 |
+
Classical.choose_spec (List.mem_iff_get.mp hbr)
|
| 28 |
+
|
| 29 |
+
noncomputable def physicalOnlineIntegersOfStreams
|
| 30 |
+
(node : PhysicalInternalNode M J) (time : Fin R) (b : ℕ) (r : TargetInterval target.length) : ℕ :=
|
| 31 |
+
if hbr : (b, r) ∈ representatives node.1 then
|
| 32 |
+
(online node (physicalRepresentativeFin source target U N P F A node.1 (b, r) hbr) time).val
|
| 33 |
+
else 0
|
| 34 |
+
|
| 35 |
+
omit [NeZero R] in
|
| 36 |
+
theorem physicalOnlineIntegersOfStreams_get (node : PhysicalInternalNode M J)
|
| 37 |
+
(representative : Fin (representatives node.1).length) (time : Fin R) :
|
| 38 |
+
physicalOnlineIntegersOfStreams source target U N P F exponent H T A tau online node time
|
| 39 |
+
((representatives node.1).get representative).1 ((representatives node.1).get representative).2 =
|
| 40 |
+
(online node representative time).val := by
|
| 41 |
+
unfold physicalOnlineIntegersOfStreams
|
| 42 |
+
rw [dite_eq_left (List.get_mem _ _)]
|
| 43 |
+
have heq : physicalRepresentativeFin source target U N P F A node.1
|
| 44 |
+
((representatives node.1).get representative) (List.get_mem _ _) = representative := by
|
| 45 |
+
apply (representativeList_nodup N P F _ _).injective_get
|
| 46 |
+
exact physicalRepresentativeFin_get source target U N P F A node.1 _ _
|
| 47 |
+
rw [heq]
|
| 48 |
+
|
| 49 |
+
theorem physicalLocalOnline_mem_iff
|
| 50 |
+
(hsize : source.length + target.length ≤ N) (hP : 66 ≤ P) (hF : 1 ≤ F) (hA : 1 ≤ A)
|
| 51 |
+
(hseed : ∀ state, stateEditCost (physicalSource source state.1) target state.2 ≤ U state ∧
|
| 52 |
+
(U state : ℚ) ≤ A * stateEditCost (physicalSource source state.1) target state.2)
|
| 53 |
+
(node : PhysicalInternalNode M J) (children : PhysicalChildTables M target.length)
|
| 54 |
+
(t : ℕ) (q : TargetInterval target.length) (action : PhysicalRationalAction M target.length) :
|
| 55 |
+
action ∈ physicalLocalOnline source target U N P F exponent H T A tau eta kappa
|
| 56 |
+
(physicalOnlineIntegersOfStreams source target U N P F exponent H T A tau online)
|
| 57 |
+
node.1 children t q ↔
|
| 58 |
+
action ∈ physicalProgramOnline source target U N P F A T exponent H tau eta kappa
|
| 59 |
+
online node.1 children t q := by
|
| 60 |
+
have hmass : physicalLocalChildMass source target U N P F A T node.1 node.2 =
|
| 61 |
+
physicalBandChildMassTable source target U N P F A T node.1 node.2 := by
|
| 62 |
+
funext i r
|
| 63 |
+
exact physicalLocalWarmupMass_eq source target U N P F A hsize hP hF hA hseed T
|
| 64 |
+
(physicalChild node.1 node.2 i, r)
|
| 65 |
+
unfold physicalLocalOnline physicalProgramOnline
|
| 66 |
+
rw [dite_eq_left node.2, dite_eq_left node.2]
|
| 67 |
+
rw [localOnlineCandidates_mem]
|
| 68 |
+
constructor
|
| 69 |
+
· rintro ⟨b, hb, hrep, hselected⟩
|
| 70 |
+
obtain ⟨representative, hget⟩ := List.mem_iff_get.mp hrep
|
| 71 |
+
change (representatives node.1).get representative =
|
| 72 |
+
(b, roundInterval (seedGridSpacing b P) q) at hget
|
| 73 |
+
have hinteger := physicalOnlineIntegersOfStreams_get source target U N P F exponent H T A tau online
|
| 74 |
+
node representative (Fin.ofNat R (t - 1))
|
| 75 |
+
rw [hget] at hinteger
|
| 76 |
+
rw [hmass, hinteger] at hselected
|
| 77 |
+
have heq := keyedOnlineCandidate_eq_physical source target U N P F exponent H T A tau eta kappa
|
| 78 |
+
node representative children (t - 1) (online node representative (Fin.ofNat R (t - 1)))
|
| 79 |
+
rw [hget] at heq
|
| 80 |
+
rw [heq] at hselected
|
| 81 |
+
apply List.mem_filterMap.mpr
|
| 82 |
+
refine ⟨representative, List.mem_filter.mpr ⟨List.mem_finRange _, ?_⟩, hselected⟩
|
| 83 |
+
apply decide_eq_true
|
| 84 |
+
unfold physicalProgramOnlineGuard
|
| 85 |
+
rw [hget]
|
| 86 |
+
exact ⟨rfl, of_decide_eq_true (List.mem_filter.mp hb).2⟩
|
| 87 |
+
· intro ha
|
| 88 |
+
obtain ⟨representative, hrep, hselected⟩ := List.mem_filterMap.mp ha
|
| 89 |
+
have hguard := of_decide_eq_true (List.mem_filter.mp hrep).2
|
| 90 |
+
let br := (representatives node.1).get representative
|
| 91 |
+
have hget : (representatives node.1).get representative =
|
| 92 |
+
(br.1, roundInterval (seedGridSpacing br.1 P) q) := Prod.ext rfl hguard.1
|
| 93 |
+
refine ⟨br.1, List.mem_filter.mpr ⟨?_, decide_eq_true hguard.2⟩, ?_, ?_⟩
|
| 94 |
+
· exact representativeList_scale_mem _ _ (List.get_mem _ representative)
|
| 95 |
+
· exact hget ▸ List.get_mem _ representative
|
| 96 |
+
· have hinteger := physicalOnlineIntegersOfStreams_get source target U N P F exponent H T A tau online
|
| 97 |
+
node representative (Fin.ofNat R (t - 1))
|
| 98 |
+
rw [hget] at hinteger
|
| 99 |
+
rw [hmass, hinteger]
|
| 100 |
+
have heq := keyedOnlineCandidate_eq_physical source target U N P F exponent H T A tau eta kappa
|
| 101 |
+
node representative children (t - 1) (online node representative (Fin.ofNat R (t - 1)))
|
| 102 |
+
rw [hget] at heq
|
| 103 |
+
exact heq.trans hselected
|
| 104 |
+
|
| 105 |
+
end Program
|
| 106 |
+
|
| 107 |
+
end EditApproximation
|
| 108 |
+
|
| 109 |
+
end OAI
|