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

Commit bfd2857

Browse files
committed
feat(algebra/order/ring): generalize some mono lemmas, use them (#14691)
* generalize lemmas like `monotone_mul_left_of_nonneg` to `ordered_semiring`s, add `decidable.*` versions as needed; * add some `antitone` lemmas; * use these lemmas to prove `le_of_mul_le_mul_left` etc; * use section-local attributes instead of `letI := @linear_order.decidable_le α _`.
1 parent 6155d43 commit bfd2857

File tree

2 files changed

+130
-99
lines changed

2 files changed

+130
-99
lines changed

src/algebra/order/field.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ end
481481

482482
lemma monotone.div_const {β : Type*} [preorder β] {f : β → α} (hf : monotone f)
483483
{c : α} (hc : 0 ≤ c) : monotone (λ x, (f x) / c) :=
484-
by simpa only [div_eq_mul_inv] using hf.mul_const (inv_nonneg.2 hc)
484+
begin
485+
haveI := @linear_order.decidable_le α _,
486+
simpa only [div_eq_mul_inv]
487+
using (decidable.monotone_mul_right_of_nonneg (inv_nonneg.2 hc)).comp hf
488+
end
485489

486490
lemma strict_mono.div_const {β : Type*} [preorder β] {f : β → α} (hf : strict_mono f)
487491
{c : α} (hc : 0 < c) :

src/algebra/order/ring.lean

Lines changed: 125 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,93 @@ protected lemma decidable.one_le_mul_of_one_le_of_one_le [@decidable_rel α (≤
383383
lemma one_le_mul_of_one_le_of_one_le {a b : α} : 1 ≤ a → 1 ≤ b → (1 : α) ≤ a * b :=
384384
by classical; exact decidable.one_le_mul_of_one_le_of_one_le
385385

386+
namespace decidable
387+
388+
variables {β : Type*} [@decidable_rel α (≤)] [preorder β] {f g : β → α}
389+
390+
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
391+
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_left b_le_c ha
392+
393+
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
394+
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_right b_le_c ha
395+
396+
lemma monotone_mul {β : Type*} [preorder β] {f g : β → α}
397+
(hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
398+
monotone (λ x, f x * g x) :=
399+
λ x y h, decidable.mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)
400+
401+
lemma strict_mono_mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
402+
(hg0 : ∀ x, 0 < g x) :
403+
strict_mono (λ x, f x * g x) :=
404+
λ x y h, decidable.mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)
405+
406+
lemma monotone_mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
407+
(hg0 : ∀ x, 0 ≤ g x) :
408+
strict_mono (λ x, f x * g x) :=
409+
λ x y h, decidable.mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)
410+
411+
lemma strict_mono_mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
412+
(hg0 : ∀ x, 0 ≤ g x) :
413+
strict_mono (λ x, f x * g x) :=
414+
λ x y h, decidable.mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)
415+
416+
end decidable
417+
418+
section mono
419+
420+
open_locale classical
421+
422+
variables {β : Type*} [preorder β] {f g : β → α}
423+
424+
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
425+
decidable.monotone_mul_left_of_nonneg ha
426+
427+
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
428+
decidable.monotone_mul_right_of_nonneg ha
429+
430+
lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) :
431+
monotone (λ x, (f x) * a) :=
432+
(monotone_mul_right_of_nonneg ha).comp hf
433+
434+
lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) :
435+
monotone (λ x, a * (f x)) :=
436+
(monotone_mul_left_of_nonneg ha).comp hf
437+
438+
lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
439+
monotone (λ x, f x * g x) :=
440+
decidable.monotone_mul hf hg hf0 hg0
441+
442+
lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) :=
443+
assume b c b_lt_c, mul_lt_mul_of_pos_left b_lt_c ha
444+
445+
lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) :=
446+
assume b c b_lt_c, mul_lt_mul_of_pos_right b_lt_c ha
447+
448+
lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :
449+
strict_mono (λ x, (f x) * a) :=
450+
(strict_mono_mul_right_of_pos ha).comp hf
451+
452+
lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :
453+
strict_mono (λ x, a * (f x)) :=
454+
(strict_mono_mul_left_of_pos ha).comp hf
455+
456+
lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
457+
(hg0 : ∀ x, 0 < g x) :
458+
strict_mono (λ x, f x * g x) :=
459+
decidable.strict_mono_mul_monotone hf hg hf0 hg0
460+
461+
lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
462+
(hg0 : ∀ x, 0 ≤ g x) :
463+
strict_mono (λ x, f x * g x) :=
464+
decidable.monotone_mul_strict_mono hf hg hf0 hg0
465+
466+
lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
467+
(hg0 : ∀ x, 0 ≤ g x) :
468+
strict_mono (λ x, f x * g x) :=
469+
decidable.strict_mono_mul hf hg hf0 hg0
470+
471+
end mono
472+
386473
/-- Pullback an `ordered_semiring` under an injective map.
387474
See note [reducible non-instances]. -/
388475
@[reducible]
@@ -586,6 +673,8 @@ class linear_ordered_semiring (α : Type u)
586673
section linear_ordered_semiring
587674
variables [linear_ordered_semiring α] {a b c d : α}
588675

