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

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

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

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

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied clear-num_binary641.0

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x}{1 - \cos x}}}\]
    4. Simplified1.0

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{1 - \cos x}{x}}}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt_binary641.1

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{x}{\frac{1 - \cos x}{x}}}} \cdot \sqrt{\frac{1}{\frac{x}{\frac{1 - \cos x}{x}}}}}\]
    7. Simplified1.1

      \[\leadsto \color{blue}{\sqrt{\frac{\frac{1 - \cos x}{x}}{x}}} \cdot \sqrt{\frac{1}{\frac{x}{\frac{1 - \cos x}{x}}}}\]
    8. Simplified0.6

      \[\leadsto \sqrt{\frac{\frac{1 - \cos x}{x}}{x}} \cdot \color{blue}{\sqrt{\frac{\frac{1 - \cos x}{x}}{x}}}\]
    9. Using strategy rm
    10. Applied flip--_binary640.7

      \[\leadsto \sqrt{\frac{\frac{1 - \cos x}{x}}{x}} \cdot \sqrt{\frac{\frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x}}{x}}\]
    11. Using strategy rm
    12. Applied sqr-cos-a_binary640.8

      \[\leadsto \sqrt{\frac{\frac{1 - \cos x}{x}}{x}} \cdot \sqrt{\frac{\frac{\frac{1 \cdot 1 - \color{blue}{\left(0.5 + 0.5 \cdot \cos \left(2 \cdot x\right)\right)}}{1 + \cos x}}{x}}{x}}\]
    13. Applied associate--r+_binary640.8

      \[\leadsto \sqrt{\frac{\frac{1 - \cos x}{x}}{x}} \cdot \sqrt{\frac{\frac{\frac{\color{blue}{\left(1 \cdot 1 - 0.5\right) - 0.5 \cdot \cos \left(2 \cdot x\right)}}{1 + \cos x}}{x}}{x}}\]

    if -0.0256016836812942884 < x < 0.0259712941369484619

    1. Initial program 62.1

      \[\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.0259712941369484619 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied clear-num_binary641.1

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

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

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

Reproduce

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