Average Error: 30.1 → 1.0
Time: 24.7s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.04371460353231055445677455395525612402707:\\ \;\;\;\;\frac{e^{\log \left({1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \left(\cos x \cdot \cos x\right)\right)\right)\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}, 1 \cdot 1\right)}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 6.2937074645496283672486959037684073337 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot \left(x \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.04371460353231055445677455395525612402707:\\
\;\;\;\;\frac{e^{\log \left({1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \left(\cos x \cdot \cos x\right)\right)\right)\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}, 1 \cdot 1\right)}\\

\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 6.2937074645496283672486959037684073337 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot \left(x \cdot x\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\

\end{array}
double f(double x) {
        double r2555490 = 1.0;
        double r2555491 = x;
        double r2555492 = cos(r2555491);
        double r2555493 = r2555490 - r2555492;
        double r2555494 = sin(r2555491);
        double r2555495 = r2555493 / r2555494;
        return r2555495;
}

double f(double x) {
        double r2555496 = 1.0;
        double r2555497 = x;
        double r2555498 = cos(r2555497);
        double r2555499 = r2555496 - r2555498;
        double r2555500 = sin(r2555497);
        double r2555501 = r2555499 / r2555500;
        double r2555502 = -0.043714603532310554;
        bool r2555503 = r2555501 <= r2555502;
        double r2555504 = 3.0;
        double r2555505 = pow(r2555496, r2555504);
        double r2555506 = r2555498 * r2555498;
        double r2555507 = r2555498 * r2555506;
        double r2555508 = log1p(r2555507);
        double r2555509 = expm1(r2555508);
        double r2555510 = r2555505 - r2555509;
        double r2555511 = log(r2555510);
        double r2555512 = exp(r2555511);
        double r2555513 = r2555496 * r2555496;
        double r2555514 = r2555513 - r2555506;
        double r2555515 = r2555514 / r2555499;
        double r2555516 = fma(r2555498, r2555515, r2555513);
        double r2555517 = r2555500 * r2555516;
        double r2555518 = r2555512 / r2555517;
        double r2555519 = 6.293707464549628e-05;
        bool r2555520 = r2555501 <= r2555519;
        double r2555521 = 0.004166666666666667;
        double r2555522 = 5.0;
        double r2555523 = pow(r2555497, r2555522);
        double r2555524 = 0.5;
        double r2555525 = 0.041666666666666664;
        double r2555526 = r2555497 * r2555497;
        double r2555527 = r2555525 * r2555526;
        double r2555528 = r2555524 + r2555527;
        double r2555529 = r2555497 * r2555528;
        double r2555530 = fma(r2555521, r2555523, r2555529);
        double r2555531 = exp(1.0);
        double r2555532 = log(r2555499);
        double r2555533 = pow(r2555531, r2555532);
        double r2555534 = r2555533 / r2555500;
        double r2555535 = r2555520 ? r2555530 : r2555534;
        double r2555536 = r2555503 ? r2555518 : r2555535;
        return r2555536;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/ (- 1.0 (cos x)) (sin x)) < -0.043714603532310554

    1. Initial program 0.7

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
    4. Using strategy rm
    5. Applied flip3--0.8

      \[\leadsto \frac{e^{\log \color{blue}{\left(\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}\right)}}}{\sin x}\]
    6. Applied log-div0.8

      \[\leadsto \frac{e^{\color{blue}{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right) - \log \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}}{\sin x}\]
    7. Applied exp-diff0.8

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

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

      \[\leadsto \frac{e^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}}{\color{blue}{\sin x \cdot \mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}\]
    10. Using strategy rm
    11. Applied expm1-log1p-u0.8

      \[\leadsto \frac{e^{\log \left({1}^{3} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\]
    12. Simplified0.8

      \[\leadsto \frac{e^{\log \left({1}^{3} - \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right)}\right)\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\]
    13. Using strategy rm
    14. Applied flip-+0.8

      \[\leadsto \frac{e^{\log \left({1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right)\right)\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}}, 1 \cdot 1\right)}\]

    if -0.043714603532310554 < (/ (- 1.0 (cos x)) (sin x)) < 6.293707464549628e-05

    1. Initial program 59.2

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
    4. Taylor expanded around 0 0.9

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{24} \cdot {x}^{3} + \frac{1}{240} \cdot {x}^{5}\right)}\]
    5. Simplified0.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, x \cdot \left(\frac{1}{2} + \left(x \cdot x\right) \cdot \frac{1}{24}\right)\right)}\]

    if 6.293707464549628e-05 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.1

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
    4. Using strategy rm
    5. Applied pow11.1

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

      \[\leadsto \frac{e^{\color{blue}{1 \cdot \log \left(1 - \cos x\right)}}}{\sin x}\]
    7. Applied exp-prod1.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.04371460353231055445677455395525612402707:\\ \;\;\;\;\frac{e^{\log \left({1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left(\cos x \cdot \left(\cos x \cdot \cos x\right)\right)\right)\right)}}{\sin x \cdot \mathsf{fma}\left(\cos x, \frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}, 1 \cdot 1\right)}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 6.2937074645496283672486959037684073337 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{240}, {x}^{5}, x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot \left(x \cdot x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{e}^{\left(\log \left(1 - \cos x\right)\right)}}{\sin x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019179 +o rules:numerics
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 2

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

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