Average Error: 30.1 → 0.5
Time: 7.8s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0236105927013185481:\\ \;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\ \mathbf{elif}\;x \le 0.0199371016091038876:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{1}{\frac{\sin x}{1 - \cos x}}}\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0236105927013185481:\\
\;\;\;\;\frac{1}{\sin x} - \frac{\cos x}{\sin x}\\

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

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

\end{array}
double f(double x) {
        double r63930 = 1.0;
        double r63931 = x;
        double r63932 = cos(r63931);
        double r63933 = r63930 - r63932;
        double r63934 = sin(r63931);
        double r63935 = r63933 / r63934;
        return r63935;
}

double f(double x) {
        double r63936 = x;
        double r63937 = -0.023610592701318548;
        bool r63938 = r63936 <= r63937;
        double r63939 = 1.0;
        double r63940 = sin(r63936);
        double r63941 = r63939 / r63940;
        double r63942 = cos(r63936);
        double r63943 = r63942 / r63940;
        double r63944 = r63941 - r63943;
        double r63945 = 0.019937101609103888;
        bool r63946 = r63936 <= r63945;
        double r63947 = 0.041666666666666664;
        double r63948 = 3.0;
        double r63949 = pow(r63936, r63948);
        double r63950 = r63947 * r63949;
        double r63951 = 0.004166666666666667;
        double r63952 = 5.0;
        double r63953 = pow(r63936, r63952);
        double r63954 = r63951 * r63953;
        double r63955 = 0.5;
        double r63956 = r63955 * r63936;
        double r63957 = r63954 + r63956;
        double r63958 = r63950 + r63957;
        double r63959 = 1.0;
        double r63960 = r63939 - r63942;
        double r63961 = r63940 / r63960;
        double r63962 = r63959 / r63961;
        double r63963 = exp(r63962);
        double r63964 = log(r63963);
        double r63965 = r63946 ? r63958 : r63964;
        double r63966 = r63938 ? r63944 : r63965;
        return r63966;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -0.023610592701318548

    1. Initial program 0.9

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

      \[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]

    if -0.023610592701318548 < x < 0.019937101609103888

    1. Initial program 59.7

      \[\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)}\]

    if 0.019937101609103888 < x

    1. Initial program 0.8

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

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

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

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

Reproduce

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

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

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