Average Error: 31.5 → 0.3
Time: 4.2s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0356686461129850571 \lor \neg \left(x \le 0.02982085320761324\right):\\ \;\;\;\;\frac{\sqrt{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0356686461129850571 \lor \neg \left(x \le 0.02982085320761324\right):\\
\;\;\;\;\frac{\sqrt{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
	double VAR;
	if (((x <= -0.03566864611298506) || !(x <= 0.02982085320761324))) {
		VAR = ((sqrt(((pow(1.0, 3.0) - pow(cos(x), 3.0)) / ((cos(x) * (cos(x) + 1.0)) + (1.0 * 1.0)))) / x) * (sqrt(log(exp((1.0 - cos(x))))) / x));
	} else {
		VAR = (((0.001388888888888889 * pow(x, 4.0)) + 0.5) - (0.041666666666666664 * pow(x, 2.0)));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -0.03566864611298506 or 0.02982085320761324 < x

    1. Initial program 1.2

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

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

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

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

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

      \[\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 flip3--0.6

      \[\leadsto \frac{\sqrt{\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 \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\]
    12. Simplified0.6

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

    if -0.03566864611298506 < x < 0.02982085320761324

    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. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0356686461129850571 \lor \neg \left(x \le 0.02982085320761324\right):\\ \;\;\;\;\frac{\sqrt{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2020105 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))