Average Error: 29.4 → 0.1
Time: 8.7s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.422043425737493039:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2 \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right)}{e^{-2 \cdot x} + 1} + 1 \cdot 1}\\ \mathbf{elif}\;-2 \cdot x \le 9.24010699698761472 \cdot 10^{-9}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}} \cdot \left(\frac{\sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right)\right) + 1 \cdot 1}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.422043425737493039:\\
\;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2 \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right)}{e^{-2 \cdot x} + 1} + 1 \cdot 1}\\

\mathbf{elif}\;-2 \cdot x \le 9.24010699698761472 \cdot 10^{-9}:\\
\;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\

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

\end{array}
double f(double x, double __attribute__((unused)) y) {
        double r101007 = 2.0;
        double r101008 = 1.0;
        double r101009 = -2.0;
        double r101010 = x;
        double r101011 = r101009 * r101010;
        double r101012 = exp(r101011);
        double r101013 = r101008 + r101012;
        double r101014 = r101007 / r101013;
        double r101015 = r101014 - r101008;
        return r101015;
}

double f(double x, double __attribute__((unused)) y) {
        double r101016 = -2.0;
        double r101017 = x;
        double r101018 = r101016 * r101017;
        double r101019 = -0.42204342573749304;
        bool r101020 = r101018 <= r101019;
        double r101021 = 2.0;
        double r101022 = 1.0;
        double r101023 = exp(r101018);
        double r101024 = r101022 + r101023;
        double r101025 = r101021 / r101024;
        double r101026 = 3.0;
        double r101027 = pow(r101025, r101026);
        double r101028 = pow(r101022, r101026);
        double r101029 = r101027 - r101028;
        double r101030 = r101023 + r101022;
        double r101031 = r101021 / r101030;
        double r101032 = r101022 + r101031;
        double r101033 = r101021 * r101032;
        double r101034 = r101033 / r101030;
        double r101035 = r101022 * r101022;
        double r101036 = r101034 + r101035;
        double r101037 = r101029 / r101036;
        double r101038 = 9.240106996987615e-09;
        bool r101039 = r101018 <= r101038;
        double r101040 = r101022 * r101017;
        double r101041 = 5.551115123125783e-17;
        double r101042 = 4.0;
        double r101043 = pow(r101017, r101042);
        double r101044 = r101041 * r101043;
        double r101045 = 0.33333333333333337;
        double r101046 = pow(r101017, r101026);
        double r101047 = r101045 * r101046;
        double r101048 = r101044 + r101047;
        double r101049 = r101040 - r101048;
        double r101050 = cbrt(r101021);
        double r101051 = r101050 * r101050;
        double r101052 = sqrt(r101030);
        double r101053 = r101051 / r101052;
        double r101054 = r101050 / r101052;
        double r101055 = r101054 * r101032;
        double r101056 = r101053 * r101055;
        double r101057 = r101056 + r101035;
        double r101058 = r101029 / r101057;
        double r101059 = r101039 ? r101049 : r101058;
        double r101060 = r101020 ? r101037 : r101059;
        return r101060;
}

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

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied flip3--0.0

      \[\leadsto \color{blue}{\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} + \left(1 \cdot 1 + \frac{2}{1 + e^{-2 \cdot x}} \cdot 1\right)}}\]
    4. Simplified0.0

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\color{blue}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}}\]
    5. Using strategy rm
    6. Applied associate-*l/0.0

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

    if -0.42204342573749304 < (* -2.0 x) < 9.240106996987615e-09

    1. Initial program 59.4

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

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

    if 9.240106996987615e-09 < (* -2.0 x)

    1. Initial program 0.2

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied flip3--0.2

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

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\color{blue}{\frac{2}{e^{-2 \cdot x} + 1} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt0.2

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2}{\color{blue}{\sqrt{e^{-2 \cdot x} + 1} \cdot \sqrt{e^{-2 \cdot x} + 1}}} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\]
    7. Applied add-cube-cbrt0.2

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{\color{blue}{\left(\sqrt[3]{2} \cdot \sqrt[3]{2}\right) \cdot \sqrt[3]{2}}}{\sqrt{e^{-2 \cdot x} + 1} \cdot \sqrt{e^{-2 \cdot x} + 1}} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\]
    8. Applied times-frac0.2

      \[\leadsto \frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\color{blue}{\left(\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}} \cdot \frac{\sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}}\right)} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right) + 1 \cdot 1}\]
    9. Applied associate-*l*0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.422043425737493039:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{2 \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right)}{e^{-2 \cdot x} + 1} + 1 \cdot 1}\\ \mathbf{elif}\;-2 \cdot x \le 9.24010699698761472 \cdot 10^{-9}:\\ \;\;\;\;1 \cdot x - \left(5.55112 \cdot 10^{-17} \cdot {x}^{4} + 0.33333333333333337 \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\frac{2}{1 + e^{-2 \cdot x}}\right)}^{3} - {1}^{3}}{\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}} \cdot \left(\frac{\sqrt[3]{2}}{\sqrt{e^{-2 \cdot x} + 1}} \cdot \left(1 + \frac{2}{e^{-2 \cdot x} + 1}\right)\right) + 1 \cdot 1}\\ \end{array}\]

Reproduce

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