Average Error: 31.5 → 0.3
Time: 4.6s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0294506023913276259:\\ \;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - {\left(\cos x\right)}^{3}} \cdot \left(1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}\right)}}{x}\\ \mathbf{elif}\;x \le 0.031832795793103552:\\ \;\;\;\;\frac{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0294506023913276259:\\
\;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - {\left(\cos x\right)}^{3}} \cdot \left(1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}\right)}}{x}\\

\mathbf{elif}\;x \le 0.031832795793103552:\\
\;\;\;\;\frac{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}{x}\\

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / (x * x));
}
double code(double x) {
	double VAR;
	if ((x <= -0.029450602391327626)) {
		VAR = ((1.0 / ((x / (pow(1.0, 3.0) - pow(cos(x), 3.0))) * ((1.0 * 1.0) + ((pow(cos(x), 2.0) * (pow(cos(x), 2.0) - (1.0 * 1.0))) / (cos(x) * (cos(x) - 1.0)))))) / x);
	} else {
		double VAR_1;
		if ((x <= 0.03183279579310355)) {
			VAR_1 = ((((0.5 * x) + (0.001388888888888889 * pow(x, 5.0))) - (0.041666666666666664 * pow(x, 3.0))) / x);
		} else {
			VAR_1 = ((1.0 / ((x / (pow(1.0, 3.0) - cbrt(pow(pow(cos(x), 3.0), 3.0)))) * ((1.0 * 1.0) + ((cos(x) * cos(x)) + (1.0 * 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.029450602391327626

    1. Initial program 1.0

      \[\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 clear-num0.5

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

      \[\leadsto \frac{\frac{1}{\frac{x}{\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}\]
    8. Applied associate-/r/0.5

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{x}{{1}^{3} - {\left(\cos x\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}}{x}\]
    9. Using strategy rm
    10. Applied flip-+0.5

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

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

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

    if -0.029450602391327626 < x < 0.03183279579310355

    1. Initial program 62.3

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

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]
    4. Taylor expanded around 0 0.0

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

    if 0.03183279579310355 < x

    1. Initial program 1.0

      \[\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 clear-num0.5

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

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

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{x}{{1}^{3} - {\left(\cos x\right)}^{3}} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}}{x}\]
    9. Using strategy rm
    10. Applied add-cbrt-cube0.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0294506023913276259:\\ \;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - {\left(\cos x\right)}^{3}} \cdot \left(1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}\right)}}{x}\\ \mathbf{elif}\;x \le 0.031832795793103552:\\ \;\;\;\;\frac{\left(\frac{1}{2} \cdot x + \frac{1}{720} \cdot {x}^{5}\right) - \frac{1}{24} \cdot {x}^{3}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\frac{x}{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}} \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}{x}\\ \end{array}\]

Reproduce

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