676+
local attribute [instance] linear_ordered_semiring.decidable_le
677+
589678
-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument
590679
-- (see `norm_num.prove_pos_nat`).
591680
-- Rather than working out how to relax that assumption,
@@ -594,33 +683,20 @@ variables [linear_ordered_semiring α] {a b c d : α}
594683
lemma zero_lt_one' : 0 < (1 : α) := zero_lt_one
595684

596685
lemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : 0 ≤ c) : a < b :=
597-
by haveI := @linear_order.decidable_le α _; exact lt_of_not_ge
598-
(assume h1 : b ≤ a,
599-
have h2 : c * b ≤ c * a, from decidable.mul_le_mul_of_nonneg_left h1 hc,
600-
h2.not_lt h)
686+
(decidable.monotone_mul_left_of_nonneg hc).reflect_lt h
601687

602688
lemma lt_of_mul_lt_mul_right (h : a * c < b * c) (hc : 0 ≤ c) : a < b :=
603-
by haveI := @linear_order.decidable_le α _; exact lt_of_not_ge
604-
(assume h1 : b ≤ a,
605-
have h2 : b * c ≤ a * c, from decidable.mul_le_mul_of_nonneg_right h1 hc,
606-
h2.not_lt h)
689+
(decidable.monotone_mul_right_of_nonneg hc).reflect_lt h
607690

608691
lemma le_of_mul_le_mul_left (h : c * a ≤ c * b) (hc : 0 < c) : a ≤ b :=
609-
le_of_not_gt
610-
(assume h1 : b < a,
611-
have h2 : c * b < c * a, from mul_lt_mul_of_pos_left h1 hc,
612-
h2.not_le h)
692+
(strict_mono_mul_left_of_pos hc).le_iff_le.1 h
613693

614694
lemma le_of_mul_le_mul_right (h : a * c ≤ b * c) (hc : 0 < c) : a ≤ b :=
615-
le_of_not_gt
616-
(assume h1 : b < a,
617-
have h2 : b * c < a * c, from mul_lt_mul_of_pos_right h1 hc,
618-
h2.not_le h)
695+
(strict_mono_mul_right_of_pos hc).le_iff_le.1 h
619696

620697
lemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :
621698
(0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0) :=
622699
begin
623-
haveI := @linear_order.decidable_le α _,
624700
rcases lt_trichotomy 0 a with (ha|rfl|ha),
625701
{ refine or.inl ⟨ha, lt_imp_lt_of_le_imp_le (λ hb, _) hab⟩,
626702
exact decidable.mul_nonpos_of_nonneg_of_nonpos ha.le hb },
@@ -632,7 +708,6 @@ end
632708
lemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 ≤ a * b) :
633709
(0 ≤ a ∧ 0 ≤ b) ∨ (a ≤ 0 ∧ b ≤ 0) :=
634710
begin
635-
haveI := @linear_order.decidable_le α _,
636711
refine decidable.or_iff_not_and_not.2 _,
637712
simp only [not_and, not_le], intros ab nab, apply not_lt_of_le hab _,
638713
rcases lt_trichotomy 0 a with (ha|rfl|ha),
@@ -665,12 +740,10 @@ lemma nonneg_of_mul_nonneg_right (h : 0 ≤ a * b) (ha : 0 < a) : 0 ≤ b :=
665740
le_of_not_gt $ λ hb, (mul_neg_of_pos_of_neg ha hb).not_le h
666741

667742
lemma neg_of_mul_neg_left (h : a * b < 0) (hb : 0 ≤ b) : a < 0 :=
668-
by haveI := @linear_order.decidable_le α _; exact
669-
lt_of_not_ge (λ ha : a ≥ 0, (decidable.mul_nonneg ha hb).not_lt h)
743+
lt_of_not_ge $ λ ha, (decidable.mul_nonneg ha hb).not_lt h
670744

