Skip to content

Commit 5faf7aa

Browse files
committed
feat(Tactic/SimpIntro): add support for introducing non-propositions (#24372)
This PR improves the `simp_intro` tactic so that it can be used when there are non-propositions. Non-propositions are not added to the simp set. This lets `simp_intro` be used in situations that previously needed manual `intro` and `simp`. For example, the following one can be solved like this ```lean example (r : Nat → Prop) : (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by simp intro hr try simp at hr -- does nothing try simp [hr] -- does nothing intro y z try simp [hr] -- does nothing intro hy try simp [hr] at hy -- does nothing simp [hr, hy] intro hyz try simp [hr, hy] at hyz simp [hr, hy, hyz] -- accomplish the goal successfully ``` while the previous `simp_intro` cannot introduce `y` and `z` here. ```lean example (r : Nat → Prop) : (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by /- the previous `simp_intro` fails with message: invalid 'simp', proposition expected Nat -/ simp_intro .. -- or `simp_intro hr y` example (r : Nat → Prop) : (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by -- unsolved simp_intro hr ``` Now with this PR, the tactic is successful: ```lean example (r : Nat → Prop) : (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by simp_intro .. -- or `simp_intro hr y z hy hz` ```
1 parent 7e92ad1 commit 5faf7aa

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Mathlib/Tactic/SimpIntro.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ partial def simpIntroCore (g : MVarId) (ctx : Simp.Context) (simprocs : Simp.Sim
3030
let n := if var.isIdent then var.getId else `_
3131
let withFVar := fun (fvar, g) ↦ g.withContext do
3232
Term.addLocalVarInfo var (mkFVar fvar)
33-
let simpTheorems ← ctx.simpTheorems.addTheorem (.fvar fvar) (.fvar fvar)
34-
simpIntroCore g (ctx.setSimpTheorems simpTheorems) simprocs discharge? more ids'
33+
let ctx : Simp.Context ←
34+
if (← Meta.isProp <| ← fvar.getType) then
35+
let simpTheorems ← ctx.simpTheorems.addTheorem (.fvar fvar) (.fvar fvar)
36+
pure <| ctx.setSimpTheorems simpTheorems
37+
else
38+
pure ctx
39+
simpIntroCore g ctx simprocs discharge? more ids'
3540
match t with
3641
| .letE .. => withFVar (← g.intro n)
3742
| .forallE (body := body) .. =>

MathlibTest/simp_intro.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ example (h : y = z) : x + 0 = y → x = z := by
1414
simp_intro .. [h]
1515

1616
example (h : y = z) : x + 0 = y → x = z := by simp_intro _; exact h
17+
18+
example : ∀ (r : Nat → Prop), (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by
19+
simp_intro ..
20+
21+
example : ∀ (r : Nat → Prop), (∀ x, x > 0 → r x) → ∀ y z, y = 0 → z > y → r z := by
22+
simp_intro r hr y z hy hz

0 commit comments

Comments
 (0)