Average Error: 30.0 → 0.6
Time: 8.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.021475731437802487:\\ \;\;\;\;\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\left(\sqrt[3]{\cos x + 1} \cdot \sqrt[3]{\cos x + 1}\right) \cdot \sqrt[3]{\cos x + 1}\right) + 1 \cdot 1}}{\sin x}\\ \mathbf{elif}\;x \le 0.024065556079906431:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\sqrt{\cos x + 1} \cdot \sqrt{\cos x + 1}\right) + 1 \cdot 1}}{\sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.021475731437802487:\\
\;\;\;\;\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\left(\sqrt[3]{\cos x + 1} \cdot \sqrt[3]{\cos x + 1}\right) \cdot \sqrt[3]{\cos x + 1}\right) + 1 \cdot 1}}{\sin x}\\

\mathbf{elif}\;x \le 0.024065556079906431:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\

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

\end{array}
double f(double x) {
        double r61866 = 1.0;
        double r61867 = x;
        double r61868 = cos(r61867);
        double r61869 = r61866 - r61868;
        double r61870 = sin(r61867);
        double r61871 = r61869 / r61870;
        return r61871;
}

double f(double x) {
        double r61872 = x;
        double r61873 = -0.021475731437802487;
        bool r61874 = r61872 <= r61873;
        double r61875 = cos(r61872);
        double r61876 = 1.0;
        double r61877 = r61875 + r61876;
        double r61878 = r61875 * r61877;
        double r61879 = r61876 * r61876;
        double r61880 = r61878 + r61879;
        double r61881 = r61876 - r61875;
        double r61882 = cbrt(r61877);
        double r61883 = r61882 * r61882;
        double r61884 = r61883 * r61882;
        double r61885 = r61875 * r61884;
        double r61886 = r61885 + r61879;
        double r61887 = r61881 / r61886;
        double r61888 = sin(r61872);
        double r61889 = r61887 / r61888;
        double r61890 = r61880 * r61889;
        double r61891 = 0.02406555607990643;
        bool r61892 = r61872 <= r61891;
        double r61893 = 0.041666666666666664;
        double r61894 = 3.0;
        double r61895 = pow(r61872, r61894);
        double r61896 = r61893 * r61895;
        double r61897 = 0.004166666666666667;
        double r61898 = 5.0;
        double r61899 = pow(r61872, r61898);
        double r61900 = r61897 * r61899;
        double r61901 = 0.5;
        double r61902 = r61901 * r61872;
        double r61903 = r61900 + r61902;
        double r61904 = r61896 + r61903;
        double r61905 = sqrt(r61877);
        double r61906 = r61905 * r61905;
        double r61907 = r61875 * r61906;
        double r61908 = r61907 + r61879;
        double r61909 = r61881 / r61908;
        double r61910 = r61909 / r61888;
        double r61911 = r61880 * r61910;
        double r61912 = r61892 ? r61904 : r61911;
        double r61913 = r61874 ? r61890 : r61912;
        return r61913;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.8

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--0.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. Simplified0.9

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.9

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\color{blue}{1 \cdot \sin x}}\]
    7. Applied *-un-lft-identity0.9

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}}{1 \cdot \sin x}\]
    8. Applied difference-cubes0.9

      \[\leadsto \frac{\frac{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}{1 \cdot \sin x}\]
    9. Applied times-frac0.9

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1} \cdot \frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{1 \cdot \sin x}\]
    10. Applied times-frac1.0

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1}}{1} \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}}\]
    11. Simplified0.9

      \[\leadsto \color{blue}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)} \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    12. Using strategy rm
    13. Applied add-cube-cbrt1.1

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

    if -0.021475731437802487 < x < 0.02406555607990643

    1. Initial program 59.9

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

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

    if 0.02406555607990643 < 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. Simplified1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\color{blue}{1 \cdot \sin x}}\]
    7. Applied *-un-lft-identity1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}}{1 \cdot \sin x}\]
    8. Applied difference-cubes1.0

      \[\leadsto \frac{\frac{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}{1 \cdot \sin x}\]
    9. Applied times-frac1.0

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1} \cdot \frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{1 \cdot \sin x}\]
    10. Applied times-frac1.0

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1}}{1} \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}}\]
    11. Simplified1.0

      \[\leadsto \color{blue}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)} \cdot \frac{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    12. Using strategy rm
    13. Applied add-sqr-sqrt1.1

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

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

Reproduce

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

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

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