Average Error: 31.7 → 0.3
Time: 4.2s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0331923795595217772:\\ \;\;\;\;\frac{1}{x} \cdot \frac{1 - \cos x}{x}\\ \mathbf{elif}\;x \le 0.030982935793368763:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - \mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0331923795595217772:\\
\;\;\;\;\frac{1}{x} \cdot \frac{1 - \cos x}{x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - \mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}\\

\end{array}
double code(double x) {
	return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) (x * x))));
}
double code(double x) {
	double VAR;
	if ((x <= -0.03319237955952178)) {
		VAR = ((double) (((double) (1.0 / x)) * ((double) (((double) (1.0 - ((double) cos(x)))) / x))));
	} else {
		double VAR_1;
		if ((x <= 0.030982935793368763)) {
			VAR_1 = ((double) fma(((double) pow(x, 4.0)), 0.001388888888888889, ((double) (0.5 - ((double) (0.041666666666666664 * ((double) pow(x, 2.0))))))));
		} else {
			VAR_1 = ((double) (((double) (1.0 / x)) * ((double) (((double) (((double) pow(1.0, 3.0)) - ((double) log1p(((double) expm1(((double) pow(((double) cos(x)), 3.0)))))))) / ((double) (((double) fma(1.0, 1.0, ((double) fma(((double) cos(x)), ((double) cos(x)), ((double) (1.0 * ((double) cos(x)))))))) * 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.03319237955952178

    1. Initial program 1.1

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

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

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

    if -0.03319237955952178 < x < 0.030982935793368763

    1. Initial program 62.2

      \[\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)}\]

    if 0.030982935793368763 < x

    1. Initial program 1.2

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

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

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \frac{1 - \cos x}{x}}\]
    5. Using strategy rm
    6. Applied flip3--0.6

      \[\leadsto \frac{1}{x} \cdot \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}\]
    7. Applied associate-/l/0.6

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

      \[\leadsto \frac{1}{x} \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}}\]
    9. Using strategy rm
    10. Applied log1p-expm1-u0.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0331923795595217772:\\ \;\;\;\;\frac{1}{x} \cdot \frac{1 - \cos x}{x}\\ \mathbf{elif}\;x \le 0.030982935793368763:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, \frac{1}{720}, \frac{1}{2} - \frac{1}{24} \cdot {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} \cdot \frac{{1}^{3} - \mathsf{log1p}\left(\mathsf{expm1}\left({\left(\cos x\right)}^{3}\right)\right)}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot x}\\ \end{array}\]

Reproduce

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