Download data/lean/OAI/Algebra/GroupRing/BlockGrid.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 16.1 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algebra/GroupRing/BlockGrid.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Algebra/GroupRing/BlockGrid.lean
-
curl -L -o BlockGrid.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algebra/GroupRing/BlockGrid.lean
16.1 kB
| import Mathlib | |
| namespace OAI | |
| noncomputable section | |
| namespace TorsionFreeZeroDivisors.BlockGrid | |
| /-- Partition the unit interval into N half-open equal cells. -/ | |
| def cell (N : β) (hN : 0 < N) (x : β) : Fin N := | |
| β¨β(N : β) * Int.fract xββ, by | |
| apply (Nat.floor_lt (mul_nonneg (Nat.cast_nonneg _) (Int.fract_nonneg x))).mpr | |
| simpa using mul_lt_mul_of_pos_left (Int.fract_lt_one x) (Nat.cast_pos.mpr hN)β© | |
| theorem same_cell {N : β} (hN : 0 < N) {x y : β} (he : cell N hN x = cell N hN y) : | |
| |Int.fract x - Int.fract y| < 1 / (N : β) := by | |
| have hf := congrArg Fin.val he | |
| dsimp [cell] at hf | |
| have hx0 := Nat.floor_le (mul_nonneg (Nat.cast_nonneg N) (Int.fract_nonneg x)) | |
| have hy0 := Nat.floor_le (mul_nonneg (Nat.cast_nonneg N) (Int.fract_nonneg y)) | |
| have hx1 := Nat.lt_floor_add_one ((N : β) * Int.fract x) | |
| have hy1 := Nat.lt_floor_add_one ((N : β) * Int.fract y) | |
| rw [hf] at hx0 hx1 | |
| have hNr : (0 : β) < N := Nat.cast_pos.mpr hN | |
| rw [abs_lt] | |
| constructor | |
| Β· apply (neg_lt_iff_pos_add).mpr | |
| apply (mul_pos_iff_of_pos_left hNr).mp | |
| have hi : (N : β) * (1 / N) = 1 := by field_simp | |
| nlinarith | |
| Β· apply (lt_div_iffβ hNr).mpr | |
| nlinarith | |
| /-- Simultaneous approximation in all d coordinates, with the exact | |
| denominator bound N^d, by the pigeonhole principle. -/ | |
| theorem simultaneous {d N : β} (hN : 0 < N) (a : Fin d β β) : | |
| β u : β, 1 β€ u β§ u β€ N ^ d β§ | |
| β z : Fin d β β€, β i, |(u : β) * a i - (z i : β)| < 1 / (N : β) := by | |
| classical | |
| let code : Fin (N ^ d + 1) β (Fin d β Fin N) := | |
| fun k i => cell N hN ((k.val : β) * a i) | |
| obtain β¨j, k, hne, heβ© := Fintype.exists_ne_map_eq_of_card_lt code (by simp) | |
| have diff (j k : Fin (N^d+1)) (hjk : j.val < k.val) (he : code j = code k) : | |
| β u : β, 1 β€ u β§ u β€ N^d β§ | |
| β z : Fin d β β€, β i, |(u : β)*a i - (z i : β)| < 1/(N : β) := by | |
| refine β¨k.val-j.val, by omega, by omega, | |
| (fun i => β(k.val : β)*a iβ - β(j.val : β)*a iβ), ?_β© | |
| intro i | |
| have hi := same_cell hN (congrFun he i).symm | |
| have hcast : ((k.val-j.val : β) : β) = (k.val : β) - j.val := | |
| Nat.cast_sub (Nat.le_of_lt hjk) | |
| simpa only [code] using (by | |
| rw [hcast, Int.cast_sub] | |
| convert hi using 1 | |
| simp only [Int.fract] | |
| ring_nf) | |
| rcases lt_or_gt_of_ne (Fin.val_injective.ne hne) with hjk | hkj | |
| Β· exact diff j k hjk he | |
| Β· exact diff k j hkj he.symm | |
| /-- Scaling the simultaneous approximation gives the common block | |
| scale s=L/(uR), with error at most R/N for every prescribed offset. -/ | |
| theorem scale_approximation {d N : β} (hN : 0 < N) | |
| (L R : β) (hL : 0 < L) (hR : 0 < R) (offset : Fin d β β) : | |
| β u : β, 1 β€ u β§ u β€ N^d β§ | |
| β z : Fin d β β€, | |
| let s := L / ((u : β)*R) | |
| 0 < s β§ L / ((N^d : β)*R) β€ s β§ s β€ L/R β§ | |
| β i, |offset i / s - R*(z i : β)| < R / N := by | |
| obtain β¨u, hu, hub, z, hzβ© := simultaneous hN (fun i => offset i / L) | |
| have hur : (0 : β) < u := by exact_mod_cast hu | |
| have hNr : (0 : β) < N := Nat.cast_pos.mpr hN | |
| have hpow : (0 : β) < (N^d : β) := by positivity | |
| refine β¨u,hu,hub,z,?_,?_,?_,?_β© | |
| Β· exact div_pos hL (mul_pos hur hR) | |
| Β· exact div_le_div_of_nonneg_left hL.le (mul_pos hur hR) | |
| (mul_le_mul_of_nonneg_right (by exact_mod_cast hub) hR.le) | |
| Β· apply div_le_div_of_nonneg_left hL.le hR | |
| simpa using mul_le_mul_of_nonneg_right (show (1 : β) β€ u by exact_mod_cast hu) hR.le | |
| Β· intro i | |
| have he := mul_lt_mul_of_pos_left (hz i) hR | |
| have hscalar : offset i / (L / ((u : β)*R)) - R*(z i : β) = | |
| R*((u : β)*(offset i/L) - (z i : β)) := by field_simp | |
| rw [hscalar, abs_mul, abs_of_pos hR] | |
| simpa [div_eq_mul_inv, mul_assoc] using he | |
| end TorsionFreeZeroDivisors.BlockGrid | |
| /-! Exact half-integer alignment, including the reflection endpoint conventions. | |
| Uniform deficit bounds converge to zero relative to s | |
| when |a/s-Ξ½| does; no rounding of the prescribed real grid s is needed. -/ | |
| namespace TorsionFreeZeroDivisors.BlockAlignment | |
| section | |
| open scoped Classical | |
| /-- Integer edge indices whose half-integer centers belong to a real interval. -/ | |
| def positions (lo hi : β) : Finset β€ := Finset.Ico βlo-1/2β βhi-1/2β | |
| theorem mem_positions {lo hi : β} {q : β€} : | |
| q β positions lo hi β lo β€ (q : β)+1/2 β§ (q : β)+1/2 < hi := by | |
| simp only [positions,Finset.mem_Ico,Int.ceil_le,Int.lt_ceil] | |
| constructor <;> rintro β¨h1,h2β© <;> constructor <;> linarith | |
| /-- Works even for a reversed/empty real interval. -/ | |
| theorem card_lower (lo hi : β) : hi-lo-1 β€ ((positions lo hi).card : β) := by | |
| have h1 := Int.le_ceil (lo-1/2) | |
| have h2 := Int.ceil_lt_add_one (lo-1/2) | |
| have h3 := Int.le_ceil (hi-1/2) | |
| have h4 : (βhi-1/2β-βlo-1/2β : β€) β€ ((positions lo hi).card : β€) := by | |
| simp only [positions,Int.card_Ico] | |
| exact Int.self_le_toNat _ | |
| have h5 : ((βhi-1/2β : β€) : β)-βlo-1/2β β€ ((positions lo hi).card : β) := by exact_mod_cast h4 | |
| linarith | |
| theorem card_upper {lo hi : β} (hab : lo β€ hi) : | |
| ((positions lo hi).card : β) β€ hi-lo+1 := by | |
| have hc : βlo-1/2β β€ βhi-1/2β := Int.ceil_mono (by linarith) | |
| have he : ((positions lo hi).card : β€) = βhi-1/2β-βlo-1/2β := by | |
| simp only [positions,Int.card_Ico] | |
| exact Int.toNat_of_nonneg (sub_nonneg.mpr hc) | |
| have he' : ((positions lo hi).card : β) = ((βhi-1/2β : β€) : β)-βlo-1/2β := by exact_mod_cast he | |
| have h1 := Int.le_ceil (lo-1/2) | |
| have h2 := Int.ceil_lt_add_one (hi-1/2) | |
| linarith | |
| def block (s : β) (k : β€) : Finset β€ := positions ((k : β)*s) (((k : β)+1)*s) | |
| def affine (reverse : Bool) (a q : β€) : β€ := if reverse then a-1-q else q+a | |
| def partnerIndex (reverse : Bool) (Ξ½ k : β€) : β€ := if reverse then Ξ½-k-1 else k+Ξ½ | |
| def overlap (s : β) (reverse : Bool) (a k Ξ½ : β€) : Finset β€ := | |
| (block s k).filter (fun q => affine reverse a q β block s (partnerIndex reverse Ξ½ k)) | |
| /-- A central interval survives both translation and reflection. Using one | |
| extra unit of margin removes the open/closed endpoint distinction. -/ | |
| theorem core_subset (s : β) (reverse : Bool) (a k Ξ½ : β€) : | |
| positions ((k : β)*s+(|a-(Ξ½ : β)*s|+1)) | |
| (((k : β)+1)*s-(|a-(Ξ½ : β)*s|+1)) β overlap s reverse a k Ξ½ := by | |
| intro q hq | |
| obtain β¨hlo,hhiβ© := mem_positions.mp hq | |
| have ha0 := abs_nonneg ((a : β)-(Ξ½ : β)*s) | |
| have ha1 := le_abs_self ((a : β)-(Ξ½ : β)*s) | |
| have ha2 := neg_abs_le ((a : β)-(Ξ½ : β)*s) | |
| refine Finset.mem_filter.mpr β¨?_,?_β© | |
| Β· apply mem_positions.mpr | |
| constructor <;> linarith | |
| Β· apply mem_positions.mpr | |
| cases reverse <;> simp only [affine,partnerIndex,Bool.false_eq_true,ite_false,ite_true, | |
| Int.cast_add,Int.cast_sub,Int.cast_one] <;> constructor <;> nlinarith | |
| /-- An explicit o(s) deficit for the exact grid and signed isometry. -/ | |
| theorem overlap_deficit (s : β) (hs : 0 β€ s) (reverse : Bool) (a k Ξ½ : β€) : | |
| (((block s k).card - (overlap s reverse a k Ξ½).card : β) : β) β€ | |
| 2*|a-(Ξ½ : β)*s|+4 := by | |
| have hlo := card_lower ((k : β)*s+(|a-(Ξ½ : β)*s|+1)) | |
| (((k : β)+1)*s-(|a-(Ξ½ : β)*s|+1)) | |
| have hsub := Finset.card_le_card (core_subset s reverse a k Ξ½) | |
| have hsub' : ((positions ((k : β)*s+(|a-(Ξ½ : β)*s|+1)) | |
| (((k : β)+1)*s-(|a-(Ξ½ : β)*s|+1))).card : β) β€ (overlap s reverse a k Ξ½).card := by exact_mod_cast hsub | |
| have hhi := card_upper (lo := (k : β)*s) (hi := ((k : β)+1)*s) (by nlinarith) | |
| have hcard : (overlap s reverse a k Ξ½).card β€ (block s k).card := | |
| Finset.card_le_card (Finset.filter_subset _ _) | |
| rw [Nat.cast_sub hcard] | |
| dsimp [block] at * | |
| linarith | |
| /-- An overlap larger than half of its block dominates every disjoint one. -/ | |
| theorem dominant_unique {B D E : Finset β€} (hD : D β B) (hE : E β B) | |
| (hdis : Disjoint D E) (hd : B.card < 2*D.card) (he : B.card < 2*E.card) : False := by | |
| have hc : D.card+E.card β€ B.card := by | |
| rw [β Finset.card_union_of_disjoint hdis] | |
| exact Finset.card_le_card (Finset.union_subset hD hE) | |
| omega | |
| end | |
| open scoped Classical BigOperators | |
| def inverseOffset (reverse : Bool) (a : β€) : β€ := if reverse then a else -a | |
| theorem affine_inverse (reverse : Bool) (a q : β€) : | |
| affine reverse (inverseOffset reverse a) (affine reverse a q) = q := by | |
| cases reverse <;> simp [affine,inverseOffset] | |
| theorem affine_injective (reverse : Bool) (a : β€) : Function.Injective (affine reverse a) := | |
| Function.LeftInverse.injective (affine_inverse reverse a) | |
| theorem partner_inverse (reverse : Bool) (Ξ½ k : β€) : | |
| partnerIndex reverse (inverseOffset reverse Ξ½) (partnerIndex reverse Ξ½ k) = k := by | |
| cases reverse <;> simp [partnerIndex,inverseOffset]; omega | |
| /-- The overlap on the partner block is exactly the image of the first overlap. -/ | |
| def overlapEquiv (s : β) (reverse : Bool) (a k Ξ½ : β€) : | |
| overlap s reverse a k Ξ½ β | |
| overlap s reverse (inverseOffset reverse a) (partnerIndex reverse Ξ½ k) (inverseOffset reverse Ξ½) where | |
| toFun q := β¨affine reverse a q.val, by | |
| obtain β¨hq,hpβ© := Finset.mem_filter.mp q.property | |
| apply Finset.mem_filter.mpr | |
| exact β¨hp,by rw [affine_inverse,partner_inverse]; exact hqβ©β© | |
| invFun q := β¨affine reverse (inverseOffset reverse a) q.val,by | |
| obtain β¨hq,hpβ© := Finset.mem_filter.mp q.property | |
| apply Finset.mem_filter.mpr | |
| refine β¨?_,?_β© | |
| Β· rwa [partner_inverse] at hp | |
| Β· have he : affine reverse a (affine reverse (inverseOffset reverse a) q.val) = q.val := by | |
| cases reverse <;> simp [affine,inverseOffset] | |
| rw [he] | |
| exact hqβ© | |
| left_inv q := Subtype.ext (affine_inverse reverse a q.val) | |
| right_inv q := by | |
| apply Subtype.ext | |
| cases reverse <;> simp [affine,inverseOffset] | |
| theorem block_disjoint (s : β) (hs : 0 < s) {k j : β€} (hne : k β j) : | |
| Disjoint (block s k) (block s j) := by | |
| apply Finset.disjoint_left.mpr | |
| intro q hk hj | |
| obtain β¨hk0,hk1β© := mem_positions.mp hk | |
| obtain β¨hj0,hj1β© := mem_positions.mp hj | |
| rcases lt_or_gt_of_ne hne with hkj | hjk | |
| Β· have hh : (k : β)+1 β€ j := by exact_mod_cast hkj | |
| nlinarith | |
| Β· have hh : (j : β)+1 β€ k := by exact_mod_cast hjk | |
| nlinarith | |
| def blockCount (s : β) (ell : β) : β := β(ell : β)/sββ | |
| def tail (s : β) (ell : β) : Finset β€ := positions ((blockCount s ell : β)*s) ell | |
| theorem count_bound (s : β) (hs : 0 < s) (ell : β) : | |
| (blockCount s ell : β)*s β€ ell β§ (ell : β) < (blockCount s ell+1)*s := by | |
| have h1 := Nat.floor_le (div_nonneg (Nat.cast_nonneg ell) hs.le) | |
| have h2 := Nat.lt_floor_add_one ((ell : β)/s) | |
| constructor | |
| Β· exact (le_div_iffβ hs).mp h1 | |
| Β· exact (div_lt_iffβ hs).mp h2 | |
| theorem tail_bound (s : β) (hs : 0 < s) (ell : β) : | |
| ((tail s ell).card : β) β€ s+1 := by | |
| have he := count_bound s hs ell | |
| have hh := card_upper he.1 | |
| dsimp [tail] | |
| linarith | |
| /-- Literal partition into full blocks and the end fragment. -/ | |
| theorem full_or_tail (s : β) (hs : 0 < s) (ell : β) {q : β€} | |
| (hq : q β positions 0 ell) : | |
| (β k : Fin (blockCount s ell), q β block s k.val) β¨ q β tail s ell := by | |
| obtain β¨hq0,hq1β© := mem_positions.mp hq | |
| by_cases he : (q : β)+1/2 < (blockCount s ell : β)*s | |
| Β· let k := β((q : β)+1/2)/sββ | |
| have hk : k < blockCount s ell := by | |
| apply (Nat.floor_lt (div_nonneg hq0 hs.le)).mpr | |
| exact (div_lt_iffβ hs).mpr he | |
| left | |
| refine β¨β¨k,hkβ©,?_β© | |
| apply mem_positions.mpr | |
| simp only [Int.cast_natCast] | |
| exact β¨(le_div_iffβ hs).mp (Nat.floor_le (div_nonneg hq0 hs.le)), | |
| (div_lt_iffβ hs).mp (Nat.lt_floor_add_one (((q : β)+1/2)/s))β© | |
| Β· right | |
| exact mem_positions.mpr β¨not_lt.mp he,hq1β© | |
| /-- A full block is entirely within its marked chain. -/ | |
| theorem full_subset (s : β) (hs : 0 < s) (ell : β) (k : Fin (blockCount s ell)) : | |
| block s k.val β positions 0 ell := by | |
| intro q hq | |
| obtain β¨hlo,hhiβ© := mem_positions.mp hq | |
| apply mem_positions.mpr | |
| have hk : (k.val : β)+1 β€ blockCount s ell := by exact_mod_cast k.isLt | |
| have he := (count_bound s hs ell).1 | |
| simp only [Int.cast_natCast] at hlo hhi | |
| constructor | |
| Β· have hkn : (0 : β) β€ k.val := Nat.cast_nonneg _ | |
| nlinarith | |
| Β· nlinarith | |
| /-- A grid block situated inside a comparison with one-block margins has a | |
| full indicated target block. This includes negative offsets and reflections. -/ | |
| theorem partner_full (s : β) (hs : 0 < s) (reverse : Bool) (a k Ξ½ : β€) | |
| (lo hi ell : β) (herr : |(a : β)-(Ξ½ : β)*s| β€ s) | |
| (hlo : lo β€ (k : β)*s-s) (hhi : ((k : β)+1)*s+s β€ hi) | |
| (htarget : if reverse then 0 β€ (a : β)-hi β§ (a : β)-lo β€ ell | |
| else 0 β€ lo+(a : β) β§ hi+(a : β) β€ ell) : | |
| 0 β€ partnerIndex reverse Ξ½ k β§ ((partnerIndex reverse Ξ½ k : β€)+1 : β)*s β€ ell := by | |
| have he1 : (a : β)-(Ξ½ : β)*s β€ s := (le_abs_self _).trans herr | |
| have he2 : -s β€ (a : β)-(Ξ½ : β)*s := by | |
| have hh := neg_abs_le ((a : β)-(Ξ½ : β)*s) | |
| linarith | |
| cases reverse <;> simp only [Bool.false_eq_true,ite_false,ite_true,partnerIndex, | |
| Int.cast_add,Int.cast_sub,Int.cast_one] at htarget β’ | |
| Β· constructor | |
| Β· have hz : (0 : β) β€ (k : β)+(Ξ½ : β) := by nlinarith [htarget.1] | |
| exact_mod_cast hz | |
| Β· nlinarith [htarget.2] | |
| Β· constructor | |
| Β· have hz : (0 : β) β€ (Ξ½ : β)-(k : β)-1 := by nlinarith [htarget.1] | |
| exact_mod_cast hz | |
| Β· nlinarith [htarget.2] | |
| theorem inverse_error (reverse : Bool) (a Ξ½ : β€) (s : β) : | |
| |(inverseOffset reverse a : β)-(inverseOffset reverse Ξ½ : β)*s| = | |
| |(a : β)-(Ξ½ : β)*s| := by | |
| cases reverse | |
| Β· simp only [inverseOffset,Bool.false_eq_true,ite_false,Int.cast_neg] | |
| have he : -(a : β)- -(Ξ½ : β)*s = -((a : β)-(Ξ½ : β)*s) := by ring | |
| rw [he,abs_neg] | |
| Β· rfl | |
| /-- Uniformly bounded exceptional grid indices near one real cut. -/ | |
| def nearCut (s t : β) : Finset β€ := Finset.Icc βt/s-5β βt/s+5β | |
| theorem mem_nearCut (s t : β) (k : β€) : | |
| k β nearCut s t β |(k : β)-t/s| β€ 5 := by | |
| simp only [nearCut,Finset.mem_Icc,Int.ceil_le,Int.le_floor,abs_le] | |
| constructor <;> rintro β¨h1,h2β© <;> constructor <;> linarith | |
| theorem nearCut_card (s t : β) : (nearCut s t).card β€ 11 := by | |
| have h1 := Int.le_ceil (t/s-5) | |
| have h2 := Int.floor_le (t/s+5) | |
| have hi : βt/s+5β+1-βt/s-5β β€ (11 : β€) := by | |
| have hr : ((βt/s+5β : β€) : β)+1-βt/s-5β β€ 11 := by linarith | |
| exact_mod_cast hr | |
| simp only [nearCut,Int.card_Icc] | |
| omega | |
| /-- A block containing a compared position and avoiding both endpoint | |
| neighborhoods is deep inside that exact comparison interval. -/ | |
| theorem margin_of_not_near (s : β) (hs : 0 < s) (lo hi : β) (k q : β€) | |
| (hq : q β block s k) (hdom : q β positions lo hi) | |
| (hnlo : k β nearCut s lo) (hnhi : k β nearCut s hi) : | |
| lo β€ (k : β)*s-s β§ ((k : β)+1)*s+s β€ hi := by | |
| have hlo := not_le.mp (mt (mem_nearCut s lo k).mpr hnlo) | |
| have hhi := not_le.mp (mt (mem_nearCut s hi k).mpr hnhi) | |
| obtain β¨hk0,hk1β© := mem_positions.mp hq | |
| obtain β¨hq0,hq1β© := mem_positions.mp hdom | |
| rcases (lt_abs.mp hlo) with hl | hl | |
| Β· have hz : 5+lo/s < (k : β) := by linarith | |
| have hz' := (div_lt_iffβ hs).mp (show lo/s < (k : β)-5 by linarith) | |
| constructor | |
| Β· nlinarith | |
| Β· rcases (lt_abs.mp hhi) with hh | hh | |
| Β· have ht := (div_lt_iffβ hs).mp (show hi/s < (k : β)-5 by linarith) | |
| nlinarith | |
| Β· have ht := (lt_div_iffβ hs).mp (show (k : β)+5 < hi/s by linarith) | |
| nlinarith | |
| Β· have ht := (lt_div_iffβ hs).mp (show (k : β)+5 < lo/s by linarith) | |
| nlinarith | |
| end TorsionFreeZeroDivisors.BlockAlignment | |
| /-! Extraction of the actual partial matching of block occurrences from the | |
| original comparison pairing. Comparison sides are retained, | |
| so a block cannot join itself by aggregating several short comparisons. -/ | |
| end | |
| end OAI | |