Average Error: 28.8 → 0.4
Time: 27.4s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.758738334497317:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 3.6827627847384156 \cdot 10^{-16}:\\ \;\;\;\;x + \frac{-1}{3} \cdot \left(x \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{2}, \frac{\sqrt{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 -2.758738334497317:\\
\;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\

\mathbf{elif}\;-2 \cdot x \le 3.6827627847384156 \cdot 10^{-16}:\\
\;\;\;\;x + \frac{-1}{3} \cdot \left(x \cdot \left(x \cdot x\right)\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2340613 = 2.0;
        double r2340614 = 1.0;
        double r2340615 = -2.0;
        double r2340616 = x;
        double r2340617 = r2340615 * r2340616;
        double r2340618 = exp(r2340617);
        double r2340619 = r2340614 + r2340618;
        double r2340620 = r2340613 / r2340619;
        double r2340621 = r2340620 - r2340614;
        return r2340621;
}

double f(double x, double __attribute__((unused)) y) {
        double r2340622 = -2.0;
        double r2340623 = x;
        double r2340624 = r2340622 * r2340623;
        double r2340625 = -2.758738334497317;
        bool r2340626 = r2340624 <= r2340625;
        double r2340627 = 2.0;
        double r2340628 = exp(r2340624);
        double r2340629 = 1.0;
        double r2340630 = r2340628 + r2340629;
        double r2340631 = r2340627 / r2340630;
        double r2340632 = r2340631 - r2340629;
        double r2340633 = 3.6827627847384156e-16;
        bool r2340634 = r2340624 <= r2340633;
        double r2340635 = -0.3333333333333333;
        double r2340636 = r2340623 * r2340623;
        double r2340637 = r2340623 * r2340636;
        double r2340638 = r2340635 * r2340637;
        double r2340639 = r2340623 + r2340638;
        double r2340640 = sqrt(r2340627);
        double r2340641 = r2340640 / r2340630;
        double r2340642 = -1.0;
        double r2340643 = fma(r2340640, r2340641, r2340642);
        double r2340644 = r2340634 ? r2340639 : r2340643;
        double r2340645 = r2340626 ? r2340632 : r2340644;
        return r2340645;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if (* -2 x) < -2.758738334497317

    1. Initial program 0.0

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

      \[\leadsto \color{blue}{2 \cdot \frac{1}{e^{-2 \cdot x} + 1} - 1}\]
    3. Simplified0.0

      \[\leadsto \color{blue}{\frac{2}{1 + e^{-2 \cdot x}} - 1}\]

    if -2.758738334497317 < (* -2 x) < 3.6827627847384156e-16

    1. Initial program 59.5

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity59.5

      \[\leadsto \frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\]
    4. Applied add-sqr-sqrt60.6

      \[\leadsto \frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \left(1 + e^{-2 \cdot x}\right)} - 1\]
    5. Applied times-frac60.6

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

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

      \[\leadsto \mathsf{fma}\left(\frac{\sqrt{2}}{1}, \frac{\sqrt{2}}{1 + e^{-2 \cdot x}}, \color{blue}{-1}\right)\]
    8. Taylor expanded around 0 60.7

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot x\right) + \frac{1}{2} \cdot {\left(\sqrt{2}\right)}^{2}\right) - \left(\frac{1}{6} \cdot \left({\left(\sqrt{2}\right)}^{2} \cdot {x}^{3}\right) + 1\right)}\]
    9. Simplified0.2

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

    if 3.6827627847384156e-16 < (* -2 x)

    1. Initial program 1.2

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity1.2

      \[\leadsto \frac{2}{\color{blue}{1 \cdot \left(1 + e^{-2 \cdot x}\right)}} - 1\]
    4. Applied add-sqr-sqrt1.3

      \[\leadsto \frac{\color{blue}{\sqrt{2} \cdot \sqrt{2}}}{1 \cdot \left(1 + e^{-2 \cdot x}\right)} - 1\]
    5. Applied times-frac1.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.758738334497317:\\ \;\;\;\;\frac{2}{e^{-2 \cdot x} + 1} - 1\\ \mathbf{elif}\;-2 \cdot x \le 3.6827627847384156 \cdot 10^{-16}:\\ \;\;\;\;x + \frac{-1}{3} \cdot \left(x \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{2}, \frac{\sqrt{2}}{e^{-2 \cdot x} + 1}, -1\right)\\ \end{array}\]

Reproduce

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