Average Error: 29.4 → 0.1
Time: 4.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.07473290851215121100015181809794739820063 \lor \neg \left(-2 \cdot x \le 1.119851185614108205585662952907810563374 \cdot 10^{-5}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.07473290851215121100015181809794739820063 \lor \neg \left(-2 \cdot x \le 1.119851185614108205585662952907810563374 \cdot 10^{-5}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

\mathbf{else}:\\
\;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r64054 = 2.0;
        double r64055 = 1.0;
        double r64056 = -2.0;
        double r64057 = x;
        double r64058 = r64056 * r64057;
        double r64059 = exp(r64058);
        double r64060 = r64055 + r64059;
        double r64061 = r64054 / r64060;
        double r64062 = r64061 - r64055;
        return r64062;
}

double f(double x, double __attribute__((unused)) y) {
        double r64063 = -2.0;
        double r64064 = x;
        double r64065 = r64063 * r64064;
        double r64066 = -0.07473290851215121;
        bool r64067 = r64065 <= r64066;
        double r64068 = 1.1198511856141082e-05;
        bool r64069 = r64065 <= r64068;
        double r64070 = !r64069;
        bool r64071 = r64067 || r64070;
        double r64072 = 2.0;
        double r64073 = 1.0;
        double r64074 = exp(r64065);
        double r64075 = r64073 + r64074;
        double r64076 = r64072 / r64075;
        double r64077 = r64076 - r64073;
        double r64078 = exp(r64077);
        double r64079 = log(r64078);
        double r64080 = r64073 * r64064;
        double r64081 = 5.551115123125783e-17;
        double r64082 = 4.0;
        double r64083 = pow(r64064, r64082);
        double r64084 = r64081 * r64083;
        double r64085 = 0.33333333333333337;
        double r64086 = 3.0;
        double r64087 = pow(r64064, r64086);
        double r64088 = r64085 * r64087;
        double r64089 = r64084 + r64088;
        double r64090 = r64080 - r64089;
        double r64091 = r64071 ? r64079 : r64090;
        return r64091;
}

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 2 regimes
  2. if (* -2.0 x) < -0.07473290851215121 or 1.1198511856141082e-05 < (* -2.0 x)

    1. Initial program 0.1

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

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

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

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

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

    if -0.07473290851215121 < (* -2.0 x) < 1.1198511856141082e-05

    1. Initial program 59.2

      \[\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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.07473290851215121100015181809794739820063 \lor \neg \left(-2 \cdot x \le 1.119851185614108205585662952907810563374 \cdot 10^{-5}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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