Average Error: 31.5 → 0.3
Time: 17.7s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03119874976006306588338645724434172734618:\\ \;\;\;\;\left(\frac{1}{x} \cdot \frac{1}{x}\right) \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \le 0.03649639588302253101481653629889478906989:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)} \cdot \frac{1 \cdot 1}{x} - \frac{\cos x}{x} \cdot \frac{\cos x \cdot \cos x}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03119874976006306588338645724434172734618:\\
\;\;\;\;\left(\frac{1}{x} \cdot \frac{1}{x}\right) \cdot \left(1 - \cos x\right)\\

\mathbf{elif}\;x \le 0.03649639588302253101481653629889478906989:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)} \cdot \frac{1 \cdot 1}{x} - \frac{\cos x}{x} \cdot \frac{\cos x \cdot \cos x}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}}{x}\\

\end{array}
double f(double x) {
        double r857252 = 1.0;
        double r857253 = x;
        double r857254 = cos(r857253);
        double r857255 = r857252 - r857254;
        double r857256 = r857253 * r857253;
        double r857257 = r857255 / r857256;
        return r857257;
}

double f(double x) {
        double r857258 = x;
        double r857259 = -0.031198749760063066;
        bool r857260 = r857258 <= r857259;
        double r857261 = 1.0;
        double r857262 = r857261 / r857258;
        double r857263 = r857262 * r857262;
        double r857264 = 1.0;
        double r857265 = cos(r857258);
        double r857266 = r857264 - r857265;
        double r857267 = r857263 * r857266;
        double r857268 = 0.03649639588302253;
        bool r857269 = r857258 <= r857268;
        double r857270 = -0.041666666666666664;
        double r857271 = r857258 * r857258;
        double r857272 = r857271 * r857271;
        double r857273 = 0.001388888888888889;
        double r857274 = 0.5;
        double r857275 = fma(r857272, r857273, r857274);
        double r857276 = fma(r857270, r857271, r857275);
        double r857277 = r857264 + r857265;
        double r857278 = r857264 * r857264;
        double r857279 = fma(r857277, r857265, r857278);
        double r857280 = r857264 / r857279;
        double r857281 = r857278 / r857258;
        double r857282 = r857280 * r857281;
        double r857283 = r857265 / r857258;
        double r857284 = r857265 * r857265;
        double r857285 = r857284 / r857279;
        double r857286 = r857283 * r857285;
        double r857287 = r857282 - r857286;
        double r857288 = r857287 / r857258;
        double r857289 = r857269 ? r857276 : r857288;
        double r857290 = r857260 ? r857267 : r857289;
        return r857290;
}

Error

Bits error versus x

Derivation

  1. Split input into 3 regimes
  2. if x < -0.031198749760063066

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.2

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied div-inv0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \color{blue}{\left(\sqrt{1 - \cos x} \cdot \frac{1}{x}\right)}\]
    7. Applied div-inv0.6

      \[\leadsto \color{blue}{\left(\sqrt{1 - \cos x} \cdot \frac{1}{x}\right)} \cdot \left(\sqrt{1 - \cos x} \cdot \frac{1}{x}\right)\]
    8. Applied swap-sqr0.6

      \[\leadsto \color{blue}{\left(\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}\right) \cdot \left(\frac{1}{x} \cdot \frac{1}{x}\right)}\]
    9. Simplified0.5

      \[\leadsto \color{blue}{\left(1 - \cos x\right)} \cdot \left(\frac{1}{x} \cdot \frac{1}{x}\right)\]

    if -0.031198749760063066 < x < 0.03649639588302253

    1. Initial program 62.4

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.4

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac61.4

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\]
    6. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)}\]

    if 0.03649639588302253 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.2

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied associate-*r/0.6

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{1 - \cos x}}{x} \cdot \sqrt{1 - \cos x}}{x}}\]
    7. Simplified0.5

      \[\leadsto \frac{\color{blue}{\frac{1 - \cos x}{x}}}{x}\]
    8. Using strategy rm
    9. Applied flip3--0.5

      \[\leadsto \frac{\frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{x}}{x}\]
    10. Applied associate-/l/0.5

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}}{x}\]
    11. Simplified0.5

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right) \cdot x}}}{x}\]
    12. Using strategy rm
    13. Applied div-sub0.5

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3}}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right) \cdot x} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right) \cdot x}}}{x}\]
    14. Simplified0.6

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1}{x} \cdot \frac{1}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right) \cdot x}}{x}\]
    15. Simplified0.6

      \[\leadsto \frac{\frac{1 \cdot 1}{x} \cdot \frac{1}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)} - \color{blue}{\frac{\cos x \cdot \cos x}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)} \cdot \frac{\cos x}{x}}}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.03119874976006306588338645724434172734618:\\ \;\;\;\;\left(\frac{1}{x} \cdot \frac{1}{x}\right) \cdot \left(1 - \cos x\right)\\ \mathbf{elif}\;x \le 0.03649639588302253101481653629889478906989:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{720}, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)} \cdot \frac{1 \cdot 1}{x} - \frac{\cos x}{x} \cdot \frac{\cos x \cdot \cos x}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}}{x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1.0 (cos x)) (* x x)))