Average Error: 31.6 → 0.6
Time: 3.9s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.03651380642110043:\\ \;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.03386786279469105:\\ \;\;\;\;{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \frac{x}{1 - \cos x}}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.03651380642110043:\\
\;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot x}\\

\mathbf{elif}\;x \leq 0.03386786279469105:\\
\;\;\;\;{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{1 - \cos x}}\\

\end{array}
double code(double x) {
	return (((double) (1.0 - ((double) cos(x)))) / ((double) (x * x)));
}
double code(double x) {
	double VAR;
	if ((x <= -0.03651380642110043)) {
		VAR = ((double) ((1.0 / ((double) (x * x))) - (((double) cos(x)) / ((double) (x * x)))));
	} else {
		double VAR_1;
		if ((x <= 0.03386786279469105)) {
			VAR_1 = ((double) (((double) (((double) pow(x, 4.0)) * 0.001388888888888889)) + ((double) (0.5 + ((double) (x * ((double) (x * -0.041666666666666664))))))));
		} else {
			VAR_1 = (1.0 / ((double) (x * (x / ((double) (1.0 - ((double) cos(x))))))));
		}
		VAR = VAR_1;
	}
	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 3 regimes
  2. if x < -0.036513806421100428

    1. Initial program Error: 1.0 bits

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied div-subError: 1.1 bits

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

    if -0.036513806421100428 < x < 0.033867862794691048

    1. Initial program Error: 62.2 bits

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Taylor expanded around 0 Error: 0.0 bits

      \[\leadsto \color{blue}{\left(0.001388888888888889 \cdot {x}^{4} + 0.5\right) - 0.041666666666666664 \cdot {x}^{2}}\]
    3. SimplifiedError: 0.0 bits

      \[\leadsto \color{blue}{{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)}\]

    if 0.033867862794691048 < x

    1. Initial program Error: 1.2 bits

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied clear-numError: 1.3 bits

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x}{1 - \cos x}}}\]
    4. SimplifiedError: 1.2 bits

      \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{1 - \cos x}}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 0.6 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.03651380642110043:\\ \;\;\;\;\frac{1}{x \cdot x} - \frac{\cos x}{x \cdot x}\\ \mathbf{elif}\;x \leq 0.03386786279469105:\\ \;\;\;\;{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x \cdot \frac{x}{1 - \cos x}}\\ \end{array}\]

Reproduce

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