Average Error: 30.3 → 0.8
Time: 17.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le \frac{-6098617222933643}{288230376151711744} \lor \neg \left(\frac{1 - \cos x}{\sin x} \le \frac{722237112392411}{9444732965739290427392}\right):\\ \;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{2} \cdot x + \frac{1}{24} \cdot {x}^{3}\right) + \frac{{x}^{5}}{240}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le \frac{-6098617222933643}{288230376151711744} \lor \neg \left(\frac{1 - \cos x}{\sin x} \le \frac{722237112392411}{9444732965739290427392}\right):\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\

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

\end{array}
double f(double x) {
        double r43100 = 1.0;
        double r43101 = x;
        double r43102 = cos(r43101);
        double r43103 = r43100 - r43102;
        double r43104 = sin(r43101);
        double r43105 = r43103 / r43104;
        return r43105;
}

double f(double x) {
        double r43106 = 1.0;
        double r43107 = x;
        double r43108 = cos(r43107);
        double r43109 = r43106 - r43108;
        double r43110 = sin(r43107);
        double r43111 = r43109 / r43110;
        double r43112 = -6098617222933643.0;
        double r43113 = 2.8823037615171174e+17;
        double r43114 = r43112 / r43113;
        bool r43115 = r43111 <= r43114;
        double r43116 = 722237112392411.0;
        double r43117 = 9.44473296573929e+21;
        double r43118 = r43116 / r43117;
        bool r43119 = r43111 <= r43118;
        double r43120 = !r43119;
        bool r43121 = r43115 || r43120;
        double r43122 = 1.0;
        double r43123 = r43110 / r43109;
        double r43124 = r43122 / r43123;
        double r43125 = 2.0;
        double r43126 = r43122 / r43125;
        double r43127 = r43126 * r43107;
        double r43128 = 24.0;
        double r43129 = r43122 / r43128;
        double r43130 = 3.0;
        double r43131 = pow(r43107, r43130);
        double r43132 = r43129 * r43131;
        double r43133 = r43127 + r43132;
        double r43134 = 5.0;
        double r43135 = pow(r43107, r43134);
        double r43136 = 240.0;
        double r43137 = r43135 / r43136;
        double r43138 = r43133 + r43137;
        double r43139 = r43121 ? r43124 : r43138;
        return r43139;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (/ (- 1.0 (cos x)) (sin x)) < -0.021158828935238943 or 7.64698287407724e-08 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.0

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

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

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

    1. Initial program 59.8

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

      \[\leadsto \frac{1 - \color{blue}{\log \left(e^{\cos x}\right)}}{\sin x}\]
    4. Applied add-log-exp59.8

      \[\leadsto \frac{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}{\sin x}\]
    5. Applied diff-log59.8

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

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

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

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

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

Reproduce

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

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

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