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

Commit afc3f03

Browse files
committed
feat(algebra/ordered_group): add linear_ordered_comm_group and linear_ordered_cancel_comm_monoid (#5286)
We have `linear_ordered_add_comm_group` but we didn't have `linear_ordered_comm_group`. This PR adds it, as well as multiplicative versions of `canonically_ordered_add_monoid`, `canonically_linear_ordered_add_monoid` and `linear_ordered_cancel_add_comm_monoid`. I added multiplicative versions of the lemmas about these structures too. The motivation is that I want to slightly generalise the notion of a valuation. [ also random other bits of tidying which I noticed along the way (docstring fixes, adding `norm_cast` attributes) ].
1 parent d94f0a2 commit afc3f03

File tree

2 files changed

+156
-82
lines changed

2 files changed

+156
-82
lines changed

src/algebra/ordered_group.lean

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,33 @@ lt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm
511511

512512
end ordered_add_comm_group
513513

514-
/-- A decidable linearly ordered additive commutative group is an
515-
additive commutative group with a decidable linear order in which
516-
addition is strictly monotone. -/
514+
/-!
515+
516+
### Linearly ordered commutative groups
517+
518+
-/
519+
520+
/-- A linearly ordered additive commutative group is an
521+
additive commutative group with a linear order in which
522+
addition is monotone. -/
517523
@[protect_proj] class linear_ordered_add_comm_group (α : Type u)
518524
extends add_comm_group α, linear_order α :=
519525
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b)
520526

521-
@[priority 100] -- see Note [lower instance priority]
522-
instance linear_ordered_comm_group.to_ordered_add_comm_group (α : Type u)
523-
[s : linear_ordered_add_comm_group α] : ordered_add_comm_group α :=
524-
{ add := s.add, ..s }
527+
/-- A linearly ordered commutative group is a
528+
commutative group with a linear order in which
529+
multiplication is monotone. -/
530+
@[protect_proj, to_additive] class linear_ordered_comm_group (α : Type u)
531+
extends comm_group α, linear_order α :=
532+
(mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b)
533+
534+
@[to_additive, priority 100] -- see Note [lower instance priority]
535+
instance linear_ordered_comm_group.to_ordered_comm_group (α : Type u)
536+
[s : linear_ordered_comm_group α] : ordered_comm_group α :=
537+
{ ..s }
525538

526539
section linear_ordered_add_comm_group
540+
527541
variables [linear_ordered_add_comm_group α] {a b c : α}
528542

529543
@[priority 100] -- see Note [lower instance priority]

src/algebra/ordered_monoid.lean

Lines changed: 135 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ instance [ordered_comm_monoid α] : ordered_comm_monoid (with_zero α) :=
311311
..with_zero.partial_order
312312
}
313313

314+
/-
315+
Note 1 : the below is not an instance because it requires `zero_le`. It seems
316+
like a rather pathological definition because α already has a zero.
317+
318+
Note 2 : there is no multiplicative analogue because it does not seem necessary.
319+
Mathematicians might be more likely to use the order-dual version, where all
320+
elements are ≤ 1 and then 1 is the top element.
321+
-/
322+
314323
/--
315324
If `0` is the least element in `α`, then `with_zero α` is an `ordered_add_comm_monoid`.
316325
-/
@@ -520,55 +529,74 @@ by norm_cast
520529
end with_bot
521530

522531
/-- A canonically ordered additive monoid is an ordered commutative additive monoid
523-
in which the ordering coincides with the divisibility relation,
532+
in which the ordering coincides with the subtractibility relation,
524533
which is to say, `a ≤ b` iff there exists `c` with `b = a + c`.
525534
This is satisfied by the natural numbers, for example, but not
526-
the integers or other ordered groups. -/
527-
@[protect_proj]
535+
the integers or other nontrivial `ordered_add_comm_group`s. -/
536+
@[protect_proj, ancestor ordered_add_comm_monoid order_bot]
528537
class canonically_ordered_add_monoid (α : Type*) extends ordered_add_comm_monoid α, order_bot α :=
529-
(le_iff_exists_add : ∀a b:α, a ≤ b ↔ ∃c, b = a + c)
538+
(le_iff_exists_add : ∀ a b : α, a ≤ b ↔ ∃ c, b = a + c)
539+
540+
/-- A canonically ordered monoid is an ordered commutative monoid
541+
in which the ordering coincides with the divisibility relation,
542+
which is to say, `a ≤ b` iff there exists `c` with `b = a * c`.
543+
Example seem rare; it seems more likely that the `order_dual`
544+
of a naturally-occurring lattice satisfies this than the lattice
545+
itself (for example, dual of the lattice of ideals of a PID or
546+
Dedekind domain satisfy this; collections of all things ≤ 1 seem to
547+
be more natural that collections of all things ≥ 1).
548+
-/
549+
@[protect_proj, ancestor ordered_comm_monoid order_bot, to_additive]
550+
class canonically_ordered_monoid (α : Type*) extends ordered_comm_monoid α, order_bot α :=
551+
(le_iff_exists_mul : ∀ a b : α, a ≤ b ↔ ∃ c, b = a * c)
530552

