Average Error: 30.1 → 0.5
Time: 8.3s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.019039573390386873:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x} \cdot 1\\ \mathbf{elif}\;x \le 0.0240442248467046295:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.019039573390386873:\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x} \cdot 1\\

\mathbf{elif}\;x \le 0.0240442248467046295:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\

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

\end{array}
double f(double x) {
        double r48628 = 1.0;
        double r48629 = x;
        double r48630 = cos(r48629);
        double r48631 = r48628 - r48630;
        double r48632 = sin(r48629);
        double r48633 = r48631 / r48632;
        return r48633;
}

double f(double x) {
        double r48634 = x;
        double r48635 = -0.019039573390386873;
        bool r48636 = r48634 <= r48635;
        double r48637 = 1.0;
        double r48638 = 3.0;
        double r48639 = pow(r48637, r48638);
        double r48640 = cos(r48634);
        double r48641 = pow(r48640, r48638);
        double r48642 = r48639 - r48641;
        double r48643 = r48637 * r48640;
        double r48644 = fma(r48640, r48640, r48643);
        double r48645 = fma(r48637, r48637, r48644);
        double r48646 = sin(r48634);
        double r48647 = r48645 * r48646;
        double r48648 = r48642 / r48647;
        double r48649 = 1.0;
        double r48650 = r48648 * r48649;
        double r48651 = 0.02404422484670463;
        bool r48652 = r48634 <= r48651;
        double r48653 = 0.04166666666666663;
        double r48654 = pow(r48634, r48638);
        double r48655 = 0.004166666666666624;
        double r48656 = 5.0;
        double r48657 = pow(r48634, r48656);
        double r48658 = 0.5;
        double r48659 = r48658 * r48634;
        double r48660 = fma(r48655, r48657, r48659);
        double r48661 = fma(r48653, r48654, r48660);
        double r48662 = 2.0;
        double r48663 = pow(r48640, r48662);
        double r48664 = r48663 * r48640;
        double r48665 = r48639 - r48664;
        double r48666 = r48665 / r48647;
        double r48667 = exp(r48666);
        double r48668 = log(r48667);
        double r48669 = r48652 ? r48661 : r48668;
        double r48670 = r48636 ? r48650 : r48669;
        return r48670;
}

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp1.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
    4. Using strategy rm
    5. Applied flip3--1.1

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Applied associate-/l/1.1

      \[\leadsto \log \left(e^{\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)}}}\right)\]
    7. Simplified1.1

      \[\leadsto \log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}}\right)\]
    8. Using strategy rm
    9. Applied *-un-lft-identity1.1

      \[\leadsto \log \left(e^{\color{blue}{1 \cdot \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}}\right)\]
    10. Applied exp-prod1.2

      \[\leadsto \log \color{blue}{\left({\left(e^{1}\right)}^{\left(\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}\right)}\right)}\]
    11. Applied log-pow1.0

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

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

    if -0.019039573390386873 < x < 0.02404422484670463

    1. Initial program 60.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp60.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
    4. Using strategy rm
    5. Applied flip3--60.0

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Applied associate-/l/60.0

      \[\leadsto \log \left(e^{\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)}}}\right)\]
    7. Simplified60.0

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

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

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

    if 0.02404422484670463 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp1.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]
    4. Using strategy rm
    5. Applied flip3--1.1

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Applied associate-/l/1.1

      \[\leadsto \log \left(e^{\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)}}}\right)\]
    7. Simplified1.1

      \[\leadsto \log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}}\right)\]
    8. Using strategy rm
    9. Applied add-cube-cbrt1.9

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

      \[\leadsto \log \left(e^{\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}}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}\right)\]
    11. Simplified1.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.019039573390386873:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x} \cdot 1\\ \mathbf{elif}\;x \le 0.0240442248467046295:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\mathsf{fma}\left(1, 1, \mathsf{fma}\left(\cos x, \cos x, 1 \cdot \cos x\right)\right) \cdot \sin x}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020033 +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)))