Average Error: 29.2 → 0.1
Time: 4.3s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} \le 0.98743305280796312 \lor \neg \left(\frac{2}{1 + e^{-2 \cdot x}} \le 1.00000004824416\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}\;\frac{2}{1 + e^{-2 \cdot x}} \le 0.98743305280796312 \lor \neg \left(\frac{2}{1 + e^{-2 \cdot x}} \le 1.00000004824416\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 r57633 = 2.0;
        double r57634 = 1.0;
        double r57635 = -2.0;
        double r57636 = x;
        double r57637 = r57635 * r57636;
        double r57638 = exp(r57637);
        double r57639 = r57634 + r57638;
        double r57640 = r57633 / r57639;
        double r57641 = r57640 - r57634;
        return r57641;
}

double f(double x, double __attribute__((unused)) y) {
        double r57642 = 2.0;
        double r57643 = 1.0;
        double r57644 = -2.0;
        double r57645 = x;
        double r57646 = r57644 * r57645;
        double r57647 = exp(r57646);
        double r57648 = r57643 + r57647;
        double r57649 = r57642 / r57648;
        double r57650 = 0.9874330528079631;
        bool r57651 = r57649 <= r57650;
        double r57652 = 1.00000004824416;
        bool r57653 = r57649 <= r57652;
        double r57654 = !r57653;
        bool r57655 = r57651 || r57654;
        double r57656 = 1.0;
        double r57657 = sqrt(r57648);
        double r57658 = r57656 / r57657;
        double r57659 = r57642 / r57657;
        double r57660 = -r57643;
        double r57661 = fma(r57658, r57659, r57660);
        double r57662 = 5.551115123125783e-17;
        double r57663 = 4.0;
        double r57664 = pow(r57645, r57663);
        double r57665 = 0.33333333333333337;
        double r57666 = 3.0;
        double r57667 = pow(r57645, r57666);
        double r57668 = r57665 * r57667;
        double r57669 = fma(r57662, r57664, r57668);
        double r57670 = -r57669;
        double r57671 = fma(r57643, r57645, r57670);
        double r57672 = r57655 ? r57661 : r57671;
        return r57672;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) < 0.9874330528079631 or 1.00000004824416 < (/ 2.0 (+ 1.0 (exp (* -2.0 x))))

    1. Initial program 0.1

      \[\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 0.9874330528079631 < (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) < 1.00000004824416

    1. Initial program 59.4

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

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

      \[\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.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} \le 0.98743305280796312 \lor \neg \left(\frac{2}{1 + e^{-2 \cdot x}} \le 1.00000004824416\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 2020033 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2 (+ 1 (exp (* -2 x)))) 1))