Skip to content

Commit

Permalink
refactor(data/real/ereal): sub_neg_zero_monoid instance (#16688)
Browse files Browse the repository at this point in the history
Add a `sub_neg_zero_monoid` instance for `ereal`, so eliminating its `neg_zero`, `sub_zero` and `sub_eq_add_neg` lemmas and allowing results for `neg_zero_class` to be applied to `ereal`.
  • Loading branch information
jsm28 committed Sep 29, 2022
1 parent 8f89631 commit 0ec98ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/data/real/ereal.lean
Expand Up @@ -380,7 +380,6 @@ instance : has_neg ereal := ⟨ereal.neg⟩

@[simp] lemma neg_top : - (⊤ : ereal) = ⊥ := rfl
@[simp] lemma neg_bot : - (⊥ : ereal) = ⊤ := rfl
@[simp] lemma neg_zero : - (0 : ereal) = 0 := by { change ((-0 : ℝ) : ereal) = 0, simp }

instance : has_involutive_neg ereal :=
{ neg := has_neg.neg,
Expand All @@ -402,7 +401,7 @@ by { rw neg_eq_iff_neg_eq, simp [eq_comm] }
by { rw neg_eq_iff_neg_eq, simp [eq_comm] }

@[simp] lemma neg_eg_zero_iff {x : ereal} : - x = 0 ↔ x = 0 :=
by { rw neg_eq_iff_neg_eq, simp [eq_comm] }
by { rw neg_eq_iff_neg_eq, change ((-0 : ℝ) : ereal) = _ ↔ _, simp [eq_comm] }

/-- if `-a ≤ b` then `-b ≤ a` on `ereal`. -/
protected theorem neg_le_of_neg_le : ∀ {a b : ereal} (h : -a ≤ b), -b ≤ a
Expand Down Expand Up @@ -448,23 +447,25 @@ lemma neg_lt_iff_neg_lt {a b : ereal} : -a < b ↔ -b < a :=

/-- Subtraction on `ereal`, defined by `x - y = x + (-y)`. Since addition is badly behaved at some
points, so is subtraction. There is no standard algebraic typeclass involving subtraction that is
registered on `ereal` because of this bad behavior. -/
registered on `ereal`, beyond `sub_neg_zero_monoid`, because of this bad behavior. -/
protected noncomputable def sub (x y : ereal) : ereal := x + (-y)

noncomputable instance : has_sub ereal := ⟨ereal.sub⟩

noncomputable instance : sub_neg_zero_monoid ereal :=
{ neg_zero := by { change ((-0 : ℝ) : ereal) = 0, simp },
..(infer_instance : add_monoid ereal),
..ereal.has_neg }

@[simp] lemma top_sub (x : ereal) : ⊤ - x = ⊤ := top_add x
@[simp] lemma sub_bot (x : ereal) : x - ⊥ = ⊤ := add_top x

@[simp] lemma bot_sub_top : (⊥ : ereal) - ⊤ = ⊥ := rfl
@[simp] lemma bot_sub_coe (x : ℝ) : (⊥ : ereal) - x = ⊥ := rfl
@[simp] lemma coe_sub_bot (x : ℝ) : (x : ereal) - ⊤ = ⊥ := rfl

@[simp] lemma sub_zero (x : ereal) : x - 0 = x := by { change x + (-0) = x, simp }
@[simp] lemma zero_sub (x : ereal) : 0 - x = - x := by { change 0 + (-x) = - x, simp }

lemma sub_eq_add_neg (x y : ereal) : x - y = x + -y := rfl

lemma sub_le_sub {x y z t : ereal} (h : x ≤ y) (h' : t ≤ z) : x - z ≤ y - t :=
add_le_add h (neg_le_neg_iff.2 h')

Expand All @@ -491,7 +492,7 @@ end
lemma to_real_sub {x y : ereal} (hx : x ≠ ⊤) (h'x : x ≠ ⊥) (hy : y ≠ ⊤) (h'y : y ≠ ⊥) :
to_real (x - y) = to_real x - to_real y :=
begin
rw [ereal.sub_eq_add_neg, to_real_add hx h'x, to_real_neg],
rw [sub_eq_add_neg, to_real_add hx h'x, to_real_neg],
{ refl },
{ simpa using hy },
{ simpa using h'y }
Expand Down
2 changes: 1 addition & 1 deletion src/measure_theory/integral/vitali_caratheodory.lean
Expand Up @@ -480,7 +480,7 @@ begin
by { congr' 1, field_simp [δ, mul_comm] },
show ∀ᵐ (x : α) ∂μ, g x < ⊤,
{ filter_upwards [gp_lt_top] with _ hx,
simp [g, ereal.sub_eq_add_neg, lt_top_iff_ne_top, lt_top_iff_ne_top.1 hx], },
simp [g, sub_eq_add_neg, lt_top_iff_ne_top, lt_top_iff_ne_top.1 hx], },
show ∀ x, (f x : ereal) < g x,
{ assume x,
rw ereal.coe_real_ereal_eq_coe_to_nnreal_sub_coe_to_nnreal (f x),
Expand Down

0 comments on commit 0ec98ed

Please sign in to comment.