Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 172195b

Browse files
committed
feat(algebra/{ordered_monoid, ordered_monoid_lemmas}): split the ordered_[...] typeclasses (#7371)
This PR tries to split the ordering assumptions from the algebraic assumptions on the operations in the `ordered_[...]` hierarchy. The strategy is to introduce two more flexible typeclasses, `covariant_class` and `contravariant_class`. * `covariant_class` models the implication `a ≤ b → c * a ≤ c * b` (multiplication is monotone), * `contravariant_class` models the implication `a * b < a * c → b < c`. Since `co(ntra)variant_class` takes as input the operation (typically `(+)` or `(*)`) and the order relation (typically `(≤)` or `(<)`), these are the only two typeclasses that I have used. The general approach is to formulate the lemma that you are interested in and prove it, with the `ordered_[...]` typeclass of your liking. After that, you convert the single typeclass, say `[ordered_cancel_monoid M]`, to three typeclasses, e.g. `[partial_order M] [left_cancel_semigroup M] [covariant_class M M (function.swap (*)) (≤)]` and have a go at seeing if the proof still works! Note that it is possible (or even expected) to combine several `co(ntra)variant_class` assumptions together. Indeed, the usual `ordered` typeclasses arise from assuming the pair `[covariant_class M M (*) (≤)] [contravariant_class M M (*) (<)]` on top of order/algebraic assumptions. A formal remark is that *normally* `covariant_class` uses the `(≤)`-relation, while `contravariant_class` uses the `(<)`-relation. This need not be the case in general, but seems to be the most common usage. In the opposite direction, the implication `[semigroup α] [partial_order α] [contravariant_class α α (*) (≤)] => left_cancel_semigroup α` holds (note the `co*ntra*` assumption and the `(≤)`-relation). Zulip: https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/ordered.20stuff
1 parent 738c19f commit 172195b

File tree

11 files changed

+700
-442
lines changed

11 files changed

+700
-442
lines changed

src/algebra/linear_ordered_comm_group_with_zero.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ have hb : b ≠ 0 := ne_zero_of_lt hab,
182182
have hd : d ≠ 0 := ne_zero_of_lt hcd,
183183
if ha : a = 0 then by { rw [ha, zero_mul, zero_lt_iff], exact mul_ne_zero hb hd } else
184184
if hc : c = 0 then by { rw [hc, mul_zero, zero_lt_iff], exact mul_ne_zero hb hd } else
185-
@mul_lt_mul''' _ _ (units.mk0 a ha) (units.mk0 b hb) (units.mk0 c hc) (units.mk0 d hd) hab hcd
185+
@mul_lt_mul''' _
186+
(units.mk0 a ha) (units.mk0 b hb) (units.mk0 c hc) (units.mk0 d hd) _ _ _ _ _ _ hab hcd
186187

187188
lemma mul_inv_lt_of_lt_mul' (h : x < y * z) : x * z⁻¹ < y :=
188189
have hz : z ≠ 0 := (mul_ne_zero_iff.1 $ ne_zero_of_lt h).2,

src/algebra/ordered_group.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class ordered_comm_group (α : Type u) extends comm_group α, partial_order α :
3636

3737
attribute [to_additive] ordered_comm_group
3838

39+
@[to_additive]
40+
instance units.covariant_class [ordered_comm_monoid α] :
41+
covariant_class (units α) (units α) (*) (≤) :=
42+
{ covc := λ a b c bc, by {
43+
rcases le_iff_eq_or_lt.mp bc with ⟨rfl, h⟩,
44+
{ exact rfl.le },
45+
refine le_iff_eq_or_lt.mpr (or.inr _),
46+
refine units.coe_lt_coe.mp _,
47+
cases lt_iff_le_and_ne.mp (units.coe_lt_coe.mpr h) with lef rig,
48+
exact lt_of_le_of_ne (mul_le_mul_left' lef ↑a) (λ hg, rig ((units.mul_right_inj a).mp hg)) } }
49+
3950
/--The units of an ordered commutative monoid form an ordered commutative group. -/
4051
@[to_additive]
4152
instance units.ordered_comm_group [ordered_comm_monoid α] : ordered_comm_group (units α) :=
@@ -962,7 +973,7 @@ instance [ordered_add_comm_group α] : ordered_add_comm_group (order_dual α) :=
962973

963974
instance [linear_ordered_add_comm_group α] :
964975
linear_ordered_add_comm_group (order_dual α) :=
965-
{ add_le_add_left := λ a b h c, @add_le_add_left α _ b a h _,
976+
{ add_le_add_left := λ a b h c, by exact add_le_add_left h _,
966977
..order_dual.linear_order α,
967978
..show add_comm_group α, by apply_instance }
968979

0 commit comments

Comments
 (0)