Average Error: 30.5 → 0.8
Time: 13.2s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le \frac{-5229510784124623}{144115188075855872} \lor \neg \left(\frac{1 - \cos x}{\sin x} \le \frac{7660195654784967}{4722366482869645213696}\right):\\ \;\;\;\;\frac{\cos x + \left(-1\right)}{-\sin x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le \frac{-5229510784124623}{144115188075855872} \lor \neg \left(\frac{1 - \cos x}{\sin x} \le \frac{7660195654784967}{4722366482869645213696}\right):\\
\;\;\;\;\frac{\cos x + \left(-1\right)}{-\sin x}\\

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

\end{array}
double f(double x) {
        double r39252 = 1.0;
        double r39253 = x;
        double r39254 = cos(r39253);
        double r39255 = r39252 - r39254;
        double r39256 = sin(r39253);
        double r39257 = r39255 / r39256;
        return r39257;
}

double f(double x) {
        double r39258 = 1.0;
        double r39259 = x;
        double r39260 = cos(r39259);
        double r39261 = r39258 - r39260;
        double r39262 = sin(r39259);
        double r39263 = r39261 / r39262;
        double r39264 = -5229510784124623.0;
        double r39265 = 1.4411518807585587e+17;
        double r39266 = r39264 / r39265;
        bool r39267 = r39263 <= r39266;
        double r39268 = 7660195654784967.0;
        double r39269 = 4.722366482869645e+21;
        double r39270 = r39268 / r39269;
        bool r39271 = r39263 <= r39270;
        double r39272 = !r39271;
        bool r39273 = r39267 || r39272;
        double r39274 = -r39258;
        double r39275 = r39260 + r39274;
        double r39276 = -r39262;
        double r39277 = r39275 / r39276;
        double r39278 = 0.041666666666666664;
        double r39279 = 3.0;
        double r39280 = pow(r39259, r39279);
        double r39281 = r39278 * r39280;
        double r39282 = 0.004166666666666667;
        double r39283 = 5.0;
        double r39284 = pow(r39259, r39283);
        double r39285 = r39282 * r39284;
        double r39286 = 0.5;
        double r39287 = r39286 * r39259;
        double r39288 = r39285 + r39287;
        double r39289 = r39281 + r39288;
        double r39290 = r39273 ? r39277 : r39289;
        return r39290;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.5
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.036287020500379456 or 1.622109525504274e-06 < (/ (- 1.0 (cos x)) (sin x))

    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 frac-2neg0.9

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

      \[\leadsto \frac{\color{blue}{\cos x + \left(-1\right)}}{-\sin x}\]

    if -0.036287020500379456 < (/ (- 1.0 (cos x)) (sin x)) < 1.622109525504274e-06

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)}\]
  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{-5229510784124623}{144115188075855872} \lor \neg \left(\frac{1 - \cos x}{\sin x} \le \frac{7660195654784967}{4722366482869645213696}\right):\\ \;\;\;\;\frac{\cos x + \left(-1\right)}{-\sin x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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