Average Error: 28.8 → 0.5
Time: 17.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1602025805.5623312:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 0.0036671774268135894:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -1602025805.5623312:\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\

\mathbf{elif}\;-2 \cdot x \le 0.0036671774268135894:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2322561 = 2.0;
        double r2322562 = 1.0;
        double r2322563 = -2.0;
        double r2322564 = x;
        double r2322565 = r2322563 * r2322564;
        double r2322566 = exp(r2322565);
        double r2322567 = r2322562 + r2322566;
        double r2322568 = r2322561 / r2322567;
        double r2322569 = r2322568 - r2322562;
        return r2322569;
}

double f(double x, double __attribute__((unused)) y) {
        double r2322570 = -2.0;
        double r2322571 = x;
        double r2322572 = r2322570 * r2322571;
        double r2322573 = -1602025805.5623312;
        bool r2322574 = r2322572 <= r2322573;
        double r2322575 = 2.0;
        double r2322576 = exp(r2322572);
        double r2322577 = 1.0;
        double r2322578 = r2322576 + r2322577;
        double r2322579 = r2322575 / r2322578;
        double r2322580 = r2322579 - r2322577;
        double r2322581 = exp(r2322580);
        double r2322582 = log(r2322581);
        double r2322583 = 0.0036671774268135894;
        bool r2322584 = r2322572 <= r2322583;
        double r2322585 = -0.3333333333333333;
        double r2322586 = r2322571 * r2322571;
        double r2322587 = r2322586 * r2322571;
        double r2322588 = 5.0;
        double r2322589 = pow(r2322571, r2322588);
        double r2322590 = 0.13333333333333333;
        double r2322591 = fma(r2322589, r2322590, r2322571);
        double r2322592 = fma(r2322585, r2322587, r2322591);
        double r2322593 = r2322584 ? r2322592 : r2322582;
        double r2322594 = r2322574 ? r2322582 : r2322593;
        return r2322594;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (* -2 x) < -1602025805.5623312 or 0.0036671774268135894 < (* -2 x)

    1. Initial program 0.0

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

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

    if -1602025805.5623312 < (* -2 x) < 0.0036671774268135894

    1. Initial program 57.9

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified1.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -1602025805.5623312:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 0.0036671774268135894:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, \left(x \cdot x\right) \cdot x, \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{e^{-2 \cdot x} + 1} - 1}\right)\\ \end{array}\]

Reproduce

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