l3lab/ntp-mathlib huggingface dataset:
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (μ.tilted f).rnDeriv ν
      =ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
  let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
g : α → ℝ≥0∞ := fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ Measure.rnDeriv (μ.tilted f) ν =ᵐ[ν] fun x =>
    ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x

Next tactic:
refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_ ?_
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (μ.tilted f).rnDeriv ν
      =ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
  let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
  refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_ ?_
  · 

Proof state:
case refine_1
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
g : α → ℝ≥0∞ := fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ AEMeasurable g

Next tactic:
exact ((measurable_exp.comp_aemeasurable hfμ).div_const _).ennreal_ofReal
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (μ.tilted f).rnDeriv ν
      =ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
  let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
  refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_ ?_
  · exact ((measurable_exp.comp_aemeasurable hfμ).div_const _).ennreal_ofReal
  · 

Proof state:
case refine_2
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
g : α → ℝ≥0∞ := fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ AEMeasurable g

Next tactic:
exact ((measurable_exp.comp_aemeasurable hfν).div_const _).ennreal_ofReal
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (μ.tilted f).rnDeriv ν
      =ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
  let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
  refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_ ?_
  · exact ((measurable_exp.comp_aemeasurable hfμ).div_const _).ennreal_ofReal
  · exact ((measurable_exp.comp_aemeasurable hfν).div_const _).ennreal_ofReal
  · 

Proof state:
case refine_3
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
g : α → ℝ≥0∞ := fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ ∀ᵐ (x : α) ∂μ, g x ≠ ⊤

Next tactic:
exact ae_of_all _ (fun x ↦ by simp)
lemma rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (μ.tilted f).rnDeriv ν
      =ᵐ[ν] fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ)) * μ.rnDeriv ν x := by
  let g := fun x ↦ ENNReal.ofReal (exp (f x) / (∫ x, exp (f x) ∂μ))
  refine Measure.rnDeriv_withDensity_left (μ := μ) (ν := ν) (f := g) ?_ ?_ ?_
  · exact ((measurable_exp.comp_aemeasurable hfμ).div_const _).ennreal_ofReal
  · exact ((measurable_exp.comp_aemeasurable hfν).div_const _).ennreal_ofReal
  · exact ae_of_all _ (fun x ↦ by 

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
g : α → ℝ≥0∞ := fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
x : α
⊢ g x ≠ ⊤

Next tactic:
simp
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
⊢ (fun x => ENNReal.toReal (Measure.rnDeriv (μ.tilted f) ν x)) =ᵐ[ν] fun x =>
    (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * ENNReal.toReal (Measure.rnDeriv μ ν x)

Next tactic:
filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) ν x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x
⊢ ENNReal.toReal (Measure.rnDeriv (μ.tilted f) ν x) =
    (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * ENNReal.toReal (Measure.rnDeriv μ ν x)

Next tactic:
rw [hx]
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
  rw [hx]
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) ν x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x
⊢ ENNReal.toReal (ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x) =
    (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * ENNReal.toReal (Measure.rnDeriv μ ν x)

Next tactic:
simp only [ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
  rw [hx]
  simp only [ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) ν x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x
⊢ 0 ≤ rexp (f x) / ∫ (x : α), rexp (f x) ∂μ ∨ ENNReal.toReal (Measure.rnDeriv μ ν x) = 0

Next tactic:
refine Or.inl (mul_nonneg (exp_pos _).le ?_)
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
  rw [hx]
  simp only [ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
  refine Or.inl (mul_nonneg (exp_pos _).le ?_)
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) ν x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x
⊢ 0 ≤ (∫ (x : α), rexp (f x) ∂μ)⁻¹

Next tactic:
rw [inv_nonneg]
lemma toReal_rnDeriv_tilted_left {ν : Measure α} [SigmaFinite μ] [SigmaFinite ν]
    (hfμ : AEMeasurable f μ) (hfν : AEMeasurable f ν) :
    (fun x ↦ ((μ.tilted f).rnDeriv ν x).toReal)
      =ᵐ[ν] fun x ↦ exp (f x) / (∫ x, exp (f x) ∂μ) * (μ.rnDeriv ν x).toReal := by
  filter_upwards [rnDeriv_tilted_left hfμ hfν] with x hx
  rw [hx]
  simp only [ENNReal.toReal_mul, mul_eq_mul_right_iff, ENNReal.toReal_ofReal_eq_iff]
  refine Or.inl (mul_nonneg (exp_pos _).le ?_)
  rw [inv_nonneg]
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
ν : Measure α
inst✝¹ : SigmaFinite μ
inst✝ : SigmaFinite ν
hfμ : AEMeasurable f
hfν : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) ν x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ ν x
⊢ 0 ≤ ∫ (x : α), rexp (f x) ∂μ

Next tactic:
exact (integral_nonneg (fun _ ↦ (exp_pos _).le))
lemma rnDeriv_tilted_left_self [SigmaFinite μ] (hf : AEMeasurable f μ) :
    (μ.tilted f).rnDeriv μ =ᵐ[μ] fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : AEMeasurable f
⊢ Measure.rnDeriv (μ.tilted f) μ =ᵐ[μ] fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)

Next tactic:
refine (rnDeriv_tilted_left hf hf).trans ?_
lemma rnDeriv_tilted_left_self [SigmaFinite μ] (hf : AEMeasurable f μ) :
    (μ.tilted f).rnDeriv μ =ᵐ[μ] fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) := by
  refine (rnDeriv_tilted_left hf hf).trans ?_
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : AEMeasurable f
⊢ (fun x => ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ μ x) =ᵐ[μ] fun x =>
    ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)

