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

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

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

\end{array}
double f(double x) {
        double r47069 = 1.0;
        double r47070 = x;
        double r47071 = cos(r47070);
        double r47072 = r47069 - r47071;
        double r47073 = sin(r47070);
        double r47074 = r47072 / r47073;
        return r47074;
}

double f(double x) {
        double r47075 = x;
        double r47076 = -0.023647737046597096;
        bool r47077 = r47075 <= r47076;
        double r47078 = 1.0;
        double r47079 = cos(r47075);
        double r47080 = r47078 - r47079;
        double r47081 = sqrt(r47080);
        double r47082 = log(r47081);
        double r47083 = exp(r47082);
        double r47084 = sin(r47075);
        double r47085 = r47083 / r47084;
        double r47086 = r47085 * r47081;
        double r47087 = 0.020771119462007017;
        bool r47088 = r47075 <= r47087;
        double r47089 = 0.041666666666666664;
        double r47090 = 3.0;
        double r47091 = pow(r47075, r47090);
        double r47092 = r47089 * r47091;
        double r47093 = 0.004166666666666667;
        double r47094 = 5.0;
        double r47095 = pow(r47075, r47094);
        double r47096 = r47093 * r47095;
        double r47097 = 0.5;
        double r47098 = r47097 * r47075;
        double r47099 = r47096 + r47098;
        double r47100 = r47092 + r47099;
        double r47101 = pow(r47078, r47090);
        double r47102 = pow(r47079, r47090);
        double r47103 = r47101 - r47102;
        double r47104 = exp(r47103);
        double r47105 = log(r47104);
        double r47106 = r47078 + r47079;
        double r47107 = r47079 * r47106;
        double r47108 = r47078 * r47078;
        double r47109 = r47107 + r47108;
        double r47110 = r47084 * r47109;
        double r47111 = r47105 / r47110;
        double r47112 = r47088 ? r47100 : r47111;
        double r47113 = r47077 ? r47086 : r47112;
        return r47113;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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 add-exp-log1.1

      \[\leadsto \log \left(e^{\frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}}\right)\]
    6. Using strategy rm
    7. Applied *-un-lft-identity1.1

      \[\leadsto \log \left(e^{\frac{e^{\log \left(1 - \cos x\right)}}{\color{blue}{1 \cdot \sin x}}}\right)\]
    8. Applied add-sqr-sqrt1.2

      \[\leadsto \log \left(e^{\frac{e^{\log \color{blue}{\left(\sqrt{1 - \cos x} \cdot \sqrt{1 - \cos x}\right)}}}{1 \cdot \sin x}}\right)\]
    9. Applied log-prod1.3

      \[\leadsto \log \left(e^{\frac{e^{\color{blue}{\log \left(\sqrt{1 - \cos x}\right) + \log \left(\sqrt{1 - \cos x}\right)}}}{1 \cdot \sin x}}\right)\]
    10. Applied exp-sum1.2

      \[\leadsto \log \left(e^{\frac{\color{blue}{e^{\log \left(\sqrt{1 - \cos x}\right)} \cdot e^{\log \left(\sqrt{1 - \cos x}\right)}}}{1 \cdot \sin x}}\right)\]
    11. Applied times-frac1.3

      \[\leadsto \log \left(e^{\color{blue}{\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{1} \cdot \frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{\sin x}}}\right)\]
    12. Applied exp-prod1.3

      \[\leadsto \log \color{blue}{\left({\left(e^{\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{1}}\right)}^{\left(\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{\sin x}\right)}\right)}\]
    13. Applied log-pow1.2

      \[\leadsto \color{blue}{\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{\sin x} \cdot \log \left(e^{\frac{e^{\log \left(\sqrt{1 - \cos x}\right)}}{1}}\right)}\]
    14. Simplified1.1

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

    if -0.023647737046597096 < x < 0.020771119462007017

    1. Initial program 60.0

      \[\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.020771119462007017 < x

    1. Initial program 0.9

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

      \[\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.1

      \[\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(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}}\]
    6. Using strategy rm
    7. Applied add-log-exp1.1

      \[\leadsto \frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    8. Applied add-log-exp1.1

      \[\leadsto \frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    9. Applied diff-log1.2

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{{1}^{3}}}{e^{{\left(\cos x\right)}^{3}}}\right)}}{\sin x \cdot \left(\cos x \cdot \left(1 + \cos x\right) + 1 \cdot 1\right)}\]
    10. Simplified1.1

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

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

Reproduce

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

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

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