Average Error: 30.0 → 0.2
Time: 4.6s
Precision: binary64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
\[\begin{array}{l} t_0 := \frac{2}{1 + e^{-2 \cdot x}} - 1\\ \mathbf{if}\;-2 \cdot x \leq -25.38935555970136:\\ \;\;\;\;\begin{array}{l} t_1 := \sqrt[3]{t_0}\\ t_1 \cdot {t_1}^{2} \end{array}\\ \mathbf{elif}\;-2 \cdot x \leq 9.760964936782607 \cdot 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
t_0 := \frac{2}{1 + e^{-2 \cdot x}} - 1\\
\mathbf{if}\;-2 \cdot x \leq -25.38935555970136:\\
\;\;\;\;\begin{array}{l}
t_1 := \sqrt[3]{t_0}\\
t_1 \cdot {t_1}^{2}
\end{array}\\

\mathbf{elif}\;-2 \cdot x \leq 9.760964936782607 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\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)))) 1.0)))
   (if (<= (* -2.0 x) -25.38935555970136)
     (let* ((t_1 (cbrt t_0))) (* t_1 (pow t_1 2.0)))
     (if (<= (* -2.0 x) 9.760964936782607e-10)
       (fma (pow x 3.0) -0.3333333333333333 x)
       t_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))) - 1.0;
	double tmp;
	if ((-2.0 * x) <= -25.38935555970136) {
		double t_1_1 = cbrt(t_0);
		tmp = t_1_1 * pow(t_1_1, 2.0);
	} else if ((-2.0 * x) <= 9.760964936782607e-10) {
		tmp = fma(pow(x, 3.0), -0.3333333333333333, x);
	} else {
		tmp = t_0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Derivation

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

    1. Initial program 0.0

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

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

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

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

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

    if -25.3893555597013609 < (*.f64 -2 x) < 9.7609649367826068e-10

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{x - 0.3333333333333333 \cdot {x}^{3}} \]
    3. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.3333333333333333, x\right)} \]

    if 9.7609649367826068e-10 < (*.f64 -2 x)

    1. Initial program 0.4

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Reproduce

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