Average Error: 30.5 → 0.5
Time: 8.9s
Precision: binary64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.020073534703092734:\\ \;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\ \mathbf{elif}\;x \le 0.021161987899956481:\\ \;\;\;\;\left(\frac{1}{24} \cdot {x}^{3} + \frac{1}{240} \cdot {x}^{5}\right) + \frac{1}{2} \cdot x\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\sqrt[3]{{\left(\log \left(1 - \cos x\right)\right)}^{3}}}}{\sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.020073534703092734:\\
\;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\

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

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

\end{array}
double code(double x) {
	return ((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))));
}
double code(double x) {
	double VAR;
	if ((x <= -0.020073534703092734)) {
		VAR = ((double) log(((double) exp(((double) (((double) (1.0 - ((double) cos(x)))) / ((double) sin(x))))))));
	} else {
		double VAR_1;
		if ((x <= 0.02116198789995648)) {
			VAR_1 = ((double) (((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (0.004166666666666667 * ((double) pow(x, 5.0)))))) + ((double) (0.5 * x))));
		} else {
			VAR_1 = ((double) (((double) exp(((double) cbrt(((double) pow(((double) log(((double) (1.0 - ((double) cos(x)))))), 3.0)))))) / ((double) 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.5
Target0.0
Herbie0.5
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    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)}\]

    if -0.020073534703092734 < x < 0.021161987899956481

    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)}\]
    3. Using strategy rm
    4. Applied associate-+r+0.0

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

    if 0.021161987899956481 < 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 add-cbrt-cube1.1

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

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

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

Reproduce

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

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

  (/ (- 1.0 (cos x)) (sin x)))