Average Error: 29.4 → 0.6
Time: 7.2s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0246265005946238076 \lor \neg \left(x \le 0.023818992858148251\right):\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left(\cos x\right)}^{9}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \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.0246265005946238076 \lor \neg \left(x \le 0.023818992858148251\right):\\
\;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left(\cos x\right)}^{9}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \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 r49163 = 1.0;
        double r49164 = x;
        double r49165 = cos(r49164);
        double r49166 = r49163 - r49165;
        double r49167 = sin(r49164);
        double r49168 = r49166 / r49167;
        return r49168;
}

double f(double x) {
        double r49169 = x;
        double r49170 = -0.024626500594623808;
        bool r49171 = r49169 <= r49170;
        double r49172 = 0.02381899285814825;
        bool r49173 = r49169 <= r49172;
        double r49174 = !r49173;
        bool r49175 = r49171 || r49174;
        double r49176 = 1.0;
        double r49177 = 3.0;
        double r49178 = pow(r49176, r49177);
        double r49179 = cos(r49169);
        double r49180 = 9.0;
        double r49181 = pow(r49179, r49180);
        double r49182 = cbrt(r49181);
        double r49183 = r49178 - r49182;
        double r49184 = r49179 + r49176;
        double r49185 = r49179 * r49184;
        double r49186 = r49176 * r49176;
        double r49187 = r49185 + r49186;
        double r49188 = sin(r49169);
        double r49189 = r49187 * r49188;
        double r49190 = r49183 / r49189;
        double r49191 = 0.041666666666666664;
        double r49192 = pow(r49169, r49177);
        double r49193 = r49191 * r49192;
        double r49194 = 0.004166666666666667;
        double r49195 = 5.0;
        double r49196 = pow(r49169, r49195);
        double r49197 = r49194 * r49196;
        double r49198 = 0.5;
        double r49199 = r49198 * r49169;
        double r49200 = r49197 + r49199;
        double r49201 = r49193 + r49200;
        double r49202 = r49175 ? r49190 : r49201;
        return r49202;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.024626500594623808 or 0.02381899285814825 < 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. 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 add-cbrt-cube1.1

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

      \[\leadsto \frac{{1}^{3} - \sqrt[3]{\color{blue}{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    9. Using strategy rm
    10. Applied pow-pow1.1

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

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

    if -0.024626500594623808 < x < 0.02381899285814825

    1. Initial program 59.8

      \[\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.6

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

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

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