Average Error: 29.0 → 0.2
Time: 3.1s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -337.40848159342193 \lor \neg \left(-2 \cdot x \le 4.07506997279720649 \cdot 10^{-5}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -337.40848159342193 \lor \neg \left(-2 \cdot x \le 4.07506997279720649 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r44557 = 2.0;
        double r44558 = 1.0;
        double r44559 = -2.0;
        double r44560 = x;
        double r44561 = r44559 * r44560;
        double r44562 = exp(r44561);
        double r44563 = r44558 + r44562;
        double r44564 = r44557 / r44563;
        double r44565 = r44564 - r44558;
        return r44565;
}

double f(double x, double __attribute__((unused)) y) {
        double r44566 = -2.0;
        double r44567 = x;
        double r44568 = r44566 * r44567;
        double r44569 = -337.4084815934219;
        bool r44570 = r44568 <= r44569;
        double r44571 = 4.0750699727972065e-05;
        bool r44572 = r44568 <= r44571;
        double r44573 = !r44572;
        bool r44574 = r44570 || r44573;
        double r44575 = 1.0;
        double r44576 = 1.0;
        double r44577 = exp(r44568);
        double r44578 = r44576 + r44577;
        double r44579 = sqrt(r44578);
        double r44580 = r44575 / r44579;
        double r44581 = 2.0;
        double r44582 = r44581 / r44579;
        double r44583 = -r44576;
        double r44584 = fma(r44580, r44582, r44583);
        double r44585 = 5.551115123125783e-17;
        double r44586 = 4.0;
        double r44587 = pow(r44567, r44586);
        double r44588 = 0.33333333333333337;
        double r44589 = 3.0;
        double r44590 = pow(r44567, r44589);
        double r44591 = r44588 * r44590;
        double r44592 = fma(r44585, r44587, r44591);
        double r44593 = -r44592;
        double r44594 = fma(r44576, r44567, r44593);
        double r44595 = r44574 ? r44584 : r44594;
        return r44595;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2.0 x) < -337.4084815934219 or 4.0750699727972065e-05 < (* -2.0 x)

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.1

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied *-un-lft-identity0.1

      \[\leadsto \frac{\color{blue}{1 \cdot 2}}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}} - 1\]
    5. Applied times-frac0.1

      \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + e^{-2 \cdot x}}} \cdot \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    6. Applied fma-neg0.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)}\]

    if -337.4084815934219 < (* -2.0 x) < 4.0750699727972065e-05

    1. Initial program 59.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Taylor expanded around 0 0.3

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -337.40848159342193 \lor \neg \left(-2 \cdot x \le 4.07506997279720649 \cdot 10^{-5}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{\sqrt{1 + e^{-2 \cdot x}}}, \frac{2}{\sqrt{1 + e^{-2 \cdot x}}}, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020018 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))