531-
section canonically_ordered_add_monoid
532-
variables [canonically_ordered_add_monoid α] {a b c d : α}
553+
section canonically_ordered_monoid
533554

534-
lemma le_iff_exists_add : a ≤ b ↔ ∃c, b = a + c :=
535-
canonically_ordered_add_monoid.le_iff_exists_add a b
555+
variables [canonically_ordered_monoid α] {a b c d : α}
536556

537-
@[simp] lemma zero_le (a : α) : 0 ≤ a := le_iff_exists_add.mpr ⟨a, by simp⟩
557+
@[to_additive]
558+
lemma le_iff_exists_mul : a ≤ b ↔ ∃c, b = a * c :=
559+
canonically_ordered_monoid.le_iff_exists_mul a b
560+
561+
@[simp, to_additive zero_le] lemma one_le (a : α) : 1 ≤ a := le_iff_exists_mul.mpr ⟨a, by simp⟩
538562

539-
@[simp] lemma bot_eq_zero : (⊥ : α) = 0 :=
540-
le_antisymm bot_le (zero_le ⊥)
563+
@[simp, to_additive] lemma bot_eq_one : (⊥ : α) = 1 :=
564+
le_antisymm bot_le (one_le ⊥)
541565

542-
@[simp] lemma add_eq_zero_iff : a + b = 0 ↔ a = 0 ∧ b = 0 :=
543-
add_eq_zero_iff' (zero_le _) (zero_le _)
566+
@[simp, to_additive] lemma mul_eq_one_iff : a * b = 1 ↔ a = 1 ∧ b = 1 :=
567+
mul_eq_one_iff' (one_le _) (one_le _)
544568

545-
@[simp] lemma le_zero_iff_eq : a ≤ 0 ↔ a = 0 :=
569+
-- TODO -- global replace le_zero_iff_eq by n nonpos_iff_eq_zero?
570+
@[simp, to_additive le_zero_iff_eq] lemma le_one_iff_eq : a ≤ 1 ↔ a = 1 :=
546571
iff.intro
547-
(assume h, le_antisymm h (zero_le a))
572+
(assume h, le_antisymm h (one_le a))
548573
(assume h, h ▸ le_refl a)
549574

550-
lemma zero_lt_iff_ne_zero : 0 < a ↔ a ≠ 0 :=
551-
iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (zero_le _) hne.symm
575+
-- TODO -- global replace zero_lt_iff_ne_zero by pos_iff_ne_zero?
576+
@[to_additive zero_lt_iff_ne_zero] lemma one_lt_iff_ne_one : 1 < a ↔ a ≠ 1 :=
577+
iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (one_le _) hne.symm
552578

553-
lemma exists_pos_add_of_lt (h : a < b) : ∃ c > 0, a + c = b :=
579+
@[to_additive] lemma exists_pos_mul_of_lt (h : a < b) : ∃ c > 1, a * c = b :=
554580
begin
555-
obtain ⟨c, hc⟩ := le_iff_exists_add.1 h.le,
556-
refine ⟨c, zero_lt_iff_ne_zero.2 _, hc.symm⟩,
581+
obtain ⟨c, hc⟩ := le_iff_exists_mul.1 h.le,
582+
refine ⟨c, one_lt_iff_ne_one.2 _, hc.symm⟩,
557583
rintro rfl,
558584
simpa [hc, lt_irrefl] using h
559585
end
560586