671745
lemma neg_of_mul_neg_right (h : a * b < 0) (ha : 0 ≤ a) : b < 0 :=
672-
by haveI := @linear_order.decidable_le α _; exact
673-
lt_of_not_ge (assume hb : b ≥ 0, (decidable.mul_nonneg ha hb).not_lt h)
746+
lt_of_not_ge $ λ hb, (decidable.mul_nonneg ha hb).not_lt h
674747

675748
lemma nonpos_of_mul_nonpos_left (h : a * b ≤ 0) (hb : 0 < b) : a ≤ 0 :=
676749
le_of_not_gt (assume ha : a > 0, (mul_pos ha hb).not_le h)
@@ -679,22 +752,16 @@ lemma nonpos_of_mul_nonpos_right (h : a * b ≤ 0) (ha : 0 < a) : b ≤ 0 :=
679752
le_of_not_gt (assume hb : b > 0, (mul_pos ha hb).not_le h)
680753

681754
@[simp] lemma mul_le_mul_left (h : 0 < c) : c * a ≤ c * b ↔ a ≤ b :=
682-
by haveI := @linear_order.decidable_le α _; exact
683-
⟨λ h', le_of_mul_le_mul_left h' h, λ h', decidable.mul_le_mul_of_nonneg_left h' h.le⟩
755+
(strict_mono_mul_left_of_pos h).le_iff_le
684756

685757
@[simp] lemma mul_le_mul_right (h : 0 < c) : a * c ≤ b * c ↔ a ≤ b :=
686-
by haveI := @linear_order.decidable_le α _; exact
687-
⟨λ h', le_of_mul_le_mul_right h' h, λ h', decidable.mul_le_mul_of_nonneg_right h' h.le⟩
758+
(strict_mono_mul_right_of_pos h).le_iff_le
688759

689760
@[simp] lemma mul_lt_mul_left (h : 0 < c) : c * a < c * b ↔ a < b :=
690-
by haveI := @linear_order.decidable_le α _; exact
691-
⟨lt_imp_lt_of_le_imp_le $ λ h', decidable.mul_le_mul_of_nonneg_left h' h.le,
692-
λ h', mul_lt_mul_of_pos_left h' h⟩
761+
(strict_mono_mul_left_of_pos h).lt_iff_lt
693762

694763
@[simp] lemma mul_lt_mul_right (h : 0 < c) : a * c < b * c ↔ a < b :=
695-
by haveI := @linear_order.decidable_le α _; exact
696-
⟨lt_imp_lt_of_le_imp_le $ λ h', decidable.mul_le_mul_of_nonneg_right h' h.le,
697-
λ h', mul_lt_mul_of_pos_right h' h⟩
764+
(strict_mono_mul_right_of_pos h).lt_iff_lt
698765

699766
@[simp] lemma zero_le_mul_left (h : 0 < c) : 0 ≤ c * b ↔ 0 ≤ b :=
700767
by { convert mul_le_mul_left h, simp }
@@ -842,64 +909,6 @@ ordered_semiring.to_char_zero
842909

843910
end linear_ordered_semiring
844911

845-
section mono
846-
variables {β : Type*} [linear_ordered_semiring α] [preorder β] {f g : β → α} {a : α}
847-
848-
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
849-
by haveI := @linear_order.decidable_le α _; exact
850-
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_left b_le_c ha
851-
852-
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
853-
by haveI := @linear_order.decidable_le α _; exact
854-
assume b c b_le_c, decidable.mul_le_mul_of_nonneg_right b_le_c ha
855-
856-
lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) :
857-
monotone (λ x, (f x) * a) :=
858-
(monotone_mul_right_of_nonneg ha).comp hf
859-
860-
lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) :
861-
monotone (λ x, a * (f x)) :=
862-
(monotone_mul_left_of_nonneg ha).comp hf
863-
864-
lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
865-
monotone (λ x, f x * g x) :=
866-
by haveI := @linear_order.decidable_le α _; exact
867-
λ x y h, decidable.mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)
868-
869-
lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) :=
870-
assume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c
871-
872-
lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) :=
873-
assume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c
874-
875-
lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :
876-
strict_mono (λ x, (f x) * a) :=
877-
(strict_mono_mul_right_of_pos ha).comp hf
878-
879-
lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :
880-
strict_mono (λ x, a * (f x)) :=
881-
(strict_mono_mul_left_of_pos ha).comp hf
882-
883-
lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
884-
(hg0 : ∀ x, 0 < g x) :
885-
strict_mono (λ x, f x * g x) :=
886-
by haveI := @linear_order.decidable_le α _; exact
887-
λ x y h, decidable.mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)
888-
889-
lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
890-
(hg0 : ∀ x, 0 ≤ g x) :
891-
strict_mono (λ x, f x * g x) :=
892-
by haveI := @linear_order.decidable_le α _; exact
893-
λ x y h, decidable.mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)
894-
895-
lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
896-
(hg0 : ∀ x, 0 ≤ g x) :
897-
strict_mono (λ x, f x * g x) :=
898-
by haveI := @linear_order.decidable_le α _; exact
899-
λ x y h, decidable.mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)
900-
901-
end mono
902-
903912
section linear_ordered_semiring
904913
variables [linear_ordered_semiring α] {a b c : α}
905914

