Average Error: 29.2 → 0.2
Time: 3.5s
Precision: binary64
Cost: 1218
\[\frac{2}{1 + e^{-2 \cdot x}} - 1\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1596556562901081:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.168008803591736:\\ \;\;\;\;x - x \cdot \left(0.3333333333333333 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;x \leq -1.1596556562901081:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 1.168008803591736:\\
\;\;\;\;x - x \cdot \left(0.3333333333333333 \cdot \left(x \cdot x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
(FPCore (x y)
 :precision binary64
 (if (<= x -1.1596556562901081)
   -1.0
   (if (<= x 1.168008803591736)
     (- x (* x (* 0.3333333333333333 (* x x))))
     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 tmp;
	if (x <= -1.1596556562901081) {
		tmp = -1.0;
	} else if (x <= 1.168008803591736) {
		tmp = x - (x * (0.3333333333333333 * (x * x)));
	} else {
		tmp = 1.0;
	}
	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

Alternatives

Alternative 1
Error0.4
Cost706
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0132858412942405:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 0.9947955736269323:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 2
Error30.3
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 2.79286879929623 \cdot 10^{-310}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 3
Error46.6
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if x < -1.15965565629010814

    1. Initial program 0.2

      \[-1\]

    if -1.15965565629010814 < x < 1.16800880359173598

    1. Initial program 58.5

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

      \[\leadsto \color{blue}{x - 0.3333333333333333 \cdot {x}^{3}}\]
    3. Using strategy rm
    4. Applied unpow3_binary64_18490.3

      \[\leadsto x - 0.3333333333333333 \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)}\]
    5. Applied associate-*r*_binary64_17230.3

      \[\leadsto x - \color{blue}{\left(0.3333333333333333 \cdot \left(x \cdot x\right)\right) \cdot x}\]
    6. Simplified0.3

      \[\leadsto \color{blue}{x - x \cdot \left(0.3333333333333333 \cdot \left(x \cdot x\right)\right)}\]

    if 1.16800880359173598 < x

    1. Initial program 0.2

      \[1\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.1596556562901081:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1.168008803591736:\\ \;\;\;\;x - x \cdot \left(0.3333333333333333 \cdot \left(x \cdot x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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