-- Mathlib/Analysis/SpecialFunctions/SmoothTransition.lean
theorem hasDerivAt_polynomial_eval_inv_mul (p : ℝ[X]) (x : ℝ) :
    HasDerivAt (fun x ↦ p.eval x⁻¹ * expNegInvGlue x)
      ((X ^ 2 * (p - derivative (R := ℝ) p)).eval x⁻¹ * expNegInvGlue x) x

Proof state:
case inr.inl
p : ℝ[X]
x : ℝ
⊢ Polynomial.eval x⁻¹ (p * X) * expNegInvGlue x = slope (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0 x

Tactic:
simp [slope_def_field, div_eq_mul_inv, mul_right_comm]

Result:
no goals

Proof state:
case inr.inl
p : ℝ[X]
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval 0⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue 0) 0

Tactic:
rw [expNegInvGlue.zero, mul_zero, hasDerivAt_iff_tendsto_slope]

Result:
case inr.inl
p : ℝ[X]
⊢ Tendsto (slope (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0) (𝓝[≠] 0) (𝓝 0)

Proof state:
p : ℝ[X]
x : ℝ
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Tactic:
rcases lt_trichotomy x 0 with hx | rfl | hx

Result:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

case inr.inl
p : ℝ[X]
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval 0⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue 0) 0

case inr.inr
p : ℝ[X]
x : ℝ
hx : 0 < x
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Proof state:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Tactic:
rw [zero_of_nonpos hx.le, mul_zero]

Result:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0 x

Proof state:
case h.e'_9
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ (x ^ 2)⁻¹ * (Polynomial.eval x⁻¹ p - Polynomial.eval x⁻¹ (derivative p)) * rexp (-x⁻¹) =
    -((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + -(Polynomial.eval x⁻¹ p * rexp (-x⁻¹))) * (x ^ 2)⁻¹)

Tactic:
ring

Result:
no goals

Proof state:
case inr.inr
p : ℝ[X]
x : ℝ
hx : 0 < x
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Tactic:
have := ((p.hasDerivAt x⁻¹).mul (hasDerivAt_neg _).exp).comp x (hasDerivAt_inv hx.ne')

Result:
case inr.inr
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Proof state:
case inr.inl
p : ℝ[X]
⊢ Tendsto (slope (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0) (𝓝[≠] 0) (𝓝 0)

Tactic:
refine ((tendsto_polynomial_inv_mul_zero (p * X)).mono_left inf_le_left).congr fun x ↦ ?_

Result:
case inr.inl
p : ℝ[X]
x : ℝ
⊢ Polynomial.eval x⁻¹ (p * X) * expNegInvGlue x = slope (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0 x

Proof state:
case inr.inr.convert_2
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) =ᶠ[𝓝 x] (fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv

Tactic:
filter_upwards [lt_mem_nhds hx] with y hy

Result:
case h
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
y : ℝ
hy : 0 < y
⊢ Polynomial.eval y⁻¹ p * expNegInvGlue y = ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv) y

Proof state:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) 0 x

Tactic:
refine (hasDerivAt_const _ 0).congr_of_eventuallyEq ?_

Result:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) =ᶠ[𝓝 x] fun x => 0

Proof state:
case h.e'_9
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x =
    (Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹

Tactic:
simp [expNegInvGlue, hx.not_le]

Result:
case h.e'_9
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ (x ^ 2)⁻¹ * (Polynomial.eval x⁻¹ p - Polynomial.eval x⁻¹ (derivative p)) * rexp (-x⁻¹) =
    -((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + -(Polynomial.eval x⁻¹ p * rexp (-x⁻¹))) * (x ^ 2)⁻¹)

Proof state:
case h
p : ℝ[X]
x : ℝ
hx : x < 0
y : ℝ
hy : y < 0
⊢ Polynomial.eval y⁻¹ p * expNegInvGlue y = 0

Tactic:
rw [zero_of_nonpos hy.le, mul_zero]

Result:
no goals

Proof state:
case inr.inr
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ HasDerivAt (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x)
    (Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x) x

Tactic:
convert this.congr_of_eventuallyEq _ using 1

Result:
case h.e'_9
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ Polynomial.eval x⁻¹ (X ^ 2 * (p - derivative p)) * expNegInvGlue x =
    (Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹

case inr.inr.convert_2
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
⊢ (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) =ᶠ[𝓝 x] (fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv

Proof state:
case inl
p : ℝ[X]
x : ℝ
hx : x < 0
⊢ (fun x => Polynomial.eval x⁻¹ p * expNegInvGlue x) =ᶠ[𝓝 x] fun x => 0

Tactic:
filter_upwards [gt_mem_nhds hx] with y hy

Result:
case h
p : ℝ[X]
x : ℝ
hx : x < 0
y : ℝ
hy : y < 0
⊢ Polynomial.eval y⁻¹ p * expNegInvGlue y = 0

Proof state:
case h
p : ℝ[X]
x : ℝ
hx : 0 < x
this :
  HasDerivAt ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv)
    ((Polynomial.eval x⁻¹ (derivative p) * rexp (-x⁻¹) + Polynomial.eval x⁻¹ p * (rexp (-x⁻¹) * -1)) * -(x ^ 2)⁻¹) x
y : ℝ
hy : 0 < y
⊢ Polynomial.eval y⁻¹ p * expNegInvGlue y = ((fun y => Polynomial.eval y p * rexp (-y)) ∘ Inv.inv) y

Tactic:
simp [expNegInvGlue, hy.not_le]

Result:
no goals