Average Error: 30.7 → 0.5
Time: 25.6s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right) \cdot \left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1 \cdot 1, 1, \left(\cos x \cdot \cos x\right) \cdot \cos x\right)}{\mathsf{fma}\left(1, 1 - \cos x, \cos x \cdot \cos x\right)}, \cos x, 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \frac{1}{24}, \frac{1}{2}\right), \frac{1}{240} \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right) \cdot \left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1 \cdot 1, 1, \left(\cos x \cdot \cos x\right) \cdot \cos x\right)}{\mathsf{fma}\left(1, 1 - \cos x, \cos x \cdot \cos x\right)}, \cos x, 1 \cdot 1\right) \cdot \sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\
\;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right) \cdot \left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1 \cdot 1, 1, \left(\cos x \cdot \cos x\right) \cdot \cos x\right)}{\mathsf{fma}\left(1, 1 - \cos x, \cos x \cdot \cos x\right)}, \cos x, 1 \cdot 1\right) \cdot \sin x}\\

\mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \frac{1}{24}, \frac{1}{2}\right), \frac{1}{240} \cdot {x}^{5}\right)\\

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

\end{array}
double f(double x) {
        double r3688547 = 1.0;
        double r3688548 = x;
        double r3688549 = cos(r3688548);
        double r3688550 = r3688547 - r3688549;
        double r3688551 = sin(r3688548);
        double r3688552 = r3688550 / r3688551;
        return r3688552;
}

double f(double x) {
        double r3688553 = x;
        double r3688554 = -0.02231715051571105;
        bool r3688555 = r3688553 <= r3688554;
        double r3688556 = 1.0;
        double r3688557 = 3.0;
        double r3688558 = pow(r3688556, r3688557);
        double r3688559 = cos(r3688553);
        double r3688560 = r3688559 * r3688559;
        double r3688561 = r3688560 * r3688559;
        double r3688562 = r3688560 * r3688560;
        double r3688563 = r3688562 * r3688560;
        double r3688564 = r3688561 * r3688563;
        double r3688565 = cbrt(r3688564);
        double r3688566 = r3688558 - r3688565;
        double r3688567 = r3688556 * r3688556;
        double r3688568 = fma(r3688567, r3688556, r3688561);
        double r3688569 = r3688556 - r3688559;
        double r3688570 = fma(r3688556, r3688569, r3688560);
        double r3688571 = r3688568 / r3688570;
        double r3688572 = fma(r3688571, r3688559, r3688567);
        double r3688573 = sin(r3688553);
        double r3688574 = r3688572 * r3688573;
        double r3688575 = r3688566 / r3688574;
        double r3688576 = 0.02105783752125853;
        bool r3688577 = r3688553 <= r3688576;
        double r3688578 = 0.041666666666666664;
        double r3688579 = r3688553 * r3688578;
        double r3688580 = 0.5;
        double r3688581 = fma(r3688553, r3688579, r3688580);
        double r3688582 = 0.004166666666666667;
        double r3688583 = 5.0;
        double r3688584 = pow(r3688553, r3688583);
        double r3688585 = r3688582 * r3688584;
        double r3688586 = fma(r3688553, r3688581, r3688585);
        double r3688587 = r3688577 ? r3688586 : r3688575;
        double r3688588 = r3688555 ? r3688575 : r3688587;
        return r3688588;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.02231715051571105 or 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 \mathsf{fma}\left(\cos x + 1, \cos x, 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 \mathsf{fma}\left(\cos x + 1, \cos x, 1 \cdot 1\right)}\]
    8. Simplified1.1

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

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

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

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

    if -0.02231715051571105 < x < 0.02105783752125853

    1. Initial program 60.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{24} \cdot {x}^{3} + \frac{1}{240} \cdot {x}^{5}\right)}\]
    3. Simplified0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \frac{1}{24} \cdot x, \frac{1}{2}\right), \frac{1}{240} \cdot {x}^{5}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02231715051571105112859783048406825400889:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right) \cdot \left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1 \cdot 1, 1, \left(\cos x \cdot \cos x\right) \cdot \cos x\right)}{\mathsf{fma}\left(1, 1 - \cos x, \cos x \cdot \cos x\right)}, \cos x, 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{elif}\;x \le 0.02105783752125852878456235828252829378471:\\ \;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \frac{1}{24}, \frac{1}{2}\right), \frac{1}{240} \cdot {x}^{5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - \sqrt[3]{\left(\left(\cos x \cdot \cos x\right) \cdot \cos x\right) \cdot \left(\left(\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right)\right) \cdot \left(\cos x \cdot \cos x\right)\right)}}{\mathsf{fma}\left(\frac{\mathsf{fma}\left(1 \cdot 1, 1, \left(\cos x \cdot \cos x\right) \cdot \cos x\right)}{\mathsf{fma}\left(1, 1 - \cos x, \cos x \cdot \cos x\right)}, \cos x, 1 \cdot 1\right) \cdot \sin x}\\ \end{array}\]

Reproduce

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

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

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