module

public import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog
public import Mathlib.Tactic

/-! Pointwise bounds on the Gaussian relative-entropy integrand in Section 3.1. -/
@[expose] public section
namespace SubentropyCertificates.GaussianPinching

/-- The bounds include the common zero set, where Lean's integrand is zero. -/
theorem log_ratio_bounds {a b c : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hc : a ≤ c * b) :
    -(b / Real.exp 1) ≤ a * Real.log (a / b) ∧
      a * Real.log (a / b) ≤ a * Real.log c := by
  by_cases haz : a = 0
  · simp [haz, div_nonneg hb (Real.exp_pos 1).le]
  have hap := lt_of_le_of_ne ha (Ne.symm haz)
  have hbp : 0 < b := by
    apply lt_of_le_of_ne hb
    rintro rfl
    simp at hc
    linarith
  have ht := div_pos hap hbp
  have htc := (div_le_iff₀ hbp).2 hc
  refine ⟨?_, mul_le_mul_of_nonneg_left (Real.log_le_log ht htc) ha⟩
  have he := Real.exp_pos 1
  have h := Real.self_sub_one_le_mul_log (mul_pos he ht).le
  rw [Real.log_mul he.ne' ht.ne', Real.log_exp] at h
  have hlow : -1 ≤ Real.exp 1 * (a / b) * Real.log (a / b) := by linarith
  have hscaled := mul_le_mul_of_nonneg_right hlow hbp.le
  rw [← neg_div, div_le_iff₀ he]
  convert hscaled using 1 <;> field_simp

end SubentropyCertificates.GaussianPinching
