Skip to content

Commit 214e72f

Browse files
committed
feat: add a SetLike default rule set for aesop (#7111)
This creates a new `aesop` rule set called `SetLike` to house lemmas about membership in subobjects. Lemmas like `pow_mem` should be included in the rule set: ```lean @[to_additive (attr := aesop safe apply (rule_sets [SetLike]))] theorem pow_mem {M A} [Monoid M] [SetLike A M] [SubmonoidClass A M] {S : A} {x : M} (hx : x ∈ S) : ∀ n : ℕ, x ^ n ∈ S ``` Lemmas about closures, like `AddSubmonoid.closure` should be included in the rule set, but they should be assigned a penalty (here we choose `20` throughout) so that they are not attempted before the general purpose ones like `pow_mem`. ```lean @[to_additive (attr := simp, aesop safe 20 apply (rule_sets [SetLike])) "The `AddSubmonoid` generated by a set includes the set."] theorem subset_closure : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx ``` In order for `aesop` to make effective use of `AddSubmonoid.closure` it needs the following new lemma. ```lean @[aesop 5% apply (rule_sets [SetLike])] lemma mem_of_subset {s : Set B} (hp : s ⊆ p) {x : B} (hx : x ∈ s) : x ∈ p := hp hx ``` Note: this lemma is marked as very unsafe (`5%`) because it will apply *whenever* the goal is of the form `x ∈ p` where `p` is any term of a `SetLike` instance; and moreover, it will create `s` as a metavariable, which is in general a terrible idea, but necessary for the reason mentioned above.
1 parent bd6067c commit 214e72f

File tree

25 files changed

+123
-11
lines changed

25 files changed

+123
-11
lines changed

Mathlib.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,6 +3223,7 @@ import Mathlib.Tactic.Sat.FromLRAT
32233223
import Mathlib.Tactic.Says
32243224
import Mathlib.Tactic.ScopedNS
32253225
import Mathlib.Tactic.Set
3226+
import Mathlib.Tactic.SetLike
32263227
import Mathlib.Tactic.SimpIntro
32273228
import Mathlib.Tactic.SimpRw
32283229
import Mathlib.Tactic.Simps.Basic

Mathlib/Algebra/Algebra/NonUnitalSubalgebra.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ theorem adjoin_toSubmodule (s : Set A) :
514514
(adjoin R s).toSubmodule = Submodule.span R (NonUnitalSubsemiring.closure s : Set A) :=
515515
rfl
516516

517+
@[aesop safe 20 apply (rule_sets [SetLike])]
517518
theorem subset_adjoin {s : Set A} : s ⊆ adjoin R s :=
518519
NonUnitalSubsemiring.subset_closure.trans Submodule.subset_span
519520

Mathlib/Algebra/Algebra/Subalgebra/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ variable (S : Subalgebra R A)
104104
instance instSMulMemClass : SMulMemClass (Subalgebra R A) R A where
105105
smul_mem {S} r x hx := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem' r) hx
106106

107+
@[aesop safe apply (rule_sets [SetLike])]
107108
theorem _root_.algebraMap_mem {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
108109
[SetLike S A] [OneMemClass S A] [SMulMemClass S R A] (s : S) (r : R) :
109110
algebraMap R A r ∈ s :=

Mathlib/Algebra/Star/Basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class StarMemClass (S R : Type*) [Star R] [SetLike S R] : Prop where
6262

6363
export StarMemClass (star_mem)
6464

65+
attribute [aesop safe apply (rule_sets [SetLike])] star_mem
66+
6567
namespace StarMemClass
6668

6769
variable {S : Type w} [Star R] [SetLike S R] [hS : StarMemClass S R] (s : S)

Mathlib/Algebra/Star/NonUnitalSubalgebra.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ theorem adjoin_toNonUnitalSubalgebra (s : Set A) :
633633
(adjoin R s).toNonUnitalSubalgebra = NonUnitalAlgebra.adjoin R (s ∪ star s) :=
634634
rfl
635635

636+
@[aesop safe 20 apply (rule_sets [SetLike])]
636637
theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s :=
637638
(Set.subset_union_left s (star s)).trans <| NonUnitalAlgebra.subset_adjoin R
638639

Mathlib/Algebra/Star/SelfAdjoint.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ section SMul
528528

529529
variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A]
530530

531+
@[aesop safe apply (rule_sets [SetLike])]
531532
theorem smul_mem [Monoid R] [DistribMulAction R A] [StarModule R A] (r : R) {x : A}
532533
(h : x ∈ skewAdjoint A) : r • x ∈ skewAdjoint A := by
533534
rw [mem_iff, star_smul, star_trivial, mem_iff.mp h, smul_neg r]

Mathlib/Algebra/Star/Subalgebra.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ theorem adjoin_toSubalgebra (s : Set A) :
445445
rfl
446446
#align star_subalgebra.adjoin_to_subalgebra StarSubalgebra.adjoin_toSubalgebra
447447

448+
@[aesop safe 20 apply (rule_sets [SetLike])]
448449
theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s :=
449450
(Set.subset_union_left s (star s)).trans Algebra.subset_adjoin
450451
#align star_subalgebra.subset_adjoin StarSubalgebra.subset_adjoin

Mathlib/Analysis/Convex/Cone/Basic.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ theorem ext {S T : ConvexCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :
114114
SetLike.ext h
115115
#align convex_cone.ext ConvexCone.ext
116116

117+
@[aesop safe apply (rule_sets [SetLike])]
117118
theorem smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S :=
118119
S.smul_mem' hc hx
119120
#align convex_cone.smul_mem ConvexCone.smul_mem

Mathlib/Data/SetLike/Basic.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Eric Wieser
55
-/
66
import Mathlib.Data.Set.Basic
77
import Mathlib.Tactic.Monotonicity.Attr
8+
import Mathlib.Tactic.SetLike
89

910
#align_import data.set_like.basic from "leanprover-community/mathlib"@"feb99064803fd3108e37c18b0f77d0a8344677a3"
1011

@@ -174,6 +175,9 @@ theorem coe_mem (x : p) : (x : B) ∈ p :=
174175
x.2
175176
#align set_like.coe_mem SetLike.coe_mem
176177

178+
@[aesop 5% apply (rule_sets [SetLike])]
179+
lemma mem_of_subset {s : Set B} (hp : s ⊆ p) {x : B} (hx : x ∈ s) : x ∈ p := hp hx
180+
177181
-- porting note: removed `@[simp]` because `simpNF` linter complained
178182
protected theorem eta (x : p) (hx : (x : B) ∈ p) : (⟨x, hx⟩ : p) = x := rfl
179183
#align set_like.eta SetLike.eta

Mathlib/FieldTheory/Subfield.lean

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ instance (priority := 100) toSubgroupClass : SubgroupClass S K :=
8888

8989
variable {S}
9090

91+
@[aesop safe apply (rule_sets [SetLike])]
9192
theorem coe_rat_mem (s : S) (x : ℚ) : (x : K) ∈ s := by
9293
simpa only [Rat.cast_def] using div_mem (coe_int_mem s x.num) (coe_nat_mem s x.den)
9394
#align subfield_class.coe_rat_mem SubfieldClass.coe_rat_mem
@@ -101,10 +102,16 @@ theorem coe_rat_cast (s : S) (x : ℚ) : ((x : s) : K) = x :=
101102
#align subfield_class.coe_rat_cast SubfieldClass.coe_rat_cast
102103

103104
-- Porting note: Mistranslated: used to be (a • x : K) ∈ s
105+
@[aesop safe apply (rule_sets [SetLike])]
104106
theorem rat_smul_mem (s : S) (a : ℚ) (x : s) : a • (x : K) ∈ s := by
105107
simpa only [Rat.smul_def] using mul_mem (coe_rat_mem s a) x.prop
106108
#align subfield_class.rat_smul_mem SubfieldClass.rat_smul_mem
107109

110+
@[aesop safe apply (rule_sets [SetLike])]
111+
lemma ofScientific_mem (s : S) {b : Bool} {n m : ℕ} :
112+
(OfScientific.ofScientific n b m : K) ∈ s :=
113+
SubfieldClass.coe_rat_mem ..
114+
108115
instance (s : S) : SMul ℚ s :=
109116
fun a x => ⟨a • (x : K), rat_smul_mem s a x⟩⟩
110117

@@ -694,7 +701,7 @@ theorem subring_closure_le (s : Set K) : Subring.closure s ≤ (closure s).toSub
694701
#align subfield.subring_closure_le Subfield.subring_closure_le
695702

696703
/-- The subfield generated by a set includes the set. -/
697-
@[simp]
704+
@[simp, aesop safe 20 apply (rule_sets [SetLike])]
698705
theorem subset_closure {s : Set K} : s ⊆ closure s :=
699706
Set.Subset.trans Subring.subset_closure (subring_closure_le s)
700707
#align subfield.subset_closure Subfield.subset_closure

0 commit comments

Comments
 (0)