Average Error: 31.5 → 0.3
Time: 4.4s
Precision: binary64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03257779273637018:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\sqrt{\log \left(e^{1 - \cos x}\right)}}}{\frac{x}{\sqrt{\sqrt{1 - \cos x}}}}\\ \mathbf{elif}\;x \le 0.034749697714557222:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03257779273637018:\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\sqrt{\log \left(e^{1 - \cos x}\right)}}}{\frac{x}{\sqrt{\sqrt{1 - \cos x}}}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x} \cdot \frac{\sqrt{\log \left(e^{1 - \cos x}\right)}}{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.03257779273637018)) {
		VAR = ((double) (((double) (((double) sqrt(((double) (1.0 - ((double) cos(x)))))) / x)) * ((double) (((double) sqrt(((double) sqrt(((double) log(((double) exp(((double) (1.0 - ((double) cos(x)))))))))))) / ((double) (x / ((double) sqrt(((double) sqrt(((double) (1.0 - ((double) cos(x))))))))))))));
	} else {
		double VAR_1;
		if ((x <= 0.03474969771455722)) {
			VAR_1 = ((double) (((double) (((double) (0.001388888888888889 * ((double) pow(x, 4.0)))) + 0.5)) - ((double) (0.041666666666666664 * ((double) pow(x, 2.0))))));
		} else {
			VAR_1 = ((double) (((double) (((double) sqrt(((double) (((double) (((double) (1.0 * 1.0)) - ((double) (((double) cos(x)) * ((double) cos(x)))))) / ((double) (1.0 + ((double) cos(x)))))))) / x)) * ((double) (((double) sqrt(((double) log(((double) exp(((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.03257779273637018

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.1

      \[\leadsto \frac{\color{blue}{\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}}}{x \cdot x}\]
    4. Applied times-frac0.6

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \color{blue}{\log \left(e^{\cos x}\right)}}}{x}\]
    7. Applied add-log-exp0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}}{x}\]
    8. Applied diff-log0.6

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

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\sqrt{\log \left(e^{1 - \cos x}\right)} \cdot \sqrt{\log \left(e^{1 - \cos x}\right)}}}}{x}\]
    12. Applied sqrt-prod0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\color{blue}{\sqrt{\sqrt{\log \left(e^{1 - \cos x}\right)}} \cdot \sqrt{\sqrt{\log \left(e^{1 - \cos x}\right)}}}}{x}\]
    13. Applied associate-/l*0.6

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

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

    if -0.03257779273637018 < x < 0.034749697714557222

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

    if 0.034749697714557222 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt1.0

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

      \[\leadsto \color{blue}{\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}}\]
    5. Using strategy rm
    6. Applied add-log-exp0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \color{blue}{\log \left(e^{\cos x}\right)}}}{x}\]
    7. Applied add-log-exp0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}}{x}\]
    8. Applied diff-log0.6

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\color{blue}{\log \left(\frac{e^{1}}{e^{\cos x}}\right)}}}{x}\]
    9. Simplified0.5

      \[\leadsto \frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{\log \color{blue}{\left(e^{1 - \cos x}\right)}}}{x}\]
    10. Using strategy rm
    11. Applied flip--0.7

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

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

Reproduce

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