Average Error: 29.7 → 0.5
Time: 14.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02328095837562494524464185019496653694659 \lor \neg \left(x \le 0.02122713234710593005472034633385192137212\right):\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}\\ \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.02328095837562494524464185019496653694659 \lor \neg \left(x \le 0.02122713234710593005472034633385192137212\right):\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}\\

\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 r68190 = 1.0;
        double r68191 = x;
        double r68192 = cos(r68191);
        double r68193 = r68190 - r68192;
        double r68194 = sin(r68191);
        double r68195 = r68193 / r68194;
        return r68195;
}

double f(double x) {
        double r68196 = x;
        double r68197 = -0.023280958375624945;
        bool r68198 = r68196 <= r68197;
        double r68199 = 0.02122713234710593;
        bool r68200 = r68196 <= r68199;
        double r68201 = !r68200;
        bool r68202 = r68198 || r68201;
        double r68203 = 1.0;
        double r68204 = 3.0;
        double r68205 = pow(r68203, r68204);
        double r68206 = cos(r68196);
        double r68207 = pow(r68206, r68204);
        double r68208 = r68205 - r68207;
        double r68209 = sin(r68196);
        double r68210 = r68208 / r68209;
        double r68211 = r68206 + r68203;
        double r68212 = r68206 * r68211;
        double r68213 = r68203 * r68203;
        double r68214 = r68212 + r68213;
        double r68215 = r68210 / r68214;
        double r68216 = 0.041666666666666664;
        double r68217 = pow(r68196, r68204);
        double r68218 = r68216 * r68217;
        double r68219 = 0.004166666666666667;
        double r68220 = 5.0;
        double r68221 = pow(r68196, r68220);
        double r68222 = r68219 * r68221;
        double r68223 = 0.5;
        double r68224 = r68223 * r68196;
        double r68225 = r68222 + r68224;
        double r68226 = r68218 + r68225;
        double r68227 = r68202 ? r68215 : r68226;
        return r68227;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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}\]

    if -0.023280958375624945 < x < 0.02122713234710593

    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)}\]

    if 0.02122713234710593 < 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-cube-cbrt1.2

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

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

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

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