Average Error: 31.5 → 0.3
Time: 5.5s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0354600816886072659:\\ \;\;\;\;\frac{1 \cdot \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}{x} \cdot \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.030404078865847541:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - {\left(\cos x\right)}^{2}}{1 - \cos x}, 1 \cdot 1\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0354600816886072659:\\
\;\;\;\;\frac{1 \cdot \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}{x} \cdot \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

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

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

\end{array}
double f(double x) {
        double r35168 = 1.0;
        double r35169 = x;
        double r35170 = cos(r35169);
        double r35171 = r35168 - r35170;
        double r35172 = r35169 * r35169;
        double r35173 = r35171 / r35172;
        return r35173;
}

double f(double x) {
        double r35174 = x;
        double r35175 = -0.035460081688607266;
        bool r35176 = r35174 <= r35175;
        double r35177 = 1.0;
        double r35178 = 1.0;
        double r35179 = 3.0;
        double r35180 = pow(r35178, r35179);
        double r35181 = cos(r35174);
        double r35182 = pow(r35181, r35179);
        double r35183 = r35180 - r35182;
        double r35184 = r35177 * r35183;
        double r35185 = r35184 / r35174;
        double r35186 = r35178 + r35181;
        double r35187 = r35178 * r35178;
        double r35188 = fma(r35181, r35186, r35187);
        double r35189 = r35177 / r35188;
        double r35190 = r35189 / r35174;
        double r35191 = r35185 * r35190;
        double r35192 = 0.03040407886584754;
        bool r35193 = r35174 <= r35192;
        double r35194 = 4.0;
        double r35195 = pow(r35174, r35194);
        double r35196 = 0.001388888888888889;
        double r35197 = 0.5;
        double r35198 = 0.041666666666666664;
        double r35199 = 2.0;
        double r35200 = pow(r35174, r35199);
        double r35201 = r35198 * r35200;
        double r35202 = r35197 - r35201;
        double r35203 = fma(r35195, r35196, r35202);
        double r35204 = r35177 / r35174;
        double r35205 = exp(r35182);
        double r35206 = log(r35205);
        double r35207 = r35180 - r35206;
        double r35208 = pow(r35181, r35199);
        double r35209 = r35187 - r35208;
        double r35210 = r35178 - r35181;
        double r35211 = r35209 / r35210;
        double r35212 = fma(r35181, r35211, r35187);
        double r35213 = r35207 / r35212;
        double r35214 = r35213 / r35174;
        double r35215 = r35204 * r35214;
        double r35216 = r35193 ? r35203 : r35215;
        double r35217 = r35176 ? r35191 : r35216;
        return r35217;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.2

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.2

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

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

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Simplified0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{x}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\color{blue}{1 \cdot x}}\]
    10. Applied div-inv0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\color{blue}{\left({1}^{3} - {\left(\cos x\right)}^{3}\right) \cdot \frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{1 \cdot x}\]
    11. Applied times-frac0.5

      \[\leadsto \frac{1}{x} \cdot \color{blue}{\left(\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1} \cdot \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\right)}\]
    12. Applied associate-*r*0.5

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

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

    if -0.035460081688607266 < x < 0.03040407886584754

    1. Initial program 62.3

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. 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}}\]
    3. 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.03040407886584754 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.9

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

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

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Simplified0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{x}\]
    8. Using strategy rm
    9. Applied add-log-exp0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\]
    10. Using strategy rm
    11. Applied flip-+0.5

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\mathsf{fma}\left(\cos x, \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}}, 1 \cdot 1\right)}}{x}\]
    12. Simplified0.5

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

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

Reproduce

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