Next tactic:
filter_upwards [Measure.rnDeriv_self μ] with x hx
lemma rnDeriv_tilted_left_self [SigmaFinite μ] (hf : AEMeasurable f μ) :
    (μ.tilted f).rnDeriv μ =ᵐ[μ] fun x ↦ ENNReal.ofReal (exp (f x) / ∫ x, exp (f x) ∂μ) := by
  refine (rnDeriv_tilted_left hf hf).trans ?_
  filter_upwards [Measure.rnDeriv_self μ] with x hx
  

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : AEMeasurable f
x : α
hx : Measure.rnDeriv μ μ x = 1
⊢ ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ) * Measure.rnDeriv μ μ x =
    ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)

Next tactic:
rw [hx, mul_one]
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
    · exact (integral_exp_pos hf).ne'
    · exact div_nonneg (exp_pos _).le (integral_nonneg (fun _ ↦ (exp_pos _).le))
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  

Proof state:
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
x✝ : μ = 0 ∨ NeZero μ
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
    · exact (integral_exp_pos hf).ne'
    · exact div_nonneg (exp_pos _).le (integral_nonneg (fun _ ↦ (exp_pos _).le))
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  

Proof state:
case inl
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h : μ = 0
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
| inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => 

Proof state:
case inl
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h : μ = 0
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
simp_rw [h, ae_zero, Filter.EventuallyEq]
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; 

Proof state:
case inl
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h : μ = 0
⊢ ∀ᶠ (x : α) in ⊥, log (ENNReal.toReal (Measure.rnDeriv (0.tilted f) 0 x)) = f x - log (∫ (x : α), rexp (f x) ∂0)

Next tactic:
exact Filter.eventually_bot
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  

Proof state:
case inr
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
| inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
    · exact (integral_exp_pos hf).ne'
    · exact div_nonneg (exp_pos _).le (integral_nonneg (fun _ ↦ (exp_pos _).le))
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    

Proof state:
case inr
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    

Proof state:
case inr
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
hf' : AEMeasurable f
⊢ (fun x => log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x))) =ᵐ[μ] fun x => f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
hf' : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) μ x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ log (ENNReal.toReal (Measure.rnDeriv (μ.tilted f) μ x)) = f x - log (∫ (x : α), rexp (f x) ∂μ)

Next tactic:
rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
    · 

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
hf' : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) μ x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ ∫ (x : α), rexp (f x) ∂μ ≠ 0

