Average Error: 30.2 → 0.6
Time: 7.3s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0249538198256523992:\\ \;\;\;\;\log \left(e^{\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}}\right)\\ \mathbf{elif}\;x \le 0.021774379651084565:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\cos x \cdot \left(\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.0249538198256523992:\\
\;\;\;\;\log \left(e^{\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\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.0249538198256524)) {
		VAR = ((double) log(((double) exp(((double) (((double) log(((double) exp(((double) (1.0 - ((double) cos(x)))))))) / ((double) sin(x))))))));
	} else {
		double VAR_1;
		if ((x <= 0.021774379651084565)) {
			VAR_1 = ((double) (((double) (0.041666666666666664 * ((double) pow(x, 3.0)))) + ((double) (((double) (0.004166666666666667 * ((double) pow(x, 5.0)))) + ((double) (0.5 * x))))));
		} else {
			VAR_1 = ((double) (((double) (((double) (((double) pow(1.0, 3.0)) - ((double) (((double) pow(((double) cos(x)), 2.0)) * ((double) cos(x)))))) / ((double) (((double) (((double) cos(x)) * ((double) (((double) cos(x)) + 1.0)))) + ((double) (1.0 * 1.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.2
Target0
Herbie0.6
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    1. Initial program 1.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp1.1

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

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

      \[\leadsto \log \left(e^{\frac{\color{blue}{\log \left(e^{1}\right)} - \log \left(e^{\cos x}\right)}{\sin x}}\right)\]
    7. Applied diff-log1.5

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

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

    if -0.0249538198256524 < x < 0.021774379651084565

    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.021774379651084565 < 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 add-cube-cbrt1.9

      \[\leadsto \frac{\frac{{1}^{3} - {\color{blue}{\left(\left(\sqrt[3]{\cos x} \cdot \sqrt[3]{\cos x}\right) \cdot \sqrt[3]{\cos x}\right)}}^{3}}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\]
    7. Applied unpow-prod-down1.9

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

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

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \color{blue}{\cos x}}{\cos x \cdot \left(\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.0249538198256523992:\\ \;\;\;\;\log \left(e^{\frac{\log \left(e^{1 - \cos x}\right)}{\sin x}}\right)\\ \mathbf{elif}\;x \le 0.021774379651084565:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{2} \cdot \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}{\sin x}\\ \end{array}\]

Reproduce

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

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

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