module

public import SubentropyCertificates.BinaryLogIntervals

/-! Appendix F.3. Exact signs at the two decimal endpoints using 50 logarithm terms. -/
@[expose] public section
set_option maxRecDepth 100000
set_option maxHeartbeats 3000000
namespace SubentropyCertificates.BinaryIntervals
open SubentropyCertificates.LogEnclosure SubentropyCertificates.ClassicalCurve
open SubentropyCertificates.SmallOverlap

private def leftEnd : ℚ := 767875711400/1000000000000
private def rightEnd : ℚ := 767875711401/1000000000000

private theorem left_rational :
    logUpper 50 2 - 1/2 - phiLo 50 4 ((1-leftEnd)/2) - phiLo 50 3 (leftEnd^2/4) < 0 := by
  decide +kernel

private theorem right_rational :
    0 < logLower 50 2 - 1/2 - phiHi 50 4 ((1-rightEnd)/2) - phiHi 50 3 (rightEnd^2/4) := by
  decide +kernel

/-- Exact signs of q(s)−Φ₂(s²/4) at the endpoints printed in Appendix F.3. -/
theorem crossover_endpoint_signs :
    let s : ℝ := 767875711400/1000000000000
    let t : ℝ := 767875711401/1000000000000
    conditionalCurve s - phi 0 (s^2/4) < 0 ∧ 0 < conditionalCurve t - phi 0 (t^2/4) := by
  have h₁ := comparison_interval 50 4 3 (s:=leftEnd) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)
  have h₂ := comparison_interval 50 4 3 (s:=rightEnd) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)
  have hL := h₁.2.trans_lt (show ((_ : ℚ) : ℝ) < 0 by exact_mod_cast left_rational)
  have hR := h₂.1.trans_lt' (show 0 < ((_ : ℚ) : ℝ) by exact_mod_cast right_rational)
  simpa only [leftEnd,rightEnd,Rat.cast_div,Rat.cast_ofNat] using And.intro hL hR

end SubentropyCertificates.BinaryIntervals