561-
lemma le_add_left (h : a ≤ c) : a ≤ b + c :=
562-
calc a = 0 + a : by simp
563-
... ≤ b + c : add_le_add (zero_le _) h
587+
@[to_additive] lemma le_mul_left (h : a ≤ c) : a ≤ b * c :=
588+
calc a = 1 * a : by simp
589+
... ≤ b * c : mul_le_mul' (one_le _) h
564590

565-
lemma le_add_right (h : a ≤ b) : a ≤ b + c :=
566-
calc a = a + 0 : by simp
567-
... ≤ b + c : add_le_add h (zero_le _)
591+
@[to_additive] lemma le_mul_right (h : a ≤ b) : a ≤ b * c :=
592+
calc a = a * 1 : by simp
593+
... ≤ b * c : mul_le_mul' h (one_le _)
568594

569595
local attribute [semireducible] with_zero
570596

571-
instance with_zero.canonically_ordered_add_monoid :
597+
-- This instance looks absurd: a monoid already has a zero
598+
/-- Adding a new zero to a canonically ordered additive monoid produces another one. -/
599+
instance with_zero.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] :
572600
canonically_ordered_add_monoid (with_zero α) :=
573601
{ le_iff_exists_add := λ a b, begin
574602
cases a with a,
@@ -588,7 +616,8 @@ instance with_zero.canonically_ordered_add_monoid :
588616
bot_le := assume a a' h, option.no_confusion h,
589617
.. with_zero.ordered_add_comm_monoid zero_le }
590618

591-
instance with_top.canonically_ordered_add_monoid : canonically_ordered_add_monoid (with_top α) :=
619+
instance with_top.canonically_ordered_add_monoid {α : Type u} [canonically_ordered_add_monoid α] :
620+
canonically_ordered_add_monoid (with_top α) :=
592621
{ le_iff_exists_add := assume a b,
593622
match a, b with
594623
| a, none := show a ≤ ⊤ ↔ ∃c, ⊤ = a + c, by simp; refine ⟨⊤, _⟩; cases a; refl
@@ -604,26 +633,39 @@ instance with_top.canonically_ordered_add_monoid : canonically_ordered_add_monoi
604633
.. with_top.order_bot,
605634
.. with_top.ordered_add_comm_monoid }
606635

607-
end canonically_ordered_add_monoid
636+
end canonically_ordered_monoid
608637

609638
/-- A canonically linear-ordered additive monoid is a canonically ordered additive monoid
610-
whose ordering is a decidable linear order. -/
611-
@[protect_proj]
639+
whose ordering is a linear order. -/
640+
@[protect_proj, ancestor canonically_ordered_add_monoid linear_order]
612641
class canonically_linear_ordered_add_monoid (α : Type*)
613642
extends canonically_ordered_add_monoid α, linear_order α
614643

615-
section canonically_linear_ordered_add_monoid
616-
variables [canonically_linear_ordered_add_monoid α]
644+
/-- A canonically linear-ordered monoid is a canonically ordered monoid
645+
whose ordering is a linear order. -/
646+
@[protect_proj, ancestor canonically_ordered_monoid linear_order]
647+
class canonically_linear_ordered_monoid (α : Type*)
648+
extends canonically_ordered_monoid α, linear_order α
649+
650+
section canonically_linear_ordered_monoid
651+
variables
617652

618653
@[priority 100] -- see Note [lower instance priority]
619-
instance canonically_linear_ordered_add_monoid.semilattice_sup_bot : semilattice_sup_bot α :=
654+
instance canonically_linear_ordered_add_monoid.semilattice_sup_bot
655+
[canonically_linear_ordered_add_monoid α] : semilattice_sup_bot α :=
620656
{ ..lattice_of_linear_order, ..canonically_ordered_add_monoid.to_order_bot α }
621657

622-
end canonically_linear_ordered_add_monoid
658+
@[priority 100, to_additive canonically_linear_ordered_add_monoid.semilattice_sup_bot]
659+
-- see Note [lower instance priority]
660+
instance canonically_linear_ordered_monoid.semilattice_sup_bot
661+
[canonically_linear_ordered_monoid α] : semilattice_sup_bot α :=
662+
{ ..lattice_of_linear_order, ..canonically_ordered_monoid.to_order_bot α }
663+
664+
end canonically_linear_ordered_monoid
623665

