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

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r42295 = 2.0;
        double r42296 = 1.0;
        double r42297 = -2.0;
        double r42298 = x;
        double r42299 = r42297 * r42298;
        double r42300 = exp(r42299);
        double r42301 = r42296 + r42300;
        double r42302 = r42295 / r42301;
        double r42303 = r42302 - r42296;
        return r42303;
}

double f(double x, double __attribute__((unused)) y) {
        double r42304 = -2.0;
        double r42305 = x;
        double r42306 = r42304 * r42305;
        double r42307 = -15476529172.257303;
        bool r42308 = r42306 <= r42307;
        double r42309 = 0.00011197161577118467;
        bool r42310 = r42306 <= r42309;
        double r42311 = !r42310;
        bool r42312 = r42308 || r42311;
        double r42313 = 2.0;
        double r42314 = 1.0;
        double r42315 = exp(r42306);
        double r42316 = r42314 + r42315;
        double r42317 = r42313 / r42316;
        double r42318 = r42317 - r42314;
        double r42319 = exp(r42318);
        double r42320 = log(r42319);
        double r42321 = r42314 * r42305;
        double r42322 = 3.0;
        double r42323 = pow(r42305, r42322);
        double r42324 = 0.33333333333333337;
        double r42325 = 5.551115123125783e-17;
        double r42326 = r42325 * r42305;
        double r42327 = r42324 + r42326;
        double r42328 = r42323 * r42327;
        double r42329 = r42321 - r42328;
        double r42330 = r42312 ? r42320 : r42329;
        return r42330;
}

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) < -15476529172.257303 or 0.00011197161577118467 < (* -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.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 -15476529172.257303 < (* -2.0 x) < 0.00011197161577118467

    1. Initial program 57.8

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

      \[\leadsto \color{blue}{1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)}\]
    3. Simplified1.3

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

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

Reproduce

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