Average Error: 30.1 → 0.5
Time: 7.0s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.022146274038337438 \lor \neg \left(x \le 0.020167170543871162\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{\sin x} \cdot \left(\frac{1}{\sin x} \cdot \left(\cos x + 1\right)\right)}{\frac{1}{\sin x} \cdot \left(\cos x + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.022146274038337438 \lor \neg \left(x \le 0.020167170543871162\right):\\
\;\;\;\;\frac{\frac{1 - \cos x}{\sin x} \cdot \left(\frac{1}{\sin x} \cdot \left(\cos x + 1\right)\right)}{\frac{1}{\sin x} \cdot \left(\cos x + 1\right)}\\

\mathbf{else}:\\
\;\;\;\;0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)\\

\end{array}
double f(double x) {
        double r59510 = 1.0;
        double r59511 = x;
        double r59512 = cos(r59511);
        double r59513 = r59510 - r59512;
        double r59514 = sin(r59511);
        double r59515 = r59513 / r59514;
        return r59515;
}

double f(double x) {
        double r59516 = x;
        double r59517 = -0.022146274038337438;
        bool r59518 = r59516 <= r59517;
        double r59519 = 0.02016717054387116;
        bool r59520 = r59516 <= r59519;
        double r59521 = !r59520;
        bool r59522 = r59518 || r59521;
        double r59523 = 1.0;
        double r59524 = cos(r59516);
        double r59525 = r59523 - r59524;
        double r59526 = sin(r59516);
        double r59527 = r59525 / r59526;
        double r59528 = 1.0;
        double r59529 = r59528 / r59526;
        double r59530 = r59524 + r59523;
        double r59531 = r59529 * r59530;
        double r59532 = r59527 * r59531;
        double r59533 = r59532 / r59531;
        double r59534 = 0.04166666666666667;
        double r59535 = 3.0;
        double r59536 = pow(r59516, r59535);
        double r59537 = r59534 * r59536;
        double r59538 = 0.004166666666666667;
        double r59539 = 5.0;
        double r59540 = pow(r59516, r59539);
        double r59541 = r59538 * r59540;
        double r59542 = 0.5;
        double r59543 = r59542 * r59516;
        double r59544 = r59541 + r59543;
        double r59545 = r59537 + r59544;
        double r59546 = r59522 ? r59533 : r59545;
        return r59546;
}

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.022146274038337438 or 0.02016717054387116 < x

    1. Initial program 0.9

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

      \[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]
    4. Using strategy rm
    5. Applied div-inv1.0

      \[\leadsto \frac{1}{\sin x} - \color{blue}{\cos x \cdot \frac{1}{\sin x}}\]
    6. Using strategy rm
    7. Applied flip--1.5

      \[\leadsto \color{blue}{\frac{\frac{1}{\sin x} \cdot \frac{1}{\sin x} - \left(\cos x \cdot \frac{1}{\sin x}\right) \cdot \left(\cos x \cdot \frac{1}{\sin x}\right)}{\frac{1}{\sin x} + \cos x \cdot \frac{1}{\sin x}}}\]
    8. Simplified1.6

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

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

    if -0.022146274038337438 < x < 0.02016717054387116

    1. Initial program 60.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied div-sub60.0

      \[\leadsto \color{blue}{\frac{1}{\sin x} - \frac{\cos x}{\sin x}}\]
    4. Using strategy rm
    5. Applied div-inv60.0

      \[\leadsto \frac{1}{\sin x} - \color{blue}{\cos x \cdot \frac{1}{\sin x}}\]
    6. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.022146274038337438 \lor \neg \left(x \le 0.020167170543871162\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{\sin x} \cdot \left(\frac{1}{\sin x} \cdot \left(\cos x + 1\right)\right)}{\frac{1}{\sin x} \cdot \left(\cos x + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;0.041666666666666671 \cdot {x}^{3} + \left(0.00416666666666666661 \cdot {x}^{5} + 0.5 \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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