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

Commit 23cf025

Browse files
fpvandoornFloris van Doorn
andcommitted
feat(algebra/ordered_sub): define truncated subtraction in general (#8503)
* Define and prove properties of truncated subtraction in general * We currently only instantiate it for `nat`. The other types (`multiset`, `finsupp`, `nnreal`, `ennreal`, ...) will be in future PRs. Todo in future PRs: * Provide `has_ordered_sub` instances for all specific cases * Remove the lemmas specific to each individual type Co-authored-by: Floris van Doorn <fpv@andrew.cmu.edu>
1 parent 0860c41 commit 23cf025

File tree

9 files changed

+869
-119
lines changed

9 files changed

+869
-119
lines changed

src/algebra/covariant_and_contravariant.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ instance contravariant_mul_lt_of_covariant_mul_le [has_mul N] [linear_order N]
235235
[covariant_class N N (*) (≤)] : contravariant_class N N (*) (<) :=
236236
{ elim := (covariant_le_iff_contravariant_lt N N (*)).mp covariant_class.elim }
237237

238+
@[to_additive]
239+
instance covariant_mul_lt_of_contravariant_mul_le [has_mul N] [linear_order N]
240+
[contravariant_class N N (*) (≤)] : covariant_class N N (*) (<) :=
241+
{ elim := (covariant_lt_iff_contravariant_le N N (*)).mpr contravariant_class.elim }
242+
238243
@[to_additive]
239244
instance covariant_swap_mul_le_of_covariant_mul_le [comm_semigroup N] [has_le N]
240245
[covariant_class N N (*) (≤)] : covariant_class N N (function.swap (*)) (≤) :=

src/algebra/ordered_monoid.lean

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ begin
253253
exact covariant_class.elim _ h }
254254
end
255255

256-
lemma lt_of_mul_lt_mul_left {α : Type u} [has_mul α] [partial_order α]
256+
lemma lt_of_mul_lt_mul_left {α : Type u} [has_mul α] [partial_order α]
257257
[contravariant_class α α (*) (<)] :
258258
∀ (a b c : with_zero α), a * b < a * c → b < c :=
259259
begin
@@ -581,6 +581,17 @@ calc a = a * 1 : by simp
581581
@[to_additive] lemma le_self_mul : a ≤ a * c :=
582582
le_mul_right (le_refl a)
583583

584+
@[to_additive]
585+
lemma lt_iff_exists_mul [covariant_class α α (*) (<)] : a < b ↔ ∃ c > 1, b = a * c :=
586+
begin
587+
simp_rw [lt_iff_le_and_ne, and_comm, le_iff_exists_mul, ← exists_and_distrib_left, exists_prop],
588+
apply exists_congr, intro c,
589+
rw [and.congr_left_iff, gt_iff_lt], rintro rfl,
590+
split,
591+
{ rw [one_lt_iff_ne_one], apply mt, rintro rfl, rw [mul_one] },
592+
{ rw [← (self_le_mul_right a c).lt_iff_ne], apply lt_mul_of_one_lt_right' }
593+
end
594+
584595
local attribute [semireducible] with_zero
585596

586597
-- This instance looks absurd: a monoid already has a zero
@@ -645,11 +656,10 @@ class canonically_linear_ordered_monoid (α : Type*)
645656
extends canonically_ordered_monoid α, linear_order α
646657

647658
section canonically_linear_ordered_monoid
648-
variables
659+
variables [canonically_linear_ordered_monoid α]
649660

650661
@[priority 100, to_additive] -- see Note [lower instance priority]
651-
instance canonically_linear_ordered_monoid.semilattice_sup_bot
652-
[canonically_linear_ordered_monoid α] : semilattice_sup_bot α :=
662+
instance canonically_linear_ordered_monoid.semilattice_sup_bot : semilattice_sup_bot α :=
653663
{ ..lattice_of_linear_order, ..canonically_ordered_monoid.to_order_bot α }
654664

655665
instance with_top.canonically_linear_ordered_add_monoid
@@ -658,8 +668,8 @@ instance with_top.canonically_linear_ordered_add_monoid
658668
{ .. (infer_instance : canonically_ordered_add_monoid (with_top α)),
659669
.. (infer_instance : linear_order (with_top α)) }
660670

661-
@[to_additive] lemma min_mul_distrib [canonically_linear_ordered_monoid α] (a b c : α) :
662-
min a (b * c) = min a (min a b * min a c) :=
671+
@[to_additive]
672+
lemma min_mul_distrib (a b c : α) : min a (b * c) = min a (min a b * min a c) :=
663673
begin
664674
cases le_total a b with hb hb,
665675
{ simp [hb, le_mul_right] },
@@ -668,10 +678,18 @@ begin
668678
{ simp [hb, hc] } }
669679
end
670680

