Average Error: 30.6 → 0.5
Time: 7.4s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.020582789539646131 \lor \neg \left(x \le 0.0226242778562110482\right):\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{else}:\\ \;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.020582789539646131 \lor \neg \left(x \le 0.0226242778562110482\right):\\
\;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1\right) \cdot \sin x}\\

\mathbf{else}:\\
\;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\

\end{array}
double code(double x) {
	return ((1.0 - cos(x)) / sin(x));
}
double code(double x) {
	double temp;
	if (((x <= -0.02058278953964613) || !(x <= 0.022624277856211048))) {
		temp = ((pow(1.0, 3.0) - pow(cos(x), 3.0)) / (((cos(x) * ((pow(cos(x), 2.0) - (1.0 * 1.0)) / (cos(x) - 1.0))) + (1.0 * 1.0)) * sin(x)));
	} else {
		temp = ((0.04166666666666663 * pow(x, 3.0)) + ((0.004166666666666624 * pow(x, 5.0)) + (0.5 * x)));
	}
	return temp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.02058278953964613 or 0.022624277856211048 < 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 flip-+1.0

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

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

    if -0.02058278953964613 < x < 0.022624277856211048

    1. Initial program 59.8

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

      \[\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/59.8

      \[\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. Simplified59.8

      \[\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. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.020582789539646131 \lor \neg \left(x \le 0.0226242778562110482\right):\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left(\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1\right) \cdot \sin x}\\ \mathbf{else}:\\ \;\;\;\;0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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