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

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

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

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
	double temp;
	if ((x <= -0.03305941206486147)) {
		temp = (((pow(1.0, 3.0) - pow(cos(x), 3.0)) / fma(cos(x), (1.0 + cos(x)), (1.0 * 1.0))) / (x * x));
	} else {
		double temp_1;
		if ((x <= 0.034074837610598666)) {
			temp_1 = fma(pow(x, 4.0), 0.001388888888888889, (0.5 - (0.041666666666666664 * pow(x, 2.0))));
		} else {
			temp_1 = ((sqrt((((pow((1.0 * 1.0), 3.0) - pow((cos(x) * cos(x)), 3.0)) / fma(fma(1.0, 1.0, pow(cos(x), 2.0)), pow(cos(x), 2.0), pow(1.0, 4.0))) / (1.0 + cos(x)))) / x) * (sqrt(log(exp((1.0 - cos(x))))) / 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.03305941206486147

    1. Initial program 1.0

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

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

      \[\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}\]

    if -0.03305941206486147 < x < 0.034074837610598666

    1. Initial program 62.1

      \[\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.034074837610598666 < x

    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 add-log-exp0.5

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

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

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

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x}\]
    10. Using strategy rm
    11. Applied flip--0.6

      \[\leadsto \frac{\sqrt{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\]
    12. Using strategy rm
    13. Applied flip3--0.6

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

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

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

Reproduce

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