671-
@[to_additive] lemma min_mul_distrib' [canonically_linear_ordered_monoid α] (a b c : α) :
672-
min (a * b) c = min (min a c * min b c) c :=
681+
@[to_additive]
682+
lemma min_mul_distrib' (a b c : α) : min (a * b) c = min (min a c * min b c) c :=
673683
by simpa [min_comm _ c] using min_mul_distrib c a b
674684

685+
@[simp, to_additive]
686+
lemma one_min (a : α) : min 1 a = 1 :=
687+
min_eq_left (one_le a)
688+
689+
@[simp, to_additive]
690+
lemma min_one (a : α) : min a 1 = 1 :=
691+
min_eq_right (one_le a)
692+
675693
end canonically_linear_ordered_monoid
676694

677695
/-- An ordered cancellative additive commutative monoid

src/algebra/ordered_monoid_lemmas.lean

Lines changed: 107 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,23 @@ The reason is that we did not want to change existing names in the library.
2020
2121
## Remark
2222
23-
No monoid is actually present in this file: all assumptions have been generalized to `has_mul` or
24-
`mul_one_class`.
23+
Almost no monoid is actually present in this file: most assumptions have been generalized to
24+
`has_mul` or `mul_one_class`.
2525
2626
-/
2727

2828
-- TODO: If possible, uniformize lemma names, taking special care of `'`,
2929
-- after the `ordered`-refactor is done.
3030

31+
open function
32+
3133
variables {α : Type*}
3234
section has_mul
3335
variables [has_mul α]
3436

3537
section has_le
3638
variables [has_le α]
3739

38-
@[simp, to_additive]
39-
lemma mul_le_mul_iff_left [covariant_class α α (*) (≤)] [contravariant_class α α (*) (≤)]
40-
(a : α) {b c : α} :
41-
a * b ≤ a * c ↔ b ≤ c :=
42-
rel_iff_cov α α (*) (≤) a
43-
44-
@[simp, to_additive]
45-
lemma mul_le_mul_iff_right
46-
[covariant_class α α (function.swap (*)) (≤)] [contravariant_class α α (function.swap (*)) (≤)]
47-
(a : α) {b c : α} :
48-
b * a ≤ c * a ↔ b ≤ c :=
49-
rel_iff_cov α α (function.swap (*)) (≤) a
50-
5140
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
5241
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
5342
@[to_additive add_le_add_left]
@@ -75,6 +64,19 @@ lemma le_of_mul_le_mul_right' [contravariant_class α α (function.swap (*)) (
7564
b ≤ c :=
7665
contravariant_class.elim a bc
7766

67+
@[simp, to_additive]
68+
lemma mul_le_mul_iff_left [covariant_class α α (*) (≤)] [contravariant_class α α (*) (≤)]
69+
(a : α) {b c : α} :
70+
a * b ≤ a * c ↔ b ≤ c :=
71+
rel_iff_cov α α (*) (≤) a
72+
73+
@[simp, to_additive]
74+
lemma mul_le_mul_iff_right
75+
[covariant_class α α (function.swap (*)) (≤)] [contravariant_class α α (function.swap (*)) (≤)]
76+
(a : α) {b c : α} :
77+
b * a ≤ c * a ↔ b ≤ c :=
78+
rel_iff_cov α α (function.swap (*)) (≤) a
79+
7880
end has_le
7981

