Skip to content

Commit ceb6589

Browse files
committed
chore: use ofNat more (#20546)
When a theorem statement contains both ofNat and OfNat.ofNat, replace the latter by the former: as eric-wieser [says](#20521 (review)), these are mostly theorems that work forwards, but not backwards, with simp. Very much not exhaustive, there are perhaps 160 instances in mathlib remaining. Co-authored-by: grunweg <rothgami@math.hu-berlin.de>
1 parent 0479fde commit ceb6589

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

Mathlib/Algebra/AddConstMap/Basic.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ theorem map_add_one [AddMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b]
8787
@[scoped simp]
8888
theorem map_add_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b]
8989
(f : F) (x : G) (n : ℕ) [n.AtLeastTwo] :
90-
f (x + ofNat(n)) = f x + (OfNat.ofNat n : ℕ) • b :=
90+
f (x + ofNat(n)) = f x + (ofNat(n) : ℕ) • b :=
9191
map_add_nat' f x n
9292

9393
theorem map_add_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
9494
(f : F) (x : G) (n : ℕ) : f (x + n) = f x + n := by simp
9595

9696
theorem map_add_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
9797
(f : F) (x : G) (n : ℕ) [n.AtLeastTwo] :
98-
f (x + OfNat.ofNat n) = f x + OfNat.ofNat n := map_add_nat f x n
98+
f (x + ofNat(n)) = f x + ofNat(n) := map_add_nat f x n
9999

100100
@[scoped simp]
101101
theorem map_const [AddZeroClass G] [Add H] [AddConstMapClass F G H a b] (f : F) :
@@ -118,15 +118,15 @@ theorem map_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b]
118118

119119
theorem map_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b]
120120
(f : F) (n : ℕ) [n.AtLeastTwo] :
121-
f (OfNat.ofNat n) = f 0 + (OfNat.ofNat n : ℕ) • b :=
121+
f (ofNat(n)) = f 0 + (ofNat(n) : ℕ) • b :=
122122
map_nat' f n
123123

124124
theorem map_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
125125
(f : F) (n : ℕ) : f n = f 0 + n := by simp
126126

127127
theorem map_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
128128
(f : F) (n : ℕ) [n.AtLeastTwo] :
129-
f (OfNat.ofNat n) = f 0 + OfNat.ofNat n := map_nat f n
129+
f ofNat(n) = f 0 + ofNat(n) := map_nat f n
130130

131131
@[scoped simp]
132132
theorem map_const_add [AddCommSemigroup G] [Add H] [AddConstMapClass F G H a b]
@@ -148,15 +148,15 @@ theorem map_nat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F
148148

149149
theorem map_ofNat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b]
150150
(f : F) (n : ℕ) [n.AtLeastTwo] (x : G) :
151-
f (OfNat.ofNat n + x) = f x + OfNat.ofNat n • b :=
151+
f (ofNat(n) + x) = f x + ofNat(n) • b :=
152152
map_nat_add' f n x
153153

154154
theorem map_nat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
155155
(f : F) (n : ℕ) (x : G) : f (↑n + x) = f x + n := by simp
156156

157157
theorem map_ofNat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1]
158158
(f : F) (n : ℕ) [n.AtLeastTwo] (x : G) :
159-
f (OfNat.ofNat n + x) = f x + OfNat.ofNat n :=
159+
f (ofNat(n) + x) = f x + ofNat(n) :=
160160
map_nat_add f n x
161161

162162
@[scoped simp]
@@ -181,7 +181,7 @@ theorem map_sub_nat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1
181181
@[scoped simp]
182182
theorem map_sub_ofNat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b]
183183
(f : F) (x : G) (n : ℕ) [n.AtLeastTwo] :
184-
f (x - ofNat(n)) = f x - OfNat.ofNat n • b :=
184+
f (x - ofNat(n)) = f x - ofNat(n) • b :=
185185
map_sub_nat' f x n
186186

187187
@[scoped simp]

Mathlib/Algebra/DirectSum/Internal.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ instance instSemiring : Semiring (A 0) := (subsemiring A).toSemiring
337337
@[simp, norm_cast] theorem coe_natCast (n : ℕ) : (n : A 0) = (n : R) := rfl
338338

