File size: 4,767 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | import OAI.Combinatorics.EditApproximation.Coarse.CoarseArrayStorage
import OAI.Combinatorics.EditApproximation.Refinement.ComputedCoarsePolynomial
namespace OAI
namespace EditApproximation
namespace BinaryFraction
open Filter
theorem computedCoarseRootArray_storage :
βαΆ N : β in atTop, β B d : β, β x y : List β,
B = (integerParameters N).B β d = computedCoarseDepth N (coarseEntryWidth x y) β
coarseEntryWidth x y β€ N β
β (hB : 0 < B) (hq : 0 < inputHeight N ^ 4) (hL : 0 < 64 * inputHeight N)
(i : CoarseGuessIndex (coarseEntryWidth x y)) (draws : CoarseThresholdDraws B d),
coarseArrayStorage (coarseIndexedRootArray (coarseGuess (coarseEntryWidth x y) i)
(inputHeight N ^ 4) (64 * inputHeight N) hB hq hL x y draws) β€
1 + (2 * coarseGuess (coarseEntryWidth x y) i + 1) * (2 * inputHeight N ^ 3 + 3) := by
filter_upwards [computedCoarse_bitParameters, eventually_ge_atTop 1,
inputSmallLog_tendsto.eventually (eventually_ge_atTop 200)] with N hbits hN hell
intro B d x y hBdef hddef hsize hB hq hL i draws
let H := inputHeight N
let k := coarseGuess (coarseEntryWidth x y) i
have hk : k β€ 2 * (N + 2) := (coarseGuess_le _ i).trans (by omega)
obtain β¨hden, hbound, hBbits, hqbits, hLbits, hNbits, _hDβ© :=
hbits B d (coarseEntryWidth x y) k hBdef hddef hsize hk
have hcap : coarseEntryWidth x y β€ B ^ d := by
rw [hBdef, hddef]
exact (computed_coarse_depth N _ (by omega) hsize hell).1
have htree : 0 + (coarseEntryTree B d x y).word.length β€ N := by
rw [coarseEntryTree_word B d x y hcap, coarsePadTo_length _ _ (le_max_left _ _)]
simpa only [Nat.zero_add] using hsize
rw [coarseIndexedRootArray_eq]
exact coarseRootArray_storage k (H ^ 4) (64 * H) N (10 * H ^ 2) (H ^ 3)
hB hq hL _ _ draws 0 hBbits hqbits hLbits hNbits hden hbound htree
theorem coarseRootArrayStorage_polynomial_scalar (N k : β) (hk : k β€ 2 * (N + 2)) :
1 + (2 * k + 1) * (2 * inputHeight N ^ 3 + 3) β€ (N + 2) ^ 20 := by
let X := N + 2
have hX : 2 β€ X := by dsimp only [X]; omega
have hH := Nat.pow_le_pow_left (computed_height_polynomial N) 3
rw [β pow_mul] at hH
change inputHeight N ^ 3 β€ X ^ 12 at hH
have hone : 1 β€ X ^ 12 := one_le_powβ (by omega)
have hm : (2 * k + 1) * (2 * inputHeight N ^ 3 + 3) β€ (5 * X) * (5 * X ^ 12) :=
Nat.mul_le_mul (by dsimp only [X]; omega) (by omega)
have hp : 1 β€ X ^ 13 := one_le_powβ (by omega)
have hc : 26 β€ X ^ 7 := (by decide : 26 β€ (2 : β) ^ 7).trans (Nat.pow_le_pow_left hX 7)
calc
_ β€ 26 * X ^ 13 := by nlinarith only [hm, hp]
_ β€ X ^ 7 * X ^ 13 := Nat.mul_le_mul_right _ hc
_ = _ := by rw [β pow_add]
/-- Even retaining the final array from every candidate uses polynomial
space; the implementation may release each array after its root lookup. -/
theorem computedCoarseAllRootArrays_storage :
βαΆ N : β in atTop, β B d : β, β x y : List β,
B = (integerParameters N).B β d = computedCoarseDepth N (coarseEntryWidth x y) β
coarseEntryWidth x y β€ N β
β (hB : 0 < B) (hq : 0 < inputHeight N ^ 4) (hL : 0 < 64 * inputHeight N)
(draws : CoarseGuessIndex (coarseEntryWidth x y) β CoarseThresholdDraws B d),
(β i : CoarseGuessIndex (coarseEntryWidth x y),
coarseArrayStorage (coarseIndexedRootArray (coarseGuess (coarseEntryWidth x y) i)
(inputHeight N ^ 4) (64 * inputHeight N) hB hq hL x y (draws i))) β€
(N + 2) ^ 25 := by
filter_upwards [computedCoarseRootArray_storage] with N hroot
intro B d x y hBdef hddef hsize hB hq hL draws
have hclog : Nat.clog 2 (coarseEntryWidth x y) β€ inputHeight N :=
(Nat.clog_le_iff_le_pow (by decide : 1 < (2 : β))).mpr
(hsize.trans ((Nat.le_add_right N 2).trans (inputHeight_covers_length N)))
have hcount : Nat.clog 2 (coarseEntryWidth x y) + 1 β€ (N + 2) ^ 5 := by
have hh := computed_height_polynomial N
have hp : 1 β€ (N + 2) ^ 4 := one_le_powβ (by omega)
have hm := Nat.mul_le_mul_right ((N + 2) ^ 4) (show 2 β€ N + 2 by omega)
nlinarith only [hclog, hh, hp, hm]
calc
_ β€ β _i : CoarseGuessIndex (coarseEntryWidth x y), (N + 2) ^ 20 := by
apply Finset.sum_le_sum
intro i _
exact (hroot B d x y hBdef hddef hsize hB hq hL i (draws i)).trans
(coarseRootArrayStorage_polynomial_scalar N _ ((coarseGuess_le _ i).trans (by omega)))
_ = (Nat.clog 2 (coarseEntryWidth x y) + 1) * (N + 2) ^ 20 := by
simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul]
_ β€ (N + 2) ^ 5 * (N + 2) ^ 20 := Nat.mul_le_mul_right _ hcount
_ = _ := by rw [β pow_add]
end BinaryFraction
end EditApproximation
end OAI
|