Average Error: 31.4 → 0.3
Time: 4.5s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.030737456238445281 \lor \neg \left(x \le 0.032853706672437546\right):\\ \;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.030737456238445281 \lor \neg \left(x \le 0.032853706672437546\right):\\
\;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\

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

\end{array}
double code(double x) {
	return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) (x * x))));
}
double code(double x) {
	double VAR;
	if (((x <= -0.03073745623844528) || !(x <= 0.032853706672437546))) {
		VAR = ((double) (((double) (((double) (1.0 / x)) - ((double) (((double) cos(x)) / x)))) / x));
	} else {
		VAR = ((double) (((double) (((double) (((double) (0.5 * x)) + ((double) (0.001388888888888889 * ((double) pow(x, 5.0)))))) - ((double) (0.041666666666666664 * ((double) pow(x, 3.0)))))) / x));
	}
	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.03073745623844528 or 0.032853706672437546 < 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 div-sub0.6

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - \frac{\cos x}{x}}}{x}\]

    if -0.03073745623844528 < x < 0.032853706672437546

    1. Initial program 62.2

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

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Taylor expanded around 0 0.0

      \[\leadsto \frac{\color{blue}{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}}{x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.030737456238445281 \lor \neg \left(x \le 0.032853706672437546\right):\\ \;\;\;\;\frac{\frac{1}{x} - \frac{\cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}{x}\\ \end{array}\]

Reproduce

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