Average Error: 30.8 → 0.5
Time: 5.0s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03437938882255739403426275657693622633815:\\ \;\;\;\;1 \cdot \frac{\frac{1 \cdot 1 - \cos x \cdot \cos x}{x \cdot \left(1 + \cos x\right)}}{x}\\ \mathbf{elif}\;x \le 0.0311908640075921408940651247121422784403:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x \cdot x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03437938882255739403426275657693622633815:\\
\;\;\;\;1 \cdot \frac{\frac{1 \cdot 1 - \cos x \cdot \cos x}{x \cdot \left(1 + \cos x\right)}}{x}\\

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

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

\end{array}
double f(double x) {
        double r25938 = 1.0;
        double r25939 = x;
        double r25940 = cos(r25939);
        double r25941 = r25938 - r25940;
        double r25942 = r25939 * r25939;
        double r25943 = r25941 / r25942;
        return r25943;
}

double f(double x) {
        double r25944 = x;
        double r25945 = -0.034379388822557394;
        bool r25946 = r25944 <= r25945;
        double r25947 = 1.0;
        double r25948 = 1.0;
        double r25949 = r25948 * r25948;
        double r25950 = cos(r25944);
        double r25951 = r25950 * r25950;
        double r25952 = r25949 - r25951;
        double r25953 = r25948 + r25950;
        double r25954 = r25944 * r25953;
        double r25955 = r25952 / r25954;
        double r25956 = r25955 / r25944;
        double r25957 = r25947 * r25956;
        double r25958 = 0.03119086400759214;
        bool r25959 = r25944 <= r25958;
        double r25960 = 4.0;
        double r25961 = pow(r25944, r25960);
        double r25962 = 0.001388888888888889;
        double r25963 = 0.5;
        double r25964 = 0.041666666666666664;
        double r25965 = 2.0;
        double r25966 = pow(r25944, r25965);
        double r25967 = r25964 * r25966;
        double r25968 = r25963 - r25967;
        double r25969 = fma(r25961, r25962, r25968);
        double r25970 = 3.0;
        double r25971 = pow(r25948, r25970);
        double r25972 = pow(r25950, r25970);
        double r25973 = r25971 - r25972;
        double r25974 = fma(r25950, r25953, r25949);
        double r25975 = r25973 / r25974;
        double r25976 = r25944 * r25944;
        double r25977 = r25975 / r25976;
        double r25978 = r25959 ? r25969 : r25977;
        double r25979 = r25946 ? r25957 : r25978;
        return r25979;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.0

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.5

      \[\leadsto \frac{\sqrt{1 - \cos x}}{\color{blue}{1 \cdot x}} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    7. Applied *-un-lft-identity0.5

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

      \[\leadsto \color{blue}{\left(\frac{1}{1} \cdot \frac{\sqrt{1 - \cos x}}{x}\right)} \cdot \frac{\sqrt{1 - \cos x}}{x}\]
    9. Applied associate-*l*0.5

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

      \[\leadsto \frac{1}{1} \cdot \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    11. Using strategy rm
    12. Applied flip--0.7

      \[\leadsto \frac{1}{1} \cdot \frac{\frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x}}{x}\]
    13. Applied associate-/l/0.7

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

    if -0.034379388822557394 < x < 0.03119086400759214

    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. Using strategy rm
    6. Applied add-log-exp61.4

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \color{blue}{\log \left(e^{\cos x}\right)}}}{x}\]
    7. Applied add-log-exp61.4

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}}{x}\]
    8. Applied diff-log61.4

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\log \left(\frac{e^{1}}{e^{\cos x}}\right)}}}{x}\]
    9. Simplified61.4

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x}\]
    10. 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}}\]
    11. Simplified0.0

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

    if 0.03119086400759214 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied flip3--1.1

      \[\leadsto \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 \cdot x}\]
    4. Simplified1.1

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

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

Reproduce

herbie shell --seed 2020002 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))