-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathBasic.lean
More file actions
499 lines (376 loc) · 18.3 KB
/
Basic.lean
File metadata and controls
499 lines (376 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.AddGroupWithTop
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Order.Sub.WithTop
import Mathlib.Data.ENat.Defs
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Nat.SuccPred
/-!
# Definition and basic properties of extended natural numbers
In this file we define `ENat` (notation: `ℕ∞`) to be `WithTop ℕ` and prove some basic lemmas
about this type.
## Implementation details
There are two natural coercions from `ℕ` to `WithTop ℕ = ENat`: `WithTop.some` and `Nat.cast`. In
Lean 3, this difference was hidden in typeclass instances. Since these instances were definitionally
equal, we did not duplicate generic lemmas about `WithTop α` and `WithTop.some` coercion for `ENat`
and `Nat.cast` coercion. If you need to apply a lemma about `WithTop`, you may either rewrite back
and forth using `ENat.some_eq_coe`, or restate the lemma for `ENat`.
## TODO
Unify `ENat.add_iSup`/`ENat.iSup_add` with `ENNReal.add_iSup`/`ENNReal.iSup_add`. The key property
of `ENat` and `ENNReal` we are using is that all `a` are either absorbing for addition (`a + b = a`
for all `b`), or that it's order-cancellable (`a + b ≤ a + c → b ≤ c` for all `b`, `c`), and
similarly for multiplication.
-/
assert_not_exists Field
deriving instance Zero, OrderedCommSemiring, Nontrivial,
LinearOrder, Bot, LinearOrderedAddCommMonoid, Sub,
LinearOrderedAddCommMonoidWithTop, WellFoundedRelation
for ENat
-- The `CanonicallyOrderedAdd, OrderBot, OrderTop, OrderedSub, SuccOrder, WellFoundedLT, CharZero`
-- instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
-- In `Mathlib.Data.Nat.PartENat` proofs timed out when we included `deriving AddCommMonoidWithOne`,
-- and it seems to work without.
namespace ENat
instance : CanonicallyOrderedAdd ℕ∞ := WithTop.canonicallyOrderedAdd
instance : OrderBot ℕ∞ := WithTop.orderBot
instance : OrderTop ℕ∞ := WithTop.orderTop
instance : OrderedSub ℕ∞ := inferInstanceAs (OrderedSub (WithTop ℕ))
instance : SuccOrder ℕ∞ := inferInstanceAs (SuccOrder (WithTop ℕ))
instance : WellFoundedLT ℕ∞ := inferInstanceAs (WellFoundedLT (WithTop ℕ))
instance : CharZero ℕ∞ := inferInstanceAs (CharZero (WithTop ℕ))
variable {a b c m n : ℕ∞}
/-- Lemmas about `WithTop` expect (and can output) `WithTop.some` but the normal form for coercion
`ℕ → ℕ∞` is `Nat.cast`. -/
@[simp] theorem some_eq_coe : (WithTop.some : ℕ → ℕ∞) = Nat.cast := rfl
theorem coe_inj {a b : ℕ} : (a : ℕ∞) = b ↔ a = b := WithTop.coe_inj
instance : SuccAddOrder ℕ∞ where
succ_eq_add_one x := by cases x <;> simp [SuccOrder.succ]
theorem coe_zero : ((0 : ℕ) : ℕ∞) = 0 :=
rfl
theorem coe_one : ((1 : ℕ) : ℕ∞) = 1 :=
rfl
theorem coe_add (m n : ℕ) : ↑(m + n) = (m + n : ℕ∞) :=
rfl
@[simp, norm_cast]
theorem coe_sub (m n : ℕ) : ↑(m - n) = (m - n : ℕ∞) :=
rfl
@[simp] lemma coe_mul (m n : ℕ) : ↑(m * n) = (m * n : ℕ∞) := rfl
@[simp] theorem mul_top (hm : m ≠ 0) : m * ⊤ = ⊤ := WithTop.mul_top hm
@[simp] theorem top_mul (hm : m ≠ 0) : ⊤ * m = ⊤ := WithTop.top_mul hm
theorem top_pow {n : ℕ} (n_pos : 0 < n) : (⊤ : ℕ∞) ^ n = ⊤ := WithTop.top_pow n_pos
/-- Convert a `ℕ∞` to a `ℕ` using a proof that it is not infinite. -/
def lift (x : ℕ∞) (h : x < ⊤) : ℕ := WithTop.untop x (WithTop.lt_top_iff_ne_top.mp h)
@[simp] theorem coe_lift (x : ℕ∞) (h : x < ⊤) : (lift x h : ℕ∞) = x :=
WithTop.coe_untop x (WithTop.lt_top_iff_ne_top.mp h)
@[simp] theorem lift_coe (n : ℕ) : lift (n : ℕ∞) (WithTop.coe_lt_top n) = n := rfl
@[simp] theorem lift_lt_iff {x : ℕ∞} {h} {n : ℕ} : lift x h < n ↔ x < n := WithTop.untop_lt_iff _
@[simp] theorem lift_le_iff {x : ℕ∞} {h} {n : ℕ} : lift x h ≤ n ↔ x ≤ n := WithTop.untop_le_iff _
@[simp] theorem lt_lift_iff {x : ℕ} {n : ℕ∞} {h} : x < lift n h ↔ x < n := WithTop.lt_untop_iff _
@[simp] theorem le_lift_iff {x : ℕ} {n : ℕ∞} {h} : x ≤ lift n h ↔ x ≤ n := WithTop.le_untop_iff _
@[simp] theorem lift_zero : lift 0 (WithTop.coe_lt_top 0) = 0 := rfl
@[simp] theorem lift_one : lift 1 (WithTop.coe_lt_top 1) = 1 := rfl
@[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift ofNat(n) (WithTop.coe_lt_top n) = OfNat.ofNat n := rfl
@[simp] theorem add_lt_top {a b : ℕ∞} : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ := WithTop.add_lt_top
@[simp] theorem lift_add (a b : ℕ∞) (h : a + b < ⊤) :
lift (a + b) h = lift a (add_lt_top.1 h).1 + lift b (add_lt_top.1 h).2 := by
apply coe_inj.1
simp
instance canLift : CanLift ℕ∞ ℕ (↑) (· ≠ ⊤) := WithTop.canLift
instance : WellFoundedRelation ℕ∞ where
rel := (· < ·)
wf := IsWellFounded.wf
/-- Conversion of `ℕ∞` to `ℕ` sending `∞` to `0`. -/
def toNat : ℕ∞ → ℕ := WithTop.untopD 0
/-- Homomorphism from `ℕ∞` to `ℕ` sending `∞` to `0`. -/
def toNatHom : MonoidWithZeroHom ℕ∞ ℕ where
toFun := toNat
map_one' := rfl
map_zero' := rfl
map_mul' := WithTop.untopD_zero_mul
@[simp, norm_cast] lemma coe_toNatHom : toNatHom = toNat := rfl
lemma toNatHom_apply (n : ℕ) : toNatHom n = toNat n := rfl
@[simp]
theorem toNat_coe (n : ℕ) : toNat n = n :=
rfl
@[simp]
theorem toNat_zero : toNat 0 = 0 :=
rfl
@[simp]
theorem toNat_one : toNat 1 = 1 :=
rfl
@[simp]
theorem toNat_ofNat (n : ℕ) [n.AtLeastTwo] : toNat ofNat(n) = n :=
rfl
@[simp]
theorem toNat_top : toNat ⊤ = 0 :=
rfl
@[simp] theorem toNat_eq_zero : toNat n = 0 ↔ n = 0 ∨ n = ⊤ := WithTop.untopD_eq_self_iff
@[simp]
theorem recTopCoe_zero {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) : @recTopCoe C d f 0 = f 0 :=
rfl
@[simp]
theorem recTopCoe_one {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) : @recTopCoe C d f 1 = f 1 :=
rfl
@[simp]
theorem recTopCoe_ofNat {C : ℕ∞ → Sort*} (d : C ⊤) (f : ∀ a : ℕ, C a) (x : ℕ) [x.AtLeastTwo] :
@recTopCoe C d f ofNat(x) = f (OfNat.ofNat x) :=
rfl
@[simp]
theorem top_ne_coe (a : ℕ) : ⊤ ≠ (a : ℕ∞) :=
nofun
@[simp]
theorem top_ne_ofNat (a : ℕ) [a.AtLeastTwo] : ⊤ ≠ (ofNat(a) : ℕ∞) :=
nofun
@[simp] lemma top_ne_zero : (⊤ : ℕ∞) ≠ 0 := nofun
@[simp] lemma top_ne_one : (⊤ : ℕ∞) ≠ 1 := nofun
@[simp]
theorem coe_ne_top (a : ℕ) : (a : ℕ∞) ≠ ⊤ :=
nofun
@[simp]
theorem ofNat_ne_top (a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ℕ∞) ≠ ⊤ :=
nofun
@[simp] lemma zero_ne_top : 0 ≠ (⊤ : ℕ∞) := nofun
@[simp] lemma one_ne_top : 1 ≠ (⊤ : ℕ∞) := nofun
@[simp]
theorem top_sub_coe (a : ℕ) : (⊤ : ℕ∞) - a = ⊤ :=
WithTop.top_sub_coe
@[simp]
theorem top_sub_one : (⊤ : ℕ∞) - 1 = ⊤ :=
top_sub_coe 1
@[simp]
theorem top_sub_ofNat (a : ℕ) [a.AtLeastTwo] : (⊤ : ℕ∞) - ofNat(a) = ⊤ :=
top_sub_coe a
@[simp]
theorem top_pos : (0 : ℕ∞) < ⊤ :=
WithTop.top_pos
@[deprecated ENat.top_pos (since := "2024-10-22")]
alias zero_lt_top := top_pos
theorem sub_top (a : ℕ∞) : a - ⊤ = 0 :=
WithTop.sub_top
@[simp]
theorem coe_toNat_eq_self : ENat.toNat n = n ↔ n ≠ ⊤ :=
ENat.recTopCoe (by decide) (fun _ => by simp [toNat_coe]) n
alias ⟨_, coe_toNat⟩ := coe_toNat_eq_self
@[simp] lemma toNat_eq_iff_eq_coe (n : ℕ∞) (m : ℕ) [NeZero m] :
n.toNat = m ↔ n = m := by
cases n
· simpa using NeZero.ne' m
· simp
theorem coe_toNat_le_self (n : ℕ∞) : ↑(toNat n) ≤ n :=
ENat.recTopCoe le_top (fun _ => le_rfl) n
theorem toNat_add {m n : ℕ∞} (hm : m ≠ ⊤) (hn : n ≠ ⊤) : toNat (m + n) = toNat m + toNat n := by
lift m to ℕ using hm
lift n to ℕ using hn
rfl
theorem toNat_sub {n : ℕ∞} (hn : n ≠ ⊤) (m : ℕ∞) : toNat (m - n) = toNat m - toNat n := by
lift n to ℕ using hn
induction m
· rw [top_sub_coe, toNat_top, zero_tsub]
· rw [← coe_sub, toNat_coe, toNat_coe, toNat_coe]
theorem toNat_mul (a b : ℕ∞) : (a * b).toNat = a.toNat * b.toNat := by
cases a <;> cases b <;> simp
· rename_i b; cases b <;> simp
· rename_i a; cases a <;> simp
· rfl
theorem toNat_eq_iff {m : ℕ∞} {n : ℕ} (hn : n ≠ 0) : toNat m = n ↔ m = n := by
induction m <;> simp [hn.symm]
lemma toNat_le_of_le_coe {m : ℕ∞} {n : ℕ} (h : m ≤ n) : toNat m ≤ n := by
lift m to ℕ using ne_top_of_le_ne_top (coe_ne_top n) h
simpa using h
@[gcongr]
lemma toNat_le_toNat {m n : ℕ∞} (h : m ≤ n) (hn : n ≠ ⊤) : toNat m ≤ toNat n :=
toNat_le_of_le_coe <| h.trans_eq (coe_toNat hn).symm
@[simp]
theorem succ_def (m : ℕ∞) : Order.succ m = m + 1 :=
Order.succ_eq_add_one m
@[deprecated Order.add_one_le_of_lt (since := "2024-09-04")]
theorem add_one_le_of_lt (h : m < n) : m + 1 ≤ n :=
Order.add_one_le_of_lt h
theorem add_one_le_iff (hm : m ≠ ⊤) : m + 1 ≤ n ↔ m < n :=
Order.add_one_le_iff_of_not_isMax (not_isMax_iff_ne_top.mpr hm)
@[deprecated Order.one_le_iff_pos (since := "2024-09-04")]
theorem one_le_iff_pos : 1 ≤ n ↔ 0 < n :=
Order.one_le_iff_pos
theorem one_le_iff_ne_zero : 1 ≤ n ↔ n ≠ 0 :=
Order.one_le_iff_pos.trans pos_iff_ne_zero
lemma lt_one_iff_eq_zero : n < 1 ↔ n = 0 :=
not_le.symm.trans one_le_iff_ne_zero.not_left
@[deprecated Order.le_of_lt_add_one (since := "2024-09-04")]
theorem le_of_lt_add_one (h : m < n + 1) : m ≤ n :=
Order.le_of_lt_add_one h
theorem lt_add_one_iff (hm : n ≠ ⊤) : m < n + 1 ↔ m ≤ n :=
Order.lt_add_one_iff_of_not_isMax (not_isMax_iff_ne_top.mpr hm)
theorem le_coe_iff {n : ℕ∞} {k : ℕ} : n ≤ ↑k ↔ ∃ (n₀ : ℕ), n = n₀ ∧ n₀ ≤ k :=
WithTop.le_coe_iff
@[simp]
lemma not_lt_zero (n : ℕ∞) : ¬ n < 0 := by
cases n <;> simp
@[simp]
lemma coe_lt_top (n : ℕ) : (n : ℕ∞) < ⊤ :=
WithTop.coe_lt_top n
lemma coe_lt_coe {n m : ℕ} : (n : ℕ∞) < (m : ℕ∞) ↔ n < m := by simp
lemma coe_le_coe {n m : ℕ} : (n : ℕ∞) ≤ (m : ℕ∞) ↔ n ≤ m := by simp
@[elab_as_elim]
theorem nat_induction {P : ℕ∞ → Prop} (a : ℕ∞) (h0 : P 0) (hsuc : ∀ n : ℕ, P n → P n.succ)
(htop : (∀ n : ℕ, P n) → P ⊤) : P a := by
have A : ∀ n : ℕ, P n := fun n => Nat.recOn n h0 hsuc
cases a
· exact htop A
· exact A _
lemma add_one_pos : 0 < n + 1 :=
succ_def n ▸ Order.bot_lt_succ n
lemma add_lt_add_iff_right {k : ℕ∞} (h : k ≠ ⊤) : n + k < m + k ↔ n < m :=
WithTop.add_lt_add_iff_right h
lemma add_lt_add_iff_left {k : ℕ∞} (h : k ≠ ⊤) : k + n < k + m ↔ n < m :=
WithTop.add_lt_add_iff_left h
lemma ne_top_iff_exists : n ≠ ⊤ ↔ ∃ m : ℕ, ↑m = n := WithTop.ne_top_iff_exists
lemma forall_ne_iff_eq_top : (∀ m : ℕ, ↑m ≠ n) ↔ n = ⊤ := WithTop.forall_ne_iff_eq_top
lemma forall_gt_iff_eq_top : (∀ m : ℕ, m < n) ↔ n = ⊤ := WithTop.forall_gt_iff_eq_top
lemma forall_ge_iff_eq_top : (∀ m : ℕ, m ≤ n) ↔ n = ⊤ := WithTop.forall_ge_iff_eq_top
@[deprecated (since := "2025-03-19")] alias eq_top_iff_forall_ne := forall_ne_iff_eq_top
@[deprecated (since := "2025-03-19")] alias eq_top_iff_forall_lt := forall_gt_iff_eq_top
@[deprecated (since := "2025-03-19")] alias eq_top_iff_forall_le := forall_ge_iff_eq_top
lemma forall_natCast_le_iff_le : (∀ a : ℕ, a ≤ m → a ≤ n) ↔ m ≤ n := WithTop.forall_coe_le_iff_le
protected lemma exists_nat_gt (hn : n ≠ ⊤) : ∃ m : ℕ, n < m := by
simp_rw [lt_iff_not_ge n]
exact not_forall.mp <| forall_ge_iff_eq_top.mp.mt hn
@[simp] lemma sub_eq_top_iff : a - b = ⊤ ↔ a = ⊤ ∧ b ≠ ⊤ := WithTop.sub_eq_top_iff
lemma sub_ne_top_iff : a - b ≠ ⊤ ↔ a ≠ ⊤ ∨ b = ⊤ := WithTop.sub_ne_top_iff
lemma addLECancellable_of_ne_top : a ≠ ⊤ → AddLECancellable a := WithTop.addLECancellable_of_ne_top
lemma addLECancellable_of_lt_top : a < ⊤ → AddLECancellable a := WithTop.addLECancellable_of_lt_top
lemma addLECancellable_coe (a : ℕ) : AddLECancellable (a : ℕ∞) := WithTop.addLECancellable_coe _
protected lemma le_sub_of_add_le_left (ha : a ≠ ⊤) : a + b ≤ c → b ≤ c - a :=
(addLECancellable_of_ne_top ha).le_tsub_of_add_le_left
protected lemma sub_sub_cancel (h : a ≠ ⊤) (h2 : b ≤ a) : a - (a - b) = b :=
(addLECancellable_of_ne_top <| ne_top_of_le_ne_top h tsub_le_self).tsub_tsub_cancel_of_le h2
lemma add_left_injective_of_ne_top {n : ℕ∞} (hn : n ≠ ⊤) : Function.Injective (· + n) := by
intro a b e
exact le_antisymm
((WithTop.add_le_add_iff_right hn).mp e.le)
((WithTop.add_le_add_iff_right hn).mp e.ge)
lemma add_right_injective_of_ne_top {n : ℕ∞} (hn : n ≠ ⊤) : Function.Injective (n + ·) := by
simp_rw [add_comm n _]
exact add_left_injective_of_ne_top hn
section withTop_enat
lemma add_one_natCast_le_withTop_of_lt {m : ℕ} {n : WithTop ℕ∞} (h : m < n) : (m + 1 : ℕ) ≤ n := by
match n with
| ⊤ => exact le_top
| (⊤ : ℕ∞) => exact WithTop.coe_le_coe.2 (OrderTop.le_top _)
| (n : ℕ) => simpa only [Nat.cast_le, ge_iff_le, Nat.cast_lt] using h
@[simp] lemma coe_top_add_one : ((⊤ : ℕ∞) : WithTop ℕ∞) + 1 = (⊤ : ℕ∞) := rfl
@[simp] lemma add_one_eq_coe_top_iff {n : WithTop ℕ∞} : n + 1 = (⊤ : ℕ∞) ↔ n = (⊤ : ℕ∞) := by
match n with
| ⊤ => exact Iff.rfl
| (⊤ : ℕ∞) => simp
| (n : ℕ) =>
norm_cast
simp only [coe_ne_top, iff_false, ne_eq]
@[simp] lemma natCast_ne_coe_top (n : ℕ) : (n : WithTop ℕ∞) ≠ (⊤ : ℕ∞) := nofun
@[deprecated (since := "2024-10-22")]
alias nat_ne_coe_top := natCast_ne_coe_top
lemma one_le_iff_ne_zero_withTop {n : WithTop ℕ∞} : 1 ≤ n ↔ n ≠ 0 :=
⟨fun h ↦ (zero_lt_one.trans_le h).ne',
fun h ↦ add_one_natCast_le_withTop_of_lt (pos_iff_ne_zero.mpr h)⟩
lemma natCast_le_of_coe_top_le_withTop {N : WithTop ℕ∞} (hN : (⊤ : ℕ∞) ≤ N) (n : ℕ) : n ≤ N :=
le_trans (mod_cast le_top) hN
lemma natCast_lt_of_coe_top_le_withTop {N : WithTop ℕ∞} (hN : (⊤ : ℕ∞) ≤ N) (n : ℕ) : n < N :=
lt_of_lt_of_le (mod_cast lt_add_one n) (natCast_le_of_coe_top_le_withTop hN (n + 1))
end withTop_enat
variable {α : Type*}
/--
Specialization of `WithTop.map` to `ENat`.
-/
def map (f : ℕ → α) (k : ℕ∞) : WithTop α := WithTop.map f k
@[simp]
theorem map_top (f : ℕ → α) : map f ⊤ = ⊤ := rfl
@[simp]
theorem map_coe (f : ℕ → α) (a : ℕ) : map f a = f a := rfl
@[simp]
theorem map_zero (f : ℕ → α) : map f 0 = f 0 := rfl
@[simp]
theorem map_one (f : ℕ → α) : map f 1 = f 1 := rfl
@[simp]
theorem map_ofNat (f : ℕ → α) (n : ℕ) [n.AtLeastTwo] : map f ofNat(n) = f n := rfl
@[simp]
lemma map_eq_top_iff {f : ℕ → α} : map f n = ⊤ ↔ n = ⊤ := WithTop.map_eq_top_iff
@[simp]
theorem map_natCast_nonneg [AddMonoidWithOne α] [PartialOrder α]
[AddLeftMono α] [ZeroLEOneClass α] : 0 ≤ n.map (Nat.cast : ℕ → α) := by
cases n <;> simp
@[simp]
theorem strictMono_map_iff {f : ℕ → α} [Preorder α] : StrictMono (ENat.map f) ↔ StrictMono f :=
WithTop.strictMono_map_iff
@[simp]
theorem monotone_map_iff {f : ℕ → α} [Preorder α] : Monotone (ENat.map f) ↔ Monotone f :=
WithTop.monotone_map_iff
@[simp]
protected theorem map_add {β F} [Add β] [FunLike F ℕ β] [AddHomClass F ℕ β]
(f : F) (a b : ℕ∞) : (a + b).map f = a.map f + b.map f :=
WithTop.map_add f a b
/-- A version of `ENat.map` for `OneHom`s. -/
-- @[to_additive (attr := simps -fullyApplied)
-- "A version of `ENat.map` for `ZeroHom`s"]
protected def _root_.OneHom.ENatMap {N : Type*} [One N] (f : OneHom ℕ N) :
OneHom ℕ∞ (WithTop N) where
toFun := ENat.map f
map_one' := by simp
/-- A version of `ENat.map` for `ZeroHom`s. -/
protected def _root_.ZeroHom.ENatMap {N : Type*} [Zero N] (f : ZeroHom ℕ N) :
ZeroHom ℕ∞ (WithTop N) where
toFun := ENat.map f
map_zero' := by simp
/-- A version of `WithTop.map` for `AddHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddHom.ENatMap {N : Type*} [Add N] (f : AddHom ℕ N) :
AddHom ℕ∞ (WithTop N) where
toFun := ENat.map f
map_add' := ENat.map_add f
/-- A version of `WithTop.map` for `AddMonoidHom`s. -/
@[simps -fullyApplied]
protected def _root_.AddMonoidHom.ENatMap {N : Type*} [AddZeroClass N]
(f : ℕ →+ N) : ℕ∞ →+ WithTop N :=
{ ZeroHom.ENatMap f.toZeroHom, AddHom.ENatMap f.toAddHom with toFun := ENat.map f }
/-- A version of `ENat.map` for `MonoidWithZeroHom`s. -/
@[simps -fullyApplied]
protected def _root_.MonoidWithZeroHom.ENatMap {S : Type*} [MulZeroOneClass S] [DecidableEq S]
[Nontrivial S] (f : ℕ →*₀ S)
(hf : Function.Injective f) : ℕ∞ →*₀ WithTop S :=
{ f.toZeroHom.ENatMap, f.toMonoidHom.toOneHom.ENatMap with
toFun := ENat.map f
map_mul' := fun x y => by
have : ∀ z, map f z = 0 ↔ z = 0 := fun z =>
(Option.map_injective hf).eq_iff' f.toZeroHom.ENatMap.map_zero
rcases Decidable.eq_or_ne x 0 with (rfl | hx)
· simp
rcases Decidable.eq_or_ne y 0 with (rfl | hy)
· simp
induction' x with x
· simp [hy, this]
induction' y with y
· have : (f x : WithTop S) ≠ 0 := by simpa [hf.eq_iff' (_root_.map_zero f)] using hx
simp [mul_top hx, WithTop.mul_top this]
· simp [← Nat.cast_mul, ← coe_mul] }
/-- A version of `ENat.map` for `RingHom`s. -/
@[simps -fullyApplied]
protected def _root_.RingHom.ENatMap {S : Type*} [OrderedCommSemiring S] [CanonicallyOrderedAdd S]
[DecidableEq S] [Nontrivial S] (f : ℕ →+* S) (hf : Function.Injective f) : ℕ∞ →+* WithTop S :=
{MonoidWithZeroHom.ENatMap f.toMonoidWithZeroHom hf, f.toAddMonoidHom.ENatMap with}
end ENat
lemma WithBot.lt_add_one_iff {n : WithBot ℕ∞} {m : ℕ} : n < m + 1 ↔ n ≤ m := by
rw [← WithBot.coe_one, ← ENat.coe_one, WithBot.coe_natCast, ← Nat.cast_add, ← WithBot.coe_natCast]
cases n
· simp only [bot_le, iff_true, WithBot.bot_lt_coe]
· rw [WithBot.coe_lt_coe, Nat.cast_add, ENat.coe_one, ENat.lt_add_one_iff (ENat.coe_ne_top _),
← WithBot.coe_le_coe, WithBot.coe_natCast]
lemma WithBot.add_one_le_iff {n : ℕ} {m : WithBot ℕ∞} : n + 1 ≤ m ↔ n < m := by
rw [← WithBot.coe_one, ← ENat.coe_one, WithBot.coe_natCast, ← Nat.cast_add, ← WithBot.coe_natCast]
cases m
· simp
· rw [WithBot.coe_le_coe, ENat.coe_add, ENat.coe_one, ENat.add_one_le_iff (ENat.coe_ne_top n),
← WithBot.coe_lt_coe, WithBot.coe_natCast]