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

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r2323038 = 2.0;
        double r2323039 = 1.0;
        double r2323040 = -2.0;
        double r2323041 = x;
        double r2323042 = r2323040 * r2323041;
        double r2323043 = exp(r2323042);
        double r2323044 = r2323039 + r2323043;
        double r2323045 = r2323038 / r2323044;
        double r2323046 = r2323045 - r2323039;
        return r2323046;
}

double f(double x, double __attribute__((unused)) y) {
        double r2323047 = x;
        double r2323048 = -0.00838956395365049;
        bool r2323049 = r2323047 <= r2323048;
        double r2323050 = 2.0;
        double r2323051 = 1.0;
        double r2323052 = -2.0;
        double r2323053 = r2323052 * r2323047;
        double r2323054 = exp(r2323053);
        double r2323055 = r2323051 + r2323054;
        double r2323056 = r2323050 / r2323055;
        double r2323057 = r2323056 - r2323051;
        double r2323058 = exp(r2323057);
        double r2323059 = log(r2323058);
        double r2323060 = 0.006998885945432241;
        bool r2323061 = r2323047 <= r2323060;
        double r2323062 = -0.3333333333333333;
        double r2323063 = r2323047 * r2323047;
        double r2323064 = r2323047 * r2323063;
        double r2323065 = 5.0;
        double r2323066 = pow(r2323047, r2323065);
        double r2323067 = 0.13333333333333333;
        double r2323068 = fma(r2323066, r2323067, r2323047);
        double r2323069 = fma(r2323062, r2323064, r2323068);
        double r2323070 = r2323061 ? r2323069 : r2323059;
        double r2323071 = r2323049 ? r2323059 : r2323070;
        return r2323071;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if x < -0.00838956395365049 or 0.006998885945432241 < 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 \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{\log \left(e^{1}\right)}\]
    4. Applied add-log-exp0.0

      \[\leadsto \color{blue}{\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}}}\right)} - \log \left(e^{1}\right)\]
    5. Applied diff-log0.0

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

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

    if -0.00838956395365049 < x < 0.006998885945432241

    1. Initial program 59.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.00838956395365049:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{elif}\;x \le 0.006998885945432241:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{3}, x \cdot \left(x \cdot x\right), \mathsf{fma}\left({x}^{5}, \frac{2}{15}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 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))