Skip to content

Commit 0796b06

Browse files
committed
chore(Tactic/{Positivity,NormNum}): remove support for non-canonical spellings (#10344)
`Mul.mul` or `Nat.mul` etc should not ever appear in a goal, so there is little reason for these tactics to support them. If these are in your goal, then something has already gone wrong and `norm_num` isn't responsible for saving you; that's `simp` or `dsimp`'s job. [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2310344.20removing.20norm_num.20support.20for.20Nat.2Esub.2C.20Sub.2Esub.2C.20etc/near/420507739)
1 parent 6b846c8 commit 0796b06

File tree

7 files changed

+18
-30
lines changed

7 files changed

+18
-30
lines changed

Mathlib/Analysis/SpecialFunctions/Pow/Real.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ open Lean Meta Qq
350350

351351
/-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1)
352352
when the exponent is zero. The other cases are done in `evalRpow`. -/
353-
@[positivity (_ : ℝ) ^ (0 : ℝ), Pow.pow (_ : ℝ) (0 : ℝ), Real.rpow (_ : ℝ) (0 : ℝ)]
353+
@[positivity (_ : ℝ) ^ (0 : ℝ)]
354354
def evalRpowZero : PositivityExt where eval {_ _} _ _ e := do
355355
let .app (.app (f : Q(ℝ → ℝ → ℝ)) (a : Q(ℝ))) (_ : Q(ℝ)) ← withReducible (whnf e)
356356
| throwError "not Real.rpow"
@@ -359,7 +359,7 @@ def evalRpowZero : PositivityExt where eval {_ _} _ _ e := do
359359

360360
/-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when
361361
the base is nonnegative and positive when the base is positive. -/
362-
@[positivity (_ : ℝ) ^ (_ : ℝ), Pow.pow (_ : ℝ) (_ : ℝ), Real.rpow (_ : ℝ) (_ : ℝ)]
362+
@[positivity (_ : ℝ) ^ (_ : ℝ)]
363363
def evalRpow : PositivityExt where eval {_ _} zα pα e := do
364364
let .app (.app (f : Q(ℝ → ℝ → ℝ)) (a : Q(ℝ))) (b : Q(ℝ)) ← withReducible (whnf e)
365365
| throwError "not Real.rpow"

Mathlib/Tactic/NormNum/Basic.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ instance : MonadLift Option MetaM where
202202

