Average Error: 30.7 → 0.6
Time: 25.4s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\ \;\;\;\;\frac{{1}^{3} - \frac{\sqrt[3]{\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\cos x + \cos x \cdot \cos \left(x + x\right)\right)\right)}}{\sqrt[3]{8}}}{\left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right) \cdot \sin x}\\ \mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\ \;\;\;\;\left(0.5 + \left(x \cdot x\right) \cdot 0.04166666666666667129259593593815225176513\right) \cdot x + 0.004166666666666666608842550800773096852936 \cdot {x}^{5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right)\right) \cdot \cos x}}{\left(\cos x \cdot \cos x + 1 \cdot \frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}\right) \cdot \sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\
\;\;\;\;\frac{{1}^{3} - \frac{\sqrt[3]{\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\cos x + \cos x \cdot \cos \left(x + x\right)\right)\right)}}{\sqrt[3]{8}}}{\left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right) \cdot \sin x}\\

\mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\
\;\;\;\;\left(0.5 + \left(x \cdot x\right) \cdot 0.04166666666666667129259593593815225176513\right) \cdot x + 0.004166666666666666608842550800773096852936 \cdot {x}^{5}\\

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

\end{array}
double f(double x) {
        double r3517322 = 1.0;
        double r3517323 = x;
        double r3517324 = cos(r3517323);
        double r3517325 = r3517322 - r3517324;
        double r3517326 = sin(r3517323);
        double r3517327 = r3517325 / r3517326;
        return r3517327;
}

double f(double x) {
        double r3517328 = x;
        double r3517329 = -0.02231715051571105;
        bool r3517330 = r3517328 <= r3517329;
        double r3517331 = 1.0;
        double r3517332 = 3.0;
        double r3517333 = pow(r3517331, r3517332);
        double r3517334 = cos(r3517328);
        double r3517335 = r3517328 + r3517328;
        double r3517336 = cos(r3517335);
        double r3517337 = r3517334 * r3517336;
        double r3517338 = r3517334 + r3517337;
        double r3517339 = r3517338 * r3517338;
        double r3517340 = r3517338 * r3517339;
        double r3517341 = cbrt(r3517340);
        double r3517342 = 8.0;
        double r3517343 = cbrt(r3517342);
        double r3517344 = r3517341 / r3517343;
        double r3517345 = r3517333 - r3517344;
        double r3517346 = r3517331 + r3517334;
        double r3517347 = r3517331 * r3517346;
        double r3517348 = r3517334 * r3517334;
        double r3517349 = r3517347 + r3517348;
        double r3517350 = sin(r3517328);
        double r3517351 = r3517349 * r3517350;
        double r3517352 = r3517345 / r3517351;
        double r3517353 = 0.02105783752125853;
        bool r3517354 = r3517328 <= r3517353;
        double r3517355 = 0.5;
        double r3517356 = r3517328 * r3517328;
        double r3517357 = 0.04166666666666667;
        double r3517358 = r3517356 * r3517357;
        double r3517359 = r3517355 + r3517358;
        double r3517360 = r3517359 * r3517328;
        double r3517361 = 0.004166666666666667;
        double r3517362 = 5.0;
        double r3517363 = pow(r3517328, r3517362);
        double r3517364 = r3517361 * r3517363;
        double r3517365 = r3517360 + r3517364;
        double r3517366 = r3517348 * r3517348;
        double r3517367 = r3517366 * r3517366;
        double r3517368 = r3517367 * r3517334;
        double r3517369 = cbrt(r3517368);
        double r3517370 = r3517333 - r3517369;
        double r3517371 = r3517331 * r3517331;
        double r3517372 = r3517371 - r3517348;
        double r3517373 = r3517331 - r3517334;
        double r3517374 = r3517372 / r3517373;
        double r3517375 = r3517331 * r3517374;
        double r3517376 = r3517348 + r3517375;
        double r3517377 = r3517376 * r3517350;
        double r3517378 = r3517370 / r3517377;
        double r3517379 = r3517354 ? r3517365 : r3517378;
        double r3517380 = r3517330 ? r3517352 : r3517379;
        return r3517380;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

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

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\sin x \cdot \left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\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(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right)}\]
    8. Simplified1.1

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

      \[\leadsto \frac{{1}^{3} - \sqrt[3]{\left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \color{blue}{\frac{\cos \left(x + x\right) + \cos \left(x - x\right)}{2}}\right)\right) \cdot \cos x}}{\sin x \cdot \left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right)}\]
    11. Applied associate-*r/1.2

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

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

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

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

      \[\leadsto \frac{{1}^{3} - \sqrt[3]{\color{blue}{\frac{\left(\left(\cos \left(x + x\right) + \cos \left(x - x\right)\right) \cdot \left(\cos \left(x + x\right) + \cos \left(x - x\right)\right)\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos \left(x + x\right) + \cos \left(x - x\right)\right)\right)}{\left(2 \cdot 2\right) \cdot 2}} \cdot \cos x}}{\sin x \cdot \left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right)}\]
    16. Applied associate-*l/1.2

      \[\leadsto \frac{{1}^{3} - \sqrt[3]{\color{blue}{\frac{\left(\left(\left(\cos \left(x + x\right) + \cos \left(x - x\right)\right) \cdot \left(\cos \left(x + x\right) + \cos \left(x - x\right)\right)\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos \left(x + x\right) + \cos \left(x - x\right)\right)\right)\right) \cdot \cos x}{\left(2 \cdot 2\right) \cdot 2}}}}{\sin x \cdot \left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right)}\]
    17. Applied cbrt-div1.2

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

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

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

    if -0.02231715051571105 < x < 0.02105783752125853

    1. Initial program 60.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied div-sub60.0

      \[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]
    4. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{0.5 \cdot x + \left(0.04166666666666667129259593593815225176513 \cdot {x}^{3} + 0.004166666666666666608842550800773096852936 \cdot {x}^{5}\right)}\]
    5. Simplified0.0

      \[\leadsto \color{blue}{{x}^{5} \cdot 0.004166666666666666608842550800773096852936 + x \cdot \left(0.5 + \left(x \cdot x\right) \cdot 0.04166666666666667129259593593815225176513\right)}\]

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\ \;\;\;\;\frac{{1}^{3} - \frac{\sqrt[3]{\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\left(\cos x + \cos x \cdot \cos \left(x + x\right)\right) \cdot \left(\cos x + \cos x \cdot \cos \left(x + x\right)\right)\right)}}{\sqrt[3]{8}}}{\left(1 \cdot \left(1 + \cos x\right) + \cos x \cdot \cos x\right) \cdot \sin x}\\ \mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\ \;\;\;\;\left(0.5 + \left(x \cdot x\right) \cdot 0.04166666666666667129259593593815225176513\right) \cdot x + 0.004166666666666666608842550800773096852936 \cdot {x}^{5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right)\right) \cdot \cos x}}{\left(\cos x \cdot \cos x + 1 \cdot \frac{1 \cdot 1 - \cos x \cdot \cos x}{1 - \cos x}\right) \cdot \sin x}\\ \end{array}\]

Reproduce

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

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

  (/ (- 1.0 (cos x)) (sin x)))