Skip to content

Commit 1db5431

Browse files
committed
feat(EReal): add lemmas (#25011)
Also protect some lemmas. This branch was cherry-picked from #24916.
1 parent 09af334 commit 1db5431

File tree

3 files changed

+61
-43
lines changed

3 files changed

+61
-43
lines changed

Mathlib/Data/EReal/Basic.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ instance : CanLift EReal ℝ≥0∞ (↑) (0 ≤ ·) := ⟨range_coe_ennreal.ge
620620
theorem coe_ennreal_pos {x : ℝ≥0∞} : (0 : EReal) < x ↔ 0 < x := by
621621
rw [← coe_ennreal_zero, coe_ennreal_lt_coe_ennreal_iff]
622622

623+
theorem coe_ennreal_pos_iff_ne_zero {x : ℝ≥0∞} : (0 : EReal) < x ↔ x ≠ 0 := by
624+
rw [coe_ennreal_pos, pos_iff_ne_zero]
625+
623626
@[simp]
624627
theorem bot_lt_coe_ennreal (x : ℝ≥0∞) : (⊥ : EReal) < x :=
625628
(bot_lt_coe 0).trans_le (coe_ennreal_nonneg _)
@@ -687,6 +690,10 @@ lemma toENNReal_eq_zero_iff {x : EReal} : x.toENNReal = 0 ↔ x ≤ 0 := by
687690
lemma toENNReal_ne_zero_iff {x : EReal} : x.toENNReal ≠ 00 < x := by
688691
simp [toENNReal_eq_zero_iff.not]
689692

693+
@[simp]
694+
lemma toENNReal_pos_iff {x : EReal} : 0 < x.toENNReal ↔ 0 < x := by
695+
rw [pos_iff_ne_zero, toENNReal_ne_zero_iff]
696+
690697
@[simp]
691698
lemma coe_toENNReal {x : EReal} (hx : 0 ≤ x) : (x.toENNReal : EReal) = x := by
692699
rw [toENNReal]

Mathlib/Data/EReal/Inv.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ lemma div_nonneg (h : 0 ≤ a) (h' : 0 ≤ b) : 0 ≤ a / b :=
455455
mul_nonneg h (inv_nonneg_of_nonneg h')
456456

457457
lemma div_pos (ha : 0 < a) (hb : 0 < b) (hb' : b ≠ ⊤) : 0 < a / b :=
458-
mul_pos ha (inv_pos_of_pos_ne_top hb hb')
458+
EReal.mul_pos ha (inv_pos_of_pos_ne_top hb hb')
459459

460460
lemma div_nonpos_of_nonpos_of_nonneg (h : a ≤ 0) (h' : 0 ≤ b) : a / b ≤ 0 :=
461461
mul_nonpos_of_nonpos_of_nonneg h (inv_nonneg_of_nonneg h')

Mathlib/Data/EReal/Operations.lean

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,19 @@ theorem add_top_of_ne_bot {x : EReal} (h : x ≠ ⊥) : x + ⊤ = ⊤ := by
9393
if and only if `x` is not `⊥`. -/
9494
theorem add_top_iff_ne_bot {x : EReal} : x + ⊤ = ⊤ ↔ x ≠ ⊥ := by rw [add_comm, top_add_iff_ne_bot]
9595

96+
protected theorem add_pos_of_nonneg_of_pos {a b : EReal} (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b := by
97+
lift a to ℝ≥0∞ using ha
98+
lift b to ℝ≥0∞ using hb.le
99+
norm_cast at *
100+
simp [hb]
101+
102+
protected theorem add_pos_of_pos_of_nonneg {a b : EReal} (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b :=
103+
add_comm a b ▸ EReal.add_pos_of_nonneg_of_pos hb ha
104+
96105
/-- For any two extended real numbers `a` and `b`, if both `a` and `b` are greater than `0`,
97106
then their sum is also greater than `0`. -/
98-
theorem add_pos {a b : EReal} (ha : 0 < a) (hb : 0 < b) : 0 < a + b := by
99-
induction a
100-
· exfalso; exact not_lt_bot ha
101-
· induction b
102-
· exfalso; exact not_lt_bot hb
103-
· norm_cast at *; exact Left.add_pos ha hb
104-
· exact add_top_of_ne_bot (bot_lt_zero.trans ha).ne' ▸ hb
105-
· rw [top_add_of_ne_bot (bot_lt_zero.trans hb).ne']
106-
exact ha
107+
protected theorem add_pos {a b : EReal} (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
108+
EReal.add_pos_of_nonneg_of_pos ha.le hb
107109

108110
@[simp]
109111
theorem coe_add_top (x : ℝ) : (x : EReal) + ⊤ = ⊤ :=
@@ -294,6 +296,11 @@ protected theorem neg_lt_of_neg_lt {a b : EReal} (h : -a < b) : -b < a := neg_lt
294296
theorem lt_neg_comm {a b : EReal} : a < -b ↔ b < -a := by
295297
rw [← neg_lt_neg_iff, neg_neg]
296298

299+
@[simp] protected theorem neg_lt_zero {a : EReal} : -a < 00 < a := by rw [neg_lt_comm, neg_zero]
300+
@[simp] protected theorem neg_le_zero {a : EReal} : -a ≤ 00 ≤ a := by rw [EReal.neg_le, neg_zero]
301+
@[simp] protected theorem neg_pos {a : EReal} : 0 < -a ↔ a < 0 := by rw [lt_neg_comm, neg_zero]
302+
@[simp] protected theorem neg_nonneg {a : EReal} : 0 ≤ -a ↔ a ≤ 0 := by rw [EReal.le_neg, neg_zero]
303+
297304
/-- If `a < -b` then `b < -a` on `EReal`. -/
298305
protected theorem lt_neg_of_lt_neg {a b : EReal} (h : a < -b) : b < -a := lt_neg_comm.mp h
299306

@@ -313,6 +320,31 @@ lemma neg_sub {x y : EReal} (h1 : x ≠ ⊥ ∨ y ≠ ⊥) (h2 : x ≠ ⊤ ∨ y
313320
- (x - y) = - x + y := by
314321
rw [sub_eq_add_neg, neg_add _ _, sub_eq_add_neg, neg_neg] <;> simp_all
315322

323+
/-- Induction principle for `EReal`s splitting into cases `↑(x : ℝ≥0∞)` and `-↑(x : ℝ≥0∞)`.
324+
In the latter case, we additionally assume `0 < x`. -/
325+
@[elab_as_elim]
326+
def recENNReal {motive : EReal → Sort*} (coe : ∀ x : ℝ≥0∞, motive x)
327+
(neg_coe : ∀ x : ℝ≥0∞, 0 < x → motive (-x)) (x : EReal) : motive x :=
328+
if hx : 0 ≤ x then coe_toENNReal hx ▸ coe _
329+
else
330+
have H₁ : 0 < -x := by simpa using hx
331+
have H₂ : x = -(-x).toENNReal := by rw [coe_toENNReal H₁.le, neg_neg]
332+
H₂ ▸ neg_coe _ <| by simp [H₁]
333+
334+
@[simp]
335+
theorem recENNReal_coe_ennreal {motive : EReal → Sort*} (coe : ∀ x : ℝ≥0∞, motive x)
336+
(neg_coe : ∀ x : ℝ≥0∞, 0 < x → motive (-x)) (x : ℝ≥0∞) : recENNReal coe neg_coe x = coe x := by
337+
suffices ∀ y : EReal, x = y → HEq (recENNReal coe neg_coe y : motive y) (coe x) from
338+
heq_iff_eq.mp (this x rfl)
339+
intro y hy
340+
have H₁ : 0 ≤ y := hy ▸ coe_ennreal_nonneg x
341+
obtain rfl : y.toENNReal = x := by simp [← hy]
342+
simp [recENNReal, H₁]
343+
344+
proof_wanted recENNReal_neg_coe_ennreal {motive : EReal → Sort*} (coe : ∀ x : ℝ≥0∞, motive x)
345+
(neg_coe : ∀ x : ℝ≥0∞, 0 < x → motive (-x)) {x : ℝ≥0∞} (hx : 0 < x) :
346+
recENNReal coe neg_coe (-x) = neg_coe x hx
347+
316348
/-!
317349
### Subtraction
318350
@@ -639,8 +671,11 @@ lemma mul_nonneg_iff {a b : EReal} : 0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a
639671
rcases lt_trichotomy a 0 with (h | h | h) <;> rcases lt_trichotomy b 0 with (h' | h' | h')
640672
<;> simp only [h, h', true_or, true_and, or_true, and_true] <;> tauto
641673

674+
protected lemma mul_nonneg {a b : EReal} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
675+
mul_nonneg_iff.mpr <| .inl ⟨ha, hb⟩
676+
642677
/-- The product of two positive extended real numbers is positive. -/
643-
lemma mul_pos {a b : EReal} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
678+
protected lemma mul_pos {a b : EReal} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
644679
mul_pos_iff.mpr (Or.inl ⟨ha, hb⟩)
645680

646681
/-- Induct on two ereals by performing case splits on the sign of one whenever the other is
@@ -772,38 +807,14 @@ lemma toENNReal_mul' {x y : EReal} (hy : 0 ≤ y) :
772807

773808
lemma right_distrib_of_nonneg {a b c : EReal} (ha : 0 ≤ a) (hb : 0 ≤ b) :
774809
(a + b) * c = a * c + b * c := by
775-
rcases eq_or_lt_of_le ha with (rfl | a_pos)
776-
· simp
777-
rcases eq_or_lt_of_le hb with (rfl | b_pos)
778-
· simp
779-
rcases lt_trichotomy c 0 with (c_neg | rfl | c_pos)
780-
· induction c
781-
· rw [mul_bot_of_pos a_pos, mul_bot_of_pos b_pos, mul_bot_of_pos (add_pos a_pos b_pos),
782-
add_bot ⊥]
783-
· induction a
784-
· exfalso; exact not_lt_bot a_pos
785-
· induction b
786-
· norm_cast
787-
· norm_cast; exact right_distrib _ _ _
788-
· norm_cast
789-
rw [add_top_of_ne_bot (coe_ne_bot _), top_mul_of_neg c_neg, add_bot]
790-
· rw [top_add_of_ne_bot (ne_bot_of_gt b_pos), top_mul_of_neg c_neg, bot_add]
791-
· exfalso; exact not_top_lt c_neg
792-
· simp
793-
· induction c
794-
· exfalso; exact not_lt_bot c_pos
795-
· induction a
796-
· exfalso; exact not_lt_bot a_pos
797-
· induction b
798-
· norm_cast
799-
· norm_cast; exact right_distrib _ _ _
800-
· norm_cast
801-
rw [add_top_of_ne_bot (coe_ne_bot _), top_mul_of_pos c_pos,
802-
add_top_of_ne_bot (coe_ne_bot _)]
803-
· rw [top_add_of_ne_bot (ne_bot_of_gt b_pos), top_mul_of_pos c_pos,
804-
top_add_of_ne_bot (ne_bot_of_gt (mul_pos b_pos c_pos))]
805-
· rw [mul_top_of_pos a_pos, mul_top_of_pos b_pos, mul_top_of_pos (add_pos a_pos b_pos),
806-
top_add_top]
810+
lift a to ℝ≥0∞ using ha
811+
lift b to ℝ≥0∞ using hb
812+
cases c using recENNReal with
813+
| coe c => exact_mod_cast add_mul a b c
814+
| neg_coe c hc =>
815+
simp only [mul_neg, ← coe_ennreal_add, ← coe_ennreal_mul, add_mul]
816+
rw [coe_ennreal_add, EReal.neg_add (.inl (coe_ennreal_ne_bot _)) (.inr (coe_ennreal_ne_bot _)),
817+
sub_eq_add_neg]
807818

808819
lemma left_distrib_of_nonneg {a b c : EReal} (ha : 0 ≤ a) (hb : 0 ≤ b) :
809820
c * (a + b) = c * a + c * b := by

0 commit comments

Comments
 (0)