Download data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandRounding.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 6.08 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandRounding.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandRounding.lean
-
curl -L -o BandRounding.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Geometry/BandRounding.lean
6.08 kB
| import OAI.Combinatorics.EditApproximation.Geometry.BandEnvelopes | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! | |
| # Integer rounding spacings from the dyadic band envelopes | |
| Taking the nonnegative part of the dyadic product exponent computes the | |
| integer spacing max(1, theta*h). The resulting spacing preserves the wide | |
| grid by actual divisibility of powers of two. | |
| -/ | |
| namespace EditApproximation | |
| open Finset | |
| theorem dyadic_nonnegative_spacing (exponent : β€) : | |
| ((2 ^ exponent.toNat : β) : β) = max 1 ((2 : β) ^ exponent) := by | |
| by_cases hnonneg : 0 β€ exponent | |
| Β· have hcast : ((exponent.toNat : β) : β€) = exponent := Int.toNat_of_nonneg hnonneg | |
| have hone : (1 : β) β€ 2 ^ exponent := by | |
| exact one_le_zpowβ (by norm_num) hnonneg | |
| rw [max_eq_right hone, Nat.cast_pow, Nat.cast_ofNat, β zpow_natCast, hcast] | |
| Β· have hnegative : exponent β€ 0 := by omega | |
| have htoNat : exponent.toNat = 0 := Int.toNat_eq_zero.mpr hnegative | |
| have hone : (2 : β) ^ exponent β€ 1 := by | |
| simpa only [zpow_zero] using zpow_le_zpow_rightβ (by norm_num : (1 : β) β€ 2) hnegative | |
| simp only [htoNat, pow_zero, Nat.cast_one, max_eq_left hone] | |
| theorem bandRoundSpacing_exact {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (i : Fin M) : | |
| (bandRoundSpacing thetaExponent b band initial i : β) = | |
| max 1 ((2 : β) ^ (-(thetaExponent : β€)) * bandChildEnvelope b band initial i) := by | |
| rw [bandRoundSpacing, dyadic_nonnegative_spacing] | |
| unfold bandChildEnvelope rationalDyadicCeiling bandEnvelopeExponent | |
| rw [β zpow_addβ (by norm_num : (2 : β) β 0)] | |
| congr 2 | |
| omega | |
| theorem bandRoundSpacing_pos {ny M : β} (thetaExponent b : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (i : Fin M) : | |
| 0 < bandRoundSpacing thetaExponent b band initial i := by | |
| unfold bandRoundSpacing | |
| positivity | |
| /-- Actual division rounding moves each endpoint by at most the scaled | |
| child envelope, including the special spacing-one case. -/ | |
| theorem gridRound_scaled_error (spacing position : β) (scaled : β) | |
| (hspacing : (spacing : β) = max 1 scaled) (hscaled : 0 β€ scaled) : | |
| (Nat.dist position (gridRound spacing position) : β) β€ scaled := by | |
| have hpos : 0 < spacing := by | |
| have hone : (1 : β) β€ spacing := by rw [hspacing]; exact le_max_left _ _ | |
| exact_mod_cast (lt_of_lt_of_le (by norm_num : (0 : β) < 1) hone) | |
| by_cases hone : spacing = 1 | |
| Β· simp only [hone, gridRound_one, Nat.dist_self, Nat.cast_zero] | |
| exact hscaled | |
| Β· have htwo : 1 < spacing := by omega | |
| have htwoR : (1 : β) < spacing := by exact_mod_cast htwo | |
| have hscale : 1 < scaled := by | |
| by_contra hnot | |
| have hle : scaled β€ 1 := le_of_not_gt hnot | |
| rw [max_eq_left hle] at hspacing | |
| linarith only [hspacing, htwoR] | |
| have hequal : (spacing : β) = scaled := hspacing.trans (max_eq_right hscale.le) | |
| have herr : (Nat.dist position (gridRound spacing position) : β) < spacing := by | |
| exact_mod_cast gridRound_error_lt spacing position hpos | |
| exact herr.le.trans_eq hequal | |
| theorem dyadic_dvd_of_le {small large : β} | |
| (hsmall : β e : β, small = 2 ^ e) (hlarge : β e : β, large = 2 ^ e) | |
| (hle : small β€ large) : small β£ large := by | |
| obtain β¨s, rflβ© := hsmall | |
| obtain β¨l, rflβ© := hlarge | |
| exact Nat.pow_dvd_pow 2 ((Nat.pow_le_pow_iff_right (by decide : 1 < 2)).mp hle) | |
| theorem seedGridSpacing_dyadic {b P : β} | |
| (hb : β e : β, b = 2 ^ e) (hP : β e : β, P = 2 ^ e) : | |
| β e : β, seedGridSpacing b P = 2 ^ e := by | |
| obtain β¨s, rflβ© := hb | |
| obtain β¨p, rflβ© := hP | |
| by_cases horder : p β€ s | |
| Β· refine β¨s - p, ?_β© | |
| rw [seedGridSpacing, Nat.pow_div horder (by decide : 0 < 2), max_eq_right Nat.one_le_two_pow] | |
| Β· refine β¨0, ?_β© | |
| have hlt : 2 ^ s < 2 ^ p := Nat.pow_lt_pow_right (by decide : 1 < 2) (by omega) | |
| simp only [seedGridSpacing, Nat.div_eq_of_lt hlt, max_eq_left (by decide : 0 β€ 1), pow_zero] | |
| /-- The envelope floor and the numerical theta*P β₯ M ensure that the | |
| actual rounded integer spacing is a multiple of the actual wide grid. -/ | |
| theorem bandRoundSpacing_wide_grid {ny M b P : β} (thetaExponent : β) | |
| (band : List (Fin M β TargetInterval ny)) | |
| (initial : Fin M β TargetInterval ny β β) (i : Fin M) | |
| (hM : 0 < M) (hPpos : 0 < P) | |
| (hbPower : β e : β, b = 2 ^ e) (hPPower : β e : β, P = 2 ^ e) | |
| (hscale : (M : β) β€ (2 : β) ^ (-(thetaExponent : β€)) * P) : | |
| seedGridSpacing b P β£ bandRoundSpacing thetaExponent b band initial i := by | |
| let theta : β := 2 ^ (-(thetaExponent : β€)) | |
| have htheta : 0 β€ theta := (zpow_pos (by norm_num : (0 : β) < 2) _).le | |
| have hMr : (0 : β) < M := by exact_mod_cast hM | |
| have hPr : (0 : β) < P := by exact_mod_cast hPpos | |
| have hratio : (M : β) / P β€ theta := (div_le_iffβ hPr).2 hscale | |
| have hfloor : (b : β) / P β€ theta * ((b : β) / M) := by | |
| calc | |
| _ = ((b : β) / M) * ((M : β) / P) := by field_simp [hMr.ne', hPr.ne'] | |
| _ β€ ((b : β) / M) * theta := | |
| mul_le_mul_of_nonneg_left hratio (div_nonneg (Nat.cast_nonneg _) hMr.le) | |
| _ = _ := mul_comm _ _ | |
| have henvelope := (bandChildEnvelope_lower b band initial i).1 | |
| have hproduct := hfloor.trans (mul_le_mul_of_nonneg_left henvelope htheta) | |
| have hwide : (seedGridSpacing b P : β) β€ | |
| max 1 (theta * bandChildEnvelope b band initial i) := by | |
| unfold seedGridSpacing | |
| rw [Nat.cast_max, Nat.cast_one] | |
| exact max_le_max le_rfl ((Nat.cast_div_le (m := b) (n := P)).trans hproduct) | |
| have hspacing := bandRoundSpacing_exact thetaExponent b band initial i | |
| have hle : seedGridSpacing b P β€ bandRoundSpacing thetaExponent b band initial i := by | |
| have h := hwide.trans_eq hspacing.symm | |
| exact_mod_cast h | |
| exact dyadic_dvd_of_le (seedGridSpacing_dyadic hbPower hPPower) | |
| β¨_, rflβ© hle | |
| end EditApproximation | |
| end OAI | |