Average Error: 30.3 → 0.6
Time: 21.4s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02080686540991821820156815192603971809149:\\ \;\;\;\;\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.01746364724227396011957402777170500485227:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02080686540991821820156815192603971809149:\\
\;\;\;\;\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\

\end{array}
double f(double x) {
        double r62267 = 1.0;
        double r62268 = x;
        double r62269 = cos(r62268);
        double r62270 = r62267 - r62269;
        double r62271 = sin(r62268);
        double r62272 = r62270 / r62271;
        return r62272;
}

double f(double x) {
        double r62273 = x;
        double r62274 = -0.020806865409918218;
        bool r62275 = r62273 <= r62274;
        double r62276 = 1.0;
        double r62277 = 3.0;
        double r62278 = pow(r62276, r62277);
        double r62279 = cos(r62273);
        double r62280 = pow(r62279, r62277);
        double r62281 = exp(r62280);
        double r62282 = log(r62281);
        double r62283 = r62278 - r62282;
        double r62284 = sin(r62273);
        double r62285 = r62276 + r62279;
        double r62286 = r62279 * r62285;
        double r62287 = r62276 * r62276;
        double r62288 = r62286 + r62287;
        double r62289 = r62284 * r62288;
        double r62290 = r62283 / r62289;
        double r62291 = 0.01746364724227396;
        bool r62292 = r62273 <= r62291;
        double r62293 = 0.041666666666666664;
        double r62294 = pow(r62273, r62277);
        double r62295 = r62293 * r62294;
        double r62296 = 0.004166666666666667;
        double r62297 = 5.0;
        double r62298 = pow(r62273, r62297);
        double r62299 = r62296 * r62298;
        double r62300 = 0.5;
        double r62301 = r62300 * r62273;
        double r62302 = r62299 + r62301;
        double r62303 = r62295 + r62302;
        double r62304 = pow(r62280, r62277);
        double r62305 = cbrt(r62304);
        double r62306 = r62278 - r62305;
        double r62307 = r62306 / r62289;
        double r62308 = r62292 ? r62303 : r62307;
        double r62309 = r62275 ? r62290 : r62308;
        return r62309;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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.1

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

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

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

    if -0.020806865409918218 < x < 0.01746364724227396

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

    if 0.01746364724227396 < 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}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}}\]
    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}}}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    8. Simplified1.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02080686540991821820156815192603971809149:\\ \;\;\;\;\frac{{1}^{3} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\ \mathbf{elif}\;x \le 0.01746364724227396011957402777170500485227:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\\ \end{array}\]

Reproduce

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

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

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