Average Error: 29.1 → 0.3
Time: 5.4s
Precision: binary64
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \leq -17.726881421434474:\\ \;\;\;\;\frac{\frac{\frac{4}{{\left(1 + e^{-2 \cdot x}\right)}^{2}} - 1}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}} \cdot \sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}\\ \mathbf{elif}\;-2 \cdot x \leq 1.916498673169216 \cdot 10^{-13}:\\ \;\;\;\;x - {x}^{3} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{{\left(1 + e^{-2 \cdot x}\right)}^{1.5} \cdot \sqrt{1 + e^{-2 \cdot x}}} + -1}{1 + \frac{2}{1 + e^{-2 \cdot x}}}\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -17.726881421434474:\\
\;\;\;\;\frac{\frac{\frac{4}{{\left(1 + e^{-2 \cdot x}\right)}^{2}} - 1}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}} \cdot \sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}\\

\mathbf{elif}\;-2 \cdot x \leq 1.916498673169216 \cdot 10^{-13}:\\
\;\;\;\;x - {x}^{3} \cdot 0.3333333333333333\\

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

\end{array}
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
(FPCore (x y)
 :precision binary64
 (if (<= (* -2.0 x) -17.726881421434474)
   (/
    (/
     (- (/ 4.0 (pow (+ 1.0 (exp (* -2.0 x))) 2.0)) 1.0)
     (*
      (cbrt (+ 1.0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))
      (cbrt (+ 1.0 (/ 2.0 (+ 1.0 (exp (* -2.0 x))))))))
    (cbrt (+ 1.0 (/ 2.0 (+ 1.0 (exp (* -2.0 x)))))))
   (if (<= (* -2.0 x) 1.916498673169216e-13)
     (- x (* (pow x 3.0) 0.3333333333333333))
     (/
      (+
       (/
        4.0
        (* (pow (+ 1.0 (exp (* -2.0 x))) 1.5) (sqrt (+ 1.0 (exp (* -2.0 x))))))
       -1.0)
      (+ 1.0 (/ 2.0 (+ 1.0 (exp (* -2.0 x)))))))))
double code(double x, double y) {
	return (2.0 / (1.0 + exp(-2.0 * x))) - 1.0;
}
double code(double x, double y) {
	double tmp;
	if ((-2.0 * x) <= -17.726881421434474) {
		tmp = (((4.0 / pow((1.0 + exp(-2.0 * x)), 2.0)) - 1.0) / (cbrt(1.0 + (2.0 / (1.0 + exp(-2.0 * x)))) * cbrt(1.0 + (2.0 / (1.0 + exp(-2.0 * x)))))) / cbrt(1.0 + (2.0 / (1.0 + exp(-2.0 * x))));
	} else if ((-2.0 * x) <= 1.916498673169216e-13) {
		tmp = x - (pow(x, 3.0) * 0.3333333333333333);
	} else {
		tmp = ((4.0 / (pow((1.0 + exp(-2.0 * x)), 1.5) * sqrt(1.0 + exp(-2.0 * x)))) + -1.0) / (1.0 + (2.0 / (1.0 + exp(-2.0 * x))));
	}
	return tmp;
}

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 (*.f64 -2 x) < -17.7268814214344737

    1. Initial program 0.0

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

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

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

      \[\leadsto \frac{\frac{4}{\left(1 + e^{x \cdot -2}\right) \cdot \left(1 + e^{x \cdot -2}\right)} + -1}{\color{blue}{1 + \frac{2}{1 + e^{x \cdot -2}}}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt_binary640.0

      \[\leadsto \frac{\frac{4}{\left(1 + e^{x \cdot -2}\right) \cdot \left(1 + e^{x \cdot -2}\right)} + -1}{\color{blue}{\left(\sqrt[3]{1 + \frac{2}{1 + e^{x \cdot -2}}} \cdot \sqrt[3]{1 + \frac{2}{1 + e^{x \cdot -2}}}\right) \cdot \sqrt[3]{1 + \frac{2}{1 + e^{x \cdot -2}}}}}\]
    8. Applied associate-/r*_binary640.0

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

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

    if -17.7268814214344737 < (*.f64 -2 x) < 1.91649867316921601e-13

    1. Initial program 59.1

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Simplified59.1

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

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

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

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

    if 1.91649867316921601e-13 < (*.f64 -2 x)

    1. Initial program 0.7

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

      \[\leadsto \color{blue}{\frac{\frac{2}{1 + e^{-2 \cdot x}} \cdot \frac{2}{1 + e^{-2 \cdot x}} - 1 \cdot 1}{\frac{2}{1 + e^{-2 \cdot x}} + 1}}\]
    4. Simplified0.7

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

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

      \[\leadsto \frac{\frac{4}{\left(1 + e^{x \cdot -2}\right) \cdot \color{blue}{\left(\sqrt{1 + e^{x \cdot -2}} \cdot \sqrt{1 + e^{x \cdot -2}}\right)}} + -1}{1 + \frac{2}{1 + e^{x \cdot -2}}}\]
    8. Applied associate-*r*_binary640.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-2 \cdot x \leq -17.726881421434474:\\ \;\;\;\;\frac{\frac{\frac{4}{{\left(1 + e^{-2 \cdot x}\right)}^{2}} - 1}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}} \cdot \sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}}{\sqrt[3]{1 + \frac{2}{1 + e^{-2 \cdot x}}}}\\ \mathbf{elif}\;-2 \cdot x \leq 1.916498673169216 \cdot 10^{-13}:\\ \;\;\;\;x - {x}^{3} \cdot 0.3333333333333333\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{{\left(1 + e^{-2 \cdot x}\right)}^{1.5} \cdot \sqrt{1 + e^{-2 \cdot x}}} + -1}{1 + \frac{2}{1 + e^{-2 \cdot x}}}\\ \end{array}\]

Reproduce

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