Average Error: 29.4 → 0.4
Time: 4.8s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -55422.43288444895006250590085983276367188 \lor \neg \left(-2 \cdot x \le 1.186352449555409772300601511929585285543 \cdot 10^{-4}\right):\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -55422.43288444895006250590085983276367188 \lor \neg \left(-2 \cdot x \le 1.186352449555409772300601511929585285543 \cdot 10^{-4}\right):\\
\;\;\;\;\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)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r52767 = 2.0;
        double r52768 = 1.0;
        double r52769 = -2.0;
        double r52770 = x;
        double r52771 = r52769 * r52770;
        double r52772 = exp(r52771);
        double r52773 = r52768 + r52772;
        double r52774 = r52767 / r52773;
        double r52775 = r52774 - r52768;
        return r52775;
}

double f(double x, double __attribute__((unused)) y) {
        double r52776 = -2.0;
        double r52777 = x;
        double r52778 = r52776 * r52777;
        double r52779 = -55422.43288444895;
        bool r52780 = r52778 <= r52779;
        double r52781 = 0.00011863524495554098;
        bool r52782 = r52778 <= r52781;
        double r52783 = !r52782;
        bool r52784 = r52780 || r52783;
        double r52785 = 2.0;
        double r52786 = 1.0;
        double r52787 = exp(r52778);
        double r52788 = r52786 + r52787;
        double r52789 = r52785 / r52788;
        double r52790 = r52789 - r52786;
        double r52791 = exp(r52790);
        double r52792 = sqrt(r52791);
        double r52793 = log(r52792);
        double r52794 = r52793 + r52793;
        double r52795 = r52786 * r52777;
        double r52796 = 5.551115123125783e-17;
        double r52797 = 4.0;
        double r52798 = pow(r52777, r52797);
        double r52799 = r52796 * r52798;
        double r52800 = 0.33333333333333337;
        double r52801 = 3.0;
        double r52802 = pow(r52777, r52801);
        double r52803 = r52800 * r52802;
        double r52804 = r52799 + r52803;
        double r52805 = r52795 - r52804;
        double r52806 = r52784 ? r52794 : r52805;
        return r52806;
}

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) < -55422.43288444895 or 0.00011863524495554098 < (* -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)}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt0.0

      \[\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.0

      \[\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)}\]

    if -55422.43288444895 < (* -2.0 x) < 0.00011863524495554098

    1. Initial program 58.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -55422.43288444895006250590085983276367188 \lor \neg \left(-2 \cdot x \le 1.186352449555409772300601511929585285543 \cdot 10^{-4}\right):\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \left(5.5511151231257827021181583404541015625 \cdot 10^{-17} \cdot {x}^{4} + 0.3333333333333333703407674875052180141211 \cdot {x}^{3}\right)\\ \end{array}\]

Reproduce

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