-- Mathlib/MeasureTheory/Integral/SetIntegral.lean
theorem integral_norm_eq_pos_sub_neg {f : X → ℝ} (hfi : Integrable f μ) :
    ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ :=
  have h_meas : NullMeasurableSet {x | 0 ≤ f x} μ :=
    aestronglyMeasurable_const.nullMeasurableSet_le hfi.1
  calc
    ∫ x, ‖f x‖ ∂μ = ∫ x in {x | 0 ≤ f x}, ‖f x‖ ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {x | 0 ≤ f x}ᶜ, f x ∂μ =
    ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {x | f x ≤ 0}, f x ∂μ

Tactic:
rw [← setIntegral_neg_eq_setIntegral_nonpos hfi.1, compl_setOf]

Result:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {a | ¬0 ≤ f a}, f x ∂μ =
    ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {x | f x < 0}, f x ∂μ

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, ‖f x‖ ∂μ + ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ =
    ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ + ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ

Tactic:
congr 1

Result:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, ‖f x‖ ∂μ = ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : ¬0 ≤ f x
⊢ f x ≤ 0

Tactic:
linarith

Result:
no goals

Proof state:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ = -∫ (x : X) in {x | 0 ≤ f x}ᶜ, f x ∂μ

Tactic:
rw [← integral_neg]

Result:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ = ∫ (a : X) in {x | 0 ≤ f x}ᶜ, -f a ∂μ

Proof state:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, ‖f x‖ ∂μ = ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ

Tactic:
refine setIntegral_congr_fun₀ h_meas fun x hx => ?_

Result:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}
⊢ ‖f x‖ = f x

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {a | ¬0 ≤ f a}, f x ∂μ =
    ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {x | f x < 0}, f x ∂μ

Tactic:
simp only [not_le]

Result:
no goals

Proof state:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}ᶜ
⊢ ‖f x‖ = -f x

Tactic:
rw [Real.norm_eq_abs, abs_eq_neg_self.mpr _]

Result:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}ᶜ
⊢ f x ≤ 0

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}ᶜ
⊢ f x ≤ 0

Tactic:
rw [Set.mem_compl_iff, Set.nmem_setOf_iff] at hx

Result:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : ¬0 ≤ f x
⊢ f x ≤ 0

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X), ‖f x‖ ∂μ = ∫ (x : X) in {x | 0 ≤ f x}, ‖f x‖ ∂μ + ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ

Tactic:
rw [← integral_add_compl₀ h_meas hfi.norm]

Result:
no goals

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ + ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ =
    ∫ (x : X) in {x | 0 ≤ f x}, f x ∂μ - ∫ (x : X) in {x | 0 ≤ f x}ᶜ, f x ∂μ

Tactic:
congr 1

Result:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ = -∫ (x : X) in {x | 0 ≤ f x}ᶜ, f x ∂μ

Proof state:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
⊢ ∫ (x : X) in {x | 0 ≤ f x}ᶜ, ‖f x‖ ∂μ = ∫ (a : X) in {x | 0 ≤ f x}ᶜ, -f a ∂μ

Tactic:
refine setIntegral_congr_fun₀ h_meas.compl fun x hx => ?_

Result:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}ᶜ
⊢ ‖f x‖ = -f x

Proof state:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}
⊢ 0 ≤ f x

Tactic:
exact hx

Result:
no goals

Proof state:
case e_a
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}
⊢ ‖f x‖ = f x

Tactic:
rw [Real.norm_eq_abs, abs_eq_self.mpr _]

Result:
X : Type u_1
mX : MeasurableSpace X
μ : Measure X
f : X → ℝ
hfi : Integrable f μ
h_meas : NullMeasurableSet {x | 0 ≤ f x} μ
x : X
hx : x ∈ {x | 0 ≤ f x}
⊢ 0 ≤ f x