Average Error: 31.3 → 0.3
Time: 18.9s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03161448669661249405438141479862679261714:\\ \;\;\;\;\frac{\frac{\log \left(e^{1 \cdot \left(1 \cdot 1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(x + x\right)\right) \cdot \cos x}\right)}{x \cdot \mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.0364141473996223707931818580618710257113:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, \frac{1}{720} \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \frac{1}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \left(\cos x \cdot \cos x\right)\right)\right)}{x \cdot \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.03161448669661249405438141479862679261714:\\
\;\;\;\;\frac{\frac{\log \left(e^{1 \cdot \left(1 \cdot 1\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(x + x\right)\right) \cdot \cos x}\right)}{x \cdot \mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right)}}{x}\\

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

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

\end{array}
double f(double x) {
        double r808018 = 1.0;
        double r808019 = x;
        double r808020 = cos(r808019);
        double r808021 = r808018 - r808020;
        double r808022 = r808019 * r808019;
        double r808023 = r808021 / r808022;
        return r808023;
}

double f(double x) {
        double r808024 = x;
        double r808025 = -0.031614486696612494;
        bool r808026 = r808024 <= r808025;
        double r808027 = 1.0;
        double r808028 = r808027 * r808027;
        double r808029 = r808027 * r808028;
        double r808030 = 0.5;
        double r808031 = r808024 + r808024;
        double r808032 = cos(r808031);
        double r808033 = r808030 * r808032;
        double r808034 = r808030 + r808033;
        double r808035 = cos(r808024);
        double r808036 = r808034 * r808035;
        double r808037 = r808029 - r808036;
        double r808038 = exp(r808037);
        double r808039 = log(r808038);
        double r808040 = r808027 + r808035;
        double r808041 = fma(r808040, r808035, r808028);
        double r808042 = r808024 * r808041;
        double r808043 = r808039 / r808042;
        double r808044 = r808043 / r808024;
        double r808045 = 0.03641414739962237;
        bool r808046 = r808024 <= r808045;
        double r808047 = r808024 * r808024;
        double r808048 = 0.001388888888888889;
        double r808049 = r808048 * r808047;
        double r808050 = -0.041666666666666664;
        double r808051 = fma(r808050, r808047, r808030);
        double r808052 = fma(r808047, r808049, r808051);
        double r808053 = 3.0;
        double r808054 = pow(r808027, r808053);
        double r808055 = r808035 * r808035;
        double r808056 = r808035 * r808055;
        double r808057 = log1p(r808056);
        double r808058 = expm1(r808057);
        double r808059 = r808054 - r808058;
        double r808060 = r808059 / r808042;
        double r808061 = r808060 / r808024;
        double r808062 = r808046 ? r808052 : r808061;
        double r808063 = r808026 ? r808044 : r808062;
        return r808063;
}

Error

Bits error versus x

Derivation

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

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.4

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. 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}\]
    6. 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}\]
    7. 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}\]
    8. Using strategy rm
    9. Applied add-log-exp0.5

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

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

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

      \[\leadsto \frac{\frac{\log \color{blue}{\left(e^{1 \cdot \left(1 \cdot 1\right) - \left(\cos x \cdot \cos x\right) \cdot \cos x}\right)}}{\mathsf{fma}\left(1 + \cos x, \cos x, 1 \cdot 1\right) \cdot x}}{x}\]
    13. Using strategy rm
    14. Applied sqr-cos0.6

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

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

    if -0.031614486696612494 < x < 0.03641414739962237

    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 \cdot x, \frac{1}{720} \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{-1}{24}, x \cdot x, \frac{1}{2}\right)\right)}\]

    if 0.03641414739962237 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. 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}\]
    6. 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}\]
    7. 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}\]
    8. Using strategy rm
    9. Applied expm1-log1p-u0.5

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

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

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

Reproduce

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