Average Error: 30.0 → 0.6
Time: 29.2s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.002585231506460964:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 1.53832503201192376 \cdot 10^{-8}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}}{\sin x \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.002585231506460964:\\
\;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\

\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 1.53832503201192376 \cdot 10^{-8}:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\

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

\end{array}
double f(double x) {
        double r30740 = 1.0;
        double r30741 = x;
        double r30742 = cos(r30741);
        double r30743 = r30740 - r30742;
        double r30744 = sin(r30741);
        double r30745 = r30743 / r30744;
        return r30745;
}

double f(double x) {
        double r30746 = 1.0;
        double r30747 = x;
        double r30748 = cos(r30747);
        double r30749 = r30746 - r30748;
        double r30750 = sin(r30747);
        double r30751 = r30749 / r30750;
        double r30752 = -0.0025852315064609638;
        bool r30753 = r30751 <= r30752;
        double r30754 = log(r30749);
        double r30755 = exp(r30754);
        double r30756 = r30755 / r30750;
        double r30757 = 1.5383250320119238e-08;
        bool r30758 = r30751 <= r30757;
        double r30759 = 0.041666666666666664;
        double r30760 = 3.0;
        double r30761 = pow(r30747, r30760);
        double r30762 = r30759 * r30761;
        double r30763 = 0.004166666666666667;
        double r30764 = 5.0;
        double r30765 = pow(r30747, r30764);
        double r30766 = r30763 * r30765;
        double r30767 = 0.5;
        double r30768 = r30767 * r30747;
        double r30769 = r30766 + r30768;
        double r30770 = r30762 + r30769;
        double r30771 = pow(r30746, r30760);
        double r30772 = pow(r30748, r30760);
        double r30773 = r30771 - r30772;
        double r30774 = log(r30773);
        double r30775 = exp(r30774);
        double r30776 = r30748 + r30746;
        double r30777 = r30748 * r30776;
        double r30778 = r30746 * r30746;
        double r30779 = r30777 + r30778;
        double r30780 = r30750 * r30779;
        double r30781 = r30775 / r30780;
        double r30782 = r30758 ? r30770 : r30781;
        double r30783 = r30753 ? r30756 : r30782;
        return r30783;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity0.9

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

    if -0.0025852315064609638 < (/ (- 1.0 (cos x)) (sin x)) < 1.5383250320119238e-08

    1. Initial program 60.3

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

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

    if 1.5383250320119238e-08 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.3

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
    6. Using strategy rm
    7. Applied flip3--1.4

      \[\leadsto \frac{1 \cdot 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}\]
    8. Applied log-div1.5

      \[\leadsto \frac{1 \cdot 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}\]
    9. Applied exp-diff1.4

      \[\leadsto \frac{1 \cdot \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}\]
    10. Applied associate-*r/1.4

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 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}\]
    11. Applied associate-/l/1.4

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}}}\]
    12. Simplified1.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.002585231506460964:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 1.53832503201192376 \cdot 10^{-8}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left({1}^{3} - {\left(\cos x\right)}^{3}\right)}}{\sin x \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}\\ \end{array}\]

Reproduce

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

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

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