@@ -1030,6 +1039,26 @@ lemma mul_pos_of_neg_of_neg {a b : α} (ha : a < 0) (hb : b < 0) : 0 < a * b :=
10301039
have 0 * b < a * b, from mul_lt_mul_of_neg_right ha hb,
10311040
by rwa zero_mul at this
10321041

1042+
lemma decidable.antitone_mul_left [@decidable_rel α (≤)] {a : α} (ha : a ≤ 0) :
1043+
antitone ((*) a) :=
1044+
λ b c b_le_c, decidable.mul_le_mul_of_nonpos_left b_le_c ha
1045+
1046+
lemma antitone_mul_left {a : α} (ha : a ≤ 0) : antitone ((*) a) :=
1047+
λ b c b_le_c, mul_le_mul_of_nonpos_left b_le_c ha
1048+
1049+
lemma decidable.antitone_mul_right [@decidable_rel α (≤)] {a : α} (ha : a ≤ 0) :
1050+
antitone (λ x, x * a) :=
1051+
λ b c b_le_c, decidable.mul_le_mul_of_nonpos_right b_le_c ha
1052+
1053+
lemma antitone_mul_right {a : α} (ha : a ≤ 0) : antitone (λ x, x * a) :=
1054+
λ b c b_le_c, mul_le_mul_of_nonpos_right b_le_c ha
1055+
1056+
lemma strict_anti_mul_left {a : α} (ha : a < 0) : strict_anti ((*) a) :=
1057+
λ b c b_lt_c, mul_lt_mul_of_neg_left b_lt_c ha
1058+
1059+
lemma strict_anti_mul_right {a : α} (ha : a < 0) : strict_anti (λ x, x * a) :=
1060+
λ b c b_lt_c, mul_lt_mul_of_neg_right b_lt_c ha
1061+
10331062
/-- Pullback an `ordered_ring` under an injective map.
10341063
See note [reducible non-instances]. -/
10351064
@[reducible]
@@ -1123,6 +1152,8 @@ end linear_ordered_semiring
11231152
section linear_ordered_ring
11241153
variables [linear_ordered_ring α] {a b c : α}
11251154

1155+
local attribute [instance] linear_ordered_ring.decidable_le linear_ordered_ring.decidable_lt
1156+
11261157
@[priority 100] -- see Note [lower instance priority]
11271158
instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring α :=
11281159
{ mul_zero := mul_zero,
@@ -1244,20 +1275,16 @@ lt_of_mul_lt_mul_left h3 nhc
12441275
lemma neg_one_lt_zero : -1 < (0:α) := neg_lt_zero.2 zero_lt_one
12451276

12461277
@[simp] lemma mul_le_mul_left_of_neg {a b c : α} (h : c < 0) : c * a ≤ c * b ↔ b ≤ a :=
1247-
by haveI := @linear_order.decidable_le α _; exact
1248-
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_left h' h,
1249-
λ h', decidable.mul_le_mul_of_nonpos_left h' h.le⟩
1278+
(strict_anti_mul_left h).le_iff_le
12501279

12511280
@[simp] lemma mul_le_mul_right_of_neg {a b c : α} (h : c < 0) : a * c ≤ b * c ↔ b ≤ a :=
1252-
by haveI := @linear_order.decidable_le α _; exact
1253-
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_right h' h,
1254-
λ h', decidable.mul_le_mul_of_nonpos_right h' h.le⟩
1281+
(strict_anti_mul_right h).le_iff_le
12551282

12561283
@[simp] lemma mul_lt_mul_left_of_neg {a b c : α} (h : c < 0) : c * a < c * b ↔ b < a :=
1257-
lt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)
1284+
(strict_anti_mul_left h).lt_iff_lt
12581285

12591286
@[simp] lemma mul_lt_mul_right_of_neg {a b c : α} (h : c < 0) : a * c < b * c ↔ b < a :=
1260-
lt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)
1287+
(strict_anti_mul_right h).lt_iff_lt
12611288

12621289
lemma sub_one_lt (a : α) : a - 1 < a :=
12631290
sub_lt_iff_lt_add.2 (lt_add_one a)

0 commit comments

Comments
 (0)