Average Error: 30.5 → 0.5
Time: 7.3s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.019289673476821159:\\ \;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\ \mathbf{elif}\;x \le 0.023613340017627771:\\ \;\;\;\;\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)}^{3}}{\cos x \cdot \log \left(e^{\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.019289673476821159:\\
\;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\

\mathbf{elif}\;x \le 0.023613340017627771:\\
\;\;\;\;\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)}^{3}}{\cos x \cdot \log \left(e^{\cos x + 1}\right) + 1 \cdot 1}}{\sin x}\\

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

Derivation

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

    1. Initial program 0.9

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

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

    if -0.01928967347682116 < x < 0.02361334001762777

    1. Initial program 59.8

      \[\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.02361334001762777 < 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-log-exp1.0

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.019289673476821159:\\ \;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\ \mathbf{elif}\;x \le 0.023613340017627771:\\ \;\;\;\;\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)}^{3}}{\cos x \cdot \log \left(e^{\cos x + 1}\right) + 1 \cdot 1}}{\sin x}\\ \end{array}\]

Reproduce

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

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

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