8082
section has_lt
@@ -361,6 +363,17 @@ calc a * b ≤ a * 1 : mul_le_mul_left' h a
361363

362364
end mul_one_class
363365

366+
@[to_additive]
367+
lemma mul_left_cancel'' [semigroup α] [partial_order α]
368+
[contravariant_class α α (*) (≤)] {a b c : α} (h : a * b = a * c) : b = c :=
369+
(le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge)
370+
371+
@[to_additive]
372+
lemma mul_right_cancel'' [semigroup α] [partial_order α]
373+
[contravariant_class α α (function.swap (*)) (≤)] {a b c : α} (h : a * b = c * b) :
374+
a = c :=
375+
le_antisymm (le_of_mul_le_mul_right' h.le) (le_of_mul_le_mul_right' h.ge)
376+
364377
/- This is not instance, since we want to have an instance from `left_cancel_semigroup`s
365378
to the appropriate `covariant_class`. -/
366379
/-- A semigroup with a partial order and satisfying `left_cancel_semigroup`
@@ -369,10 +382,9 @@ to the appropriate `covariant_class`. -/
369382
"An additive semigroup with a partial order and satisfying `left_cancel_add_semigroup`
370383
(i.e. `c + a < c + b → a < b`) is a `left_cancel add_semigroup`."]
371384
def contravariant.to_left_cancel_semigroup [semigroup α] [partial_order α]
372-
[contravariant_class α α ((*) : α → α → α) (≤)] :
385+
[contravariant_class α α (*) (≤)] :
373386
left_cancel_semigroup α :=
374-
{ mul_left_cancel := λ a b c bc,
375-
(le_of_mul_le_mul_left' bc.le).antisymm (le_of_mul_le_mul_left' bc.ge),
387+
{ mul_left_cancel := λ a b c, mul_left_cancel''
376388
..‹semigroup α› }
377389

378390
/- This is not instance, since we want to have an instance from `right_cancel_semigroup`s
@@ -383,10 +395,9 @@ to the appropriate `covariant_class`. -/
383395
"An additive semigroup with a partial order and satisfying `right_cancel_add_semigroup`
384396
(`a + c < b + c → a < b`) is a `right_cancel add_semigroup`."]
385397
def contravariant.to_right_cancel_semigroup [semigroup α] [partial_order α]
386-
[contravariant_class α α (function.swap (*) : α → α → α) (≤)] :
398+
[contravariant_class α α (function.swap (*)) (≤)] :
387399
right_cancel_semigroup α :=
388-
{ mul_right_cancel := λ a b c bc,
389-
le_antisymm (le_of_mul_le_mul_right' bc.le) (le_of_mul_le_mul_right' bc.ge)
400+
{ mul_right_cancel := λ a b c, mul_right_cancel''
390401
..‹semigroup α› }
391402

392403
variables {a b c d : α}
@@ -740,3 +751,78 @@ lemma strict_mono.mul_monotone' (hf : strict_mono f) (hg : monotone g) :
740751
λ x y h, mul_lt_mul_of_lt_of_le (hf h) (hg h.le)
741752

742753
end strict_mono
754+
755+
/--
756+
An element `a : α` is `mul_le_cancellable` if `x ↦ a * x` is order-reflecting.
757+
We will make a separate version of many lemmas that require `[contravariant_class α α (*) (≤)]` with
758+
`mul_le_cancellable` assumptions instead. These lemmas can then be instantiated to specific types,
759+
like `ennreal`, where we can replace the assumption `add_le_cancellable x` by `x ≠ ∞`.
760+
-/
761+
@[to_additive /-" An element `a : α` is `add_le_cancellable` if `x ↦ a + x` is order-reflecting.
762+
We will make a separate version of many lemmas that require `[contravariant_class α α (+) (≤)]` with
763+
`mul_le_cancellable` assumptions instead. These lemmas can then be instantiated to specific types,
764+
like `ennreal`, where we can replace the assumption `add_le_cancellable x` by `x ≠ ∞`. "-/
765+
]
766+
def mul_le_cancellable [has_mul α] [has_le α] (a : α) : Prop :=
767+
∀ ⦃b c⦄, a * b ≤ a * c → b ≤ c
768+
769+
@[to_additive]
770+
lemma contravariant.mul_le_cancellable [has_mul α] [has_le α] [contravariant_class α α (*) (≤)]
771+
{a : α} : mul_le_cancellable a :=
772+
λ b c, le_of_mul_le_mul_left'
773+
774+
namespace mul_le_cancellable
775+
776+
@[to_additive]
777+
protected lemma injective [has_mul α] [partial_order α] {a : α} (ha : mul_le_cancellable a) :
778+
injective ((*) a) :=
779+
λ b c h, le_antisymm (ha h.le) (ha h.ge)
780+
781+
@[to_additive]
782+
protected lemma inj [has_mul α] [partial_order α] {a b c : α} (ha : mul_le_cancellable a) :
783+
a * b = a * c ↔ b = c :=
784+
ha.injective.eq_iff
785+
786+
@[to_additive]
787+
protected lemma injective_left [comm_semigroup α] [partial_order α] {a : α}
788+
(ha : mul_le_cancellable a) : injective (* a) :=
789+
λ b c h, ha.injective $ by rwa [mul_comm a, mul_comm a]
790+
791+
@[to_additive]
792+
protected lemma inj_left [comm_semigroup α] [partial_order α] {a b c : α}
793+
(hc : mul_le_cancellable c) : a * c = b * c ↔ a = b :=
794+
hc.injective_left.eq_iff
795+
796+
variable [has_le α]
797+
798+
@[to_additive]
799+
protected lemma mul_le_mul_iff_left [has_mul α] [covariant_class α α (*) (≤)]
800+
{a b c : α} (ha : mul_le_cancellable a) : a * b ≤ a * c ↔ b ≤ c :=
801+
⟨λ h, ha h, λ h, mul_le_mul_left' h a⟩
802+
803+
@[to_additive]
804+
protected lemma mul_le_mul_iff_right [comm_semigroup α] [covariant_class α α (*) (≤)]
805+
{a b c : α} (ha : mul_le_cancellable a) : b * a ≤ c * a ↔ b ≤ c :=
806+
by rw [mul_comm b, mul_comm c, ha.mul_le_mul_iff_left]
807+
808+
@[to_additive]
809+
protected lemma le_mul_iff_one_le_right [mul_one_class α] [covariant_class α α (*) (≤)]
810+
{a b : α} (ha : mul_le_cancellable a) : a ≤ a * b ↔ 1 ≤ b :=
811+
iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left
812+
813+
@[to_additive]
814+
protected lemma mul_le_iff_le_one_right [mul_one_class α] [covariant_class α α (*) (≤)]
815+
{a b : α} (ha : mul_le_cancellable a) : a * b ≤ a ↔ b ≤ 1 :=
816+
iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left
817+
818+
@[to_additive]
819+
protected lemma le_mul_iff_one_le_left [comm_monoid α] [covariant_class α α (*) (≤)]
820+
{a b : α} (ha : mul_le_cancellable a) : a ≤ b * a ↔ 1 ≤ b :=
821+
by rw [mul_comm, ha.le_mul_iff_one_le_right]
822+
823+
@[to_additive]
824+
protected lemma mul_le_iff_le_one_left [comm_monoid α] [covariant_class α α (*) (≤)]
825+
{a b : α} (ha : mul_le_cancellable a) : b * a ≤ a ↔ b ≤ 1 :=
826+
by rw [mul_comm, ha.mul_le_iff_le_one_right]
827+
828+
end mul_le_cancellable

0 commit comments

Comments
 (0)