Average Error: 31.7 → 0.7
Time: 4.4s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.47813864352879791 \cdot 10^{-8} \lor \neg \left(x \le 1.50638514398549192 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{\frac{1}{x}}{x} - \frac{\frac{\cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \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 -1.47813864352879791 \cdot 10^{-8} \lor \neg \left(x \le 1.50638514398549192 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{\frac{1}{x}}{x} - \frac{\frac{\cos x}{x}}{x}\\

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

\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 <= -1.4781386435287979e-08) || !(x <= 1.506385143985492e-08))) {
		VAR = ((double) (((double) (((double) (1.0 / x)) / x)) - ((double) (((double) (((double) cos(x)) / x)) / x))));
	} else {
		VAR = ((double) (((double) (x + 0.5)) - ((double) (0.041666666666666664 * ((double) 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 < -1.47813864352879791e-8 or 1.50638514398549192e-8 < x

    1. Initial program 1.6

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

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Using strategy rm
    5. Applied div-sub1.2

      \[\leadsto \frac{\color{blue}{\frac{1}{x} - \frac{\cos x}{x}}}{x}\]
    6. Applied div-sub1.0

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

    if -1.47813864352879791e-8 < x < 1.50638514398549192e-8

    1. Initial program 63.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Taylor expanded around 0 0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.47813864352879791 \cdot 10^{-8} \lor \neg \left(x \le 1.50638514398549192 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{\frac{1}{x}}{x} - \frac{\frac{\cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left(x + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]

Reproduce

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