Average Error: 31.3 → 0.2
Time: 4.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0323079859093642272 \lor \neg \left(x \le 0.032378188989300311\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0323079859093642272 \lor \neg \left(x \le 0.032378188989300311\right):\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
	double VAR;
	if (((x <= -0.03230798590936423) || !(x <= 0.03237818898930031))) {
		VAR = (((1.0 - cos(x)) / x) / x);
	} else {
		VAR = fma(pow(x, 4.0), 0.001388888888888889, (0.5 - (0.041666666666666664 * 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 < -0.03230798590936423 or 0.03237818898930031 < x

    1. Initial program 1.0

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

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

    if -0.03230798590936423 < x < 0.03237818898930031

    1. Initial program 62.3

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

      \[\leadsto \color{blue}{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\]
    3. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0323079859093642272 \lor \neg \left(x \le 0.032378188989300311\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020103 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  :precision binary64
  (/ (- 1 (cos x)) (* x x)))