Skip to content

Commit 8bb99c1

Browse files
committed
chore: add instance from Nat.AtLeastTwo n to NeZero n
1 parent a62da66 commit 8bb99c1

6 files changed

Lines changed: 32 additions & 28 deletions

File tree

Mathlib/Algebra/CharZero/Defs.lean

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Copyright (c) 2014 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro
55
-/
6-
import Mathlib.Init.Data.Nat.Lemmas
76
import Mathlib.Data.Int.Cast.Defs
87
import Mathlib.Tactic.Cases
98
import Mathlib.Algebra.NeZero
@@ -100,21 +99,23 @@ theorem cast_ne_one {n : ℕ} : (n : R) ≠ 1 ↔ n ≠ 1 :=
10099
cast_eq_one.not
101100
#align nat.cast_ne_one Nat.cast_ne_one
102101

102+
instance AtLeastTwo.instNeZero (n : ℕ) [n.AtLeastTwo] : NeZero n :=
103+
⟨Nat.ne_of_gt (Nat.le_of_lt one_lt)⟩
104+
103105
end Nat
104106

105107
namespace OfNat
106108

107109
variable [AddMonoidWithOne R] [CharZero R]
108110

109-
@[simp] lemma ofNat_ne_zero (n : ℕ) [h : n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 0 :=
110-
Nat.cast_ne_zero.2 <| ne_of_gt <| lt_trans Nat.one_pos h.prop
111+
@[simp] lemma ofNat_ne_zero (n : ℕ) [n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 0 :=
112+
Nat.cast_ne_zero.2 (NeZero.ne n)
111113

112114
@[simp] lemma zero_ne_ofNat (n : ℕ) [n.AtLeastTwo] : 0 ≠ (no_index (ofNat n) : R) :=
113115
(ofNat_ne_zero n).symm
114116

115-
@[simp] lemma ofNat_ne_one (n : ℕ) [h : n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 1 := by
116-
rw [← Nat.cast_eq_ofNat, ← @Nat.cast_one R, Ne.def, Nat.cast_inj]
117-
exact ne_of_gt h.prop
117+
@[simp] lemma ofNat_ne_one (n : ℕ) [n.AtLeastTwo] : (no_index (ofNat n) : R) ≠ 1 :=
118+
Nat.cast_ne_one.2 (Nat.AtLeastTwo.ne_one)
118119

119120
@[simp] lemma one_ne_ofNat (n : ℕ) [n.AtLeastTwo] : (1 : R) ≠ no_index (ofNat n) :=
120121
(ofNat_ne_one n).symm

Mathlib/Analysis/Complex/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ lemma nat_cast_mem_slitPlane {n : ℕ} : ↑n ∈ slitPlane ↔ n ≠ 0 := by
724724
simpa [pos_iff_ne_zero] using @ofReal_mem_slitPlane n
725725

726726
@[simp]
727-
lemma ofNat_mem_slitPlane (n : ℕ) [h : n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ slitPlane :=
728-
nat_cast_mem_slitPlane.2 h.ne_zero
727+
lemma ofNat_mem_slitPlane (n : ℕ) [n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ slitPlane :=
728+
nat_cast_mem_slitPlane.2 (NeZero.ne n)
729729

730730
lemma mem_slitPlane_iff_not_le_zero {z : ℂ} : z ∈ slitPlane ↔ ¬z ≤ 0 :=
731731
mem_slitPlane_iff.trans not_le_zero_iff.symm

Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ theorem cpow_nat_inv_pow (x : ℂ) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℂ
161161

162162
/-- See Note [no_index around OfNat.ofNat] -/
163163
@[simp]
164-
lemma cpow_ofNat_inv_pow (x : ℂ) (n : ℕ) [h : n.AtLeastTwo] :
164+
lemma cpow_ofNat_inv_pow (x : ℂ) (n : ℕ) [n.AtLeastTwo] :
165165
(x ^ ((no_index (OfNat.ofNat n) : ℂ)⁻¹)) ^ (no_index (OfNat.ofNat n) : ℕ) = x :=
166-
cpow_nat_inv_pow _ (two_pos.trans_le h.1).ne'
166+
cpow_nat_inv_pow _ (NeZero.ne n)
167167

168168
/-- A version of `Complex.cpow_int_mul` with RHS that matches `Complex.cpow_mul`.
169169
@@ -193,10 +193,10 @@ lemma pow_cpow_nat_inv {x : ℂ} {n : ℕ} (h₀ : n ≠ 0) (hlt : -(π / n) < x
193193
· rwa [← div_lt_iff' (Nat.cast_pos.2 h₀.bot_lt), neg_div]
194194
· rwa [← le_div_iff' (Nat.cast_pos.2 h₀.bot_lt)]
195195

196-
lemma pow_cpow_ofNat_inv {x : ℂ} {n : ℕ} [h : n.AtLeastTwo] (hlt : -(π / OfNat.ofNat n) < x.arg)
196+
lemma pow_cpow_ofNat_inv {x : ℂ} {n : ℕ} [n.AtLeastTwo] (hlt : -(π / OfNat.ofNat n) < x.arg)
197197
(hle : x.arg ≤ π / OfNat.ofNat n) :
198198
(x ^ (OfNat.ofNat n : ℕ)) ^ ((OfNat.ofNat n : ℂ)⁻¹) = x :=
199-
pow_cpow_nat_inv (two_pos.trans_le h.1).ne' hlt hle
199+
pow_cpow_nat_inv (NeZero.ne n) hlt hle
200200

201201
/-- See also `Complex.pow_cpow_ofNat_inv` for a version that also works for `x * I`, `0 ≤ x`. -/
202202
lemma sq_cpow_two_inv {x : ℂ} (hx : 0 < x.re) : (x ^ (2 : ℕ)) ^ (2⁻¹ : ℂ) = x :=

Mathlib/Data/ENNReal/Real.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by
237237
exact mod_cast ofReal_lt_nat_cast one_ne_zero
238238

239239
@[simp]
240-
lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [h : n.AtLeastTwo] :
240+
lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] :
241241
ENNReal.ofReal p < no_index (OfNat.ofNat n) ↔ p < OfNat.ofNat n :=
242-
ofReal_lt_nat_cast h.ne_zero
242+
ofReal_lt_nat_cast (NeZero.ne n)
243243

244244
@[simp]
245245
lemma nat_cast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by
@@ -250,9 +250,9 @@ lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by
250250
exact mod_cast nat_cast_le_ofReal one_ne_zero
251251

252252
@[simp]
253-
lemma ofNat_le_ofReal {n : ℕ} [h : n.AtLeastTwo] {p : ℝ} :
253+
lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} :
254254
no_index (OfNat.ofNat n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p :=
255-
nat_cast_le_ofReal h.ne_zero
255+
nat_cast_le_ofReal (NeZero.ne n)
256256

257257
@[simp]
258258
lemma ofReal_le_nat_cast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n :=
@@ -288,9 +288,9 @@ lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 :=
288288
ENNReal.coe_inj.trans Real.toNNReal_eq_one
289289

290290
@[simp]
291-
lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [h : n.AtLeastTwo] :
291+
lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
292292
ENNReal.ofReal r = no_index (OfNat.ofNat n) ↔ r = OfNat.ofNat n :=
293-
ofReal_eq_nat_cast h.ne_zero
293+
ofReal_eq_nat_cast (NeZero.ne n)
294294

295295
theorem ofReal_sub (p : ℝ) {q : ℝ} (hq : 0 ≤ q) :
296296
ENNReal.ofReal (p - q) = ENNReal.ofReal p - ENNReal.ofReal q := by

Mathlib/Data/Nat/Cast/Defs.lean

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ class Nat.AtLeastTwo (n : ℕ) : Prop where
4747
instance instNatAtLeastTwo : Nat.AtLeastTwo (n + 2) where
4848
prop := Nat.succ_le_succ <| Nat.succ_le_succ <| Nat.zero_le _
4949

50-
lemma Nat.AtLeastTwo.ne_zero (n : ℕ) [h : n.AtLeastTwo] : n ≠ 0 := by
51-
rintro rfl; exact absurd h.1 (by decide)
50+
namespace Nat.AtLeastTwo
5251

53-
lemma Nat.AtLeastTwo.ne_one (n : ℕ) [h : n.AtLeastTwo] : n ≠ 1 := by
54-
rintro rfl; exact absurd h.1 (by decide)
52+
variable {n : ℕ} [n.AtLeastTwo]
53+
54+
lemma one_lt : 1 < n := prop
55+
lemma ne_one : n ≠ 1 := Nat.ne_of_gt one_lt
56+
57+
end Nat.AtLeastTwo
5558

5659
/-- Recognize numeric literals which are at least `2` as terms of `R` via `Nat.cast`. This
5760
instance is what makes things like `37 : R` type check. Note that `0` and `1` are not needed

Mathlib/Data/Real/NNReal.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,9 @@ lemma toNNReal_eq_nat_cast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal = n
670670
mod_cast toNNReal_eq_iff_eq_coe <| Nat.cast_ne_zero.2 hn
671671

672672
@[simp]
673-
lemma toNNReal_eq_ofNat {r : ℝ} {n : ℕ} [h : n.AtLeastTwo] :
673+
lemma toNNReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
674674
r.toNNReal = no_index (OfNat.ofNat n) ↔ r = OfNat.ofNat n :=
675-
toNNReal_eq_nat_cast h.ne_zero
675+
toNNReal_eq_nat_cast (NeZero.ne n)
676676

677677
@[simp]
678678
theorem toNNReal_le_toNNReal_iff {r p : ℝ} (hp : 0 ≤ p) :
@@ -751,14 +751,14 @@ lemma nat_cast_le_toNNReal {n : ℕ} {r : ℝ} (hn : n ≠ 0) : ↑n ≤ r.toNNR
751751
lemma toNNReal_lt_nat_cast {r : ℝ} {n : ℕ} (hn : n ≠ 0) : r.toNNReal < n ↔ r < n := by simp [hn]
752752

753753
@[simp]
754-
lemma toNNReal_lt_ofNat {r : ℝ} {n : ℕ} [h : n.AtLeastTwo] :
754+
lemma toNNReal_lt_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] :
755755
r.toNNReal < no_index (OfNat.ofNat n) ↔ r < OfNat.ofNat n :=
756-
toNNReal_lt_nat_cast h.ne_zero
756+
toNNReal_lt_nat_cast (NeZero.ne n)
757757

758758
@[simp]
759-
lemma ofNat_le_toNNReal {n : ℕ} {r : ℝ} [h : n.AtLeastTwo] :
759+
lemma ofNat_le_toNNReal {n : ℕ} {r : ℝ} [n.AtLeastTwo] :
760760
no_index (OfNat.ofNat n) ≤ r.toNNReal ↔ OfNat.ofNat n ≤ r :=
761-
nat_cast_le_toNNReal h.ne_zero
761+
nat_cast_le_toNNReal (NeZero.ne n)
762762

763763
@[simp]
764764
theorem toNNReal_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :

0 commit comments

Comments
 (0)