624666
/-- An ordered cancellative additive commutative monoid
625667
is an additive commutative monoid with a partial order,
626-
in which addition is cancellative and strictly monotone. -/
668+
in which addition is cancellative and monotone. -/
627669
@[protect_proj, ancestor add_comm_monoid add_left_cancel_semigroup
628670
add_right_cancel_semigroup partial_order]
629671
class ordered_cancel_add_comm_monoid (α : Type u)
@@ -634,16 +676,15 @@ class ordered_cancel_add_comm_monoid (α : Type u)
634676

635677
/-- An ordered cancellative commutative monoid
636678
is a commutative monoid with a partial order,
637-
in which multiplication is cancellative and strictly monotone. -/
638-
@[protect_proj, ancestor comm_monoid left_cancel_semigroup right_cancel_semigroup partial_order]
679+
in which multiplication is cancellative and monotone. -/
680+
@[protect_proj, ancestor comm_monoid left_cancel_semigroup right_cancel_semigroup partial_order,
681+
to_additive]
639682
class ordered_cancel_comm_monoid (α : Type u)
640683
extends comm_monoid α, left_cancel_semigroup α,
641684
right_cancel_semigroup α, partial_order α :=
642685
(mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b)
643686
(le_of_mul_le_mul_left : ∀ a b c : α, a * b ≤ a * c → b ≤ c)
644687

645-
attribute [to_additive] ordered_cancel_comm_monoid
646-
647688
section ordered_cancel_comm_monoid
648689
variables [ordered_cancel_comm_monoid α] {a b c d : α}
649690

@@ -894,12 +935,6 @@ by simpa [add_comm] using @with_bot.add_lt_add_iff_left _ _ a b c
894935

895936
end ordered_cancel_add_comm_monoid
896937

897-
/-- A decidable linearly ordered cancellative additive commutative monoid
898-
is an additive commutative monoid with a decidable linear order
899-
in which addition is cancellative and strictly monotone. -/
900-
@[protect_proj] class linear_ordered_cancel_add_comm_monoid (α : Type u)
901-
extends ordered_cancel_add_comm_monoid α, linear_order α
902-
903938
/-! Some lemmas about types that have an ordering and a binary operation, with no
904939
rules relating them. -/
905940
@[to_additive]
@@ -912,50 +947,75 @@ lemma min_mul_max [linear_order α] [comm_semigroup α] (n m : α) :
912947
min n m * max n m = n * m :=
913948
fn_min_mul_fn_max id n m
914949

915-
section linear_ordered_cancel_add_comm_monoid
916-
variables [linear_ordered_cancel_add_comm_monoid α]
950+
/-- A linearly ordered cancellative additive commutative monoid
951+
is an additive commutative monoid with a decidable linear order
952+
in which addition is cancellative and monotone. -/
953+
@[protect_proj, ancestor ordered_cancel_add_comm_monoid linear_order]
954+
class linear_ordered_cancel_add_comm_monoid (α : Type u)
955+
extends ordered_cancel_add_comm_monoid α, linear_order α
917956

918-
lemma min_add_add_left (a b c : α) : min (a + b) (a + c) = a + min b c :=
919-
(monotone_id.const_add a).map_min.symm
957+
/-- A linearly ordered cancellative commutative monoid
958+
is a commutative monoid with a linear order
959+
in which multiplication is cancellative and monotone. -/
960+
@[protect_proj, ancestor ordered_cancel_comm_monoid linear_order, to_additive]
961+
class linear_ordered_cancel_comm_monoid (α : Type u)
962+
extends ordered_cancel_comm_monoid α, linear_order α
920963

921-
lemma min_add_add_right (a b c : α) : min (a + c) (b + c) = min a b + c :=
922-
(monotone_id.add_const c).map_min.symm
964+
section linear_ordered_cancel_comm_monoid
923965

924-
lemma max_add_add_left (a b c : α) : max (a + b) (a + c) = a + max b c :=
925-
(monotone_id.const_add a).map_max.symm
966+
variables [linear_ordered_cancel_comm_monoid α]
926967

