Average Error: 30.6 → 0.5
Time: 9.2s
Precision: binary64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.023756317422124803:\\ \;\;\;\;\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\\ \mathbf{elif}\;x \leq 0.023890754284735707:\\ \;\;\;\;0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left({1}^{6} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}\right)} \cdot \left(\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.023756317422124803:\\
\;\;\;\;\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\\

\mathbf{elif}\;x \leq 0.023890754284735707:\\
\;\;\;\;0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + x \cdot 0.5\right)\\

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

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

Derivation

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

    1. Initial program Error: 1.0 bits

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--Error: 1.1 bits

      \[\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/Error: 1.1 bits

      \[\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. SimplifiedError: 1.1 bits

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}}\]
    6. Using strategy rm
    7. Applied add-log-expError: 1.1 bits

      \[\leadsto \frac{{1}^{3} - \color{blue}{\log \left(e^{{\left(\cos x\right)}^{3}}\right)}}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\]
    8. Applied add-log-expError: 1.1 bits

      \[\leadsto \frac{\color{blue}{\log \left(e^{{1}^{3}}\right)} - \log \left(e^{{\left(\cos x\right)}^{3}}\right)}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\]
    9. Applied diff-logError: 1.2 bits

      \[\leadsto \frac{\color{blue}{\log \left(\frac{e^{{1}^{3}}}{e^{{\left(\cos x\right)}^{3}}}\right)}}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\]
    10. SimplifiedError: 1.1 bits

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

    if -0.0237563174221248029 < x < 0.023890754284735707

    1. Initial program Error: 60.0 bits

      \[\frac{1 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 Error: 0.0 bits

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + 0.5 \cdot x\right)}\]
    3. SimplifiedError: 0.0 bits

      \[\leadsto \color{blue}{0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + x \cdot 0.5\right)}\]

    if 0.023890754284735707 < x

    1. Initial program Error: 0.9 bits

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--Error: 1.0 bits

      \[\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/Error: 1.0 bits

      \[\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. SimplifiedError: 1.0 bits

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}}\]
    6. Using strategy rm
    7. Applied flip3-+Error: 1.1 bits

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\frac{{\left(1 \cdot 1\right)}^{3} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}}{\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)}} \cdot \sin x}\]
    8. Applied associate-*l/Error: 1.1 bits

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\frac{\left({\left(1 \cdot 1\right)}^{3} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}\right) \cdot \sin x}{\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)}}}\]
    9. Applied associate-/r/Error: 1.1 bits

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\left({\left(1 \cdot 1\right)}^{3} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}\right) \cdot \sin x} \cdot \left(\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)\right)}\]
    10. SimplifiedError: 1.1 bits

      \[\leadsto \color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left({1}^{6} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}\right)}} \cdot \left(\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplificationError: 0.5 bits

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.023756317422124803:\\ \;\;\;\;\frac{\log \left(e^{{1}^{3} - {\left(\cos x\right)}^{3}}\right)}{\left(1 \cdot 1 + \cos x \cdot \left(1 + \cos x\right)\right) \cdot \sin x}\\ \mathbf{elif}\;x \leq 0.023890754284735707:\\ \;\;\;\;0.041666666666666664 \cdot {x}^{3} + \left(0.004166666666666667 \cdot {x}^{5} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\sin x \cdot \left({1}^{6} + {\left(\cos x \cdot \left(1 + \cos x\right)\right)}^{3}\right)} \cdot \left(\left(1 \cdot 1\right) \cdot \left(1 \cdot 1\right) + \left(\left(\cos x \cdot \left(1 + \cos x\right)\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right) - \left(1 \cdot 1\right) \cdot \left(\cos x \cdot \left(1 + \cos x\right)\right)\right)\right)\\ \end{array}\]

Reproduce

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

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

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