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

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

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

\end{array}
double f(double x) {
        double r83691 = 1.0;
        double r83692 = x;
        double r83693 = cos(r83692);
        double r83694 = r83691 - r83693;
        double r83695 = sin(r83692);
        double r83696 = r83694 / r83695;
        return r83696;
}

double f(double x) {
        double r83697 = x;
        double r83698 = -0.022628612332283863;
        bool r83699 = r83697 <= r83698;
        double r83700 = 1.0;
        double r83701 = 3.0;
        double r83702 = pow(r83700, r83701);
        double r83703 = cos(r83697);
        double r83704 = pow(r83703, r83701);
        double r83705 = pow(r83704, r83701);
        double r83706 = cbrt(r83705);
        double r83707 = r83702 - r83706;
        double r83708 = r83703 + r83700;
        double r83709 = r83703 * r83708;
        double r83710 = r83700 * r83700;
        double r83711 = r83709 + r83710;
        double r83712 = sin(r83697);
        double r83713 = r83711 * r83712;
        double r83714 = r83707 / r83713;
        double r83715 = 0.02286088640089938;
        bool r83716 = r83697 <= r83715;
        double r83717 = 0.041666666666666664;
        double r83718 = pow(r83697, r83701);
        double r83719 = r83717 * r83718;
        double r83720 = 0.004166666666666667;
        double r83721 = 5.0;
        double r83722 = pow(r83697, r83721);
        double r83723 = r83720 * r83722;
        double r83724 = 0.5;
        double r83725 = r83724 * r83697;
        double r83726 = r83723 + r83725;
        double r83727 = r83719 + r83726;
        double r83728 = 2.0;
        double r83729 = pow(r83703, r83728);
        double r83730 = r83703 * r83729;
        double r83731 = r83702 - r83730;
        double r83732 = r83731 / r83713;
        double r83733 = r83716 ? r83727 : r83732;
        double r83734 = r83699 ? r83714 : r83733;
        return r83734;
}

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.5
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    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}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}}\]
    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}}}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    8. Simplified1.1

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

    if -0.022628612332283863 < x < 0.02286088640089938

    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.02286088640089938 < 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}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}}\]
    6. Using strategy rm
    7. Applied cube-mult1.0

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

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

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

Reproduce

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

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

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