Average Error: 31.5 → 0.3
Time: 3.9s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0340458149574629151 \lor \neg \left(x \le 0.032087851221962699\right):\\ \;\;\;\;\frac{\frac{\sqrt[3]{{\left(1 - \cos x\right)}^{3}}}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\right)\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0340458149574629151 \lor \neg \left(x \le 0.032087851221962699\right):\\
\;\;\;\;\frac{\frac{\sqrt[3]{{\left(1 - \cos x\right)}^{3}}}{x}}{x}\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\right)\\

\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.034045814957462915) || !(x <= 0.0320878512219627))) {
		VAR = ((double) (((double) (((double) cbrt(((double) pow(((double) (1.0 - ((double) cos(x)))), 3.0)))) / x)) / x));
	} else {
		VAR = ((double) log(((double) exp(((double) (((double) (((double) (0.001388888888888889 * ((double) pow(x, 4.0)))) + 0.5)) - ((double) (0.041666666666666664 * ((double) 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.034045814957462915 or 0.0320878512219627 < x

    1. Initial program 1.1

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

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

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

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

    if -0.034045814957462915 < x < 0.0320878512219627

    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. Using strategy rm
    4. Applied add-log-exp0.0

      \[\leadsto \left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \color{blue}{\log \left(e^{\frac{1}{24} \cdot {x}^{2}}\right)}\]
    5. Applied add-log-exp0.0

      \[\leadsto \left(\frac{1}{720} \cdot {x}^{4} + \color{blue}{\log \left(e^{\frac{1}{2}}\right)}\right) - \log \left(e^{\frac{1}{24} \cdot {x}^{2}}\right)\]
    6. Applied add-log-exp0.0

      \[\leadsto \left(\color{blue}{\log \left(e^{\frac{1}{720} \cdot {x}^{4}}\right)} + \log \left(e^{\frac{1}{2}}\right)\right) - \log \left(e^{\frac{1}{24} \cdot {x}^{2}}\right)\]
    7. Applied sum-log0.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{1}{720} \cdot {x}^{4}} \cdot e^{\frac{1}{2}}\right)} - \log \left(e^{\frac{1}{24} \cdot {x}^{2}}\right)\]
    8. Applied diff-log0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0340458149574629151 \lor \neg \left(x \le 0.032087851221962699\right):\\ \;\;\;\;\frac{\frac{\sqrt[3]{{\left(1 - \cos x\right)}^{3}}}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\right)\\ \end{array}\]

Reproduce

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