Skip to content

Commit a3041c4

Browse files
committed
chore(*): replace @[simp, nolint simpNF] with @[simp high] for specialized lemmas (#23261)
These are specialized lemmas and should therefore apply faster than the more general lemmas introduced later (which need to look for typeclass instances). If we raise their `simp` priority, we can remove the `simpNF` annotation. On the other hand, `simp?` output will look more ugly... Since `simp` now prefers lemmas declared lower down in the hierarchy, it looks like we can get in a bit of shaking! From the "specialized high priority simp lemma" library note: ``` It sometimes happens that a `@[simp]` lemma declared early in the library can be proved by `simp` using later, more general simp lemmas. In that case, the following reasons might be arguments for the early lemma to be tagged `@[simp high]` (rather than `@[simp, nolint simpNF]` or un``@[simp]``ed): 1. There is a significant portion of the library which needs the early lemma to be available via `simp` and which doesn't have access to the more general lemmas. 2. The more general lemmas have more complicated typeclass assumptions, causing rewrites with them to be slower. ```
1 parent 480c498 commit a3041c4

File tree

8 files changed

+25
-36
lines changed

8 files changed

+25
-36
lines changed

Mathlib/Algebra/Group/Int/Even.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Authors: Jeremy Avigad
55
-/
66
import Mathlib.Algebra.Group.Int.Defs
77
import Mathlib.Algebra.Group.Nat.Even
8-
import Mathlib.Algebra.Group.Nat.Units
9-
import Mathlib.Algebra.Group.Units.Basic
108
import Mathlib.Data.Int.Sqrt
119

1210
/-!

Mathlib/Algebra/Order/Ring/Basic.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Copyright (c) 2015 Jeremy Avigad. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad, Robert Y. Lewis
55
-/
6-
import Mathlib.Algebra.Group.Nat.Units
76
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
87
import Mathlib.Algebra.Order.Ring.Defs
98
import Mathlib.Algebra.Ring.Parity

Mathlib/Data/Int/Init.lean

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,23 @@ lemma zero_le_ofNat (n : ℕ) : 0 ≤ ofNat n := @le.intro _ _ n (by rw [Int.zer
5656

5757
protected theorem neg_eq_neg {a b : ℤ} (h : -a = -b) : a = b := Int.neg_inj.1 h
5858

59-
-- We want to use these lemmas earlier than the lemmas simp can prove them with
60-
@[simp, nolint simpNF]
59+
@[simp high]
6160
protected lemma neg_pos : 0 < -a ↔ a < 0 := ⟨Int.neg_of_neg_pos, Int.neg_pos_of_neg⟩
6261

63-
@[simp, nolint simpNF]
62+
@[simp high]
6463
protected lemma neg_nonneg : 0 ≤ -a ↔ a ≤ 0 := ⟨Int.nonpos_of_neg_nonneg, Int.neg_nonneg_of_nonpos⟩
6564

66-
@[simp, nolint simpNF]
65+
@[simp high]
6766
protected lemma neg_neg_iff_pos : -a < 00 < a := ⟨Int.pos_of_neg_neg, Int.neg_neg_of_pos⟩
6867

69-
@[simp, nolint simpNF]
68+
@[simp high]
7069
protected lemma neg_nonpos_iff_nonneg : -a ≤ 00 ≤ a :=
7170
⟨Int.nonneg_of_neg_nonpos, Int.neg_nonpos_of_nonneg⟩
7271

73-
@[simp, nolint simpNF]
72+
@[simp high]
7473
protected lemma sub_pos : 0 < a - b ↔ b < a := ⟨Int.lt_of_sub_pos, Int.sub_pos_of_lt⟩
7574

76-
@[simp, nolint simpNF]
75+
@[simp high]
7776
protected lemma sub_nonneg : 0 ≤ a - b ↔ b ≤ a := ⟨Int.le_of_sub_nonneg, Int.sub_nonneg_of_le⟩
7877

7978
protected theorem ofNat_add_out (m n : ℕ) : ↑m + ↑n = (↑(m + n) : ℤ) := rfl
@@ -91,20 +90,17 @@ protected theorem ofNat_add_one_out (n : ℕ) : ↑n + (1 : ℤ) = ↑(succ n) :
9190
@[norm_cast]
9291
protected lemma natCast_sub {n m : ℕ} : n ≤ m → (↑(m - n) : ℤ) = ↑m - ↑n := ofNat_sub
9392

94-
-- We want to use this lemma earlier than the lemmas simp can prove it with
95-
@[simp, nolint simpNF] lemma natCast_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 := by omega
93+
@[simp high] lemma natCast_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 := by omega
9694

9795
lemma natCast_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 := by omega
9896

9997
lemma natCast_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 00 < n := by omega
10098

101-
-- We want to use this lemma earlier than the lemmas simp can prove it with
102-
@[simp, nolint simpNF] lemma natCast_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n := by omega
99+
@[simp high] lemma natCast_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n := by omega
103100

104101
lemma natCast_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := natCast_pos.2 n.succ_pos
105102

106-
-- We want to use this lemma earlier than the lemmas simp can prove it with
107-
@[simp, nolint simpNF] lemma natCast_nonpos_iff {n : ℕ} : (n : ℤ) ≤ 0 ↔ n = 0 := by omega
103+
@[simp high] lemma natCast_nonpos_iff {n : ℕ} : (n : ℤ) ≤ 0 ↔ n = 0 := by omega
108104

109105
lemma natCast_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := ofNat_le.2 (Nat.zero_le _)
110106

Mathlib/Data/Multiset/AddSub.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ protected lemma add_comm (s t : Multiset α) : s + t = t + s :=
7373
protected lemma add_assoc (s t u : Multiset α) : s + t + u = s + (t + u) :=
7474
Quotient.inductionOn₃ s t u fun _ _ _ ↦ congr_arg _ <| append_assoc ..
7575

76-
@[simp, nolint simpNF] -- We want to use this lemma earlier than `zero_add`
76+
@[simp high]
7777
protected lemma zero_add (s : Multiset α) : 0 + s = s := Quotient.inductionOn s fun _ ↦ rfl
7878

79-
@[simp, nolint simpNF] -- We want to use this lemma earlier than `add_zero`
79+
@[simp high]
8080
protected lemma add_zero (s : Multiset α) : s + 0 = s :=
8181
Quotient.inductionOn s fun l ↦ congr_arg _ <| append_nil l
8282

@@ -283,7 +283,7 @@ lemma coe_sub (s t : List α) : (s - t : Multiset α) = s.diff t :=
283283

284284
/-- This is a special case of `tsub_zero`, which should be used instead of this.
285285
This is needed to prove `OrderedSub (Multiset α)`. -/
286-
@[simp, nolint simpNF] -- We want to use this lemma earlier than the lemma simp can prove it with
286+
@[simp high]
287287
protected lemma sub_zero (s : Multiset α) : s - 0 = s :=
288288
Quot.inductionOn s fun _l => rfl
289289

Mathlib/Data/Nat/Init.lean

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,10 @@ attribute [simp] le_add_left le_add_right Nat.lt_add_left_iff_pos Nat.lt_add_rig
196196
Nat.add_le_add_iff_left Nat.add_le_add_iff_right Nat.add_lt_add_iff_left Nat.add_lt_add_iff_right
197197
not_lt_zero
198198

199-
-- We want to use these two lemmas earlier than the lemmas simp can prove them with
200-
@[simp, nolint simpNF] protected alias add_left_inj := Nat.add_right_cancel_iff
201-
@[simp, nolint simpNF] protected alias add_right_inj := Nat.add_left_cancel_iff
202-
@[simp, nolint simpNF] protected lemma add_eq_left : a + b = a ↔ b = 0 := by omega
203-
@[simp, nolint simpNF] protected lemma add_eq_right : a + b = b ↔ a = 0 := by omega
199+
@[simp high] protected alias add_left_inj := Nat.add_right_cancel_iff
200+
@[simp high] protected alias add_right_inj := Nat.add_left_cancel_iff
201+
@[simp high] protected lemma add_eq_left : a + b = a ↔ b = 0 := by omega
202+
@[simp high] protected lemma add_eq_right : a + b = b ↔ a = 0 := by omega
204203

205204
lemma two_le_iff : ∀ n, 2 ≤ n ↔ n ≠ 0 ∧ n ≠ 1
206205
| 0 => by simp
@@ -210,8 +209,7 @@ lemma two_le_iff : ∀ n, 2 ≤ n ↔ n ≠ 0 ∧ n ≠ 1
210209
lemma add_eq_max_iff : m + n = max m n ↔ m = 0 ∨ n = 0 := by omega
211210
lemma add_eq_min_iff : m + n = min m n ↔ m = 0 ∧ n = 0 := by omega
212211

213-
-- We want to use this lemma earlier than the lemma simp can prove it with
214-
@[simp, nolint simpNF] protected lemma add_eq_zero : m + n = 0 ↔ m = 0 ∧ n = 0 := by omega
212+
@[simp high] protected lemma add_eq_zero : m + n = 0 ↔ m = 0 ∧ n = 0 := by omega
215213

216214
lemma add_pos_iff_pos_or_pos : 0 < m + n ↔ 0 < m ∨ 0 < n := by omega
217215

@@ -604,8 +602,7 @@ protected lemma pow_le_pow_iff_left {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ b ^ n
604602
protected lemma pow_lt_pow_iff_left (hn : n ≠ 0) : a ^ n < b ^ n ↔ a < b := by
605603
simp only [← Nat.not_le, Nat.pow_le_pow_iff_left hn]
606604

607-
-- We want to use this lemma earlier than the lemma simp can prove it with
608-
@[simp, nolint simpNF] protected lemma pow_eq_zero {a : ℕ} : ∀ {n : ℕ}, a ^ n = 0 ↔ a = 0 ∧ n ≠ 0
605+
@[simp high] protected lemma pow_eq_zero {a : ℕ} : ∀ {n : ℕ}, a ^ n = 0 ↔ a = 0 ∧ n ≠ 0
609606
| 0 => by simp
610607
| n + 1 => by rw [Nat.pow_succ, mul_eq_zero, Nat.pow_eq_zero]; omega
611608

Mathlib/Data/Rat/Defs.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ lemma intCast_injective : Injective (Int.cast : ℤ → ℚ) := fun _ _ ↦ cong
6464
lemma natCast_injective : Injective (Nat.cast : ℕ → ℚ) :=
6565
intCast_injective.comp fun _ _ ↦ Int.natCast_inj.1
6666

67-
-- We want to use these lemmas earlier than the lemmas simp can prove them with
68-
@[simp, nolint simpNF, norm_cast] lemma natCast_inj {m n : ℕ} : (m : ℚ) = n ↔ m = n :=
67+
@[simp high, norm_cast] lemma natCast_inj {m n : ℕ} : (m : ℚ) = n ↔ m = n :=
6968
natCast_injective.eq_iff
70-
@[simp, nolint simpNF, norm_cast] lemma intCast_eq_zero {n : ℤ} : (n : ℚ) = 0 ↔ n = 0 := intCast_inj
71-
@[simp, nolint simpNF, norm_cast] lemma natCast_eq_zero {n : ℕ} : (n : ℚ) = 0 ↔ n = 0 := natCast_inj
72-
@[simp, nolint simpNF, norm_cast] lemma intCast_eq_one {n : ℤ} : (n : ℚ) = 1 ↔ n = 1 := intCast_inj
73-
@[simp, nolint simpNF, norm_cast] lemma natCast_eq_one {n : ℕ} : (n : ℚ) = 1 ↔ n = 1 := natCast_inj
69+
@[simp high, norm_cast] lemma intCast_eq_zero {n : ℤ} : (n : ℚ) = 0 ↔ n = 0 := intCast_inj
70+
@[simp high, norm_cast] lemma natCast_eq_zero {n : ℕ} : (n : ℚ) = 0 ↔ n = 0 := natCast_inj
71+
@[simp high, norm_cast] lemma intCast_eq_one {n : ℤ} : (n : ℚ) = 1 ↔ n = 1 := intCast_inj
72+
@[simp high, norm_cast] lemma natCast_eq_one {n : ℕ} : (n : ℚ) = 1 ↔ n = 1 := natCast_inj
7473

7574
lemma mkRat_eq_divInt (n d) : mkRat n d = n /. d := rfl
7675

Mathlib/Order/Nat.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ instance instNoMaxOrder : NoMaxOrder ℕ where
3030

3131
/-! ### Miscellaneous lemmas -/
3232

33-
-- We want to use this lemma earlier than the lemma simp can prove it with
34-
@[simp, nolint simpNF] protected lemma bot_eq_zero : ⊥ = 0 := rfl
33+
@[simp high] protected lemma bot_eq_zero : ⊥ = 0 := rfl
3534

3635
/-- `Nat.find` is the minimum natural number satisfying a predicate `p`. -/
3736
lemma isLeast_find {p : ℕ → Prop} [DecidablePred p] (hp : ∃ n, p n) :

Mathlib/RingTheory/Coprime/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Kenny Lau, Ken Lee, Chris Hughes
55
-/
66
import Mathlib.Algebra.Group.Action.Units
7+
import Mathlib.Algebra.Group.Nat.Units
78
import Mathlib.Algebra.GroupWithZero.Divisibility
89
import Mathlib.Algebra.Ring.Divisibility.Basic
910
import Mathlib.Algebra.Ring.Hom.Defs

0 commit comments

Comments
 (0)