
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x, double y) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x, double y) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x, y): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x, y) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x, y) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_, y_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))
double code(double x, double y) {
return (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (2.0d0 / (1.0d0 + exp(((-2.0d0) * x)))) - 1.0d0
end function
public static double code(double x, double y) {
return (2.0 / (1.0 + Math.exp((-2.0 * x)))) - 1.0;
}
def code(x, y): return (2.0 / (1.0 + math.exp((-2.0 * x)))) - 1.0
function code(x, y) return Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) - 1.0) end
function tmp = code(x, y) tmp = (2.0 / (1.0 + exp((-2.0 * x)))) - 1.0; end
code[x_, y_] := N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{1 + e^{-2 \cdot x}} - 1
\end{array}
(FPCore (x y)
:precision binary64
(if (<= (* -2.0 x) -5000.0)
(+ (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) -1.0)
(if (<= (* -2.0 x) 0.002)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* x (* x x))
x)
-1.0)))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -5000.0) {
tmp = (2.0 / (1.0 + exp((-2.0 * x)))) + -1.0;
} else if ((-2.0 * x) <= 0.002) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= -5000.0) tmp = Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) + -1.0); elseif (Float64(-2.0 * x) <= 0.002) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = -1.0; end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -5000.0], N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[N[(-2.0 * x), $MachinePrecision], 0.002], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], -1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -5000:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} + -1\\
\mathbf{elif}\;-2 \cdot x \leq 0.002:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -5e3Initial program 100.0%
if -5e3 < (*.f64 #s(literal -2 binary64) x) < 2e-3Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 2e-3 < (*.f64 #s(literal -2 binary64) x) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (exp (* -2.0 x))))
(if (<= t_0 0.0)
(fma (/ (fma x x -1.0) (fma x (* x x) 1.0)) (fma x (+ x -1.0) 1.0) 1.0)
(if (<= t_0 2.0)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* x (* x x))
x)
-1.0))))
double code(double x, double y) {
double t_0 = exp((-2.0 * x));
double tmp;
if (t_0 <= 0.0) {
tmp = fma((fma(x, x, -1.0) / fma(x, (x * x), 1.0)), fma(x, (x + -1.0), 1.0), 1.0);
} else if (t_0 <= 2.0) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = -1.0;
}
return tmp;
}
function code(x, y) t_0 = exp(Float64(-2.0 * x)) tmp = 0.0 if (t_0 <= 0.0) tmp = fma(Float64(fma(x, x, -1.0) / fma(x, Float64(x * x), 1.0)), fma(x, Float64(x + -1.0), 1.0), 1.0); elseif (t_0 <= 2.0) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = -1.0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(x * x + -1.0), $MachinePrecision] / N[(x * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], -1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-2 \cdot x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{\mathsf{fma}\left(x, x \cdot x, 1\right)}, \mathsf{fma}\left(x, x + -1, 1\right), 1\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 0.0Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f645.3
Simplified5.3%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr20.8%
if 0.0 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 2Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 2 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (exp (* -2.0 x))) (t_1 (* x (* x x))))
(if (<= t_0 0.0)
(fma (/ (fma x x -1.0) t_1) (fma x (+ x -1.0) 1.0) 1.0)
(if (<= t_0 2.0)
(fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) t_1 x)
-1.0))))
double code(double x, double y) {
double t_0 = exp((-2.0 * x));
double t_1 = x * (x * x);
double tmp;
if (t_0 <= 0.0) {
tmp = fma((fma(x, x, -1.0) / t_1), fma(x, (x + -1.0), 1.0), 1.0);
} else if (t_0 <= 2.0) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), t_1, x);
} else {
tmp = -1.0;
}
return tmp;
}
function code(x, y) t_0 = exp(Float64(-2.0 * x)) t_1 = Float64(x * Float64(x * x)) tmp = 0.0 if (t_0 <= 0.0) tmp = fma(Float64(fma(x, x, -1.0) / t_1), fma(x, Float64(x + -1.0), 1.0), 1.0); elseif (t_0 <= 2.0) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), t_1, x); else tmp = -1.0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(x * x + -1.0), $MachinePrecision] / t$95$1), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * t$95$1 + x), $MachinePrecision], -1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-2 \cdot x}\\
t_1 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{t\_1}, \mathsf{fma}\left(x, x + -1, 1\right), 1\right)\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), t\_1, x\right)\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 0.0Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f645.3
Simplified5.3%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr20.8%
Taylor expanded in x around inf
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6420.8
Simplified20.8%
if 0.0 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 2Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 2 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= (exp (* -2.0 x)) 1.001) x (+ -1.0 (/ 2.0 (fma x (fma x (fma x -1.3333333333333333 2.0) -2.0) 2.0)))))
double code(double x, double y) {
double tmp;
if (exp((-2.0 * x)) <= 1.001) {
tmp = x;
} else {
tmp = -1.0 + (2.0 / fma(x, fma(x, fma(x, -1.3333333333333333, 2.0), -2.0), 2.0));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (exp(Float64(-2.0 * x)) <= 1.001) tmp = x; else tmp = Float64(-1.0 + Float64(2.0 / fma(x, fma(x, fma(x, -1.3333333333333333, 2.0), -2.0), 2.0))); end return tmp end
code[x_, y_] := If[LessEqual[N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision], 1.001], x, N[(-1.0 + N[(2.0 / N[(x * N[(x * N[(x * -1.3333333333333333 + 2.0), $MachinePrecision] + -2.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-2 \cdot x} \leq 1.001:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{2}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, -1.3333333333333333, 2\right), -2\right), 2\right)}\\
\end{array}
\end{array}
if (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 1.0009999999999999Initial program 36.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f647.1
Simplified7.1%
associate--l+N/A
metadata-evalN/A
+-rgt-identity70.8
Applied egg-rr70.8%
if 1.0009999999999999 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.5
Simplified99.5%
Final simplification77.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (fma x (+ x -1.0) 1.0)) (t_1 (* x (* x x))))
(if (<= x -1.22)
-1.0
(if (<= x 1.6)
(fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) t_1 x)
(if (<= x 5.8e+102)
(fma
(* (/ (fma x x -1.0) (fma t_1 t_1 -1.0)) (fma x (* x x) -1.0))
t_0
1.0)
(fma (/ (fma x x -1.0) t_1) t_0 1.0))))))
double code(double x, double y) {
double t_0 = fma(x, (x + -1.0), 1.0);
double t_1 = x * (x * x);
double tmp;
if (x <= -1.22) {
tmp = -1.0;
} else if (x <= 1.6) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), t_1, x);
} else if (x <= 5.8e+102) {
tmp = fma(((fma(x, x, -1.0) / fma(t_1, t_1, -1.0)) * fma(x, (x * x), -1.0)), t_0, 1.0);
} else {
tmp = fma((fma(x, x, -1.0) / t_1), t_0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = fma(x, Float64(x + -1.0), 1.0) t_1 = Float64(x * Float64(x * x)) tmp = 0.0 if (x <= -1.22) tmp = -1.0; elseif (x <= 1.6) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), t_1, x); elseif (x <= 5.8e+102) tmp = fma(Float64(Float64(fma(x, x, -1.0) / fma(t_1, t_1, -1.0)) * fma(x, Float64(x * x), -1.0)), t_0, 1.0); else tmp = fma(Float64(fma(x, x, -1.0) / t_1), t_0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.22], -1.0, If[LessEqual[x, 1.6], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * t$95$1 + x), $MachinePrecision], If[LessEqual[x, 5.8e+102], N[(N[(N[(N[(x * x + -1.0), $MachinePrecision] / N[(t$95$1 * t$95$1 + -1.0), $MachinePrecision]), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision], N[(N[(N[(x * x + -1.0), $MachinePrecision] / t$95$1), $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, x + -1, 1\right)\\
t_1 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.22:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), t\_1, x\right)\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{\mathsf{fma}\left(t\_1, t\_1, -1\right)} \cdot \mathsf{fma}\left(x, x \cdot x, -1\right), t\_0, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{t\_1}, t\_0, 1\right)\\
\end{array}
\end{array}
if x < -1.21999999999999997Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
if -1.21999999999999997 < x < 1.6000000000000001Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 1.6000000000000001 < x < 5.8000000000000005e102Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f647.7
Simplified7.7%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr7.7%
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
flip-+N/A
associate-/r/N/A
lower-*.f64N/A
Applied egg-rr66.9%
if 5.8000000000000005e102 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f644.2
Simplified4.2%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr26.8%
Taylor expanded in x around inf
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6426.8
Simplified26.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (fma x (+ x -1.0) 1.0)) (t_1 (* x (* x x))))
(if (<= x -1.22)
-1.0
(if (<= x 1.6)
(fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) t_1 x)
(if (<= x 1.15e+77)
(fma
(/ (fma x t_1 -1.0) (* (fma x (* x x) 1.0) (fma x x 1.0)))
t_0
1.0)
(if (<= x 5.8e+102)
(fma
(fma x (* x x) -1.0)
(/ (fma x x (- 1.0 x)) (fma x t_1 (+ 1.0 (* x x))))
1.0)
(fma (/ (fma x x -1.0) t_1) t_0 1.0)))))))
double code(double x, double y) {
double t_0 = fma(x, (x + -1.0), 1.0);
double t_1 = x * (x * x);
double tmp;
if (x <= -1.22) {
tmp = -1.0;
} else if (x <= 1.6) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), t_1, x);
} else if (x <= 1.15e+77) {
tmp = fma((fma(x, t_1, -1.0) / (fma(x, (x * x), 1.0) * fma(x, x, 1.0))), t_0, 1.0);
} else if (x <= 5.8e+102) {
tmp = fma(fma(x, (x * x), -1.0), (fma(x, x, (1.0 - x)) / fma(x, t_1, (1.0 + (x * x)))), 1.0);
} else {
tmp = fma((fma(x, x, -1.0) / t_1), t_0, 1.0);
}
return tmp;
}
function code(x, y) t_0 = fma(x, Float64(x + -1.0), 1.0) t_1 = Float64(x * Float64(x * x)) tmp = 0.0 if (x <= -1.22) tmp = -1.0; elseif (x <= 1.6) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), t_1, x); elseif (x <= 1.15e+77) tmp = fma(Float64(fma(x, t_1, -1.0) / Float64(fma(x, Float64(x * x), 1.0) * fma(x, x, 1.0))), t_0, 1.0); elseif (x <= 5.8e+102) tmp = fma(fma(x, Float64(x * x), -1.0), Float64(fma(x, x, Float64(1.0 - x)) / fma(x, t_1, Float64(1.0 + Float64(x * x)))), 1.0); else tmp = fma(Float64(fma(x, x, -1.0) / t_1), t_0, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.22], -1.0, If[LessEqual[x, 1.6], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * t$95$1 + x), $MachinePrecision], If[LessEqual[x, 1.15e+77], N[(N[(N[(x * t$95$1 + -1.0), $MachinePrecision] / N[(N[(x * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision], If[LessEqual[x, 5.8e+102], N[(N[(x * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision] * N[(N[(x * x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * t$95$1 + N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(x * x + -1.0), $MachinePrecision] / t$95$1), $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, x + -1, 1\right)\\
t_1 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.22:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), t\_1, x\right)\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{+77}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, t\_1, -1\right)}{\mathsf{fma}\left(x, x \cdot x, 1\right) \cdot \mathsf{fma}\left(x, x, 1\right)}, t\_0, 1\right)\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot x, -1\right), \frac{\mathsf{fma}\left(x, x, 1 - x\right)}{\mathsf{fma}\left(x, t\_1, 1 + x \cdot x\right)}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{t\_1}, t\_0, 1\right)\\
\end{array}
\end{array}
if x < -1.21999999999999997Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
if -1.21999999999999997 < x < 1.6000000000000001Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 1.6000000000000001 < x < 1.14999999999999997e77Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f648.5
Simplified8.5%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr8.5%
lift-*.f64N/A
flip-+N/A
lift-*.f64N/A
lift-fma.f64N/A
associate-/l/N/A
lower-/.f64N/A
metadata-evalN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
lift-*.f64N/A
metadata-evalN/A
lower-fma.f6444.5
Applied egg-rr44.5%
if 1.14999999999999997e77 < x < 5.8000000000000005e102Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f645.9
Simplified5.9%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr5.9%
Applied egg-rr100.0%
if 5.8000000000000005e102 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f644.2
Simplified4.2%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr26.8%
Taylor expanded in x around inf
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6426.8
Simplified26.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (* x x))))
(if (<= x -1.22)
-1.0
(if (<= x 1.6)
(fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) t_0 x)
(if (<= x 5.8e+102)
(fma
(fma x (* x x) -1.0)
(/ (fma x x (- 1.0 x)) (fma x t_0 (+ 1.0 (* x x))))
1.0)
(fma (/ (fma x x -1.0) t_0) (fma x (+ x -1.0) 1.0) 1.0))))))
double code(double x, double y) {
double t_0 = x * (x * x);
double tmp;
if (x <= -1.22) {
tmp = -1.0;
} else if (x <= 1.6) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), t_0, x);
} else if (x <= 5.8e+102) {
tmp = fma(fma(x, (x * x), -1.0), (fma(x, x, (1.0 - x)) / fma(x, t_0, (1.0 + (x * x)))), 1.0);
} else {
tmp = fma((fma(x, x, -1.0) / t_0), fma(x, (x + -1.0), 1.0), 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(x * Float64(x * x)) tmp = 0.0 if (x <= -1.22) tmp = -1.0; elseif (x <= 1.6) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), t_0, x); elseif (x <= 5.8e+102) tmp = fma(fma(x, Float64(x * x), -1.0), Float64(fma(x, x, Float64(1.0 - x)) / fma(x, t_0, Float64(1.0 + Float64(x * x)))), 1.0); else tmp = fma(Float64(fma(x, x, -1.0) / t_0), fma(x, Float64(x + -1.0), 1.0), 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.22], -1.0, If[LessEqual[x, 1.6], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * t$95$0 + x), $MachinePrecision], If[LessEqual[x, 5.8e+102], N[(N[(x * N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision] * N[(N[(x * x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision] / N[(x * t$95$0 + N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(x * x + -1.0), $MachinePrecision] / t$95$0), $MachinePrecision] * N[(x * N[(x + -1.0), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.22:\\
\;\;\;\;-1\\
\mathbf{elif}\;x \leq 1.6:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), t\_0, x\right)\\
\mathbf{elif}\;x \leq 5.8 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot x, -1\right), \frac{\mathsf{fma}\left(x, x, 1 - x\right)}{\mathsf{fma}\left(x, t\_0, 1 + x \cdot x\right)}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x, -1\right)}{t\_0}, \mathsf{fma}\left(x, x + -1, 1\right), 1\right)\\
\end{array}
\end{array}
if x < -1.21999999999999997Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
if -1.21999999999999997 < x < 1.6000000000000001Initial program 8.4%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64100.0
Simplified100.0%
if 1.6000000000000001 < x < 5.8000000000000005e102Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f647.7
Simplified7.7%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr7.7%
Applied egg-rr37.4%
if 5.8000000000000005e102 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f644.2
Simplified4.2%
+-commutativeN/A
associate--l+N/A
+-commutativeN/A
flip--N/A
flip3-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied egg-rr26.8%
Taylor expanded in x around inf
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6426.8
Simplified26.8%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) 0.002) x -1.0))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 0.002) {
tmp = x;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((-2.0d0) * x) <= 0.002d0) then
tmp = x
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 0.002) {
tmp = x;
} else {
tmp = -1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (-2.0 * x) <= 0.002: tmp = x else: tmp = -1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= 0.002) tmp = x; else tmp = -1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((-2.0 * x) <= 0.002) tmp = x; else tmp = -1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 0.002], x, -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 0.002:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2e-3Initial program 36.3%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f647.3
Simplified7.3%
associate--l+N/A
metadata-evalN/A
+-rgt-identity70.8
Applied egg-rr70.8%
if 2e-3 < (*.f64 #s(literal -2 binary64) x) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Simplified100.0%
Taylor expanded in x around inf
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.12e-154) -1.0 0.0))
double code(double x, double y) {
double tmp;
if (x <= -1.12e-154) {
tmp = -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.12d-154)) then
tmp = -1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.12e-154) {
tmp = -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.12e-154: tmp = -1.0 else: tmp = 0.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.12e-154) tmp = -1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.12e-154) tmp = -1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.12e-154], -1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-154}:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1.12e-154Initial program 67.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6467.7
Simplified67.7%
Taylor expanded in x around inf
Simplified66.7%
if -1.12e-154 < x Initial program 41.5%
Taylor expanded in x around 0
Simplified4.8%
metadata-eval4.8
Applied egg-rr4.8%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 51.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6427.8
Simplified27.8%
Taylor expanded in x around inf
Simplified25.5%
herbie shell --seed 2024215
(FPCore (x y)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))