Average Error: 28.8 → 0.1
Time: 4.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.002635842201220140595951946238528762478381:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\\ \mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.002635842201220140595951946238528762478381:\\
\;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\\

\mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\
\;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r59984 = 2.0;
        double r59985 = 1.0;
        double r59986 = -2.0;
        double r59987 = x;
        double r59988 = r59986 * r59987;
        double r59989 = exp(r59988);
        double r59990 = r59985 + r59989;
        double r59991 = r59984 / r59990;
        double r59992 = r59991 - r59985;
        return r59992;
}

double f(double x, double __attribute__((unused)) y) {
        double r59993 = -2.0;
        double r59994 = x;
        double r59995 = r59993 * r59994;
        double r59996 = -0.0026358422012201406;
        bool r59997 = r59995 <= r59996;
        double r59998 = 2.0;
        double r59999 = 1.0;
        double r60000 = exp(r59995);
        double r60001 = r59999 + r60000;
        double r60002 = r59998 / r60001;
        double r60003 = 3.0;
        double r60004 = pow(r60002, r60003);
        double r60005 = pow(r59999, r60003);
        double r60006 = r60004 - r60005;
        double r60007 = r60000 + r59999;
        double r60008 = r59998 / r60007;
        double r60009 = r59999 + r60008;
        double r60010 = r60008 * r60009;
        double r60011 = r59999 * r59999;
        double r60012 = r60010 + r60011;
        double r60013 = r60006 / r60012;
        double r60014 = 2.546151029787973e-07;
        bool r60015 = r59995 <= r60014;
        double r60016 = r59999 * r59994;
        double r60017 = 5.551115123125783e-17;
        double r60018 = 4.0;
        double r60019 = pow(r59994, r60018);
        double r60020 = r60017 * r60019;
        double r60021 = 0.33333333333333337;
        double r60022 = pow(r59994, r60003);
        double r60023 = r60021 * r60022;
        double r60024 = r60020 + r60023;
        double r60025 = r60016 - r60024;
        double r60026 = sqrt(r60001);
        double r60027 = r59998 / r60026;
        double r60028 = r60027 / r60026;
        double r60029 = r60028 - r59999;
        double r60030 = r60015 ? r60025 : r60029;
        double r60031 = r59997 ? r60013 : r60030;
        return r60031;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

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

    1. Initial program 0.0

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

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

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

    if -0.0026358422012201406 < (* -2.0 x) < 2.546151029787973e-07

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)}\]

    if 2.546151029787973e-07 < (* -2.0 x)

    1. Initial program 0.2

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

      \[\leadsto \frac{2}{\color{blue}{\sqrt{1 + e^{-2 \cdot x}} \cdot \sqrt{1 + e^{-2 \cdot x}}}} - 1\]
    4. Applied associate-/r*0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.002635842201220140595951946238528762478381:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\\ \mathbf{elif}\;-2 \cdot x \le 2.54615102978797293259243233326527544591 \cdot 10^{-7}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{2}{\sqrt{1 + e^{-2 \cdot x}}}}{\sqrt{1 + e^{-2 \cdot x}}} - 1\\ \end{array}\]

Reproduce

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