Computable Range Reduction for Trigonometric Functions #
This file implements range reduction for sin and cos to improve Taylor series convergence for intervals far from 0.
Problem #
Standard Taylor series for sin/cos centered at 0 have remainder bounds of
|x|^{n+1} / (n+1)!. For intervals far from 0 (e.g., [10, 11]), this remainder
is huge even for moderate n.
Solution: Range Reduction #
Use the periodicity of sin/cos:
sin(x) = sin(x - 2πk)for any integer kcos(x) = cos(x - 2πk)for any integer k
By choosing k to bring x - 2πk into [-π, π], the Taylor series converges much faster since |x - 2πk| ≤ π ≈ 3.14.
Main definitions #
twoPiRatLo,twoPiRatHi- Rational bounds for 2πreduceToMainPeriod- Shift interval to be near 0sinComputableReduced,cosComputableReduced- Computable evaluation with range reduction
Rational approximations of π and 2π #
Lower bound for π: 314159265/100000000 < π
Equations
- LeanCert.Core.IntervalRat.piRatLo = 314159265 / 100000000
Instances For
Lower bound for 2π
Instances For
Upper bound for 2π
Instances For
twoPiRatLo < 2π
2π < twoPiRatHi
twoPiRatLo ≤ twoPiRatHi
Range reduction #
Compute the shift amount k such that I.midpoint - k * 2π is approximately in [-π, π].
Equations
Instances For
Shift an interval by subtracting k * 2π (using rational bounds).
For positive k: subtract k * twoPiRatHi from lo, k * twoPiRatLo from hi For negative k: opposite to maintain containment
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reduce interval to be approximately in [-π, π] by subtracting multiples of 2π.
Equations
Instances For
Correctness of range reduction #
If x ∈ I (as reals), then x - 2πk ∈ shiftInterval I k (as reals).
Computable reduced evaluation #
Computable sin evaluation with range reduction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Computable cos evaluation with range reduction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
sin x ∈ sinComputableReduced I for all x ∈ I
cos x ∈ cosComputableReduced I for all x ∈ I