File size: 4,848 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 92 93 94 | import OAI.Combinatorics.EditApproximation.Queries.QueryRawCenterCost
import OAI.Combinatorics.EditApproximation.Binary.BinaryCellCentersWork
namespace OAI
/-! Uniform bounds for the actual cell scan at an accepted query scale.
The scale-window test controls its count; the binary arithmetic controls
its coordinate widths independently of the numeric target length. -/
namespace EditApproximation.BinaryFraction
theorem queryCellCoordinates_count (F b exponent p : β) (w : β)
(hF : 1 β€ F) (hb : 1 β€ b) (hw : 0 β€ w) (hwindow : w / (16 * F) β€ b) :
(localCellCoordinates ((2 : β) ^ (-(exponent : β€)) * b) p βwββ).length β€
(32 * F + 2) * 2 ^ exponent + 2 := by
have hbR : (1 : β) β€ b := by exact_mod_cast hb
have hs : 0 < (2 : β) ^ (-(exponent : β€)) * b := by
have hbp : (0 : β) < b := by exact_mod_cast (show 0 < b by omega)
positivity
apply localCellCoordinates_length_le _ hs _ _ ((32 * F + 2) * 2 ^ exponent)
apply (div_le_iffβ hs).2
have hw' : w β€ 16 * (F : β) * b := by
have hf : (0 : β) < F := by exact_mod_cast (show 0 < F by omega)
nlinarith only [(div_le_iffβ (by positivity : (0 : β) < 16 * F)).mp hwindow]
have hc : (βwββ : β) < w + 1 := Nat.ceil_lt_add_one hw
have heq : (((32 * F + 2) * 2 ^ exponent : β) : β) *
((2 : β) ^ (-(exponent : β€)) * b) = (32 * (F : β) + 2) * b := by
push_cast
rw [zpow_neg, zpow_natCast]
field_simp
rw [heq]
nlinarith only [hc, hw', hbR]
theorem queryScalesWithWork_window (N F : β) (a value : BinaryFraction) (b : β)
(hb : b β (queryScalesWithWork N F a value).1) :
(β e : β, b = 2 ^ e) β§ value.value / (16 * F) β€ b := by
rw [queryScalesWithWork_value] at hb
obtain β¨hd, hgβ© := List.mem_filter.mp hb
refine β¨?_, (of_decide_eq_true hg).1β©
obtain β¨e, _, rflβ© := List.mem_map.mp hd
exact β¨e, rflβ©
def queryCellScanBitBudget (F exponent B : β) : β :=
let K := (32 * F + 2) * 2 ^ exponent + 2
2000 * (B + 4) ^ 2 + targetCellsBitBudget K K (4 * B + 40)
theorem queryCellScan_bounds {n : β} (F b exponent B : β)
(value : BinaryFraction) (q : TargetInterval n)
(hF : 1 β€ F) (hb : 1 β€ b) (hbs : Nat.size b β€ B + 1)
(he : exponent + 1 β€ B) (hn : Nat.size n β€ B) (hv : value.width β€ B)
(hw : 0 β€ value.value) (hwindow : value.value / (16 * F) β€ b) :
let side := canonicalMulWithWork (inversePowerTwo exponent) (nat b)
let radius := naturalCeilingWithWork value
let cells := targetCellsWithWork side.1 (bitWordValue radius.1) q
cells.1.length β€ ((32 * F + 2) * 2 ^ exponent + 2) ^ 2 β§
side.2 + cells.2 β€ queryCellScanBitBudget F exponent B β§
β cell β cells.1, Nat.size cell.1 β€ 16 * B + 183 β§ Nat.size cell.2 β€ 16 * B + 183 := by
let side := canonicalMulWithWork (inversePowerTwo exponent) (nat b)
let radius := naturalCeilingWithWork value
let cells := targetCellsWithWork side.1 (bitWordValue radius.1) q
let K := (32 * F + 2) * 2 ^ exponent + 2
have htheta : (inversePowerTwo exponent).width β€ B := by rw [inversePowerTwo_width]; exact he
have hbn : (nat b).width β€ B + 3 := (nat_width_le b).trans (by omega)
have hsw := canonicalMulWithWork_width (inversePowerTwo exponent) (nat b) (B + 3) (by omega) hbn
have hsc := canonicalMulWithWork_cost (inversePowerTwo exponent) (nat b) (B + 3) (by omega) hbn
have hrw : Nat.size (bitWordValue radius.1) β€ B + 2 :=
(Nat.size_le.mpr (bitWordValue_lt_pow_length radius.1)).trans
((naturalCeilingWithWork_length value).trans (by omega))
have hcoords (p : β) : (localCellCoordinates side.1.value p (bitWordValue radius.1)).length β€ K := by
simp only [side, canonicalMulWithWork_value, inversePowerTwo_value, nat_value,
radius, naturalCeilingWithWork_value]
exact queryCellCoordinates_count F b exponent p value.value hF hb hw hwindow
have hcc := targetCellsWithWork_cost side.1 (bitWordValue radius.1) (4 * B + 40)
q (by change side.1.width β€ _ at hsw; omega) (by omega) (by omega)
have hcells : cells.2 β€ targetCellsBitBudget K K (4 * B + 40) := hcc.trans (by
unfold targetCellsBitBudget
gcongr <;> apply hcoords)
refine β¨?_, ?_, ?_β©
Β· rw [targetCellsWithWork_value]
simp only [canonicalMulWithWork_value, inversePowerTwo_value, nat_value,
naturalCeilingWithWork_value]
exact localTargetCells_query_length F b exponent q value.value hF hb hw hwindow
Β· change side.2 + cells.2 β€ _
change side.2 β€ _ at hsc
exact Nat.add_le_add hsc hcells
Β· intro cell hc
have hk := targetCellsWithWork_keys side.1 (bitWordValue radius.1) (4 * B + 40) q
(by change side.1.width β€ _ at hsw; omega) (by omega) (by omega) cell hc
constructor <;> omega
end EditApproximation.BinaryFraction
end OAI
|