Average Error: 29.6 → 0.3
Time: 3.6s
Precision: binary64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
\[\begin{array}{l} t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\ \mathbf{if}\;-2 \cdot x \leq -14.282067032076004:\\ \;\;\;\;\sqrt[3]{{\left(t_0 - 1\right)}^{3}}\\ \mathbf{elif}\;-2 \cdot x \leq 8.041944314323065 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \sqrt{t_0}\\ \mathsf{fma}\left(t_1, t_1, -1\right) \end{array}\\ \end{array} \]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}}\\
\mathbf{if}\;-2 \cdot x \leq -14.282067032076004:\\
\;\;\;\;\sqrt[3]{{\left(t_0 - 1\right)}^{3}}\\

\mathbf{elif}\;-2 \cdot x \leq 8.041944314323065 \cdot 10^{-11}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \sqrt{t_0}\\
\mathsf{fma}\left(t_1, t_1, -1\right)
\end{array}\\


\end{array}
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
   (if (<= (* -2.0 x) -14.282067032076004)
     (cbrt (pow (- t_0 1.0) 3.0))
     (if (<= (* -2.0 x) 8.041944314323065e-11)
       x
       (let* ((t_1 (sqrt t_0))) (fma t_1 t_1 -1.0))))))
double code(double x, double y) {
	return (2.0 / (1.0 + exp(-2.0 * x))) - 1.0;
}
double code(double x, double y) {
	double t_0 = 2.0 / (1.0 + exp(-2.0 * x));
	double tmp;
	if ((-2.0 * x) <= -14.282067032076004) {
		tmp = cbrt(pow((t_0 - 1.0), 3.0));
	} else if ((-2.0 * x) <= 8.041944314323065e-11) {
		tmp = x;
	} else {
		double t_1 = sqrt(t_0);
		tmp = fma(t_1, t_1, -1.0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 -2 x) < -14.282067032076004

    1. Initial program 0.0

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
    2. Applied add-cbrt-cube_binary640.0

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

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

    if -14.282067032076004 < (*.f64 -2 x) < 8.0419443143230653e-11

    1. Initial program 59.4

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

      \[\leadsto \color{blue}{x} \]

    if 8.0419443143230653e-11 < (*.f64 -2 x)

    1. Initial program 0.5

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
    2. Applied add-sqr-sqrt_binary640.5

      \[\leadsto \color{blue}{\sqrt{\frac{2}{1 + e^{-2 \cdot x}}} \cdot \sqrt{\frac{2}{1 + e^{-2 \cdot x}}}} - 1 \]
    3. Applied fma-neg_binary640.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \leq -14.282067032076004:\\ \;\;\;\;\sqrt[3]{{\left(\frac{2}{1 + e^{-2 \cdot x}} - 1\right)}^{3}}\\ \mathbf{elif}\;-2 \cdot x \leq 8.041944314323065 \cdot 10^{-11}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{\frac{2}{1 + e^{-2 \cdot x}}}, \sqrt{\frac{2}{1 + e^{-2 \cdot x}}}, -1\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2021329 
(FPCore (x y)
  :name "Logistic function from Lakshay Garg"
  :precision binary64
  (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))