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

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

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

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
	double VAR;
	if ((x <= -0.023141644690732637)) {
		VAR = ((1.0 / sin(x)) - (cos(x) / sin(x)));
	} else {
		double VAR_1;
		if ((x <= 0.025186331199138896)) {
			VAR_1 = ((0.041666666666666664 * pow(x, 3.0)) + ((0.004166666666666667 * pow(x, 5.0)) + (0.5 * x)));
		} else {
			VAR_1 = (exp(log(((pow(1.0, 3.0) - cbrt(cbrt(pow(pow(pow(cos(x), 3.0), 3.0), 3.0)))) / ((cos(x) * (cos(x) + 1.0)) + (1.0 * 1.0))))) / sin(x));
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.9

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

      \[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]

    if -0.023141644690732637 < x < 0.025186331199138896

    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.025186331199138896 < x

    1. Initial program 1.0

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

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

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

      \[\leadsto \frac{e^{\log \left(\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}\right)}}{\sin x}\]
    7. Using strategy rm
    8. Applied add-cbrt-cube1.2

      \[\leadsto \frac{e^{\log \left(\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}}}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}\right)}}{\sin x}\]
    9. Simplified1.2

      \[\leadsto \frac{e^{\log \left(\frac{{1}^{3} - \sqrt[3]{\color{blue}{{\left({\left(\cos x\right)}^{3}\right)}^{3}}}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}\right)}}{\sin x}\]
    10. Using strategy rm
    11. Applied add-cbrt-cube1.2

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

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

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

Reproduce

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

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

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