Average Error: 29.4 → 0.2
Time: 4.5s
Precision: 64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \le -0.168673542136596771:\\ \;\;\;\;1 \cdot \left(\frac{2}{e^{-2 \cdot x} + 1} - 1\right)\\ \mathbf{elif}\;-2 \cdot x \le 9.00792072330781855 \cdot 10^{-11}:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\left(\sqrt{\frac{2}{e^{-2 \cdot x} + 1}} + \sqrt{1}\right) \cdot \left(\sqrt{\frac{2}{e^{-2 \cdot x} + 1}} - \sqrt{1}\right)\right)\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \le -0.168673542136596771:\\
\;\;\;\;1 \cdot \left(\frac{2}{e^{-2 \cdot x} + 1} - 1\right)\\

\mathbf{elif}\;-2 \cdot x \le 9.00792072330781855 \cdot 10^{-11}:\\
\;\;\;\;1 \cdot \mathsf{fma}\left(1, x, -\mathsf{fma}\left(5.55112 \cdot 10^{-17}, {x}^{4}, 0.33333333333333337 \cdot {x}^{3}\right)\right)\\

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

\end{array}
double code(double x, double y) {
	return ((2.0 / (1.0 + exp((-2.0 * x)))) - 1.0);
}
double code(double x, double y) {
	double temp;
	if (((-2.0 * x) <= -0.16867354213659677)) {
		temp = (1.0 * ((2.0 / (exp((-2.0 * x)) + 1.0)) - 1.0));
	} else {
		double temp_1;
		if (((-2.0 * x) <= 9.007920723307819e-11)) {
			temp_1 = (1.0 * fma(1.0, x, -fma(5.551115123125783e-17, pow(x, 4.0), (0.33333333333333337 * pow(x, 3.0)))));
		} else {
			temp_1 = (1.0 * ((sqrt((2.0 / (exp((-2.0 * x)) + 1.0))) + sqrt(1.0)) * (sqrt((2.0 / (exp((-2.0 * x)) + 1.0))) - sqrt(1.0))));
		}
		temp = temp_1;
	}
	return temp;
}

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.16867354213659677

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.0

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{1 \cdot 1}\]
    4. Applied *-un-lft-identity0.0

      \[\leadsto \color{blue}{1 \cdot \frac{2}{1 + e^{-2 \cdot x}}} - 1 \cdot 1\]
    5. Applied distribute-lft-out--0.0

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

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

    if -0.16867354213659677 < (* -2.0 x) < 9.007920723307819e-11

    1. Initial program 59.2

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity59.2

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{1 \cdot 1}\]
    4. Applied *-un-lft-identity59.2

      \[\leadsto \color{blue}{1 \cdot \frac{2}{1 + e^{-2 \cdot x}}} - 1 \cdot 1\]
    5. Applied distribute-lft-out--59.2

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

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

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

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

    if 9.007920723307819e-11 < (* -2.0 x)

    1. Initial program 0.5

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.5

      \[\leadsto \frac{2}{1 + e^{-2 \cdot x}} - \color{blue}{1 \cdot 1}\]
    4. Applied *-un-lft-identity0.5

      \[\leadsto \color{blue}{1 \cdot \frac{2}{1 + e^{-2 \cdot x}}} - 1 \cdot 1\]
    5. Applied distribute-lft-out--0.5

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

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

      \[\leadsto 1 \cdot \left(\frac{2}{e^{-2 \cdot x} + 1} - \color{blue}{\sqrt{1} \cdot \sqrt{1}}\right)\]
    9. Applied add-sqr-sqrt0.5

      \[\leadsto 1 \cdot \left(\color{blue}{\sqrt{\frac{2}{e^{-2 \cdot x} + 1}} \cdot \sqrt{\frac{2}{e^{-2 \cdot x} + 1}}} - \sqrt{1} \cdot \sqrt{1}\right)\]
    10. Applied difference-of-squares0.5

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

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

Reproduce

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