File size: 3,796 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 | import OAI.Combinatorics.EditApproximation.Queries.QueryGroupKeyCost
namespace OAI
namespace EditApproximation.BinaryFraction
def queryCellStatesWithWork (n P b exponent : β) (cell : β Γ β) :
List (TargetInterval n) Γ β :=
let spacing := seedGridSpacingWithWork b P
let side := canonicalMulWithWork (inversePowerTwo exponent) (nat b)
let states := cellStatesWithWork n (bitWordValue spacing.1) side.1 cell
(states.1, spacing.2 + side.2 + states.2 + exponent + 3)
def queryCellStatesBitBudget (P exponent B : β) : β :=
100 * (B + 5) ^ 2 + 2000 * (B + 4) ^ 2 +
cellStatesBitBudget P P (16 * B + 200) + exponent + 3
theorem queryCellStatesWithWork_bounds (n P b exponent B : β) (cell : β Γ β)
(hP : 0 < P) (hPb : Nat.size P β€ B) (hb : Nat.size b β€ B + 1)
(he : exponent + 1 β€ B) (hn : Nat.size n β€ B)
(hc : Nat.size cell.1 β€ 16 * B + 183 β§ Nat.size cell.2 β€ 16 * B + 183)
(hbd : β e : β, b = 2 ^ e) (hPd : β e : β, P = 2 ^ e) :
(queryCellStatesWithWork n P b exponent cell).1.length β€ P ^ 2 β§
(queryCellStatesWithWork n P b exponent cell).2 β€ queryCellStatesBitBudget P exponent B := by
let spacing := seedGridSpacingWithWork b P
let theta := inversePowerTwo exponent
let side := canonicalMulWithWork theta (nat b)
let states := cellStatesWithWork n (bitWordValue spacing.1) side.1 cell
let C := 16 * B + 200
have hsp := seedGridSpacingWithWork_bounds b P (B + 3) (by omega) (by omega)
have hgs : Nat.size (bitWordValue spacing.1) β€ B + 4 :=
(Nat.size_le.mpr (bitWordValue_lt_pow_length _)).trans hsp.1
have ht : theta.width β€ B + 3 := by dsimp only [theta]; rw [inversePowerTwo_width]; omega
have hsw := canonicalMulWithWork_width theta (nat b) (B + 3) ht ((nat_width_le b).trans (by omega))
have hsc := canonicalMulWithWork_cost theta (nat b) (B + 3) ht ((nat_width_le b).trans (by omega))
have htheta : 0 β€ theta.value β§ theta.value β€ 1 := by
rw [inversePowerTwo_value]
exact β¨by positivity, zpow_le_one_of_nonposβ (by norm_num) (by omega)β©
have hv : side.1.value = theta.value * b := by rw [canonicalMulWithWork_value, nat_value]
have hg : (0 : β) < seedGridSpacing b P := by
exact_mod_cast (show 0 < seedGridSpacing b P by unfold seedGridSpacing; omega)
have hcover : (b : β) β€ P * (seedGridSpacing b P : β) := by
exact_mod_cast seedGridSpacing_covers_dyadic hbd hPd
have hratio : theta.value * b / seedGridSpacing b P β€ (P : β) := by
apply (div_le_iffβ hg).2
exact (mul_le_mul_of_nonneg_right htheta.2 (Nat.cast_nonneg b)).trans (by simpa only [one_mul] using hcover)
have hlen (j : β) : (cellGridPoints side.1.value (bitWordValue spacing.1) j).length β€ P := by
rw [hv, seedGridSpacingWithWork_value b P hP]
exact cellGridPoints_length_le (mul_nonneg htheta.1 (Nat.cast_nonneg _)) hratio
have hstate := cellStatesWithWork_cost n (bitWordValue spacing.1) C side.1 cell
(by dsimp only [C]; omega) (by dsimp only [C]; omega)
(by dsimp only [C]; change side.1.width β€ _ at hsw; omega)
(by dsimp only [C]; omega) (by dsimp only [C]; omega)
have hstate' : states.2 β€ cellStatesBitBudget P P C := hstate.trans (by
unfold cellStatesBitBudget cellGridPointsBitBudget
gcongr <;> apply hlen)
constructor
Β· have hlength := (cellStatesWithWork_length n (bitWordValue spacing.1) side.1 cell).trans
(Nat.mul_le_mul (hlen cell.1) (hlen cell.2))
simpa only [queryCellStatesWithWork, spacing, theta, side, states, pow_two] using hlength
Β· change spacing.2 + side.2 + states.2 + exponent + 3 β€ _
exact Nat.add_le_add_right (Nat.add_le_add_right
(Nat.add_le_add (Nat.add_le_add hsp.2 hsc) hstate') exponent) 3
end EditApproximation.BinaryFraction
end OAI
|