Download lean/OAI/Combinatorics/EditApproximation/Binary/BinaryCellGrid.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.79 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryCellGrid.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryCellGrid.lean
-
curl -L -o BinaryCellGrid.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Combinatorics/EditApproximation/Binary/BinaryCellGrid.lean
3.79 kB
| 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 | |