Average Error: 29.4 → 0.2
Time: 8.9s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.850333007111792715804199360718484967947 \lor \neg \left(-2 \cdot x \le 7.158249832607255782421567983942815014721 \cdot 10^{-12}\right):\\ \;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(1 - \log \left(e^{x \cdot \left(x \cdot \left(0.3333333333333333703407674875052180141211 + 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot x\right)\right)}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.850333007111792715804199360718484967947 \lor \neg \left(-2 \cdot x \le 7.158249832607255782421567983942815014721 \cdot 10^{-12}\right):\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} - 1\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r45174 = 2.0;
        double r45175 = 1.0;
        double r45176 = -2.0;
        double r45177 = x;
        double r45178 = r45176 * r45177;
        double r45179 = exp(r45178);
        double r45180 = r45175 + r45179;
        double r45181 = r45174 / r45180;
        double r45182 = r45181 - r45175;
        return r45182;
}

double f(double x, double __attribute__((unused)) y) {
        double r45183 = -2.0;
        double r45184 = x;
        double r45185 = r45183 * r45184;
        double r45186 = -0.8503330071117927;
        bool r45187 = r45185 <= r45186;
        double r45188 = 7.158249832607256e-12;
        bool r45189 = r45185 <= r45188;
        double r45190 = !r45189;
        bool r45191 = r45187 || r45190;
        double r45192 = 2.0;
        double r45193 = 1.0;
        double r45194 = exp(r45185);
        double r45195 = r45193 + r45194;
        double r45196 = r45192 / r45195;
        double r45197 = r45196 - r45193;
        double r45198 = 0.33333333333333337;
        double r45199 = 5.551115123125783e-17;
        double r45200 = r45199 * r45184;
        double r45201 = r45198 + r45200;
        double r45202 = r45184 * r45201;
        double r45203 = r45184 * r45202;
        double r45204 = exp(r45203);
        double r45205 = log(r45204);
        double r45206 = r45193 - r45205;
        double r45207 = r45184 * r45206;
        double r45208 = r45191 ? r45197 : r45207;
        return r45208;
}

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.8503330071117927 or 7.158249832607256e-12 < (* -2.0 x)

    1. Initial program 0.3

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]

    if -0.8503330071117927 < (* -2.0 x) < 7.158249832607256e-12

    1. Initial program 59.5

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

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

      \[\leadsto \color{blue}{x \cdot \left(1 - x \cdot \left(x \cdot \left(0.3333333333333333703407674875052180141211 + 5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot x\right)\right)\right)}\]
    4. Using strategy rm
    5. Applied add-log-exp0.1

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

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

Reproduce

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