Average Error: 29.1 → 0.1
Time: 6.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -2.989922347722678175330202066106721758842:\\ \;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\ \mathbf{elif}\;-2 \cdot x \le 8.994147945975712989466477331745863921242 \cdot 10^{-4}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}}\right) + \log \left(\sqrt{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}\;-2 \cdot x \le -2.989922347722678175330202066106721758842:\\
\;\;\;\;\log \left(e^{\frac{2}{1 + e^{-2 \cdot x}} - 1}\right)\\

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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r66348 = 2.0;
        double r66349 = 1.0;
        double r66350 = -2.0;
        double r66351 = x;
        double r66352 = r66350 * r66351;
        double r66353 = exp(r66352);
        double r66354 = r66349 + r66353;
        double r66355 = r66348 / r66354;
        double r66356 = r66355 - r66349;
        return r66356;
}

double f(double x, double __attribute__((unused)) y) {
        double r66357 = -2.0;
        double r66358 = x;
        double r66359 = r66357 * r66358;
        double r66360 = -2.989922347722678;
        bool r66361 = r66359 <= r66360;
        double r66362 = 2.0;
        double r66363 = 1.0;
        double r66364 = exp(r66359);
        double r66365 = r66363 + r66364;
        double r66366 = r66362 / r66365;
        double r66367 = r66366 - r66363;
        double r66368 = exp(r66367);
        double r66369 = log(r66368);
        double r66370 = 0.0008994147945975713;
        bool r66371 = r66359 <= r66370;
        double r66372 = r66363 * r66358;
        double r66373 = 5.551115123125783e-17;
        double r66374 = 4.0;
        double r66375 = pow(r66358, r66374);
        double r66376 = r66373 * r66375;
        double r66377 = 0.33333333333333337;
        double r66378 = 3.0;
        double r66379 = pow(r66358, r66378);
        double r66380 = r66377 * r66379;
        double r66381 = r66376 + r66380;
        double r66382 = r66372 - r66381;
        double r66383 = sqrt(r66368);
        double r66384 = log(r66383);
        double r66385 = r66384 + r66384;
        double r66386 = r66371 ? r66382 : r66385;
        double r66387 = r66361 ? r66369 : r66386;
        return r66387;
}

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) < -2.989922347722678

    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}{1 + e^{-2 \cdot x}} - 1}\right)}\]

    if -2.989922347722678 < (* -2.0 x) < 0.0008994147945975713

    1. Initial program 59.0

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

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

    if 0.0008994147945975713 < (* -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)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.1

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

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

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

Reproduce

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