Average Error: 30.3 → 0.8
Time: 22.3s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.02115882893523894289766751342085626674816 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 7.646982874077240654179165799120276858503 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.02115882893523894289766751342085626674816 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 7.646982874077240654179165799120276858503 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\

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

\end{array}
double f(double x) {
        double r57997 = 1.0;
        double r57998 = x;
        double r57999 = cos(r57998);
        double r58000 = r57997 - r57999;
        double r58001 = sin(r57998);
        double r58002 = r58000 / r58001;
        return r58002;
}

double f(double x) {
        double r58003 = 1.0;
        double r58004 = x;
        double r58005 = cos(r58004);
        double r58006 = r58003 - r58005;
        double r58007 = sin(r58004);
        double r58008 = r58006 / r58007;
        double r58009 = -0.021158828935238943;
        bool r58010 = r58008 <= r58009;
        double r58011 = 7.64698287407724e-08;
        bool r58012 = r58008 <= r58011;
        double r58013 = !r58012;
        bool r58014 = r58010 || r58013;
        double r58015 = 1.0;
        double r58016 = r58007 / r58006;
        double r58017 = r58015 / r58016;
        double r58018 = 0.041666666666666664;
        double r58019 = 3.0;
        double r58020 = pow(r58004, r58019);
        double r58021 = r58018 * r58020;
        double r58022 = 0.004166666666666667;
        double r58023 = 5.0;
        double r58024 = pow(r58004, r58023);
        double r58025 = r58022 * r58024;
        double r58026 = 0.5;
        double r58027 = r58026 * r58004;
        double r58028 = r58025 + r58027;
        double r58029 = r58021 + r58028;
        double r58030 = r58014 ? r58017 : r58029;
        return r58030;
}

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.8
\[\tan \left(\frac{x}{2}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (/ (- 1.0 (cos x)) (sin x)) < -0.021158828935238943 or 7.64698287407724e-08 < (/ (- 1.0 (cos x)) (sin x))

    1. Initial program 1.0

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\sin x}{1 - \cos x}}}\]

    if -0.021158828935238943 < (/ (- 1.0 (cos x)) (sin x)) < 7.64698287407724e-08

    1. Initial program 59.8

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

      \[\leadsto \color{blue}{\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -0.02115882893523894289766751342085626674816 \lor \neg \left(\frac{1 - \cos x}{\sin x} \le 7.646982874077240654179165799120276858503 \cdot 10^{-8}\right):\\ \;\;\;\;\frac{1}{\frac{\sin x}{1 - \cos x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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