Average Error: 29.0 → 0.2
Time: 2.6s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -337.40848159342193 \lor \neg \left(-2 \cdot x \le 4.07506997279720649 \cdot 10^{-5}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -337.40848159342193 \lor \neg \left(-2 \cdot x \le 4.07506997279720649 \cdot 10^{-5}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r41260 = 2.0;
        double r41261 = 1.0;
        double r41262 = -2.0;
        double r41263 = x;
        double r41264 = r41262 * r41263;
        double r41265 = exp(r41264);
        double r41266 = r41261 + r41265;
        double r41267 = r41260 / r41266;
        double r41268 = r41267 - r41261;
        return r41268;
}

double f(double x, double __attribute__((unused)) y) {
        double r41269 = -2.0;
        double r41270 = x;
        double r41271 = r41269 * r41270;
        double r41272 = -337.4084815934219;
        bool r41273 = r41271 <= r41272;
        double r41274 = 4.0750699727972065e-05;
        bool r41275 = r41271 <= r41274;
        double r41276 = !r41275;
        bool r41277 = r41273 || r41276;
        double r41278 = 2.0;
        double r41279 = 1.0;
        double r41280 = exp(r41271);
        double r41281 = r41279 + r41280;
        double r41282 = r41278 / r41281;
        double r41283 = r41282 - r41279;
        double r41284 = exp(r41283);
        double r41285 = log(r41284);
        double r41286 = r41279 * r41270;
        double r41287 = 5.551115123125783e-17;
        double r41288 = 4.0;
        double r41289 = pow(r41270, r41288);
        double r41290 = r41287 * r41289;
        double r41291 = 0.33333333333333337;
        double r41292 = 3.0;
        double r41293 = pow(r41270, r41292);
        double r41294 = r41291 * r41293;
        double r41295 = r41290 + r41294;
        double r41296 = r41286 - r41295;
        double r41297 = r41277 ? r41285 : r41296;
        return r41297;
}

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) < -337.4084815934219 or 4.0750699727972065e-05 < (* -2.0 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.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 -337.4084815934219 < (* -2.0 x) < 4.0750699727972065e-05

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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