Average Error: 32.1 → 0.5
Time: 4.6s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.02933386181963808:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \left(x \cdot \left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right)\right)}\\ \mathbf{elif}\;x \leq 0.03400527114210335:\\ \;\;\;\;{x}^{4} \cdot 0.001388888888888889 + \left(0.5 + x \cdot \left(x \cdot -0.041666666666666664\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt[3]{1 - \cos x}}{x} \cdot \left(\sqrt[3]{1 - \cos x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.02933386181963808:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{x \cdot \left(x \cdot \left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right)\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{1 - \cos x}}{x} \cdot \left(\sqrt[3]{1 - \cos x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}\right)\\

\end{array}
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (if (<= x -0.02933386181963808)
   (/
    (- (pow 1.0 3.0) (pow (cos x) 3.0))
    (* x (* x (+ (* 1.0 1.0) (* (cos x) (+ 1.0 (cos x)))))))
   (if (<= x 0.03400527114210335)
     (+
      (* (pow x 4.0) 0.001388888888888889)
      (+ 0.5 (* x (* x -0.041666666666666664))))
     (*
      (/ (cbrt (- 1.0 (cos x))) x)
      (* (cbrt (- 1.0 (cos x))) (/ (cbrt (- 1.0 (cos x))) x))))))
double code(double x) {
	return (((double) (1.0 - ((double) cos(x)))) / ((double) (x * x)));
}
double code(double x) {
	double tmp;
	if ((x <= -0.02933386181963808)) {
		tmp = (((double) (((double) pow(1.0, 3.0)) - ((double) pow(((double) cos(x)), 3.0)))) / ((double) (x * ((double) (x * ((double) (((double) (1.0 * 1.0)) + ((double) (((double) cos(x)) * ((double) (1.0 + ((double) cos(x)))))))))))));
	} else {
		double tmp_1;
		if ((x <= 0.03400527114210335)) {
			tmp_1 = ((double) (((double) (((double) pow(x, 4.0)) * 0.001388888888888889)) + ((double) (0.5 + ((double) (x * ((double) (x * -0.041666666666666664))))))));
		} else {
			tmp_1 = ((double) ((((double) cbrt(((double) (1.0 - ((double) cos(x)))))) / x) * ((double) (((double) cbrt(((double) (1.0 - ((double) cos(x)))))) * (((double) cbrt(((double) (1.0 - ((double) cos(x)))))) / x)))));
		}
		tmp = tmp_1;
	}
	return tmp;
}

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.0293338618196380789

    1. Initial program Error: 1.2 bits

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied flip3--Error: 1.2 bits

      \[\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. Applied associate-/l/Error: 1.2 bits

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(x \cdot x\right) \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}\]
    5. SimplifiedError: 1.2 bits

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

    if -0.0293338618196380789 < x < 0.034005271142103347

    1. Initial program Error: 62.3 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.034005271142103347 < x

    1. Initial program Error: 1.1 bits

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-cube-cbrtError: 1.5 bits

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}\right) \cdot \sqrt[3]{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-fracError: 0.9 bits

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1 - \cos x} \cdot \sqrt[3]{1 - \cos x}}{x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}}\]
    5. SimplifiedError: 0.9 bits

      \[\leadsto \color{blue}{\left(\sqrt[3]{1 - \cos x} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}\right)} \cdot \frac{\sqrt[3]{1 - \cos x}}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 0.5 bits

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

Reproduce

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