Average Error: 32.3 → 0.4
Time: 5.0s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.031852880928243552 \lor \neg \left(x \le 0.0331689024500812293\right):\\ \;\;\;\;\frac{1}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{1 - \cos x}{\sqrt[3]{x} \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.031852880928243552 \lor \neg \left(x \le 0.0331689024500812293\right):\\
\;\;\;\;\frac{1}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{1 - \cos x}{\sqrt[3]{x} \cdot x}\\

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

\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.03185288092824355) || !(x <= 0.03316890245008123))) {
		VAR = ((double) (((double) (1.0 / ((double) (((double) cbrt(x)) * ((double) cbrt(x)))))) * ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) (((double) cbrt(x)) * x))))));
	} else {
		VAR = ((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.03185288092824355 or 0.03316890245008123 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt1.5

      \[\leadsto \frac{1 - \cos x}{\color{blue}{\left(\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}\right)} \cdot x}\]
    4. Applied associate-*l*1.5

      \[\leadsto \frac{1 - \cos x}{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \left(\sqrt[3]{x} \cdot x\right)}}\]
    5. Applied *-un-lft-identity1.5

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

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

    if -0.03185288092824355 < x < 0.03316890245008123

    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. Recombined 2 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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