203203
/-- The `norm_num` extension which identifies expressions of the form `a + b`,
204204
such that `norm_num` successfully recognises both `a` and `b`. -/
205-
@[norm_num _ + _, Add.add _ _] def evalAdd : NormNumExt where eval {u α} e := do
205+
@[norm_num _ + _] def evalAdd : NormNumExt where eval {u α} e := do
206206
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← whnfR e | failure
207207
let ra ← derive a; let rb ← derive b
208208
match ra, rb with
@@ -310,7 +310,7 @@ theorem isRat_sub {α} [Ring α] {f : α → α → α} {a b : α} {na nb nc :
310310

311311
/-- The `norm_num` extension which identifies expressions of the form `a - b` in a ring,
312312
such that `norm_num` successfully recognises both `a` and `b`. -/
313-
@[norm_num _ - _, Sub.sub _ _] def evalSub : NormNumExt where eval {u α} e := do
313+
@[norm_num _ - _] def evalSub : NormNumExt where eval {u α} e := do
314314
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← whnfR e | failure
315315
let rα ← inferRing α
316316
let ⟨(_f_eq : $f =Q HSub.hSub)⟩ ← withNewMCtxDepth <| assertDefEqQ _ _
@@ -380,7 +380,7 @@ theorem isRat_mul {α} [Ring α] {f : α → α → α} {a b : α} {na nb nc :
380380

381381
/-- The `norm_num` extension which identifies expressions of the form `a * b`,
382382
such that `norm_num` successfully recognises both `a` and `b`. -/
383-
@[norm_num _ * _, Mul.mul _ _] def evalMul : NormNumExt where eval {u α} e := do
383+
@[norm_num _ * _] def evalMul : NormNumExt where eval {u α} e := do
384384
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← whnfR e | failure
385385
let sα ← inferSemiring α
386386
let ra ← derive a; let rb ← derive b
@@ -433,7 +433,7 @@ def inferDivisionRing (α : Q(Type u)) : MetaM Q(DivisionRing $α) :=
433433

434434
/-- The `norm_num` extension which identifies expressions of the form `a / b`,
435435
such that `norm_num` successfully recognises both `a` and `b`. -/
436-
@[norm_num _ / _, Div.div _ _] def evalDiv : NormNumExt where eval {u α} e := do
436+
@[norm_num _ / _] def evalDiv : NormNumExt where eval {u α} e := do
437437
let .app (.app f (a : Q($α))) (b : Q($α)) ← whnfR e | failure
438438
let dα ← inferDivisionRing α
439439
haveI' : $e =Q $a / $b := ⟨⟩
@@ -509,7 +509,7 @@ theorem isNat_natSub : {a b : ℕ} → {a' b' c : ℕ} →
509509

510510
/-- The `norm_num` extension which identifies expressions of the form `Nat.sub a b`,
511511
such that `norm_num` successfully recognises both `a` and `b`. -/
512-
@[norm_num (_ : ℕ) - _, Sub.sub (_ : ℕ) _, Nat.sub _ _] def evalNatSub :
512+
@[norm_num (_ : ℕ) - _] def evalNatSub :
513513
NormNumExt where eval {u α} e := do
514514
let .app (.app f (a : Q(ℕ))) (b : Q(ℕ)) ← whnfR e | failure
515515
-- We assert that the default instance for `HSub` is `Nat.sub` when the first parameter is `ℕ`.
@@ -528,7 +528,7 @@ theorem isNat_natMod : {a b : ℕ} → {a' b' c : ℕ} →
528528

529529
/-- The `norm_num` extension which identifies expressions of the form `Nat.mod a b`,
530530
such that `norm_num` successfully recognises both `a` and `b`. -/
531-
@[norm_num (_ : ℕ) % _, Mod.mod (_ : ℕ) _, Nat.mod _ _] def evalNatMod :
531+
@[norm_num (_ : ℕ) % _] def evalNatMod :
532532
NormNumExt where eval {u α} e := do
533533
let .app (.app f (a : Q(ℕ))) (b : Q(ℕ)) ← whnfR e | failure
534534
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
@@ -547,7 +547,7 @@ theorem isNat_natDiv : {a b : ℕ} → {a' b' c : ℕ} →
547547

548548
/-- The `norm_num` extension which identifies expressions of the form `Nat.div a b`,
549549
such that `norm_num` successfully recognises both `a` and `b`. -/
550-
@[norm_num (_ : ℕ) / _, Div.div (_ : ℕ) _, Nat.div _ _]
550+
@[norm_num (_ : ℕ) / _]
551551
def evalNatDiv : NormNumExt where eval {u α} e := do
552552
let .app (.app f (a : Q(ℕ))) (b : Q(ℕ)) ← whnfR e | failure
553553
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩

Mathlib/Tactic/NormNum/DivMod.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ lemma isNat_neg_of_isNegNat {a : ℤ} {b : ℕ} (h : IsInt a (.negOfNat b)) : Is
4242

4343
/-- The `norm_num` extension which identifies expressions of the form `Int.ediv a b`,
4444
such that `norm_num` successfully recognises both `a` and `b`. -/
45-
@[norm_num (_ : ℤ) / _, Div.div (_ : ℤ) _, Int.ediv _ _]
45+
@[norm_num (_ : ℤ) / _, Int.ediv _ _]
4646
partial def evalIntDiv : NormNumExt where eval {u α} e := do
4747
let .app (.app f (a : Q(ℤ))) (b : Q(ℤ)) ← whnfR e | failure
4848
-- We assert that the default instance for `HDiv` is `Int.div` when the first parameter is `ℤ`.
@@ -100,7 +100,7 @@ lemma isInt_emod_neg {a b : ℤ} {r : ℕ} (h : IsNat (a % -b) r) : IsNat (a % b
100100

101101
/-- The `norm_num` extension which identifies expressions of the form `Int.emod a b`,
102102
such that `norm_num` successfully recognises both `a` and `b`. -/
103-
@[norm_num (_ : ℤ) % _, Mod.mod (_ : ℤ) _, Int.emod _ _]
103+
@[norm_num (_ : ℤ) % _, Int.emod _ _]
104104
partial def evalIntMod : NormNumExt where eval {u α} e := do
105105
let .app (.app f (a : Q(ℤ))) (b : Q(ℤ)) ← whnfR e | failure
106106
-- We assert that the default instance for `HMod` is `Int.mod` when the first parameter is `ℤ`.

Mathlib/Tactic/NormNum/Eq.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ theorem isRat_eq_false [Ring α] [CharZero α] : {a b : α} → {na nb : ℤ}
3636

3737
/-- The `norm_num` extension which identifies expressions of the form `a = b`,
3838
such that `norm_num` successfully recognises both `a` and `b`. -/
39-
@[norm_num _ = _, Eq _ _] def evalEq : NormNumExt where eval {v β} e := do
39+
@[norm_num _ = _] def evalEq : NormNumExt where eval {v β} e := do
4040
haveI' : v =QL 0 := ⟨⟩; haveI' : $β =Q Prop := ⟨⟩
4141
let .app (.app f a) b ← whnfR e | failure
4242
let ⟨u, α, a⟩ ← inferTypeQ' a

Mathlib/Tactic/NormNum/Pow.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ theorem isRat_pow {α} [Ring α] {f : α → ℕ → α} {a : α} {an cn : ℤ}
163163

164164
/-- The `norm_num` extension which identifies expressions of the form `a ^ b`,
165165
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℕ`. -/
166-
@[norm_num (_ : α) ^ (_ : ℕ), Pow.pow _ (_ : ℕ)]
166+
@[norm_num (_ : α) ^ (_ : ℕ)]
167167
def evalPow : NormNumExt where eval {u α} e := do
168168
let .app (.app (f : Q($α → ℕ → $α)) (a : Q($α))) (b : Q(ℕ)) ← whnfR e | failure
169169
let ⟨nb, pb⟩ ← deriveNat b q(instAddMonoidWithOneNat)

Mathlib/Tactic/Positivity/Basic.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ is nonnegative, strictly positive if at least one is positive, and nonzero if bo
148148

149149
/-- The `positivity` extension which identifies expressions of the form `a + b`,
150150
such that `positivity` successfully recognises both `a` and `b`. -/
151-
@[positivity _ + _, Add.add _ _] def evalAdd : PositivityExt where eval {u α} zα pα e := do
151+
@[positivity _ + _] def evalAdd : PositivityExt where eval {u α} zα pα e := do
152152
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e)
153153
| throwError "not +"
154154
let _e_eq : $e =Q $f $a $b := ⟨⟩
@@ -189,7 +189,7 @@ private theorem mul_ne_zero_of_pos_of_ne_zero [OrderedSemiring α] [NoZeroDiviso
189189

190190
/-- The `positivity` extension which identifies expressions of the form `a * b`,
191191
such that `positivity` successfully recognises both `a` and `b`. -/
192-
@[positivity _ * _, Mul.mul _ _] def evalMul : PositivityExt where eval {u α} zα pα e := do
192+
@[positivity _ * _] def evalMul : PositivityExt where eval {u α} zα pα e := do
193193
let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e)
194194
| throwError "not *"
195195
let _e_eq : $e =Q $f $a $b := ⟨⟩
@@ -251,7 +251,7 @@ private theorem pow_zero_pos [OrderedSemiring α] [Nontrivial α] (a : α) : 0 <
251251

252252
/-- The `positivity` extension which identifies expressions of the form `a ^ (0:ℕ)`.
253253
This extension is run in addition to the general `a ^ b` extension (they are overlapping). -/
254-
@[positivity (_ : α) ^ (0:ℕ), Pow.pow _ (0:ℕ)]
254+
@[positivity (_ : α) ^ (0:ℕ)]
255255
def evalPowZeroNat : PositivityExt where eval {u α} _zα _pα e := do
256256
let .app (.app _ (a : Q($α))) _ ← withReducible (whnf e) | throwError "not ^"
257257
_ ← synthInstanceQ (q(OrderedSemiring $α) : Q(Type u))
@@ -261,7 +261,7 @@ def evalPowZeroNat : PositivityExt where eval {u α} _zα _pα e := do
261261
set_option linter.deprecated false in
262262
/-- The `positivity` extension which identifies expressions of the form `a ^ (b : ℕ)`,
263263
such that `positivity` successfully recognises both `a` and `b`. -/
264-
@[positivity (_ : α) ^ (_ : ℕ), Pow.pow _ (_ : ℕ)]
264+
@[positivity (_ : α) ^ (_ : ℕ)]
265265
def evalPow : PositivityExt where eval {u α} zα pα e := do
266266
let .app (.app _ (a : Q($α))) (b : Q(ℕ)) ← withReducible (whnf e) | throwError "not ^"
267267
let result ← catchNone do

test/norm_num.lean

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ example : 10 / 1 = 10 := by norm_num1
415415
example : 5 / 4 = 1 := by norm_num1
416416
example : 9 / 4 = 2 := by norm_num1
417417
example : 0 / 1 = 0 := by norm_num1
418-
example : Nat.div 10 9 = 1 := by norm_num1
418+
example : 10 / 9 = 1 := by norm_num1
419419
example : 1099 / 100 = 10 := by norm_num1
420420

421421
end Nat.div
@@ -521,18 +521,6 @@ section
521521
example : - (-4 / 3) = 1 / (3 / (4 : α)) := by norm_num1
522522
end
523523

524-
section Transparency
525-
526-
example : Add.add 10 2 = 12 := by norm_num1
527-
example : Nat.sub 10 1 = 9 := by norm_num1
528-
example : Nat.mod 10 5 = 0 := by norm_num1
529-
example : Sub.sub 10 1 = 9 := by norm_num1
530-
example : Sub.sub 10 (-2) = 12 := by norm_num1
531-
example : Mul.mul 10 1 = 10 := by norm_num1
532-
example : (Div.div 10 1 : ℚ) = 10 := by norm_num1
533-
534-
end Transparency
535-
536524
-- user command
537525

538526
/-- info: True -/

0 commit comments

Comments
 (0)