Average Error: 31.8 → 0.3
Time: 7.2s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0340620183492770026:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \sqrt[3]{1 + \cos x}\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.0328884568480627:\\ \;\;\;\;\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} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 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.0340620183492770026:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \sqrt[3]{1 + \cos x}\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

\mathbf{elif}\;x \le 0.0328884568480627:\\
\;\;\;\;\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} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
	double temp;
	if ((x <= -0.034062018349277)) {
		temp = ((1.0 / x) * (((pow(1.0, 3.0) / fma(cos(x), ((cbrt((1.0 + cos(x))) * cbrt((1.0 + cos(x)))) * cbrt((1.0 + cos(x)))), (1.0 * 1.0))) - (pow(cos(x), 3.0) / fma(cos(x), (1.0 + cos(x)), (1.0 * 1.0)))) / x));
	} else {
		double temp_1;
		if ((x <= 0.0328884568480627)) {
			temp_1 = fma(pow(x, 4.0), 0.001388888888888889, (0.5 - (0.041666666666666664 * pow(x, 2.0))));
		} else {
			temp_1 = ((1.0 / x) * (((pow(1.0, 3.0) - cbrt(pow(pow(cos(x), 3.0), 3.0))) / fma(cos(x), (1.0 + cos(x)), (1.0 * 1.0))) / x));
		}
		temp = temp_1;
	}
	return temp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

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

    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.6

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

      \[\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.6

      \[\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 div-sub0.6

      \[\leadsto \frac{1}{x} \cdot \frac{\color{blue}{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{x}\]
    10. Using strategy rm
    11. Applied add-cube-cbrt0.7

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

    if -0.034062018349277 < x < 0.0328884568480627

    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.0328884568480627 < 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.4

      \[\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-cbrt-cube0.5

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

      \[\leadsto \frac{1}{x} \cdot \frac{\frac{{1}^{3} - \sqrt[3]{\color{blue}{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}}{\mathsf{fma}\left(\cos x, 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.0340620183492770026:\\ \;\;\;\;\frac{1}{x} \cdot \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, \left(\sqrt[3]{1 + \cos x} \cdot \sqrt[3]{1 + \cos x}\right) \cdot \sqrt[3]{1 + \cos x}, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \mathbf{elif}\;x \le 0.0328884568480627:\\ \;\;\;\;\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} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{x}\\ \end{array}\]

Reproduce

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