File size: 3,789 Bytes
e63eb7f | 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 | import OAI.Combinatorics.EditApproximation.Binary.BinaryScaleGrid
import OAI.Combinatorics.EditApproximation.Geometry.LocalCells
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! The whole-cell grids and nearby cell indices are generated by literal
binary quotient, endpoint and bounded-range operations. -/
namespace EditApproximation
namespace BinaryFraction
@[simp] theorem naturalFloorWithWork_value (a : BinaryFraction) :
bitWordValue (naturalFloorWithWork a).1 = ⌊a.value⌋₊ := by
cases hs : a.numerator.negative
· have hdiv := bitDivModWithWork_value a.denominator a.numerator.bits a.denominator_pos
have hq : bitWordValue (bitDivModWithWork a.denominator a.numerator.bits).1 =
bitWordValue a.numerator.bits / bitWordValue a.denominator := by
conv_rhs => rw [hdiv.1]
rw [Nat.mul_add_div a.denominator_pos, Nat.div_eq_of_lt hdiv.2, Nat.add_zero]
simpa only [naturalFloorWithWork, hs, Bool.false_eq_true, ↓reduceIte, value,
SignedBinary.value, signedMagnitude, Int.cast_natCast, Nat.floor_div_eq_div] using hq
· have hn : a.value ≤ 0 := by
simp only [value, SignedBinary.value, signedMagnitude, hs, ↓reduceIte,
Int.cast_neg, Int.cast_natCast]
exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (Nat.cast_nonneg _)) (Nat.cast_nonneg _)
simp only [naturalFloorWithWork, hs, ↓reduceIte, bitWordValue]
exact (Nat.floor_eq_zero.mpr (lt_of_le_of_lt hn (by norm_num))).symm
theorem naturalFloorWithWork_bounds (a : BinaryFraction) :
(naturalFloorWithWork a).1.length ≤ a.width ∧
(naturalFloorWithWork a).2 ≤ 200 * (a.width + 1) ^ 2 := by
have hn : a.numerator.bits.length ≤ a.width := le_max_left _ _
have hd : a.denominator.length ≤ a.width := le_max_right _ _
have hlen := (bitDivModWithWork_lengths a.denominator a.numerator.bits).1
have hc := bitDivModWithWork_cost a.denominator a.numerator.bits
unfold naturalFloorWithWork
split_ifs <;> dsimp only
· exact ⟨Nat.zero_le _, by nlinarith only [Nat.zero_le a.width]⟩
· exact ⟨hlen.le.trans hn, by nlinarith only [hc, hn, hd, Nat.zero_le a.width]⟩
@[simp] theorem cellCoordinatesWithWork_value (side : BinaryFraction) (p radius : ℕ) :
(cellCoordinatesWithWork side p radius).1 = localCellCoordinates side.value p radius := by
simp only [cellCoordinatesWithWork, naturalFloorWithWork_value, divWithWork_value,
nat_value, saturatingSubtractWithWork_value, binaryNaturalAddWithWork_value,
localCellCoordinates]
@[simp] theorem targetCellsWithWork_value {n : ℕ} (side : BinaryFraction) (radius : ℕ)
(q : TargetInterval n) :
(targetCellsWithWork side radius q).1 = localTargetCells side.value radius q := by
simp only [targetCellsWithWork, arithmeticFlatMapWithWork_value, arithmeticMapWithWork_value,
cellCoordinatesWithWork_value, localTargetCells]
@[simp] theorem cellGridPointsWithWork_value (side : BinaryFraction) (g cell : ℕ) :
(cellGridPointsWithWork side g cell).1 = cellGridPoints side.value g cell := by
simp only [cellGridPointsWithWork, arithmeticMapWithWork_value, binaryNaturalMulWithWork_value,
binaryNaturalAddWithWork_value, canonicalMulWithWork_value, divWithWork_value,
naturalCeilingWithWork_value, nat_value, saturatingSubtractWithWork_value, cellGridPoints,
Nat.cast_add, Nat.cast_one]
@[simp] theorem cellStatesWithWork_value (n g : ℕ) (side : BinaryFraction) (cell : ℕ × ℕ) :
(cellStatesWithWork n g side cell).1 = cellTargetStates n g side.value cell := by
simp only [cellStatesWithWork, arithmeticFlatMapWithWork_value, filterMapWithWork_value,
cellGridPointsWithWork_value, makeStateWithWork_value, cellTargetStates]
end BinaryFraction
end EditApproximation
end OAI
|