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

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

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

\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.022467842987435108)) {
		VAR = ((double) (((double) -(((double) (1.0 - ((double) cos(x)))))) * ((double) (1.0 / ((double) -(((double) sin(x))))))));
	} else {
		double VAR_1;
		if ((x <= 0.01916768720892558)) {
			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) log(((double) exp(((double) (1.0 / ((double) (((double) sin(x)) / ((double) (1.0 - ((double) cos(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.0
Herbie0.5
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    1. Initial program 0.9

      \[\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 clear-num1.1

      \[\leadsto \log \left(e^{\color{blue}{\frac{1}{\frac{\sin x}{1 - \cos x}}}}\right)\]
    6. Using strategy rm
    7. Applied frac-2neg1.1

      \[\leadsto \log \left(e^{\frac{1}{\color{blue}{\frac{-\sin x}{-\left(1 - \cos x\right)}}}}\right)\]
    8. Applied associate-/r/1.1

      \[\leadsto \log \left(e^{\color{blue}{\frac{1}{-\sin x} \cdot \left(-\left(1 - \cos x\right)\right)}}\right)\]
    9. Applied exp-prod1.2

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

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

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

    if -0.022467842987435108 < x < 0.01916768720892558

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

    1. Initial program 0.9

      \[\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 clear-num1.1

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

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

Reproduce

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

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

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