math / data /lean /OAI /Algebra /GroupRing /BlockGrid.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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