Average Error: 29.6 → 0.0
Time: 20.0s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.290475389181829853763039395175837853458 \cdot 10^{-4} \lor \neg \left(x \le 8.133336636844118580288998110461307078367 \cdot 10^{-4}\right):\\ \;\;\;\;\log \left(e^{\frac{2}{{\left(e^{-2}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left(e^{-2}\right)}^{\left(\frac{x}{2}\right)} + 1} - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \mathsf{fma}\left(5.5511151231257827021181583404541015625 \cdot 10^{-17}, {x}^{4}, {x}^{3} \cdot 0.3333333333333333703407674875052180141211\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \le -9.290475389181829853763039395175837853458 \cdot 10^{-4} \lor \neg \left(x \le 8.133336636844118580288998110461307078367 \cdot 10^{-4}\right):\\
\;\;\;\;\log \left(e^{\frac{2}{{\left(e^{-2}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left(e^{-2}\right)}^{\left(\frac{x}{2}\right)} + 1} - 1}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r84646 = 2.0;
        double r84647 = 1.0;
        double r84648 = -2.0;
        double r84649 = x;
        double r84650 = r84648 * r84649;
        double r84651 = exp(r84650);
        double r84652 = r84647 + r84651;
        double r84653 = r84646 / r84652;
        double r84654 = r84653 - r84647;
        return r84654;
}

double f(double x, double __attribute__((unused)) y) {
        double r84655 = x;
        double r84656 = -0.000929047538918183;
        bool r84657 = r84655 <= r84656;
        double r84658 = 0.0008133336636844119;
        bool r84659 = r84655 <= r84658;
        double r84660 = !r84659;
        bool r84661 = r84657 || r84660;
        double r84662 = 2.0;
        double r84663 = -2.0;
        double r84664 = exp(r84663);
        double r84665 = 2.0;
        double r84666 = r84655 / r84665;
        double r84667 = pow(r84664, r84666);
        double r84668 = r84667 * r84667;
        double r84669 = 1.0;
        double r84670 = r84668 + r84669;
        double r84671 = r84662 / r84670;
        double r84672 = r84671 - r84669;
        double r84673 = exp(r84672);
        double r84674 = log(r84673);
        double r84675 = r84669 * r84655;
        double r84676 = 5.551115123125783e-17;
        double r84677 = 4.0;
        double r84678 = pow(r84655, r84677);
        double r84679 = 3.0;
        double r84680 = pow(r84655, r84679);
        double r84681 = 0.33333333333333337;
        double r84682 = r84680 * r84681;
        double r84683 = fma(r84676, r84678, r84682);
        double r84684 = r84675 - r84683;
        double r84685 = r84661 ? r84674 : r84684;
        return r84685;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 2 regimes
  2. if x < -0.000929047538918183 or 0.0008133336636844119 < x

    1. Initial program 0.1

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

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

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

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + {\left(e^{-2}\right)}^{x}} - 1}\right)}\]
    8. Using strategy rm
    9. Applied sqr-pow0.1

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

    if -0.000929047538918183 < x < 0.0008133336636844119

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{\frac{2}{1 + {\left(e^{x}\right)}^{-2}} - 1}\]
    3. Using strategy rm
    4. Applied add-log-exp59.1

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

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

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

      \[\leadsto \log \color{blue}{\left(e^{\frac{2}{1 + {\left(e^{-2}\right)}^{x}} - 1}\right)}\]
    8. Taylor expanded around 0 0.0

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

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

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

Reproduce

herbie shell --seed 2019195 +o rules:numerics
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))