Average Error: 29.9 → 0.5
Time: 22.8s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02304827811785196967075961538284900598228:\\ \;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\ \mathbf{elif}\;x \le 0.02138881640774994291609445440371928270906:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{{1}^{3} + {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x - 1\right)\right)}\right)}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02304827811785196967075961538284900598228:\\
\;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\

\mathbf{elif}\;x \le 0.02138881640774994291609445440371928270906:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r66584 = 1.0;
        double r66585 = x;
        double r66586 = cos(r66585);
        double r66587 = r66584 - r66586;
        double r66588 = sin(r66585);
        double r66589 = r66587 / r66588;
        return r66589;
}

double f(double x) {
        double r66590 = x;
        double r66591 = -0.02304827811785197;
        bool r66592 = r66590 <= r66591;
        double r66593 = 1.0;
        double r66594 = 3.0;
        double r66595 = pow(r66593, r66594);
        double r66596 = cos(r66590);
        double r66597 = pow(r66596, r66594);
        double r66598 = log1p(r66597);
        double r66599 = expm1(r66598);
        double r66600 = r66595 - r66599;
        double r66601 = sin(r66590);
        double r66602 = r66593 + r66596;
        double r66603 = r66596 * r66602;
        double r66604 = fma(r66593, r66593, r66603);
        double r66605 = r66601 * r66604;
        double r66606 = r66600 / r66605;
        double r66607 = 0.021388816407749943;
        bool r66608 = r66590 <= r66607;
        double r66609 = 0.04166666666666663;
        double r66610 = pow(r66590, r66594);
        double r66611 = 0.004166666666666624;
        double r66612 = 5.0;
        double r66613 = pow(r66590, r66612);
        double r66614 = 0.5;
        double r66615 = r66614 * r66590;
        double r66616 = fma(r66611, r66613, r66615);
        double r66617 = fma(r66609, r66610, r66616);
        double r66618 = 2.0;
        double r66619 = pow(r66596, r66618);
        double r66620 = r66619 * r66596;
        double r66621 = r66595 - r66620;
        double r66622 = r66595 + r66597;
        double r66623 = r66596 - r66593;
        double r66624 = r66596 * r66623;
        double r66625 = fma(r66593, r66593, r66624);
        double r66626 = r66622 / r66625;
        double r66627 = r66596 * r66626;
        double r66628 = fma(r66593, r66593, r66627);
        double r66629 = r66601 * r66628;
        double r66630 = r66621 / r66629;
        double r66631 = r66608 ? r66617 : r66630;
        double r66632 = r66592 ? r66606 : r66631;
        return r66632;
}

Error

Bits error versus x

Target

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

Derivation

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

    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(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}\]
    6. Using strategy rm
    7. Applied expm1-log1p-u1.1

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

    if -0.02304827811785197 < x < 0.021388816407749943

    1. Initial program 59.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--59.9

      \[\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/59.9

      \[\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. Simplified59.9

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt60.0

      \[\leadsto \frac{{1}^{3} - {\color{blue}{\left(\left(\sqrt[3]{\cos x} \cdot \sqrt[3]{\cos x}\right) \cdot \sqrt[3]{\cos x}\right)}}^{3}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\]
    8. Applied unpow-prod-down60.0

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

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

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \color{blue}{\cos x}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\]
    11. Taylor expanded around 0 0.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)}\]

    if 0.021388816407749943 < 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(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt1.8

      \[\leadsto \frac{{1}^{3} - {\color{blue}{\left(\left(\sqrt[3]{\cos x} \cdot \sqrt[3]{\cos x}\right) \cdot \sqrt[3]{\cos x}\right)}}^{3}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\]
    8. Applied unpow-prod-down1.8

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

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

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \color{blue}{\cos x}}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\]
    11. Using strategy rm
    12. Applied flip3-+1.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02304827811785196967075961538284900598228:\\ \;\;\;\;\frac{{1}^{3} - \mathsf{expm1}\left(\mathsf{log1p}\left({\left(\cos x\right)}^{3}\right)\right)}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \left(1 + \cos x\right)\right)}\\ \mathbf{elif}\;x \le 0.02138881640774994291609445440371928270906:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666662965923251249478198587894, {x}^{3}, \mathsf{fma}\left(0.004166666666666624108117389368999283760786, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\sin x \cdot \mathsf{fma}\left(1, 1, \cos x \cdot \frac{{1}^{3} + {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \cos x \cdot \left(\cos x - 1\right)\right)}\right)}\\ \end{array}\]

Reproduce

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

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

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