Average Error: 30.1 → 0.7
Time: 1.2m
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0107629324502667868:\\ \;\;\;\;1 \cdot \frac{1}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)} - \frac{{\left(\cos x\right)}^{3}}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.3298603204685633 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{1}^{3}}{1}, \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}, -\frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right) + \mathsf{fma}\left(-\frac{1}{\sin x}, \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}, \frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0107629324502667868:\\
\;\;\;\;1 \cdot \frac{1}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)} - \frac{{\left(\cos x\right)}^{3}}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)}\\

\mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.3298603204685633 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{{1}^{3}}{1}, \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}, -\frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right) + \mathsf{fma}\left(-\frac{1}{\sin x}, \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}, \frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right)\\

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/ (- 1.0 (cos x)) (sin x)) < -0.010762932450266787

    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)}\]
    4. Using strategy rm
    5. Applied flip3--1.1

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Simplified1.1

      \[\leadsto \log \left(e^{\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{\sin x}}\right)\]
    7. Using strategy rm
    8. Applied div-sub1.1

      \[\leadsto \log \left(e^{\frac{\color{blue}{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{\sin x}}\right)\]
    9. Applied div-sub1.2

      \[\leadsto \log \left(e^{\color{blue}{\frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x} - \frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}\right)\]
    10. Applied exp-diff1.3

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}{e^{\frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}\right)}\]
    11. Applied log-div1.1

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

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

      \[\leadsto \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x} - \color{blue}{\frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}\]
    14. Taylor expanded around -inf 1.0

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

    if -0.010762932450266787 < (/ (- 1.0 (cos x)) (sin x)) < 0.00043298603204685633

    1. Initial program 59.8

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

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

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Simplified59.8

      \[\leadsto \log \left(e^{\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{\sin x}}\right)\]
    7. Taylor expanded around 0 0.3

      \[\leadsto \color{blue}{0.04166666666666663 \cdot {x}^{3} + \left(0.004166666666666624 \cdot {x}^{5} + 0.5 \cdot x\right)}\]
    8. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)}\]

    if 0.00043298603204685633 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.0

      \[\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)}\]
    4. Using strategy rm
    5. Applied flip3--1.2

      \[\leadsto \log \left(e^{\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}}\right)\]
    6. Simplified1.2

      \[\leadsto \log \left(e^{\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{\sin x}}\right)\]
    7. Using strategy rm
    8. Applied div-sub1.2

      \[\leadsto \log \left(e^{\frac{\color{blue}{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{\sin x}}\right)\]
    9. Applied div-sub1.2

      \[\leadsto \log \left(e^{\color{blue}{\frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x} - \frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}\right)\]
    10. Applied exp-diff1.2

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}{e^{\frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}}\right)}\]
    11. Applied log-div1.2

      \[\leadsto \color{blue}{\log \left(e^{\frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}\right) - \log \left(e^{\frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}\right)}\]
    12. Simplified1.2

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

      \[\leadsto \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x} - \color{blue}{\frac{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}}\]
    14. Using strategy rm
    15. Applied div-inv1.2

      \[\leadsto \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x} - \color{blue}{\frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} \cdot \frac{1}{\sin x}}\]
    16. Applied *-un-lft-identity1.2

      \[\leadsto \frac{\frac{{1}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\color{blue}{1 \cdot \sin x}} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} \cdot \frac{1}{\sin x}\]
    17. Applied div-inv1.2

      \[\leadsto \frac{\color{blue}{{1}^{3} \cdot \frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}}{1 \cdot \sin x} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} \cdot \frac{1}{\sin x}\]
    18. Applied times-frac1.2

      \[\leadsto \color{blue}{\frac{{1}^{3}}{1} \cdot \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}} - \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)} \cdot \frac{1}{\sin x}\]
    19. Applied prod-diff1.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.0107629324502667868:\\ \;\;\;\;1 \cdot \frac{1}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)} - \frac{{\left(\cos x\right)}^{3}}{\sin x \cdot \left({\left(\cos x\right)}^{2} + \left(1 \cdot \cos x + 1\right)\right)}\\ \mathbf{elif}\;\frac{1 - \cos x}{\sin x} \le 4.3298603204685633 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(0.04166666666666663, {x}^{3}, \mathsf{fma}\left(0.004166666666666624, {x}^{5}, 0.5 \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{{1}^{3}}{1}, \frac{\frac{1}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}}{\sin x}, -\frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right) + \mathsf{fma}\left(-\frac{1}{\sin x}, \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}, \frac{1}{\sin x} \cdot \frac{{\left(\cos x\right)}^{3}}{\mathsf{fma}\left(\cos x, 1 + \cos x, 1 \cdot 1\right)}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

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

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