Average Error: 30.2 → 0.5
Time: 25.3s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0204534462520135039 \lor \neg \left(x \le 0.0200301762317355962\right):\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\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.0204534462520135039 \lor \neg \left(x \le 0.0200301762317355962\right):\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\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 r59688 = 1.0;
        double r59689 = x;
        double r59690 = cos(r59689);
        double r59691 = r59688 - r59690;
        double r59692 = sin(r59689);
        double r59693 = r59691 / r59692;
        return r59693;
}

double f(double x) {
        double r59694 = x;
        double r59695 = -0.020453446252013504;
        bool r59696 = r59694 <= r59695;
        double r59697 = 0.020030176231735596;
        bool r59698 = r59694 <= r59697;
        double r59699 = !r59698;
        bool r59700 = r59696 || r59699;
        double r59701 = 1.0;
        double r59702 = cos(r59694);
        double r59703 = r59701 - r59702;
        double r59704 = log(r59703);
        double r59705 = exp(r59704);
        double r59706 = sin(r59694);
        double r59707 = r59705 / r59706;
        double r59708 = 0.041666666666666664;
        double r59709 = 3.0;
        double r59710 = pow(r59694, r59709);
        double r59711 = r59708 * r59710;
        double r59712 = 0.004166666666666667;
        double r59713 = 5.0;
        double r59714 = pow(r59694, r59713);
        double r59715 = r59712 * r59714;
        double r59716 = 0.5;
        double r59717 = r59716 * r59694;
        double r59718 = r59715 + r59717;
        double r59719 = r59711 + r59718;
        double r59720 = r59700 ? r59707 : r59719;
        return r59720;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.2
Target0.0
Herbie0.5
\[\tan \left(\frac{x}{2}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if x < -0.020453446252013504 or 0.020030176231735596 < x

    1. Initial program 0.9

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

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

    if -0.020453446252013504 < x < 0.020030176231735596

    1. Initial program 59.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0204534462520135039 \lor \neg \left(x \le 0.0200301762317355962\right):\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\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 2019198 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 2

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

  (/ (- 1.0 (cos x)) (sin x)))