Skip to content

Commit dd7678a

Browse files
refactor: remove order instances from SetLike (leanprover-community#32984)
* Remove order instances from `SetLike` * Add class `IsConcreteLE` for `SetLike` instances whose map is order-preserving See discussion at https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Abstracting.20the.20substructure.20lattice.20construction/with/563952738 Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent ab89ddb commit dd7678a

99 files changed

Lines changed: 382 additions & 150 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Mathlib/Algebra/Algebra/NonUnitalSubalgebra.lean

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ lemma toSubmodule_injective : (toSubmodule : NonUnitalSubalgebra R A → Submodu
9090
lemma toSubmodule_inj {s t : NonUnitalSubalgebra R A} : s.toSubmodule = t.toSubmodule ↔ s = t :=
9191
toSubmodule_injective.eq_iff
9292

93+
instance : PartialOrder (NonUnitalSubalgebra R A) := .ofSetLike (NonUnitalSubalgebra R A) A
94+
9395
/-- The actual `NonUnitalSubalgebra` obtained from an element of a type satisfying
9496
`NonUnitalSubsemiringClass` and `SMulMemClass`. -/
9597
@[simps]
@@ -905,32 +907,22 @@ theorem mem_prod {S : NonUnitalSubalgebra R A} {S₁ : NonUnitalSubalgebra R B}
905907
x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ :=
906908
Set.mem_prod
907909

910+
theorem prod_mono {S T : NonUnitalSubalgebra R A} {S₁ T₁ : NonUnitalSubalgebra R B} :
911+
S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=
912+
Set.prod_mono
913+
908914
variable [IsScalarTower R A A] [SMulCommClass R A A] [IsScalarTower R B B] [SMulCommClass R B B]
909915

910916
@[simp]
911917
theorem prod_top : (prod ⊤ ⊤ : NonUnitalSubalgebra R (A × B)) = ⊤ := by ext; simp
912918

913-
theorem prod_mono {S T : NonUnitalSubalgebra R A} {S₁ T₁ : NonUnitalSubalgebra R B} :
914-
S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=
915-
Set.prod_mono
916-
917919
@[simp]
918920
theorem prod_inf_prod {S T : NonUnitalSubalgebra R A} {S₁ T₁ : NonUnitalSubalgebra R B} :
919921
S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=
920922
SetLike.coe_injective Set.prod_inter_prod
921923

922924
end Prod
923925

924-
variable [IsScalarTower R A A] [SMulCommClass R A A]
925-
926-
instance _root_.NonUnitalAlgHom.subsingleton [Subsingleton (NonUnitalSubalgebra R A)] :
927-
Subsingleton (A →ₙₐ[R] B) :=
928-
fun f g =>
929-
NonUnitalAlgHom.ext fun a =>
930-
have : a ∈ (⊥ : NonUnitalSubalgebra R A) :=
931-
Subsingleton.elim (⊤ : NonUnitalSubalgebra R A) ⊥ ▸ mem_top
932-
(mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩
933-
934926

935927
/-- The map `S → T` when `S` is a non-unital subalgebra contained in the non-unital subalgebra `T`.
936928
@@ -969,6 +961,16 @@ theorem coe_inclusion {S T : NonUnitalSubalgebra R A} (h : S ≤ T) (s : S) :
969961
(inclusion h s : A) = s :=
970962
rfl
971963

964+
variable [IsScalarTower R A A] [SMulCommClass R A A]
965+
966+
instance _root_.NonUnitalAlgHom.subsingleton [Subsingleton (NonUnitalSubalgebra R A)] :
967+
Subsingleton (A →ₙₐ[R] B) :=
968+
fun f g =>
969+
NonUnitalAlgHom.ext fun a =>
970+
have : a ∈ (⊥ : NonUnitalSubalgebra R A) :=
971+
Subsingleton.elim (⊤ : NonUnitalSubalgebra R A) ⊥ ▸ mem_top
972+
(mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩
973+
972974
section SuprLift
973975

974976
variable {ι : Sort*}

Mathlib/Algebra/Algebra/Subalgebra/Basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ instance : SetLike (Subalgebra R A) A where
4646
coe s := s.carrier
4747
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
4848

49+
instance : PartialOrder (Subalgebra R A) := .ofSetLike (Subalgebra R A) A
50+
4951
initialize_simps_projections Subalgebra (carrier → coe, as_prefix coe)
5052

5153
@[simp]

Mathlib/Algebra/Field/Subfield/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ instance : SetLike (Subfield K) K where
148148
coe s := s.carrier
149149
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
150150

151+
instance : PartialOrder (Subfield K) := .ofSetLike (Subfield K) K
152+
151153
instance : SubfieldClass (Subfield K) K where
152154
add_mem {s} := s.add_mem'
153155
zero_mem s := s.zero_mem'

Mathlib/Algebra/Group/Subgroup/Defs.lean

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ namespace SubgroupClass
177177
-- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ
178178
-- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ
179179
@[to_additive]
180-
theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by
181-
refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩
182-
rw [or_iff_not_imp_left, SetLike.not_le_iff_exists]
180+
theorem subset_union [LE S] [IsConcreteLE S G] {H K L : S} :
181+
(H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by
182+
refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (mem_of_le_of_mem · xH) (mem_of_le_of_mem · xH)⟩
183+
rw [or_iff_not_imp_left, SetLike.not_le_iff_exists, ← SetLike.coe_subset_coe]
183184
exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim
184185
((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·)
185186
(mul_mem_cancel_left <| (h xH).resolve_left xK).mp
@@ -253,35 +254,40 @@ theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n :=
253254
/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/
254255
@[to_additive
255256
/-- The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`. -/]
256-
def inclusion {H K : S} (h : H ≤ K) : H →* K :=
257-
MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _ => rfl
257+
def inclusion [LE S] [IsConcreteLE S G] {H K : S} (h : H ≤ K) : H →* K :=
258+
MonoidHom.mk' (fun x => ⟨x, mem_of_le_of_mem h x.prop⟩) fun _ _ => rfl
258259

259260
@[to_additive (attr := simp)]
260-
theorem inclusion_self (x : H) : inclusion le_rfl x = x := by
261+
theorem inclusion_self [Preorder S] [IsConcreteLE S G] (x : H) : inclusion le_rfl x = x := by
261262
cases x
262263
rfl
263264

264265
@[to_additive (attr := simp)]
265-
theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=
266+
theorem inclusion_mk [LE S] [IsConcreteLE S G] {h : H ≤ K} (x : G) (hx : x ∈ H) :
267+
inclusion h ⟨x, hx⟩ = ⟨x, mem_of_le_of_mem h hx⟩ :=
266268
rfl
267269

268270
@[to_additive]
269-
theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by
271+
theorem inclusion_right [LE S] [IsConcreteLE S G] (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) :
272+
inclusion h ⟨x, hx⟩ = x := by
270273
cases x
271274
rfl
272275

273276
@[simp]
274-
theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) :
277+
theorem inclusion_inclusion [Preorder S] [IsConcreteLE S G]
278+
{L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) :
275279
inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by
276280
cases x
277281
rfl
278282

279283
@[to_additive (attr := simp)]
280-
theorem coe_inclusion {H K : S} (h : H ≤ K) (a : H) : (inclusion h a : G) = a :=
281-
Set.coe_inclusion h a
284+
theorem coe_inclusion [LE S] [IsConcreteLE S G]
285+
{H K : S} (h : H ≤ K) (a : H) : (inclusion h a : G) = a :=
286+
Set.coe_inclusion (SetLike.GCongr.coe_subset_coe h) a
282287

283288
@[to_additive (attr := simp)]
284-
theorem subtype_comp_inclusion {H K : S} (h : H ≤ K) :
289+
theorem subtype_comp_inclusion [LE S] [IsConcreteLE S G]
290+
{H K : S} (h : H ≤ K) :
285291
(SubgroupClass.subtype K).comp (inclusion h) = SubgroupClass.subtype H :=
286292
rfl
287293

@@ -319,6 +325,8 @@ instance : SetLike (Subgroup G) G where
319325
obtain ⟨⟨⟨hq, _⟩, _⟩, _⟩ := q
320326
congr
321327

328+
@[to_additive] instance : PartialOrder (Subgroup G) := .ofSetLike (Subgroup G) G
329+
322330
initialize_simps_projections Subgroup (carrier → coe, as_prefix coe)
323331
initialize_simps_projections AddSubgroup (carrier → coe, as_prefix coe)
324332

Mathlib/Algebra/Group/Submonoid/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ instance : SetLike (Submonoid M) M where
139139
coe s := s.carrier
140140
coe_injective' := SetLike.coe_injective.comp toSubsemigroup_injective
141141

142+
@[to_additive] instance : PartialOrder (Submonoid M) := .ofSetLike (Submonoid M) M
143+
142144
initialize_simps_projections Submonoid (carrier → coe, as_prefix coe)
143145
initialize_simps_projections AddSubmonoid (carrier → coe, as_prefix coe)
144146

Mathlib/Algebra/Group/Subsemigroup/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ namespace Subsemigroup
9898
instance : SetLike (Subsemigroup M) M :=
9999
⟨Subsemigroup.carrier, fun p q h => by cases p; cases q; congr⟩
100100

101+
@[to_additive] instance : PartialOrder (Subsemigroup M) := .ofSetLike (Subsemigroup M) M
102+
101103
initialize_simps_projections Subsemigroup (carrier → coe, as_prefix coe)
102104
initialize_simps_projections AddSubsemigroup (carrier → coe, as_prefix coe)
103105

Mathlib/Algebra/Lie/Subalgebra.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ instance : SetLike (LieSubalgebra R L) L where
6666
congr
6767
exact SetLike.coe_injective' h
6868

69+
instance : PartialOrder (LieSubalgebra R L) := .ofSetLike (LieSubalgebra R L) L
70+
6971
instance : AddSubgroupClass (LieSubalgebra R L) L where
7072
add_mem := Submodule.add_mem _
7173
zero_mem L' := L'.zero_mem'

Mathlib/Algebra/Lie/Submodule.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ instance : SetLike (LieSubmodule R L M) M where
5555
coe s := s.carrier
5656
coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h
5757

58+
instance : PartialOrder (LieSubmodule R L M) := .ofSetLike (LieSubmodule R L M) M
59+
5860
instance : AddSubgroupClass (LieSubmodule R L M) M where
5961
add_mem {N} _ _ := N.add_mem'
6062
zero_mem N := N.zero_mem'
@@ -409,8 +411,7 @@ theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
409411
/-- The Lie submodules of a Lie module form a complete lattice. -/
410412
instance : CompleteLattice (LieSubmodule R L M) :=
411413
{ toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule
412-
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with
413-
toPartialOrder := SetLike.instPartialOrder }
414+
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with }
414415

415416
theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) :
416417
b ∈ ⨆ i, N i :=

Mathlib/Algebra/Module/Submodule/Defs.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ instance setLike : SetLike (Submodule R M) M where
5555
coe s := s.carrier
5656
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
5757

58+
instance : PartialOrder (Submodule R M) := .ofSetLike (Submodule R M) M
59+
5860
initialize_simps_projections Submodule (carrier → coe, as_prefix coe)
5961

6062
@[simp] lemma carrier_eq_coe (s : Submodule R M) : s.carrier = s := rfl

Mathlib/Algebra/Order/Group/Cone.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ instance GroupCone.instSetLike (G : Type*) [CommGroup G] : SetLike (GroupCone G)
5656
coe C := C.carrier
5757
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
5858

59+
@[to_additive]
60+
instance (G : Type*) [CommGroup G] : PartialOrder (GroupCone G) := .ofSetLike (GroupCone G) G
61+
5962
@[to_additive]
6063
instance GroupCone.instGroupConeClass (G : Type*) [CommGroup G] :
6164
GroupConeClass (GroupCone G) G where

0 commit comments

Comments
 (0)