Average Error: 30.5 → 0.5
Time: 23.6s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02120801236249347798690223498851992189884 \lor \neg \left(x \le 0.02196010544527774235867845220582239562646\right):\\ \;\;\;\;\frac{\frac{\left(1 - \cos x\right) \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\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}\;x \le -0.02120801236249347798690223498851992189884 \lor \neg \left(x \le 0.02196010544527774235867845220582239562646\right):\\
\;\;\;\;\frac{\frac{\left(1 - \cos x\right) \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\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 r68476 = 1.0;
        double r68477 = x;
        double r68478 = cos(r68477);
        double r68479 = r68476 - r68478;
        double r68480 = sin(r68477);
        double r68481 = r68479 / r68480;
        return r68481;
}

double f(double x) {
        double r68482 = x;
        double r68483 = -0.021208012362493478;
        bool r68484 = r68482 <= r68483;
        double r68485 = 0.021960105445277742;
        bool r68486 = r68482 <= r68485;
        double r68487 = !r68486;
        bool r68488 = r68484 || r68487;
        double r68489 = 1.0;
        double r68490 = cos(r68482);
        double r68491 = r68489 - r68490;
        double r68492 = r68490 + r68489;
        double r68493 = r68490 * r68492;
        double r68494 = r68489 * r68489;
        double r68495 = r68493 + r68494;
        double r68496 = r68491 * r68495;
        double r68497 = r68496 / r68495;
        double r68498 = sin(r68482);
        double r68499 = r68497 / r68498;
        double r68500 = 0.041666666666666664;
        double r68501 = 3.0;
        double r68502 = pow(r68482, r68501);
        double r68503 = r68500 * r68502;
        double r68504 = 0.004166666666666667;
        double r68505 = 5.0;
        double r68506 = pow(r68482, r68505);
        double r68507 = r68504 * r68506;
        double r68508 = 0.5;
        double r68509 = r68508 * r68482;
        double r68510 = r68507 + r68509;
        double r68511 = r68503 + r68510;
        double r68512 = r68488 ? r68499 : r68511;
        return r68512;
}

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.021208012362493478 or 0.021960105445277742 < x

    1. Initial program 0.9

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

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{\sin x}\]
    4. Simplified1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    5. Using strategy rm
    6. Applied add-log-exp1.1

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

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

      \[\leadsto \frac{\frac{\color{blue}{\log \left(\frac{e^{{1}^{3}}}{e^{{\left(\cos x\right)}^{3}}}\right)}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    9. Simplified1.0

      \[\leadsto \frac{\frac{\log \color{blue}{\left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    10. Using strategy rm
    11. Applied difference-cubes1.0

      \[\leadsto \frac{\frac{\log \left(e^{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}\right)}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    12. Applied exp-prod1.1

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

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

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

    if -0.021208012362493478 < x < 0.021960105445277742

    1. Initial program 59.9

      \[\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02120801236249347798690223498851992189884 \lor \neg \left(x \le 0.02196010544527774235867845220582239562646\right):\\ \;\;\;\;\frac{\frac{\left(1 - \cos x\right) \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\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 2019306 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

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

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