?

Average Accuracy: 54.7% → 99.8%
Time: 54.4s
Precision: binary64

?

\[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
\[\begin{array}{l} \mathbf{if}\;-2 \cdot x \leq -0.4:\\ \;\;\;\;\mathsf{expm1}\left(e^{\left(3 \cdot \log \left(\log 2 - \mathsf{log1p}\left(e^{-2 \cdot x}\right)\right)\right) \cdot 0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{fma}\left(-0.5, {x}^{2}, x\right)\right)\\ \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) -0.4)
   (expm1
    (exp
     (*
      (* 3.0 (log (- (log 2.0) (log1p (exp (* -2.0 x))))))
      0.3333333333333333)))
   (expm1 (fma -0.5 (pow x 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) <= -0.4) {
		tmp = expm1(exp(((3.0 * log((log(2.0) - log1p(exp((-2.0 * x)))))) * 0.3333333333333333)));
	} else {
		tmp = expm1(fma(-0.5, pow(x, 2.0), x));
	}
	return tmp;
}
function code(x, y)
	return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0)
end
function code(x, y)
	tmp = 0.0
	if (Float64(-2.0 * x) <= -0.4)
		tmp = expm1(exp(Float64(Float64(3.0 * log(Float64(log(2.0) - log1p(exp(Float64(-2.0 * x)))))) * 0.3333333333333333)));
	else
		tmp = expm1(fma(-0.5, (x ^ 2.0), x));
	end
	return tmp
end
code[x_, y_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.4], N[(Exp[N[Exp[N[(N[(3.0 * N[Log[N[(N[Log[2.0], $MachinePrecision] - N[Log[1 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision], N[(Exp[N[(-0.5 * N[Power[x, 2.0], $MachinePrecision] + x), $MachinePrecision]] - 1), $MachinePrecision]]
\frac{2}{1 + e^{-2 \cdot x}} - 1
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -0.4:\\
\;\;\;\;\mathsf{expm1}\left(e^{\left(3 \cdot \log \left(\log 2 - \mathsf{log1p}\left(e^{-2 \cdot x}\right)\right)\right) \cdot 0.3333333333333333}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{fma}\left(-0.5, {x}^{2}, x\right)\right)\\


\end{array}

Error?

Derivation?

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

    1. Initial program 100.0%

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\log 2 - \mathsf{log1p}\left({\left(e^{x}\right)}^{-2}\right)\right)} \]
      Proof
    3. Applied egg-rr100.0%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{e^{\left(3 \cdot \log \left(\log 2 - \mathsf{log1p}\left({\left(e^{x}\right)}^{-2}\right)\right)\right) \cdot 0.3333333333333333}}\right) \]
    4. Simplified100.0%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{e^{\left(3 \cdot \log \left(\log 2 - \mathsf{log1p}\left(e^{-2 \cdot x}\right)\right)\right) \cdot 0.3333333333333333}}\right) \]
      Proof

    if -0.40000000000000002 < (*.f64 -2 x)

    1. Initial program 39.1%

      \[\frac{2}{1 + e^{-2 \cdot x}} - 1 \]
    2. Simplified39.2%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\log 2 - \mathsf{log1p}\left({\left(e^{x}\right)}^{-2}\right)\right)} \]
      Proof
    3. Taylor expanded in x around 0 99.7%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{-0.5 \cdot {x}^{2} + x}\right) \]
    4. Simplified99.7%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left(-0.5, {x}^{2}, x\right)}\right) \]
      Proof
  3. Recombined 2 regimes into one program.

Reproduce?

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