Average Error: 30.4 → 0.5
Time: 7.6s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0198749278940998884 \lor \neg \left(x \le 0.022259987926796919\right):\\ \;\;\;\;\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{\frac{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}{1 - \cos x}}\\ \mathbf{else}:\\ \;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.0198749278940998884 \lor \neg \left(x \le 0.022259987926796919\right):\\
\;\;\;\;\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{\frac{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}{1 - \cos x}}\\

\mathbf{else}:\\
\;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\

\end{array}
double f(double x) {
        double r53088 = 1.0;
        double r53089 = x;
        double r53090 = cos(r53089);
        double r53091 = r53088 - r53090;
        double r53092 = sin(r53089);
        double r53093 = r53091 / r53092;
        return r53093;
}

double f(double x) {
        double r53094 = x;
        double r53095 = -0.01987492789409989;
        bool r53096 = r53094 <= r53095;
        double r53097 = 0.02225998792679692;
        bool r53098 = r53094 <= r53097;
        double r53099 = !r53098;
        bool r53100 = r53096 || r53099;
        double r53101 = 1.0;
        double r53102 = r53101 * r53101;
        double r53103 = cos(r53094);
        double r53104 = r53103 * r53103;
        double r53105 = r53101 * r53103;
        double r53106 = r53104 + r53105;
        double r53107 = r53102 + r53106;
        double r53108 = r53103 + r53101;
        double r53109 = r53103 * r53108;
        double r53110 = r53109 + r53102;
        double r53111 = sin(r53094);
        double r53112 = r53110 * r53111;
        double r53113 = r53101 - r53103;
        double r53114 = r53112 / r53113;
        double r53115 = r53107 / r53114;
        double r53116 = 0.04166666666666663;
        double r53117 = 3.0;
        double r53118 = pow(r53094, r53117);
        double r53119 = r53116 * r53118;
        double r53120 = 0.004166666666666624;
        double r53121 = 5.0;
        double r53122 = pow(r53094, r53121);
        double r53123 = r53120 * r53122;
        double r53124 = 0.5;
        double r53125 = r53124 * r53094;
        double r53126 = r53123 + r53125;
        double r53127 = r53119 + r53126;
        double r53128 = r53100 ? r53115 : r53127;
        return r53128;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.01987492789409989 or 0.02225998792679692 < x

    1. Initial program 0.8

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

      \[\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. Applied associate-/l/1.0

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

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

      \[\leadsto \frac{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    8. Applied associate-/l*1.0

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

    if -0.01987492789409989 < x < 0.02225998792679692

    1. Initial program 59.8

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

      \[\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. Applied associate-/l/59.9

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right)}}\]
    5. Simplified59.9

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}}\]
    6. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0198749278940998884 \lor \neg \left(x \le 0.022259987926796919\right):\\ \;\;\;\;\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{\frac{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}{1 - \cos x}}\\ \mathbf{else}:\\ \;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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