Grace/Cumulus/NumberTheory/Dirichlet.g17
Imports
Grace.Cumulus.Real.Floor · Grace.Cumulus.Combinatorics.Pigeonhole · Grace.Cumulus.Real.AbsoluteValue
Declarations
- dirichletBox.scaled_nonnegative theorem derivation
- dirichletBox.scaled_lt theorem derivation
- dirichletBox defgraph
- dirichletBox.collision theorem derivation
- dirichletBox.close theorem derivation
- natural.sub_of_add theorem derivation
- dirichletBox.difference theorem derivation
- dirichletBox.approximation_of_pair theorem derivation
- dirichlet.approximation theorem derivation
Source
1-- Dirichlet's approximation theorem by pigeonhole: for a nonnegative real2-- α and N > 0 there are naturals x and 0 < y ≤ N with |x − y α| N < 1.3-- Part of Cumulus, the Grace17 mathematics library.4-- Copyright (c) 2026 Grant Passmore.5-- Released under the Apache License 2.0. See LICENSE in the repository root.6-- Authors: Grant Passmore78module Grace.Cumulus.NumberTheory.Dirichlet9import Grace.Cumulus.Real.Floor10import Grace.Cumulus.Combinatorics.Pigeonhole11import Grace.Cumulus.Real.AbsoluteValue1213-- The boxes: y ↦ ⌊N · frac(y α)⌋ sends 0..N into the N boxes 0..N − 1,14-- since the scaled fractional part N · frac(y α) lies in [0, N).1516theorem dirichletBox.scaled_nonnegative (α : Real) (N y : Nat)17 requires nonnegative : (0:R) ≤ α18 shows (0:R) ≤ (realNat(N):R) * realFrac((realNat(y):R) * α)19proof20 have yNonnegative := realNat.zero_le at y21 have product := realMulValue.nonnegative with yNonnegative, nonnegative22 have frac := realFrac.nonnegative with product23 have nNonnegative := realNat.zero_le at N24 exact realMulValue.nonnegative with nNonnegative, frac2526theorem dirichletBox.scaled_lt (α : Real) (N y : Nat)27 requires nonnegative : (0:R) ≤ α28 requires positive : 0 < N29 shows (realNat(N):R) * realFrac((realNat(y):R) * α) < realNat(N)30proof31 have yNonnegative := realNat.zero_le at y32 have product := realMulValue.nonnegative with yNonnegative, nonnegative33 have frac := realFrac.lt_one with product34 have nonzero := Less.ne_zero_of_positive with positive35 have nPositive := realNat.positive with nonzero36 have scaled := realLess.mul_left_of_positive with frac, nPositive37 have one : (realNat(N):R) * 1 = realNat(N) by ring38 rwa one at scaled3940defgraph dirichletBox (α : Set, N : Nat) (y ∈ succ(N)) : N :=41 realFloor((realNat(N):R) * realFrac((realNat(y):R) * α))42requires real : Real(α)43requires nonnegative : (0:R) ≤ α44requires positive : 0 < N45proof46 have yNat := natural.member at succ(N) with member47 have lower := dirichletBox.scaled_nonnegative at α, N, y with *48 have upper := dirichletBox.scaled_lt at α, N, y with *49 have below := realFloor.lt_natural with lower, upper50 exact membership.of_Less with *, below5152-- N + 1 values into N boxes: two of them collide.53theorem dirichletBox.collision (α : Real) (N : Nat)54 requires nonnegative : (0:R) ≤ α55 requires positive : 0 < N56 shows ∃ y ∈ succ(N), ∃ z ∈ succ(N), y ≠ z ∧57 dirichletBox(α, N)(y) = dirichletBox(α, N)(z)58proof59 have function := dirichletBox.function with *60 have finite := Finite.natural at N61 have more : cardinality(N) < cardinality(succ(N))62 rw [(cardinality.natural at N), (cardinality.natural at succ(N))]63 unfold Less64 exact LessEqual.reflexive at succ(N) with *65 exact pigeonhole.collision with function, finite, more6667-- A collision: two fractional parts in one box of width 1/N differ by68-- less than 1/N, and their difference is x − (y − z) α for a natural x.6970theorem dirichletBox.close (α : Real) (N y z : Nat)71 requires nonnegative : (0:R) ≤ α72 requires positive : 0 < N73 requires yBound : y ≤ N74 requires zBound : z ≤ N75 requires same : dirichletBox(α, N)(y) = dirichletBox(α, N)(z)76 shows abs(realFrac((realNat(y):R) * α) - realFrac((realNat(z):R) * α)) *77 (realNat(N):R) < (1:R)78proof79 have yMember := membership.successor_of_LessEqual with yBound80 have zMember := membership.successor_of_LessEqual with zBound81 have yValue := dirichletBox.value with nonnegative, positive, yMember82 have zValue := dirichletBox.value with nonnegative, positive, zMember83 rw [yValue, zValue] at same84 have nNonnegative := realNat.zero_le at N85 -- The two scaled fractional parts lie in [⌊·⌋, ⌊·⌋ + 1) for one floor.86 have yScaled := dirichletBox.scaled_nonnegative at α, N, y with nonnegative87 have zScaled := dirichletBox.scaled_nonnegative at α, N, z with nonnegative88 have yLower := realFloor.le with yScaled89 have yUpper := realFloor.lt with yScaled90 have zLower := realFloor.le with zScaled91 have zUpper := realFloor.lt with zScaled92 rw ← same at zLower93 rw ← same at zUpper94 have absN := abs.of_nonnegative with nNonnegative95 have split := abs.mul at realFrac((realNat(y):R) * α) -96 realFrac((realNat(z):R) * α), realNat(N)97 rw [absN] at split98 rw ← split99 have difference : (realFrac((realNat(y):R) * α) -100 realFrac((realNat(z):R) * α)) * realNat(N) =101 (realNat(N):R) * realFrac((realNat(y):R) * α) -102 (realNat(N):R) * realFrac((realNat(z):R) * α)103 ring104 rw difference105 by_cases sign : (0:R) ≤ (realNat(N):R) * realFrac((realNat(y):R) * α) -106 (realNat(N):R) * realFrac((realNat(z):R) * α)107 . rw abs.of_nonnegative with sign108 linarith109 . have negative := realLess.of_not_le with sign110 have nonpositive := realLess.implies_le with negative111 rw abs.of_nonpositive with nonpositive112 linarith113114-- The difference y − z of naturals z ≤ y is the k with z + k = y.115theorem natural.sub_of_add (y z k : Nat)116 requires equation : add(z, k) = y117 shows y - z = k118proof119 have commute := add.commutative at k, z with *120 rw [← equation, commute]121 exact sub.add_right at k, z122123-- For z < y, the floors of z α and y α differ by a natural x124-- (realFloor.monotone), and x − (y − z) α is the difference of the two125-- fractional parts.126theorem dirichletBox.difference (α : Real) (y z : Nat)127 requires nonnegative : (0:R) ≤ α128 requires below : z < y129 shows ∃ x, Nat(x) ∧ (realNat(x):R) - (realNat(y - z):R) * α =130 realFrac((realNat(z):R) * α) - realFrac((realNat(y):R) * α)131proof132 have zNonnegative := realNat.zero_le at z133 have zProduct := realMulValue.nonnegative with zNonnegative, nonnegative134 have le := Less.implies_LessEqual with below135 have mono := realNat.le_of_natural_le with le136 have scaled := realLe.mul_right_of_nonnegative with mono, nonnegative137 obtain ⟨x, xNat, equation⟩ := realFloor.monotone with zProduct, scaled138 have sum := realNat.add at realFloor((realNat(z):R) * α), x with *139 rw equation at sum140 obtain ⟨k, kNat, decomposition⟩ := le141 have split := natural.sub_of_add with decomposition142 have parts := realNat.add at z, k143 rw decomposition at parts144 witness x145 rw [realFrac.value, realFrac.value, sum, split, parts]146 ring147148-- Dirichlet's theorem: a colliding pair z < y gives the approximation149-- with denominator y − z.150151theorem dirichletBox.approximation_of_pair (α : Real) (N y z : Nat)152 requires nonnegative : (0:R) ≤ α153 requires positive : 0 < N154 requires yBound : y ≤ N155 requires zBound : z ≤ N156 requires below : z < y157 requires same : dirichletBox(α, N)(y) = dirichletBox(α, N)(z)158 shows ∃ x, Nat(x) ∧ ∃ w, Nat(w) ∧ 0 < w ∧ w ≤ N ∧159 abs((realNat(x):R) - (realNat(w):R) * α) * (realNat(N):R) < (1:R)160proof161 obtain ⟨x, xNat, equation⟩ :=162 dirichletBox.difference with nonnegative, below163 have close := dirichletBox.close with *164 obtain ⟨k, kNat, decomposition⟩ := Less.implies_LessEqual with below165 have split := natural.sub_of_add with decomposition166 have kPositive : 0 < k by arith167 have kBound : k ≤ N by arith168 have flip : realFrac((realNat(z):R) * α) - realFrac((realNat(y):R) * α) =169 -(realFrac((realNat(y):R) * α) - realFrac((realNat(z):R) * α))170 ring171 rw [split, flip] at equation172 refine ⟨x, xNat, k, kNat, kPositive, kBound, ?_⟩173 rw [equation, abs.neg]174 exact close175176theorem dirichlet.approximation (α : Real) (N : Nat)177 requires nonnegative : (0:R) ≤ α178 requires positive : 0 < N179 shows ∃ x, Nat(x) ∧ ∃ y, Nat(y) ∧ 0 < y ∧ y ≤ N ∧180 abs((realNat(x):R) - (realNat(y):R) * α) * (realNat(N):R) < (1:R)181proof182 obtain ⟨y, yMember, z, zMember, different, same⟩ :=183 dirichletBox.collision with nonnegative, positive184 have yNat := natural.member at succ(N) with yMember185 have zNat := natural.member at succ(N) with zMember186 have yBound := LessEqual.of_membership_successor with yMember187 have zBound := LessEqual.of_membership_successor with zMember188 have shape := Less.trichotomy at y, z with *189 rcases shape with less | equal | greater190 . symm at same191 exact dirichletBox.approximation_of_pair with192 nonnegative, positive, zBound, yBound, less, same193 . exfalso194 exact different with equal195 . exact dirichletBox.approximation_of_pair with196 nonnegative, positive, yBound, zBound, greater, same197