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

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

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

\end{array}
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
 :precision binary64
 (if (<= x -0.032035318607155715)
   (* (/ 1.0 x) (/ (- 1.0 (cos x)) x))
   (if (<= x 0.029706365761949148)
     (+
      (* (pow x 4.0) 0.001388888888888889)
      (- 0.5 (* (* x x) 0.041666666666666664)))
     (* (/ (sqrt (- 1.0 (cos x))) x) (/ (sqrt (- 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.032035318607155715)) {
		tmp = ((double) ((1.0 / x) * (((double) (1.0 - ((double) cos(x)))) / x)));
	} else {
		double tmp_1;
		if ((x <= 0.029706365761949148)) {
			tmp_1 = ((double) (((double) (((double) pow(x, 4.0)) * 0.001388888888888889)) + ((double) (0.5 - ((double) (((double) (x * x)) * 0.041666666666666664))))));
		} else {
			tmp_1 = ((double) ((((double) sqrt(((double) (1.0 - ((double) cos(x)))))) / x) * (((double) sqrt(((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.0320353186071557147

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity_binary640.9

      \[\leadsto \frac{\color{blue}{1 \cdot \left(1 - \cos x\right)}}{x \cdot x}\]
    4. Applied times-frac_binary640.5

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

    if -0.0320353186071557147 < x < 0.029706365761949148

    1. Initial program 62.3

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

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

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

    if 0.029706365761949148 < x

    1. Initial program 1.2

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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