Next tactic:
exact (integral_exp_pos hf).ne'
lemma log_rnDeriv_tilted_left_self [SigmaFinite μ] (hf : Integrable (fun x ↦ exp (f x)) μ) :
    (fun x ↦ log ((μ.tilted f).rnDeriv μ x).toReal)
      =ᵐ[μ] fun x ↦ f x - log (∫ x, exp (f x) ∂μ) := by
  cases eq_zero_or_neZero μ with
  | inl h => simp_rw [h, ae_zero, Filter.EventuallyEq]; exact Filter.eventually_bot
  | inr h0 =>
    have hf' : AEMeasurable f μ := aemeasurable_of_aemeasurable_exp hf.1.aemeasurable
    filter_upwards [rnDeriv_tilted_left_self hf'] with x hx
    rw [hx, ENNReal.toReal_ofReal, log_div (exp_pos _).ne', log_exp]
    · exact (integral_exp_pos hf).ne'
    · 

Proof state:
case h
α : Type u_1
mα : MeasurableSpace α
μ : Measure α
f : α → ℝ
inst✝ : SigmaFinite μ
hf : Integrable fun x => rexp (f x)
h0 : NeZero μ
hf' : AEMeasurable f
x : α
hx : Measure.rnDeriv (μ.tilted f) μ x = ENNReal.ofReal (rexp (f x) / ∫ (x : α), rexp (f x) ∂μ)
⊢ 0 ≤ rexp (f x) / ∫ (x : α), rexp (f x) ∂μ

Next tactic:
exact div_nonneg (exp_pos _).le (integral_nonneg (fun _ ↦ (exp_pos _).le))
@[simp]
theorem invOf_mul_self_assoc' [Monoid α] (a b : α) {_ : Invertible a} : ⅟ a * (a * b) = b := by
  

Proof state:
α : Type u
inst✝ : Monoid α
a b : α
x✝ : Invertible a
⊢ ⅟a * (a * b) = b

Next tactic:
rw [← mul_assoc, invOf_mul_self, one_mul]
theorem invOf_mul_self_assoc [Monoid α] (a b : α) [Invertible a] : ⅟ a * (a * b) = b := by
  

Proof state:
α : Type u
inst✝¹ : Monoid α
a b : α
inst✝ : Invertible a
⊢ ⅟a * (a * b) = b

Next tactic:
rw [← mul_assoc, invOf_mul_self, one_mul]
@[simp]
theorem mul_invOf_self_assoc' [Monoid α] (a b : α) {_ : Invertible a} : a * (⅟ a * b) = b := by
  

Proof state:
α : Type u
inst✝ : Monoid α
a b : α
x✝ : Invertible a
⊢ a * (⅟a * b) = b

Next tactic:
rw [← mul_assoc, mul_invOf_self, one_mul]
theorem mul_invOf_self_assoc [Monoid α] (a b : α) [Invertible a] : a * (⅟ a * b) = b := by
  

Proof state:
α : Type u
inst✝¹ : Monoid α
a b : α
inst✝ : Invertible a
⊢ a * (⅟a * b) = b

Next tactic:
rw [← mul_assoc, mul_invOf_self, one_mul]
@[simp]
theorem mul_invOf_mul_self_cancel' [Monoid α] (a b : α) {_ : Invertible b} : a * ⅟ b * b = a := by
  

Proof state:
α : Type u
inst✝ : Monoid α
a b : α
x✝ : Invertible b
⊢ a * ⅟b * b = a

Next tactic:
simp [mul_assoc]
theorem mul_invOf_mul_self_cancel [Monoid α] (a b : α) [Invertible b] : a * ⅟ b * b = a := by
  

Proof state:
α : Type u
inst✝¹ : Monoid α
a b : α
inst✝ : Invertible b
⊢ a * ⅟b * b = a

Next tactic:
simp [mul_assoc]
@[simp]
theorem mul_mul_invOf_self_cancel' [Monoid α] (a b : α) {_ : Invertible b} : a * b * ⅟ b = a := by
  

Proof state:
α : Type u
inst✝ : Monoid α
a b : α
x✝ : Invertible b
⊢ a * b * ⅟b = a

Next tactic:
simp [mul_assoc]
theorem mul_mul_invOf_self_cancel [Monoid α] (a b : α) [Invertible b] : a * b * ⅟ b = a := by
  

Proof state:
α : Type u
inst✝¹ : Monoid α
a b : α
inst✝ : Invertible b
⊢ a * b * ⅟b = a

Next tactic:
simp [mul_assoc]
theorem invertible_unique {α : Type u} [Monoid α] (a b : α) [Invertible a] [Invertible b]
    (h : a = b) : ⅟ a = ⅟ b := by
  

Proof state:
α✝ α : Type u
inst✝² : Monoid α
a b : α
inst✝¹ : Invertible a
inst✝ : Invertible b
h : a = b
⊢ ⅟a = ⅟b

Next tactic:
apply invOf_eq_right_inv
theorem invertible_unique {α : Type u} [Monoid α] (a b : α) [Invertible a] [Invertible b]
    (h : a = b) : ⅟ a = ⅟ b := by
  apply invOf_eq_right_inv
  

Proof state:
case hac
α✝ α : Type u
inst✝² : Monoid α
a b : α
inst✝¹ : Invertible a
inst✝ : Invertible b
h : a = b
⊢ a * ⅟b = 1

Next tactic:
rw [h, mul_invOf_self]
instance Invertible.subsingleton [Monoid α] (a : α) : Subsingleton (Invertible a) :=
  ⟨fun ⟨b, hba, hab⟩ ⟨c, _, hac⟩ => by
    

Proof state:
α : Type u
inst✝ : Monoid α
a : α
x✝¹ x✝ : Invertible a
b : α
hba : b * a = 1
hab : a * b = 1
c : α
invOf_mul_self✝ : c * a = 1
hac : a * c = 1
⊢ { invOf := b, invOf_mul_self := hba, mul_invOf_self := hab } =
    { invOf := c, invOf_mul_self := invOf_mul_self✝, mul_invOf_self := hac }

Next tactic:
congr
instance Invertible.subsingleton [Monoid α] (a : α) : Subsingleton (Invertible a) :=
  ⟨fun ⟨b, hba, hab⟩ ⟨c, _, hac⟩ => by
    congr
    

Proof state:
case e_invOf
α : Type u
inst✝ : Monoid α
a : α
x✝¹ x✝ : Invertible a
b : α
hba : b * a = 1
hab : a * b = 1
c : α
invOf_mul_self✝ : c * a = 1
hac : a * c = 1
⊢ b = c

Next tactic:
exact left_inv_eq_right_inv hba hac
/-- If `a` is invertible and `a = b`, then `⅟a = ⅟b`. -/
@[congr]
theorem Invertible.congr [Monoid α] (a b : α) [Invertible a] [Invertible b] (h : a = b) :
    ⅟a = ⅟b := by 

Proof state:
α : Type u
inst✝² : Monoid α
a b : α
inst✝¹ : Invertible a
inst✝ : Invertible b
h : a = b
⊢ ⅟a = ⅟b

Next tactic:
subst h
/-- If `a` is invertible and `a = b`, then `⅟a = ⅟b`. -/
@[congr]
theorem Invertible.congr [Monoid α] (a b : α) [Invertible a] [Invertible b] (h : a = b) :
    ⅟a = ⅟b := by subst h; 

Proof state:
α : Type u
inst✝² : Monoid α
a : α
inst✝¹ inst✝ : Invertible a
⊢ ⅟a = ⅟a

Next tactic:
congr
/-- If `a` is invertible and `a = b`, then `⅟a = ⅟b`. -/
@[congr]
theorem Invertible.congr [Monoid α] (a b : α) [Invertible a] [Invertible b] (h : a = b) :
    ⅟a = ⅟b := by subst h; congr; 

Proof state:
case h.e_5.h
α : Type u
inst✝² : Monoid α
a : α
inst✝¹ inst✝ : Invertible a
⊢ inst✝¹ = inst✝

Next tactic:
apply Subsingleton.allEq
/-- If `r` is invertible and `s = r` and `si = ⅟r`, then `s` is invertible with `⅟s = si`. -/
def Invertible.copy' [MulOneClass α] {r : α} (hr : Invertible r) (s : α) (si : α) (hs : s = r)
    (hsi : si = ⅟ r) : Invertible s where
  invOf := si
  invOf_mul_self := by 

Proof state:
α : Type u
inst✝ : MulOneClass α
r : α
hr : Invertible r
s si : α
hs : s = r
hsi : si = ⅟r
⊢ si * s = 1

Next tactic:
rw [hs, hsi, invOf_mul_self]