339339
@[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] :
340-
(ofNat(n) : A 0) = (OfNat.ofNat n : R) := rfl
340+
(ofNat(n) : A 0) = (ofNat(n) : R) := rfl
341341

342342
end Semiring
343343

Mathlib/Algebra/Module/LinearMap/End.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ theorem _root_.Module.End.natCast_apply (n : ℕ) (m : M) : (↑n : Module.End R
8989

9090
@[simp]
9191
theorem _root_.Module.End.ofNat_apply (n : ℕ) [n.AtLeastTwo] (m : M) :
92-
(ofNat(n) : Module.End R M) m = OfNat.ofNat n • m := rfl
92+
(ofNat(n) : Module.End R M) m = ofNat(n) • m := rfl
9393

9494
instance _root_.Module.End.ring : Ring (Module.End R N₁) :=
9595
{ Module.End.semiring, LinearMap.addCommGroup with

Mathlib/Algebra/Module/NatInt.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ lemma Nat.cast_smul_eq_nsmul (n : ℕ) (b : M) : (n : R) • b = n • b := by
103103

104104
/-- `nsmul` is equal to any other module structure via a cast. -/
105105
lemma ofNat_smul_eq_nsmul (n : ℕ) [n.AtLeastTwo] (b : M) :
106-
(ofNat(n) : R) • b = OfNat.ofNat n • b := Nat.cast_smul_eq_nsmul ..
106+
(ofNat(n) : R) • b = ofNat(n) • b := Nat.cast_smul_eq_nsmul ..
107107

108108
/-- `nsmul` is equal to any other module structure via a cast. -/
109109
@[deprecated Nat.cast_smul_eq_nsmul (since := "2024-07-23")]

Mathlib/Algebra/Order/SuccPred/WithBot.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ lemma succ_one : succ (1 : WithBot α) = 2 := by simpa [one_add_one_eq_two] usin
2424

2525
@[simp]
2626
lemma succ_ofNat (n : ℕ) [n.AtLeastTwo] :
27-
succ (ofNat(n) : WithBot α) = OfNat.ofNat n + 1 := succ_natCast n
27+
succ (ofNat(n) : WithBot α) = ofNat(n) + 1 := succ_natCast n
2828

2929
end WithBot

Mathlib/Algebra/Polynomial/Eval/Defs.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ alias eval₂_nat_cast := eval₂_natCast
104104

105105
@[simp]
106106
lemma eval₂_ofNat {S : Type*} [Semiring S] (n : ℕ) [n.AtLeastTwo] (f : R →+* S) (a : S) :
107-
(ofNat(n) : R[X]).eval₂ f a = OfNat.ofNat n := by
107+
(ofNat(n) : R[X]).eval₂ f a = ofNat(n) := by
108108
simp [OfNat.ofNat]
109109

110110
variable [Semiring T]
@@ -264,7 +264,7 @@ alias eval₂_at_nat_cast := eval₂_at_natCast
264264

265265
@[simp]
266266
theorem eval₂_at_ofNat {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) [n.AtLeastTwo] :
267-
p.eval₂ f ofNat(n) = f (p.eval (OfNat.ofNat n)) := by
267+
p.eval₂ f ofNat(n) = f (p.eval (ofNat(n))) := by
268268
simp [OfNat.ofNat]
269269

270270
@[simp]
@@ -279,7 +279,7 @@ alias eval_nat_cast := eval_natCast
279279

280280
@[simp]
281281
lemma eval_ofNat (n : ℕ) [n.AtLeastTwo] (a : R) :
282-
(ofNat(n) : R[X]).eval a = OfNat.ofNat n := by
282+
(ofNat(n) : R[X]).eval a = ofNat(n) := by
283283
simp only [OfNat.ofNat, eval_natCast]
284284

285285
@[simp]
@@ -549,7 +549,7 @@ alias map_nat_cast := map_natCast
549549

550550
@[simp]
551551
protected theorem map_ofNat (n : ℕ) [n.AtLeastTwo] :
552-
(ofNat(n) : R[X]).map f = OfNat.ofNat n :=
552+
(ofNat(n) : R[X]).map f = ofNat(n) :=
553553
show (n : R[X]).map f = n by rw [Polynomial.map_natCast]
554554

555555
--TODO rename to `map_dvd_map`

Mathlib/Algebra/Star/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ theorem star_natCast [NonAssocSemiring R] [StarRing R] (n : ℕ) : star (n : R)
289289

290290
@[simp]
291291
theorem star_ofNat [NonAssocSemiring R] [StarRing R] (n : ℕ) [n.AtLeastTwo] :
292-
star (ofNat(n) : R) = OfNat.ofNat n :=
292+
star (ofNat(n) : R) = ofNat(n) :=
293293
star_natCast _
294294

295295
section

Mathlib/Analysis/Normed/Group/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,10 +1240,10 @@ theorem le_norm_self (r : ℝ) : r ≤ ‖r‖ :=
12401240
@[deprecated (since := "2024-04-05")] alias nnnorm_coe_nat := nnnorm_natCast
12411241

12421242
@[simp 1100] lemma norm_ofNat (n : ℕ) [n.AtLeastTwo] :
1243-
‖(ofNat(n) : ℝ)‖ = OfNat.ofNat n := norm_natCast n
1243+
‖(ofNat(n) : ℝ)‖ = ofNat(n) := norm_natCast n
12441244

12451245
@[simp 1100] lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] :
1246-
‖(ofNat(n) : ℝ)‖₊ = OfNat.ofNat n := nnnorm_natCast n
1246+
‖(ofNat(n) : ℝ)‖₊ = ofNat(n) := nnnorm_natCast n
12471247

12481248
lemma norm_two : ‖(2 : ℝ)‖ = 2 := abs_of_pos zero_lt_two
12491249
lemma nnnorm_two : ‖(2 : ℝ)‖₊ = 2 := NNReal.eq <| by simp

Mathlib/Data/Matrix/Kronecker.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ theorem natCast_kronecker [NonAssocSemiring α] [DecidableEq l] (a : ℕ) (B : M
314314

315315
theorem kronecker_ofNat [Semiring α] [DecidableEq n] (A : Matrix l m α) (b : ℕ) [b.AtLeastTwo] :
316316
A ⊗ₖ (ofNat(b) : Matrix n n α) =
317-
blockDiagonal fun _ => A <• (OfNat.ofNat b : α) :=
317+
blockDiagonal fun _ => A <• (ofNat(b) : α) :=
318318
kronecker_diagonal _ _
319319

320320
theorem ofNat_kronecker [Semiring α] [DecidableEq l] (a : ℕ) [a.AtLeastTwo] (B : Matrix m n α) :
321321
(ofNat(a) : Matrix l l α) ⊗ₖ B =
322322
Matrix.reindex (.prodComm _ _) (.prodComm _ _)
323-
(blockDiagonal fun _ => (OfNat.ofNat a : α) • B) :=
323+
(blockDiagonal fun _ => (ofNat(a) : α) • B) :=
324324
diagonal_kronecker _ _
325325

326326
theorem one_kronecker_one [MulZeroOneClass α] [DecidableEq m] [DecidableEq n] :

Mathlib/Data/Matrix/Notation.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ theorem natCast_fin_three (n : ℕ) :
420420

421421
theorem ofNat_fin_two (n : ℕ) [n.AtLeastTwo] :
422422
(ofNat(n) : Matrix (Fin 2) (Fin 2) α) =
423-
!![OfNat.ofNat n, 0; 0, OfNat.ofNat n] :=
423+
!![ofNat(n), 0; 0, ofNat(n)] :=
424424
natCast_fin_two _
425425

426426
theorem ofNat_fin_three (n : ℕ) [n.AtLeastTwo] :
427427
(ofNat(n) : Matrix (Fin 3) (Fin 3) α) =
428-
!![OfNat.ofNat n, 0, 0; 0, OfNat.ofNat n, 0; 0, 0, OfNat.ofNat n] :=
428+
!![ofNat(n), 0, 0; 0, ofNat(n), 0; 0, 0, ofNat(n)] :=
429429
natCast_fin_three _
430430

431431
end AddMonoidWithOne

0 commit comments

Comments
 (0)