Average Error: 29.6 → 0.7
Time: 48.7s
Precision: 64
\[\frac{1.0 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1.0 - \cos x}{\sin x} \le -0.008153236898019485:\\ \;\;\;\;\log \left(e^{\frac{1.0 - \cos x}{\sin x}}\right)\\ \mathbf{elif}\;\frac{1.0 - \cos x}{\sin x} \le 0.0:\\ \;\;\;\;\left(\frac{1}{2} \cdot x + x \cdot \left(\frac{1}{24} \cdot \left(x \cdot x\right)\right)\right) + {x}^{5} \cdot \frac{1}{240}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1.0 \cdot \left(1.0 \cdot 1.0\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(x + x\right)\right) \cdot \cos x}{1.0 \cdot 1.0 + \left(1.0 \cdot \cos x + \cos x \cdot \cos x\right)}}{\sin x}\\ \end{array}\]
\frac{1.0 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1.0 - \cos x}{\sin x} \le -0.008153236898019485:\\
\;\;\;\;\log \left(e^{\frac{1.0 - \cos x}{\sin x}}\right)\\

\mathbf{elif}\;\frac{1.0 - \cos x}{\sin x} \le 0.0:\\
\;\;\;\;\left(\frac{1}{2} \cdot x + x \cdot \left(\frac{1}{24} \cdot \left(x \cdot x\right)\right)\right) + {x}^{5} \cdot \frac{1}{240}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1.0 \cdot \left(1.0 \cdot 1.0\right) - \left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(x + x\right)\right) \cdot \cos x}{1.0 \cdot 1.0 + \left(1.0 \cdot \cos x + \cos x \cdot \cos x\right)}}{\sin x}\\

\end{array}
double f(double x) {
        double r4712979 = 1.0;
        double r4712980 = x;
        double r4712981 = cos(r4712980);
        double r4712982 = r4712979 - r4712981;
        double r4712983 = sin(r4712980);
        double r4712984 = r4712982 / r4712983;
        return r4712984;
}

double f(double x) {
        double r4712985 = 1.0;
        double r4712986 = x;
        double r4712987 = cos(r4712986);
        double r4712988 = r4712985 - r4712987;
        double r4712989 = sin(r4712986);
        double r4712990 = r4712988 / r4712989;
        double r4712991 = -0.008153236898019485;
        bool r4712992 = r4712990 <= r4712991;
        double r4712993 = exp(r4712990);
        double r4712994 = log(r4712993);
        double r4712995 = 0.0;
        bool r4712996 = r4712990 <= r4712995;
        double r4712997 = 0.5;
        double r4712998 = r4712997 * r4712986;
        double r4712999 = 0.041666666666666664;
        double r4713000 = r4712986 * r4712986;
        double r4713001 = r4712999 * r4713000;
        double r4713002 = r4712986 * r4713001;
        double r4713003 = r4712998 + r4713002;
        double r4713004 = 5.0;
        double r4713005 = pow(r4712986, r4713004);
        double r4713006 = 0.004166666666666667;
        double r4713007 = r4713005 * r4713006;
        double r4713008 = r4713003 + r4713007;
        double r4713009 = r4712985 * r4712985;
        double r4713010 = r4712985 * r4713009;
        double r4713011 = r4712986 + r4712986;
        double r4713012 = cos(r4713011);
        double r4713013 = r4712997 * r4713012;
        double r4713014 = r4712997 + r4713013;
        double r4713015 = r4713014 * r4712987;
        double r4713016 = r4713010 - r4713015;
        double r4713017 = r4712985 * r4712987;
        double r4713018 = r4712987 * r4712987;
        double r4713019 = r4713017 + r4713018;
        double r4713020 = r4713009 + r4713019;
        double r4713021 = r4713016 / r4713020;
        double r4713022 = r4713021 / r4712989;
        double r4713023 = r4712996 ? r4713008 : r4713022;
        double r4713024 = r4712992 ? r4712994 : r4713023;
        return r4713024;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.6
Target0.0
Herbie0.7
\[\tan \left(\frac{x}{2.0}\right)\]

Derivation

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

    1. Initial program 0.8

      \[\frac{1.0 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp1.0

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

    if -0.008153236898019485 < (/ (- 1.0 (cos x)) (sin x)) < 0.0

    1. Initial program 60.1

      \[\frac{1.0 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 0.1

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x + \left(\frac{1}{24} \cdot {x}^{3} + \frac{1}{240} \cdot {x}^{5}\right)}\]
    3. Simplified0.1

      \[\leadsto \color{blue}{x \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{24} + \frac{1}{2}\right) + {x}^{5} \cdot \frac{1}{240}}\]
    4. Using strategy rm
    5. Applied distribute-lft-in0.1

      \[\leadsto \color{blue}{\left(x \cdot \left(\left(x \cdot x\right) \cdot \frac{1}{24}\right) + x \cdot \frac{1}{2}\right)} + {x}^{5} \cdot \frac{1}{240}\]

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

    1. Initial program 1.5

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

      \[\leadsto \frac{\color{blue}{\frac{{1.0}^{3} - {\left(\cos x\right)}^{3}}{1.0 \cdot 1.0 + \left(\cos x \cdot \cos x + 1.0 \cdot \cos x\right)}}}{\sin x}\]
    4. Simplified1.6

      \[\leadsto \frac{\frac{\color{blue}{1.0 \cdot \left(1.0 \cdot 1.0\right) - \left(\cos x \cdot \cos x\right) \cdot \cos x}}{1.0 \cdot 1.0 + \left(\cos x \cdot \cos x + 1.0 \cdot \cos x\right)}}{\sin x}\]
    5. Using strategy rm
    6. Applied sqr-cos1.5

      \[\leadsto \frac{\frac{1.0 \cdot \left(1.0 \cdot 1.0\right) - \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \cos \left(2 \cdot x\right)\right)} \cdot \cos x}{1.0 \cdot 1.0 + \left(\cos x \cdot \cos x + 1.0 \cdot \cos x\right)}}{\sin x}\]
    7. Simplified1.5

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

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

Reproduce

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

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

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