Average Error: 31.3 → 0.4
Time: 10.3s
Precision: 64
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.03315307006442389:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{x \cdot x}\\ \mathbf{elif}\;x \le 0.0315772250058030321:\\ \;\;\;\;\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\ \end{array}\]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \le -0.03315307006442389:\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{x \cdot x}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{1 - \cos x}}{x} \cdot \frac{\sqrt{1 - \cos x}}{x}\\

\end{array}
double f(double x) {
        double r34141 = 1.0;
        double r34142 = x;
        double r34143 = cos(r34142);
        double r34144 = r34141 - r34143;
        double r34145 = r34142 * r34142;
        double r34146 = r34144 / r34145;
        return r34146;
}

double f(double x) {
        double r34147 = x;
        double r34148 = -0.03315307006442389;
        bool r34149 = r34147 <= r34148;
        double r34150 = 1.0;
        double r34151 = cos(r34147);
        double r34152 = r34150 - r34151;
        double r34153 = log(r34152);
        double r34154 = exp(r34153);
        double r34155 = r34147 * r34147;
        double r34156 = r34154 / r34155;
        double r34157 = 0.03157722500580303;
        bool r34158 = r34147 <= r34157;
        double r34159 = 0.001388888888888889;
        double r34160 = 4.0;
        double r34161 = pow(r34147, r34160);
        double r34162 = r34159 * r34161;
        double r34163 = 0.5;
        double r34164 = r34162 + r34163;
        double r34165 = 0.041666666666666664;
        double r34166 = 2.0;
        double r34167 = pow(r34147, r34166);
        double r34168 = r34165 * r34167;
        double r34169 = r34164 - r34168;
        double r34170 = sqrt(r34152);
        double r34171 = r34170 / r34147;
        double r34172 = r34171 * r34171;
        double r34173 = r34158 ? r34169 : r34172;
        double r34174 = r34149 ? r34156 : r34173;
        return r34174;
}

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.03315307006442389

    1. Initial program 0.9

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied add-exp-log0.9

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

    if -0.03315307006442389 < x < 0.03157722500580303

    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.03157722500580303 < x

    1. Initial program 1.0

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

      \[\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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

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

Reproduce

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