927-
lemma max_add_add_right (a b c : α) : max (a + c) (b + c) = max a b + c :=
928-
(monotone_id.add_const c).map_max.symm
968+
@[to_additive] lemma min_mul_mul_left (a b c : α) : min (a * b) (a * c) = a * min b c :=
969+
(monotone_id.const_mul' a).map_min.symm
970+
971+
@[to_additive]
972+
lemma min_mul_mul_right (a b c : α) : min (a * c) (b * c) = min a b * c :=
973+
(monotone_id.mul_const' c).map_min.symm
929974

930-
lemma min_le_add_of_nonneg_right {a b : α} (hb : 0 ≤ b) : min a b ≤ a + b :=
931-
min_le_iff.2 $ or.inl $ le_add_of_nonneg_right hb
975+
@[to_additive]
976+
lemma max_mul_mul_left (a b c : α) : max (a * b) (a * c) = a * max b c :=
977+
(monotone_id.const_mul' a).map_max.symm
932978

933-
lemma min_le_add_of_nonneg_left {a b : α} (ha : 0 ≤ a) : min a b ≤ a + b :=
934-
min_le_iff.2 $ or.inr $ le_add_of_nonneg_left ha
979+
@[to_additive]
980+
lemma max_mul_mul_right (a b c : α) : max (a * c) (b * c) = max a b * c :=
981+
(monotone_id.mul_const' c).map_max.symm
935982

936-
lemma max_le_add_of_nonneg {a b : α} (ha : 0 ≤ a) (hb : 0 ≤ b) : max a b ≤ a + b :=
937-
max_le_iff.2 ⟨le_add_of_nonneg_right hb, le_add_of_nonneg_left ha⟩
983+
@[to_additive]
984+
lemma min_le_mul_of_one_le_right {a b : α} (hb : 1 ≤ b) : min a b ≤ a * b :=
985+
min_le_iff.2 $ or.inl $ le_mul_of_one_le_right' hb
938986

939-
end linear_ordered_cancel_add_comm_monoid
987+
@[to_additive]
988+
lemma min_le_mul_of_one_le_left {a b : α} (ha : 1 ≤ a) : min a b ≤ a * b :=
989+
min_le_iff.2 $ or.inr $ le_mul_of_one_le_left' ha
990+
991+
@[to_additive]
992+
lemma max_le_mul_of_one_le {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : max a b ≤ a * b :=
993+
max_le_iff.2 ⟨le_mul_of_one_le_right' hb, le_mul_of_one_le_left' ha⟩
994+
995+
end linear_ordered_cancel_comm_monoid
940996

941997
namespace order_dual
942998

943-
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (order_dual α) :=
944-
{ add_le_add_left := λ a b h c, @add_le_add_left α _ b a h _,
945-
lt_of_add_lt_add_left := λ a b c h, @lt_of_add_lt_add_left α _ a c b h,
999+
@[to_additive]
1000+
instance [ordered_comm_monoid α] : ordered_comm_monoid (order_dual α) :=
1001+
{ mul_le_mul_left := λ a b h c, @mul_le_mul_left' α _ b a h _,
1002+
lt_of_mul_lt_mul_left := λ a b c h, @lt_of_mul_lt_mul_left' α _ a c b h,
9461003
..order_dual.partial_order α,
947-
..show add_comm_monoid α, by apply_instance }
1004+
..show comm_monoid α, by apply_instance }
9481005

949-
instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_add_comm_monoid (order_dual α) :=
950-
{ le_of_add_le_add_left := λ a b c : α, le_of_add_le_add_left,
951-
add_left_cancel := @add_left_cancel α _,
952-
add_right_cancel := @add_right_cancel α _,
953-
..order_dual.ordered_add_comm_monoid }
9541006

955-
instance [linear_ordered_cancel_add_comm_monoid α] :
956-
linear_ordered_cancel_add_comm_monoid (order_dual α) :=
1007+
@[to_additive]
1008+
instance [ordered_cancel_comm_monoid α] : ordered_cancel_comm_monoid (order_dual α) :=
1009+
{ le_of_mul_le_mul_left := λ a b c : α, le_of_mul_le_mul_left',
1010+
mul_left_cancel := @mul_left_cancel α _,
1011+
mul_right_cancel := @mul_right_cancel α _,
1012+
..order_dual.ordered_comm_monoid }
1013+
1014+
@[to_additive]
1015+
instance [linear_ordered_cancel_comm_monoid α] :
1016+
linear_ordered_cancel_comm_monoid (order_dual α) :=
9571017
{ .. order_dual.linear_order α,
958-
.. order_dual.ordered_cancel_add_comm_monoid }
1018+
.. order_dual.ordered_cancel_comm_monoid }
9591019

9601020
end order_dual
9611021

0 commit comments

Comments
 (0)