Average Error: 29.4 → 0.6
Time: 12.6s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0246265005946238076 \lor \neg \left(x \le 0.023818992858148251\right):\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left(\cos x\right)}^{9}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0246265005946238076 \lor \neg \left(x \le 0.023818992858148251\right):\\
\;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left(\cos x\right)}^{9}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\

\end{array}
double f(double x) {
        double r301 = 1.0;
        double r302 = x;
        double r303 = cos(r302);
        double r304 = r301 - r303;
        double r305 = sin(r302);
        double r306 = r304 / r305;
        return r306;
}

double f(double x) {
        double r307 = x;
        double r308 = -0.024626500594623808;
        bool r309 = r307 <= r308;
        double r310 = 0.02381899285814825;
        bool r311 = r307 <= r310;
        double r312 = !r311;
        bool r313 = r309 || r312;
        double r314 = 1.0;
        double r315 = 3.0;
        double r316 = pow(r314, r315);
        double r317 = cos(r307);
        double r318 = 9.0;
        double r319 = pow(r317, r318);
        double r320 = cbrt(r319);
        double r321 = r316 - r320;
        double r322 = r317 + r314;
        double r323 = r317 * r322;
        double r324 = r314 * r314;
        double r325 = r323 + r324;
        double r326 = sin(r307);
        double r327 = r325 * r326;
        double r328 = r321 / r327;
        double r329 = 0.041666666666666664;
        double r330 = pow(r307, r315);
        double r331 = r329 * r330;
        double r332 = 0.004166666666666667;
        double r333 = 5.0;
        double r334 = pow(r307, r333);
        double r335 = r332 * r334;
        double r336 = 0.5;
        double r337 = r336 * r307;
        double r338 = r335 + r337;
        double r339 = r331 + r338;
        double r340 = r313 ? r328 : r339;
        return r340;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.4
Target0.0
Herbie0.6
\[\tan \left(\frac{x}{2}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.024626500594623808 or 0.02381899285814825 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--1.0

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{\sin x}\]
    4. Applied associate-/l/1.0

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

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

      \[\leadsto \frac{{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}}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    8. Simplified1.1

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

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

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

    if -0.024626500594623808 < x < 0.02381899285814825

    1. Initial program 59.8

      \[\frac{1 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0246265005946238076 \lor \neg \left(x \le 0.023818992858148251\right):\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left(\cos x\right)}^{9}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020025 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

  :herbie-target
  (tan (/ x 2))

  (/ (- 1 (cos x)) (sin x)))