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

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

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

\end{array}
double f(double x) {
        double r51210 = 1.0;
        double r51211 = x;
        double r51212 = cos(r51211);
        double r51213 = r51210 - r51212;
        double r51214 = sin(r51211);
        double r51215 = r51213 / r51214;
        return r51215;
}

double f(double x) {
        double r51216 = x;
        double r51217 = -0.024280922068190693;
        bool r51218 = r51216 <= r51217;
        double r51219 = 1.0;
        double r51220 = sin(r51216);
        double r51221 = r51219 / r51220;
        double r51222 = cos(r51216);
        double r51223 = r51222 / r51220;
        double r51224 = r51221 - r51223;
        double r51225 = 0.02165047000055947;
        bool r51226 = r51216 <= r51225;
        double r51227 = 0.041666666666666664;
        double r51228 = 3.0;
        double r51229 = pow(r51216, r51228);
        double r51230 = r51227 * r51229;
        double r51231 = 0.004166666666666667;
        double r51232 = 5.0;
        double r51233 = pow(r51216, r51232);
        double r51234 = r51231 * r51233;
        double r51235 = 0.5;
        double r51236 = r51235 * r51216;
        double r51237 = r51234 + r51236;
        double r51238 = r51230 + r51237;
        double r51239 = r51219 - r51222;
        double r51240 = exp(r51239);
        double r51241 = log(r51240);
        double r51242 = r51241 / r51220;
        double r51243 = r51226 ? r51238 : r51242;
        double r51244 = r51218 ? r51224 : r51243;
        return r51244;
}

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.6
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    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.024280922068190693 < x < 0.02165047000055947

    1. Initial program 60.0

      \[\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.02165047000055947 < x

    1. Initial program 0.9

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

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

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

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

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

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

Reproduce

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

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

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