@@ -11,26 +11,26 @@ import Mathlib.Tactic
1111open Function Set
1212
1313/-!
14- Given a strictly monotonic function `φ : ℕ → ℕ` and `k : ℕ` with `k ≥ ϕ 0`,
15- `Nat.segment φ k` is the unique `m : ℕ` such that `φ m ≤ k < φ (k + 1)`.
16- `Nat.segment φ k` is defined to be 0 for `k < ϕ 0`.
14+ Given a strictly monotonic function `f : ℕ → ℕ` and `k : ℕ` with `k ≥ ϕ 0`,
15+ `Nat.segment f k` is the unique `m : ℕ` such that `f m ≤ k < f (k + 1)`.
16+ `Nat.segment f k` is defined to be 0 for `k < ϕ 0`.
1717This file defines `Nat.segment` and proves various properties aboout it.
1818-/
1919@[scoped grind]
20- noncomputable def Nat.segment (φ : ℕ → ℕ) (k : ℕ) : ℕ :=
20+ noncomputable def Nat.segment (f : ℕ → ℕ) (k : ℕ) : ℕ :=
2121 open scoped Classical in
22- Nat.count (· ∈ range φ ) (k + 1 ) - 1
22+ Nat.count (· ∈ range f ) (k + 1 ) - 1
2323
24- variable {φ : ℕ → ℕ}
24+ variable {f : ℕ → ℕ}
2525
26- /-- Any strictly monotonic function `φ : ℕ → ℕ` has an infinite range. -/
27- theorem Nat.strict_mono_infinite (hm : StrictMono φ ) :
28- (range φ ).Infinite :=
26+ /-- Any strictly monotonic function `f : ℕ → ℕ` has an infinite range. -/
27+ theorem Nat.strict_mono_infinite (hm : StrictMono f ) :
28+ (range f ).Infinite :=
2929 infinite_range_of_injective hm.injective
3030
3131/-- Any infinite suset of `ℕ` is the range of a strictly monotonic function. -/
3232theorem Nat.infinite_strict_mono {ns : Set ℕ} (h : ns.Infinite) :
33- ∃ φ : ℕ → ℕ, StrictMono φ ∧ range φ = ns :=
33+ ∃ f : ℕ → ℕ, StrictMono f ∧ range f = ns :=
3434 ⟨Nat.nth (· ∈ ns), Nat.nth_strictMono h, Nat.range_nth_of_infinite h⟩
3535
3636/-- There is a gap between two successive occurrences of a predicate `p : ℕ → Prop`,
@@ -45,121 +45,121 @@ theorem Nat.nth_succ_gap {p : ℕ → Prop} (hf : (setOf p).Infinite) (n : ℕ)
4545 have h_m_n : m < n + 1 := by apply (Nat.nth_lt_nth hf).mp ; omega
4646 omega
4747
48- /-- For a strictly monotonic function `φ : ℕ → ℕ`, `φ n` is exactly the n-th
49- element of the range of `φ `. -/
50- theorem Nat.nth_of_strict_mono (hm : StrictMono φ ) (n : ℕ) :
51- φ n = Nat.nth (· ∈ range φ ) n := by
52- have (hf : (range φ ).Finite) : False := hf.not_infinite (strict_mono_infinite hm)
48+ /-- For a strictly monotonic function `f : ℕ → ℕ`, `f n` is exactly the n-th
49+ element of the range of `f `. -/
50+ theorem Nat.nth_of_strict_mono (hm : StrictMono f ) (n : ℕ) :
51+ f n = Nat.nth (· ∈ range f ) n := by
52+ have (hf : (range f ).Finite) : False := hf.not_infinite (strict_mono_infinite hm)
5353 rw [←Nat.nth_comp_of_strictMono hm] <;> first | grind | simp
5454
5555open scoped Classical in
56- /-- If `φ 0 = 0`, then `0` is below any `n` not in the range of `φ `. -/
57- theorem Nat.count_notin_range_pos (h0 : φ 0 = 0 ) (n : ℕ) (hn : n ∉ range φ ) :
58- Nat.count (· ∈ range φ ) n > 0 := by
59- have := Nat.count_monotone (· ∈ range φ ) (show 1 ≤ n by grind)
56+ /-- If `f 0 = 0`, then `0` is below any `n` not in the range of `f `. -/
57+ theorem Nat.count_notin_range_pos (h0 : f 0 = 0 ) (n : ℕ) (hn : n ∉ range f ) :
58+ Nat.count (· ∈ range f ) n > 0 := by
59+ have := Nat.count_monotone (· ∈ range f ) (show 1 ≤ n by grind)
6060 grind
6161
62- /-- For a strictly monotonic function `φ : ℕ → ℕ`, no number (strictly) between
63- `φ m` and ` φ (m + 1)` is in the range of `φ `. -/
64- theorem Nat.strict_mono_range_gap (hm : StrictMono φ ) {m k : ℕ}
65- (hl : φ m < k) (hu : k < φ (m + 1 )) : k ∉ range φ := by
62+ /-- For a strictly monotonic function `f : ℕ → ℕ`, no number (strictly) between
63+ `f m` and ` f (m + 1)` is in the range of `f `. -/
64+ theorem Nat.strict_mono_range_gap (hm : StrictMono f ) {m k : ℕ}
65+ (hl : f m < k) (hu : k < f (m + 1 )) : k ∉ range f := by
6666 rw [nth_of_strict_mono hm m] at hl
6767 rw [nth_of_strict_mono hm (m + 1 )] at hu
6868 have h_inf := strict_mono_infinite hm
69- have h_gap := nth_succ_gap (p := (· ∈ range φ )) h_inf m
70- (k - Nat.nth (· ∈ range φ ) m) (by omega) (by omega)
71- rw [(show k - Nat.nth (· ∈ range φ ) m + Nat.nth (· ∈ range φ ) m = k by omega)] at h_gap
69+ have h_gap := nth_succ_gap (p := (· ∈ range f )) h_inf m
70+ (k - Nat.nth (· ∈ range f ) m) (by omega) (by omega)
71+ rw [(show k - Nat.nth (· ∈ range f ) m + Nat.nth (· ∈ range f ) m = k by omega)] at h_gap
7272 exact h_gap
7373
74- /-- For a strictly monotonic function `φ : ℕ → ℕ`, the segment of `φ k` is `k`. -/
74+ /-- For a strictly monotonic function `f : ℕ → ℕ`, the segment of `f k` is `k`. -/
7575@[simp]
76- theorem Nat.segment_idem (hm : StrictMono φ ) (k : ℕ) :
77- segment φ (φ k) = k := by
76+ theorem Nat.segment_idem (hm : StrictMono f ) (k : ℕ) :
77+ segment f (f k) = k := by
7878 classical
79- have := Nat.count_nth_of_infinite (p := (· ∈ range φ )) <| strict_mono_infinite hm
79+ have := Nat.count_nth_of_infinite (p := (· ∈ range f )) <| strict_mono_infinite hm
8080 have := nth_of_strict_mono hm
8181 grind [segment]
8282
83- /-- For a strictly monotonic function `φ : ℕ → ℕ`, `segment φ k = 0` for all `k < φ 0`. -/
83+ /-- For a strictly monotonic function `f : ℕ → ℕ`, `segment f k = 0` for all `k < f 0`. -/
8484@[scoped grind =]
85- theorem Nat.segment_pre_zero (hm : StrictMono φ ) {k : ℕ} (h : k < φ 0 ) :
86- segment φ k = 0 := by
85+ theorem Nat.segment_pre_zero (hm : StrictMono f ) {k : ℕ} (h : k < f 0 ) :
86+ segment f k = 0 := by
8787 classical
88- have h1 : Nat.count (· ∈ range φ ) (k + 1 ) = 0 := by
88+ have h1 : Nat.count (· ∈ range f ) (k + 1 ) = 0 := by
8989 apply Nat.count_of_forall_not
9090 rintro n h_n ⟨i, rfl⟩
9191 have := StrictMono.monotone hm <| zero_le i
9292 omega
9393 rw [segment, h1]
9494
95- /-- For a strictly monotonic function `φ : ℕ → ℕ` with `φ 0 = 0`, `segment φ 0 = 0`. -/
95+ /-- For a strictly monotonic function `f : ℕ → ℕ` with `f 0 = 0`, `segment f 0 = 0`. -/
9696@[scoped grind =]
97- theorem Nat.segment_zero (hm : StrictMono φ ) (h0 : φ 0 = 0 ) :
98- segment φ 0 = 0 := by
99- calc _ = segment φ (φ 0 ) := by simp [h0]
97+ theorem Nat.segment_zero (hm : StrictMono f ) (h0 : f 0 = 0 ) :
98+ segment f 0 = 0 := by
99+ calc _ = segment f (f 0 ) := by simp [h0]
100100 _ = _ := by simp [segment_idem hm]
101101
102102open scoped Classical in
103103/-- A slight restatement of the definition of `segment` which has proven useful. -/
104- theorem Nat.segment_plus_one (h0 : φ 0 = 0 ) (k : ℕ) :
105- segment φ k + 1 = Nat.count (· ∈ range φ ) (k + 1 ) := by
106- suffices _ : Nat.count (· ∈ range φ ) (k + 1 ) ≠ 0 by unfold segment ; omega
104+ theorem Nat.segment_plus_one (h0 : f 0 = 0 ) (k : ℕ) :
105+ segment f k + 1 = Nat.count (· ∈ range f ) (k + 1 ) := by
106+ suffices _ : Nat.count (· ∈ range f ) (k + 1 ) ≠ 0 by unfold segment ; omega
107107 apply Nat.count_ne_iff_exists.mpr ; use 0 ; grind
108108
109- /-- For a strictly monotonic function `φ : ℕ → ℕ` with `φ 0 = 0`,
110- `k < φ (segment φ k + 1)` for all `k : ℕ`. -/
111- theorem Nat.segment_upper_bound (hm : StrictMono φ ) (h0 : φ 0 = 0 ) (k : ℕ) :
112- k < φ (segment φ k + 1 ) := by
109+ /-- For a strictly monotonic function `f : ℕ → ℕ` with `f 0 = 0`,
110+ `k < f (segment f k + 1)` for all `k : ℕ`. -/
111+ theorem Nat.segment_upper_bound (hm : StrictMono f ) (h0 : f 0 = 0 ) (k : ℕ) :
112+ k < f (segment f k + 1 ) := by
113113 classical
114- rw [nth_of_strict_mono hm (segment φ k + 1 ), segment_plus_one h0 k]
115- suffices _ : k + 1 ≤ Nat.nth (· ∈ range φ ) (Nat.count (· ∈ range φ ) (k + 1 )) by omega
114+ rw [nth_of_strict_mono hm (segment f k + 1 ), segment_plus_one h0 k]
115+ suffices _ : k + 1 ≤ Nat.nth (· ∈ range f ) (Nat.count (· ∈ range f ) (k + 1 )) by omega
116116 apply Nat.le_nth_count
117117 exact strict_mono_infinite hm
118118
119- /-- For a strictly monotonic function `φ : ℕ → ℕ` with `φ 0 = 0`,
120- `φ (segment φ k) ≤ k` for all `k : ℕ`. -/
121- theorem Nat.segment_lower_bound (hm : StrictMono φ ) (h0 : φ 0 = 0 ) (k : ℕ) :
122- φ (segment φ k) ≤ k := by
119+ /-- For a strictly monotonic function `f : ℕ → ℕ` with `f 0 = 0`,
120+ `f (segment f k) ≤ k` for all `k : ℕ`. -/
121+ theorem Nat.segment_lower_bound (hm : StrictMono f ) (h0 : f 0 = 0 ) (k : ℕ) :
122+ f (segment f k) ≤ k := by
123123 classical
124- rw [nth_of_strict_mono hm (segment φ k), segment]
125- rcases Classical.em (k ∈ range φ ) with h_k | h_k
124+ rw [nth_of_strict_mono hm (segment f k), segment]
125+ rcases Classical.em (k ∈ range f ) with h_k | h_k
126126 · simp_all [Nat.count_succ_eq_succ_count]
127- · have h1 : Nat.count (· ∈ range φ ) k > 0 := count_notin_range_pos h0 k h_k
128- have h2 : Nat.count (· ∈ range φ ) (k + 1 ) = Nat.count (· ∈ range φ ) k :=
127+ · have h1 : Nat.count (· ∈ range f ) k > 0 := count_notin_range_pos h0 k h_k
128+ have h2 : Nat.count (· ∈ range f ) (k + 1 ) = Nat.count (· ∈ range f ) k :=
129129 Nat.count_succ_eq_count h_k
130130 rw [h2]
131- suffices _ : Nat.nth (· ∈ range φ ) (Nat.count (· ∈ range φ ) k - 1 ) < k by omega
131+ suffices _ : Nat.nth (· ∈ range f ) (Nat.count (· ∈ range f ) k - 1 ) < k by omega
132132 apply Nat.nth_lt_of_lt_count
133133 omega
134134
135- /-- For a strictly monotonic function `φ : ℕ → ℕ`, all `k` satisfying `φ m ≤ k < φ (m + 1)`
136- has `segment φ k = m`. -/
137- theorem Nat.segment_range_val (hm : StrictMono φ ) {m k : ℕ}
138- (hl : φ m ≤ k) (hu : k < φ (m + 1 )) : segment φ k = m := by
135+ /-- For a strictly monotonic function `f : ℕ → ℕ`, all `k` satisfying `f m ≤ k < f (m + 1)`
136+ has `segment f k = m`. -/
137+ theorem Nat.segment_range_val (hm : StrictMono f ) {m k : ℕ}
138+ (hl : f m ≤ k) (hu : k < f (m + 1 )) : segment f k = m := by
139139 classical
140- obtain (rfl | hu') := show φ m = k ∨ φ m < k by omega
140+ obtain (rfl | hu') := show f m = k ∨ f m < k by omega
141141 · exact segment_idem hm m
142- · obtain ⟨j, h_j, rfl⟩ : ∃ j < φ (m + 1 ) - φ m - 1 , k = j + φ m + 1 := ⟨k - φ m - 1 , by omega⟩
142+ · obtain ⟨j, h_j, rfl⟩ : ∃ j < f (m + 1 ) - f m - 1 , k = j + f m + 1 := ⟨k - f m - 1 , by omega⟩
143143 induction j
144144 case zero =>
145- have : Nat.count (· ∈ range φ ) (φ m + 1 + 1 ) = Nat.count (· ∈ range φ ) (φ m + 1 ) := by
146- have := strict_mono_range_gap hm (show φ m < φ m + 1 by grind)
145+ have : Nat.count (· ∈ range f ) (f m + 1 + 1 ) = Nat.count (· ∈ range f ) (f m + 1 ) := by
146+ have := strict_mono_range_gap hm (show f m < f m + 1 by grind)
147147 grind
148148 have := nth_of_strict_mono hm m
149149 grind [Nat.count_nth_of_infinite, strict_mono_infinite]
150150 case succ j _ =>
151- have := strict_mono_range_gap hm (show φ m < j + 1 + φ m by grind)
152- have := strict_mono_range_gap hm (show φ m < j + 1 + φ m + 1 by grind)
151+ have := strict_mono_range_gap hm (show f m < j + 1 + f m by grind)
152+ have := strict_mono_range_gap hm (show f m < j + 1 + f m + 1 by grind)
153153 grind
154154
155- /-- For a strictly monotonic function `φ : ℕ → ℕ` with `φ 0 = 0`,
156- `φ ` and `segment φ ` form a Galois connection. -/
157- theorem Nat.segment_galois_connection (hm : StrictMono φ ) (h0 : φ 0 = 0 ) :
158- GaloisConnection φ (segment φ ) := by
155+ /-- For a strictly monotonic function `f : ℕ → ℕ` with `f 0 = 0`,
156+ `f ` and `segment f ` form a Galois connection. -/
157+ theorem Nat.segment_galois_connection (hm : StrictMono f ) (h0 : f 0 = 0 ) :
158+ GaloisConnection f (segment f ) := by
159159 intro m k ; constructor
160160 · intro h
161161 by_contra! h_con
162- have h1 : segment φ k + 1 ≤ m := by omega
162+ have h1 : segment f k + 1 ≤ m := by omega
163163 have := (StrictMono.le_iff_le hm).mpr h1
164164 have := segment_upper_bound hm h0 k
165165 omega
@@ -171,38 +171,38 @@ theorem Nat.segment_galois_connection (hm : StrictMono φ) (h0 : φ 0 = 0) :
171171
172172/-- Nat.segment' is a helper function that will be proved to be equal to `Nat.segment`.
173173It facilitates the proofs of some theorems below. -/
174- noncomputable def Nat.segment' (φ : ℕ → ℕ) (k : ℕ) : ℕ :=
175- segment (φ · - φ 0 ) (k - φ 0 )
174+ noncomputable def Nat.segment' (f : ℕ → ℕ) (k : ℕ) : ℕ :=
175+ segment (f · - f 0 ) (k - f 0 )
176176
177- private lemma base_zero_shift (φ : ℕ → ℕ) :
178- (φ · - φ 0 ) 0 = 0 := by
177+ private lemma base_zero_shift (f : ℕ → ℕ) :
178+ (f · - f 0 ) 0 = 0 := by
179179 simp
180180
181- private lemma base_zero_strict_mono (hm : StrictMono φ ) :
182- StrictMono (φ · - φ 0 ) := by
181+ private lemma base_zero_strict_mono (hm : StrictMono f ) :
182+ StrictMono (f · - f 0 ) := by
183183 intro m n h_m_n ; simp
184184 have := hm h_m_n
185- have : φ 0 ≤ φ m := by simp [StrictMono.le_iff_le hm]
186- have : φ 0 ≤ φ n := by simp [StrictMono.le_iff_le hm]
185+ have : f 0 ≤ f m := by simp [StrictMono.le_iff_le hm]
186+ have : f 0 ≤ f n := by simp [StrictMono.le_iff_le hm]
187187 omega
188188
189- /-- For a strictly monotonic function `φ : ℕ → ℕ`,
190- `segment' φ ` and `segment φ ` are actually equal. -/
191- theorem Nat.segment'_eq_segment (hm : StrictMono φ ) :
192- segment' φ = segment φ := by
189+ /-- For a strictly monotonic function `f : ℕ → ℕ`,
190+ `segment' f ` and `segment f ` are actually equal. -/
191+ theorem Nat.segment'_eq_segment (hm : StrictMono f ) :
192+ segment' f = segment f := by
193193 classical
194194 ext k ; unfold segment'
195- rcases (show k < φ 0 ∨ k ≥ φ 0 by omega) with h_k | h_k
196- · have : k - φ 0 = 0 := by grind
195+ rcases (show k < f 0 ∨ k ≥ f 0 by omega) with h_k | h_k
196+ · have : k - f 0 = 0 := by grind
197197 grind
198198 unfold segment ; congr 1
199199 simp only [Nat.count_eq_card_filter_range]
200- suffices h : ∃ f , BijOn f
201- ({x ∈ Finset.range (k - φ 0 + 1 ) | x ∈ range fun x => φ x - φ 0 }).toSet
202- ({x ∈ Finset.range (k + 1 ) | x ∈ range φ }).toSet by
203- obtain ⟨f , h_bij⟩ := h
204- exact BijOn.finsetCard_eq f h_bij
205- refine ⟨fun n ↦ n + φ 0 , ?_, ?_, ?_⟩
200+ suffices h : ∃ g , BijOn g
201+ ({x ∈ Finset.range (k - f 0 + 1 ) | x ∈ range fun x => f x - f 0 }).toSet
202+ ({x ∈ Finset.range (k + 1 ) | x ∈ range f }).toSet by
203+ obtain ⟨g , h_bij⟩ := h
204+ exact BijOn.finsetCard_eq g h_bij
205+ refine ⟨fun n ↦ n + f 0 , ?_, ?_, ?_⟩
206206 · intro n ; simp only [mem_range, Finset.coe_filter, Finset.mem_range, mem_setOf_eq]
207207 rintro ⟨h_n, i, rfl⟩
208208 have := StrictMono.monotone hm <| zero_le i
@@ -211,24 +211,24 @@ theorem Nat.segment'_eq_segment (hm : StrictMono φ) :
211211 · intro n ; simp only [mem_range, Finset.coe_filter, Finset.mem_range, mem_setOf_eq, mem_image]
212212 rintro ⟨h_n, i, rfl⟩
213213 have := StrictMono.monotone hm <| zero_le i
214- refine ⟨φ i - φ 0 , ⟨by omega, i, rfl⟩, by omega⟩
214+ refine ⟨f i - f 0 , ⟨by omega, i, rfl⟩, by omega⟩
215215
216- /-- For a strictly monotonic function `φ : ℕ → ℕ`, `segment φ k = 0` for all `k ≤ φ 0`. -/
217- theorem Nat.segment_zero' (hm : StrictMono φ ) {k : ℕ} (h : k ≤ φ 0 ) :
218- segment φ k = 0 := by
219- rw [← segment'_eq_segment hm, segment', (show k - φ 0 = 0 by omega)]
216+ /-- For a strictly monotonic function `f : ℕ → ℕ`, `segment f k = 0` for all `k ≤ f 0`. -/
217+ theorem Nat.segment_zero' (hm : StrictMono f ) {k : ℕ} (h : k ≤ f 0 ) :
218+ segment f k = 0 := by
219+ rw [← segment'_eq_segment hm, segment', (show k - f 0 = 0 by omega)]
220220 grind
221221
222- /-- For a strictly monotonic function `φ : ℕ → ℕ`, `k < φ (segment φ k + 1)` for all `k ≥ φ 0`. -/
223- theorem Nat.segment_upper_bound' (hm : StrictMono φ ) {k : ℕ} (h : φ 0 ≤ k) :
224- k < φ (segment φ k + 1 ) := by
222+ /-- For a strictly monotonic function `f : ℕ → ℕ`, `k < f (segment f k + 1)` for all `k ≥ f 0`. -/
223+ theorem Nat.segment_upper_bound' (hm : StrictMono f ) {k : ℕ} (h : f 0 ≤ k) :
224+ k < f (segment f k + 1 ) := by
225225 rw [← segment'_eq_segment hm, segment']
226- have := segment_upper_bound (base_zero_strict_mono hm) (base_zero_shift φ ) (k - φ 0 )
226+ have := segment_upper_bound (base_zero_strict_mono hm) (base_zero_shift f ) (k - f 0 )
227227 omega
228228
229- /-- For a strictly monotonic function `φ : ℕ → ℕ`, `φ (segment φ k) ≤ k` for all `k ≥ φ 0`. -/
230- theorem Nat.segment_lower_bound' (hm : StrictMono φ ) {k : ℕ} (h : φ 0 ≤ k) :
231- φ (segment φ k) ≤ k := by
229+ /-- For a strictly monotonic function `f : ℕ → ℕ`, `f (segment f k) ≤ k` for all `k ≥ f 0`. -/
230+ theorem Nat.segment_lower_bound' (hm : StrictMono f ) {k : ℕ} (h : f 0 ≤ k) :
231+ f (segment f k) ≤ k := by
232232 rw [← segment'_eq_segment hm, segment']
233- have := segment_lower_bound (base_zero_strict_mono hm) (base_zero_shift φ ) (k - φ 0 )
233+ have := segment_lower_bound (base_zero_strict_mono hm) (base_zero_shift f ) (k - f 0 )
234234 omega
0 commit comments