Skip to content

Commit fd3a089

Browse files
committed
feat(NumberTheory): Rayleigh's theorem (#7027)
1 parent fe7a998 commit fd3a089

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,6 +2636,7 @@ import Mathlib.NumberTheory.PrimesCongruentOne
26362636
import Mathlib.NumberTheory.Primorial
26372637
import Mathlib.NumberTheory.PythagoreanTriples
26382638
import Mathlib.NumberTheory.RamificationInertia
2639+
import Mathlib.NumberTheory.Rayleigh
26392640
import Mathlib.NumberTheory.SumFourSquares
26402641
import Mathlib.NumberTheory.SumTwoSquares
26412642
import Mathlib.NumberTheory.VonMangoldt

Mathlib/NumberTheory/Rayleigh.lean

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/-
2+
Copyright (c) 2023 Jason Yuen. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Jason Yuen
5+
-/
6+
import Mathlib.Data.Real.ConjugateExponents
7+
import Mathlib.Data.Real.Irrational
8+
9+
/-!
10+
# Rayleigh's theorem on Beatty sequences
11+
12+
This file proves Rayleigh's theorem on Beatty sequences. We start by proving `compl_beattySeq`,
13+
which is a generalization of Rayleigh's theorem, and eventually prove
14+
`Irrational.beattySeq_symmDiff_beattySeq_pos`, which is Rayleigh's theorem.
15+
16+
## Main definitions
17+
18+
* `beattySeq`: In the Beatty sequence for real number `r`, the `k`th term is `⌊k * r⌋`.
19+
* `beattySeq'`: In this variant of the Beatty sequence for `r`, the `k`th term is `⌈k * r⌉ - 1`.
20+
21+
## Main statements
22+
23+
Define the following Beatty sets, where `r` denotes a real number:
24+
25+
* `B_r := {⌊k * r⌋ | k ∈ ℤ}`
26+
* `B'_r := {⌈k * r⌉ - 1 | k ∈ ℤ}`
27+
* `B⁺_r := {⌊r⌋, ⌊2r⌋, ⌊3r⌋, ...}`
28+
* `B⁺'_r := {⌈r⌉-1, ⌈2r⌉-1, ⌈3r⌉-1, ...}`
29+
30+
The main statements are:
31+
32+
* `compl_beattySeq`: Let `r` be a real number greater than 1, and `1/r + 1/s = 1`.
33+
Then the complement of `B_r` is `B'_s`.
34+
* `beattySeq_symmDiff_beattySeq'_pos`: Let `r` be a real number greater than 1, and `1/r + 1/s = 1`.
35+
Then `B⁺_r` and `B⁺'_s` partition the positive integers.
36+
* `Irrational.beattySeq_symmDiff_beattySeq_pos`: Let `r` be an irrational number greater than 1, and
37+
`1/r + 1/s = 1`. Then `B⁺_r` and `B⁺_s` partition the positive integers.
38+
39+
## References
40+
41+
* [Wikipedia, *Beatty sequence*](https://en.wikipedia.org/wiki/Beatty_sequence)
42+
43+
## Tags
44+
45+
beatty, sequence, rayleigh, irrational, floor, positive
46+
-/
47+
48+
/-- In the Beatty sequence for real number `r`, the `k`th term is `⌊k * r⌋`. -/
49+
noncomputable def beattySeq (r : ℝ) : ℤ → ℤ :=
50+
fun k ↦ ⌊k * r⌋
51+
52+
/-- In this variant of the Beatty sequence for `r`, the `k`th term is `⌈k * r⌉ - 1`. -/
53+
noncomputable def beattySeq' (r : ℝ) : ℤ → ℤ :=
54+
fun k ↦ ⌈k * r⌉ - 1
55+
56+
namespace Beatty
57+
58+
variable {r s : ℝ} (hrs : r.IsConjugateExponent s) {j k : ℤ}
59+
60+
/-- Let `r > 1` and `1/r + 1/s = 1`. Then `B_r` and `B'_s` are disjoint (i.e. no collision exists).
61+
-/
62+
private theorem no_collision : Disjoint {beattySeq r k | k} {beattySeq' s k | k} := by
63+
rw [Set.disjoint_left]
64+
intro j ⟨k, h₁⟩ ⟨m, h₂⟩
65+
rw [beattySeq, Int.floor_eq_iff, ← div_le_iff hrs.pos, ← lt_div_iff hrs.pos] at h₁
66+
rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one,
67+
add_sub_cancel, ← div_lt_iff hrs.symm.pos, ← le_div_iff hrs.symm.pos] at h₂
68+
have h₃ := add_lt_add_of_le_of_lt h₁.1 h₂.1
69+
have h₄ := add_lt_add_of_lt_of_le h₁.2 h₂.2
70+
simp_rw [div_eq_inv_mul, ← right_distrib, inv_eq_one_div, hrs.inv_add_inv_conj, one_mul] at h₃ h₄
71+
rw [← Int.cast_one] at h₄
72+
simp_rw [← Int.cast_add, Int.cast_lt, Int.lt_add_one_iff] at h₃ h₄
73+
exact h₄.not_lt h₃
74+
75+
/-- Let `r > 1` and `1/r + 1/s = 1`. Suppose there is an integer `j` where `B_r` and `B'_s` both
76+
jump over `j` (i.e. an anti-collision). Then this leads to a contradiction. -/
77+
private theorem no_anticollision :
78+
¬∃ j k m : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 ∧ m ≤ j / s ∧ (j + 1) / s < m + 1 := by
79+
intro ⟨j, k, m, h₁₁, h₁₂, h₂₁, h₂₂⟩
80+
have h₃ := add_lt_add_of_lt_of_le h₁₁ h₂₁
81+
have h₄ := add_lt_add_of_le_of_lt h₁₂ h₂₂
82+
simp_rw [div_eq_inv_mul, ← right_distrib, inv_eq_one_div, hrs.inv_add_inv_conj, one_mul] at h₃ h₄
83+
rw [← Int.cast_one, ← add_assoc, add_lt_add_iff_right, add_right_comm] at h₄
84+
simp_rw [← Int.cast_add, Int.cast_lt, Int.lt_add_one_iff] at h₃ h₄
85+
exact h₄.not_lt h₃
86+
87+
/-- Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B_r` or `B_r` jumps over `j`. -/
88+
private theorem hit_or_miss (h : r > 0) :
89+
j ∈ {beattySeq r k | k} ∨ ∃ k : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 := by
90+
-- for both cases, the candidate is `k = ⌈(j + 1) / r⌉ - 1`
91+
cases lt_or_ge ((⌈(j + 1) / r⌉ - 1) * r) j
92+
· refine Or.inr ⟨⌈(j + 1) / r⌉ - 1, ?_⟩
93+
rw [Int.cast_sub, Int.cast_one, lt_div_iff h, sub_add_cancel]
94+
exact ⟨‹_›, Int.le_ceil _⟩
95+
· refine Or.inl ⟨⌈(j + 1) / r⌉ - 1, ?_⟩
96+
rw [beattySeq, Int.floor_eq_iff, Int.cast_sub, Int.cast_one, ← lt_div_iff h, sub_lt_iff_lt_add]
97+
exact ⟨‹_›, Int.ceil_lt_add_one _⟩
98+
99+
/-- Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B'_r` or `B'_r` jumps over `j`. -/
100+
private theorem hit_or_miss' (h : r > 0) :
101+
j ∈ {beattySeq' r k | k} ∨ ∃ k : ℤ, k ≤ j / r ∧ (j + 1) / r < k + 1 := by
102+
-- for both cases, the candidate is `k = ⌊(j + 1) / r⌋`
103+
cases le_or_gt (⌊(j + 1) / r⌋ * r) j
104+
· exact Or.inr ⟨⌊(j + 1) / r⌋, (le_div_iff h).2 ‹_›, Int.lt_floor_add_one _⟩
105+
· refine Or.inl ⟨⌊(j + 1) / r⌋, ?_⟩
106+
rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one]
107+
constructor
108+
· rwa [add_sub_cancel]
109+
exact sub_nonneg.1 (Int.sub_floor_div_mul_nonneg (j + 1 : ℝ) h)
110+
111+
end Beatty
112+
113+
/-- Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater
114+
than 1, and `1/r + 1/s = 1`. Then the complement of `B_r` is `B'_s`. -/
115+
theorem compl_beattySeq {r s : ℝ} (hrs : r.IsConjugateExponent s) :
116+
{beattySeq r k | k}ᶜ = {beattySeq' s k | k} := by
117+
ext j
118+
by_cases h₁ : j ∈ {beattySeq r k | k} <;> by_cases h₂ : j ∈ {beattySeq' s k | k}
119+
· exact (Set.not_disjoint_iff.2 ⟨j, h₁, h₂⟩ (Beatty.no_collision hrs)).elim
120+
· simp only [Set.mem_compl_iff, h₁, h₂]
121+
· simp only [Set.mem_compl_iff, h₁, h₂]
122+
· have ⟨k, h₁₁, h₁₂⟩ := (Beatty.hit_or_miss hrs.pos).resolve_left h₁
123+
have ⟨m, h₂₁, h₂₂⟩ := (Beatty.hit_or_miss' hrs.symm.pos).resolve_left h₂
124+
exact (Beatty.no_anticollision hrs ⟨j, k, m, h₁₁, h₁₂, h₂₁, h₂₂⟩).elim
125+
126+
theorem compl_beattySeq' {r s : ℝ} (hrs : r.IsConjugateExponent s) :
127+
{beattySeq' r k | k}ᶜ = {beattySeq s k | k} := by
128+
rw [← compl_beattySeq hrs.symm, compl_compl]
129+
130+
/-- Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater
131+
than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺'_s` partition the positive integers. -/
132+
theorem beattySeq_symmDiff_beattySeq'_pos {r s : ℝ} (hrs : r.IsConjugateExponent s) :
133+
{beattySeq r k | k > 0} ∆ {beattySeq' s k | k > 0} = {n | 0 < n} := by
134+
apply Set.eq_of_subset_of_subset
135+
· rintro j (⟨⟨k, hk, hjk⟩, -⟩ | ⟨⟨k, hk, hjk⟩, -⟩)
136+
· rw [Set.mem_setOf_eq, ← hjk, beattySeq, Int.floor_pos]
137+
exact one_le_mul_of_one_le_of_one_le (by norm_cast) hrs.one_lt.le
138+
· rw [Set.mem_setOf_eq, ← hjk, beattySeq', sub_pos, Int.lt_ceil, Int.cast_one]
139+
exact one_lt_mul_of_le_of_lt (by norm_cast) hrs.symm.one_lt
140+
intro j (hj : 0 < j)
141+
have hb₁ : ∀ s ≥ 0, j ∈ {beattySeq s k | k > 0} ↔ j ∈ {beattySeq s k | k} := by
142+
intro _ hs
143+
refine ⟨fun ⟨k, _, hk⟩ ↦ ⟨k, hk⟩, fun ⟨k, hk⟩ ↦ ⟨k, ?_, hk⟩⟩
144+
rw [← hk, beattySeq, Int.floor_pos] at hj
145+
exact_mod_cast pos_of_mul_pos_left (zero_lt_one.trans_le hj) hs
146+
have hb₂ : ∀ s ≥ 0, j ∈ {beattySeq' s k | k > 0} ↔ j ∈ {beattySeq' s k | k} := by
147+
intro _ hs
148+
refine ⟨fun ⟨k, _, hk⟩ ↦ ⟨k, hk⟩, fun ⟨k, hk⟩ ↦ ⟨k, ?_, hk⟩⟩
149+
rw [← hk, beattySeq', sub_pos, Int.lt_ceil, Int.cast_one] at hj
150+
exact_mod_cast pos_of_mul_pos_left (zero_lt_one.trans hj) hs
151+
rw [Set.mem_symmDiff, hb₁ _ hrs.nonneg, hb₂ _ hrs.symm.nonneg, ← compl_beattySeq hrs,
152+
Set.not_mem_compl_iff, Set.mem_compl_iff, and_self, and_self]
153+
exact or_not
154+
155+
theorem beattySeq'_symmDiff_beattySeq_pos {r s : ℝ} (hrs : r.IsConjugateExponent s) :
156+
{beattySeq' r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by
157+
rw [symmDiff_comm, beattySeq_symmDiff_beattySeq'_pos hrs.symm]
158+
159+
/-- Let `r` be an irrational number. Then `B⁺_r` and `B⁺'_r` are equal. -/
160+
theorem Irrational.beattySeq'_pos_eq {r : ℝ} (hr : Irrational r) :
161+
{beattySeq' r k | k > 0} = {beattySeq r k | k > 0} := by
162+
dsimp only [beattySeq, beattySeq']
163+
congr! 4; rename_i k; rw [and_congr_right_iff]; intro hk; congr!
164+
rw [sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one, add_sub_cancel]
165+
refine ⟨(Int.floor_le _).lt_of_ne fun h ↦ ?_, (Int.lt_floor_add_one _).le⟩
166+
exact (hr.int_mul hk.ne').ne_int ⌊k * r⌋ h.symm
167+
168+
/-- Rayleigh's theorem on Beatty sequences. Let `r` be an irrational number greater than 1, and
169+
`1/r + 1/s = 1`. Then `B⁺_r` and `B⁺_s` partition the positive integers. -/
170+
theorem Irrational.beattySeq_symmDiff_beattySeq_pos {r s : ℝ}
171+
(hrs : r.IsConjugateExponent s) (hr : Irrational r) :
172+
{beattySeq r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by
173+
rw [← hr.beattySeq'_pos_eq, beattySeq'_symmDiff_beattySeq_pos hrs]

0 commit comments

Comments
 (0)