Average Error: 30.7 → 0.6
Time: 25.9s
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 r2739830 = 1.0;
        double r2739831 = x;
        double r2739832 = cos(r2739831);
        double r2739833 = r2739830 - r2739832;
        double r2739834 = sin(r2739831);
        double r2739835 = r2739833 / r2739834;
        return r2739835;
}

double f(double x) {
        double r2739836 = x;
        double r2739837 = -0.02231715051571105;
        bool r2739838 = r2739836 <= r2739837;
        double r2739839 = 1.0;
        double r2739840 = 3.0;
        double r2739841 = pow(r2739839, r2739840);
        double r2739842 = cos(r2739836);
        double r2739843 = r2739836 + r2739836;
        double r2739844 = cos(r2739843);
        double r2739845 = r2739842 * r2739844;
        double r2739846 = r2739842 + r2739845;
        double r2739847 = r2739846 * r2739846;
        double r2739848 = r2739846 * r2739847;
        double r2739849 = cbrt(r2739848);
        double r2739850 = 8.0;
        double r2739851 = cbrt(r2739850);
        double r2739852 = r2739849 / r2739851;
        double r2739853 = r2739841 - r2739852;
        double r2739854 = r2739839 + r2739842;
        double r2739855 = r2739839 * r2739854;
        double r2739856 = r2739842 * r2739842;
        double r2739857 = r2739855 + r2739856;
        double r2739858 = sin(r2739836);
        double r2739859 = r2739857 * r2739858;
        double r2739860 = r2739853 / r2739859;
        double r2739861 = 0.02105783752125853;
        bool r2739862 = r2739836 <= r2739861;
        double r2739863 = 0.5;
        double r2739864 = r2739836 * r2739836;
        double r2739865 = 0.04166666666666667;
        double r2739866 = r2739864 * r2739865;
        double r2739867 = r2739863 + r2739866;
        double r2739868 = r2739867 * r2739836;
        double r2739869 = 0.004166666666666667;
        double r2739870 = 5.0;
        double r2739871 = pow(r2739836, r2739870);
        double r2739872 = r2739869 * r2739871;
        double r2739873 = r2739868 + r2739872;
        double r2739874 = r2739856 * r2739856;
        double r2739875 = r2739874 * r2739874;
        double r2739876 = r2739875 * r2739842;
        double r2739877 = cbrt(r2739876);
        double r2739878 = r2739841 - r2739877;
        double r2739879 = r2739839 * r2739839;
        double r2739880 = r2739879 - r2739856;
        double r2739881 = r2739839 - r2739842;
        double r2739882 = r2739880 / r2739881;
        double r2739883 = r2739839 * r2739882;
        double r2739884 = r2739856 + r2739883;
        double r2739885 = r2739884 * r2739858;
        double r2739886 = r2739878 / r2739885;
        double r2739887 = r2739862 ? r2739873 : r2739886;
        double r2739888 = r2739838 ? r2739860 : r2739887;
        return r2739888;
}

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)))