
(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 17 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
(let* ((t_0 (exp (* -2.0 x))) (t_1 (+ 1.0 t_0)))
(if (<= (* -2.0 x) -0.01)
(fma
4.0
(/ (pow t_1 -2.0) (+ 1.0 (/ -2.0 (- -1.0 t_0))))
(/ 1.0 (+ (/ -2.0 t_1) -1.0)))
(expm1 (- (- x))))))
double code(double x, double y) {
double t_0 = exp((-2.0 * x));
double t_1 = 1.0 + t_0;
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = fma(4.0, (pow(t_1, -2.0) / (1.0 + (-2.0 / (-1.0 - t_0)))), (1.0 / ((-2.0 / t_1) + -1.0)));
} else {
tmp = expm1(-(-x));
}
return tmp;
}
function code(x, y) t_0 = exp(Float64(-2.0 * x)) t_1 = Float64(1.0 + t_0) tmp = 0.0 if (Float64(-2.0 * x) <= -0.01) tmp = fma(4.0, Float64((t_1 ^ -2.0) / Float64(1.0 + Float64(-2.0 / Float64(-1.0 - t_0)))), Float64(1.0 / Float64(Float64(-2.0 / t_1) + -1.0))); else tmp = expm1(Float64(-Float64(-x))); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + t$95$0), $MachinePrecision]}, If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.01], N[(4.0 * N[(N[Power[t$95$1, -2.0], $MachinePrecision] / N[(1.0 + N[(-2.0 / N[(-1.0 - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(N[(-2.0 / t$95$1), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Exp[(-(-x))] - 1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-2 \cdot x}\\
t_1 := 1 + t\_0\\
\mathbf{if}\;-2 \cdot x \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(4, \frac{{t\_1}^{-2}}{1 + \frac{-2}{-1 - t\_0}}, \frac{1}{\frac{-2}{t\_1} + -1}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(-\left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -0.0100000000000000002Initial program 99.7%
lift--.f64N/A
flip--N/A
metadata-evalN/A
div-subN/A
sub-negN/A
Applied rewrites99.9%
if -0.0100000000000000002 < (*.f64 #s(literal -2 binary64) x) Initial program 34.3%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval34.3
Applied rewrites34.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) -0.01) (expm1 (- (log 2.0) (log1p (exp (* -2.0 x))))) (expm1 (- (- x)))))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = expm1((log(2.0) - log1p(exp((-2.0 * x)))));
} else {
tmp = expm1(-(-x));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = Math.expm1((Math.log(2.0) - Math.log1p(Math.exp((-2.0 * x)))));
} else {
tmp = Math.expm1(-(-x));
}
return tmp;
}
def code(x, y): tmp = 0 if (-2.0 * x) <= -0.01: tmp = math.expm1((math.log(2.0) - math.log1p(math.exp((-2.0 * x))))) else: tmp = math.expm1(-(-x)) return tmp
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= -0.01) tmp = expm1(Float64(log(2.0) - log1p(exp(Float64(-2.0 * x))))); else tmp = expm1(Float64(-Float64(-x))); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.01], N[(Exp[N[(N[Log[2.0], $MachinePrecision] - N[Log[1 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision], N[(Exp[(-(-x))] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -0.01:\\
\;\;\;\;\mathsf{expm1}\left(\log 2 - \mathsf{log1p}\left(e^{-2 \cdot x}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(-\left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -0.0100000000000000002Initial program 99.7%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval99.9
Applied rewrites99.9%
rem-log-expN/A
lift-*.f64N/A
lift-log.f64N/A
exp-to-powN/A
lift-*.f64N/A
metadata-evalN/A
div-invN/A
inv-powN/A
clear-numN/A
log-divN/A
lower--.f64N/A
lower-log.f64N/A
lift-+.f64N/A
lower-log1p.f6499.9
Applied rewrites99.9%
if -0.0100000000000000002 < (*.f64 #s(literal -2 binary64) x) Initial program 34.3%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval34.3
Applied rewrites34.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) -0.01) (expm1 (- (log (fma (exp (* -2.0 x)) 0.5 0.5)))) (expm1 (- (- x)))))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = expm1(-log(fma(exp((-2.0 * x)), 0.5, 0.5)));
} else {
tmp = expm1(-(-x));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= -0.01) tmp = expm1(Float64(-log(fma(exp(Float64(-2.0 * x)), 0.5, 0.5)))); else tmp = expm1(Float64(-Float64(-x))); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.01], N[(Exp[(-N[Log[N[(N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision] * 0.5 + 0.5), $MachinePrecision]], $MachinePrecision])] - 1), $MachinePrecision], N[(Exp[(-(-x))] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -0.01:\\
\;\;\;\;\mathsf{expm1}\left(-\log \left(\mathsf{fma}\left(e^{-2 \cdot x}, 0.5, 0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(-\left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -0.0100000000000000002Initial program 99.7%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval99.9
Applied rewrites99.9%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.9
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
metadata-evalN/A
lower-fma.f6499.9
Applied rewrites99.9%
if -0.0100000000000000002 < (*.f64 #s(literal -2 binary64) x) Initial program 34.3%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval34.3
Applied rewrites34.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) -0.01) (fma (/ 2.0 (expm1 (* x -4.0))) (expm1 (* -2.0 x)) -1.0) (expm1 (- (- x)))))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = fma((2.0 / expm1((x * -4.0))), expm1((-2.0 * x)), -1.0);
} else {
tmp = expm1(-(-x));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= -0.01) tmp = fma(Float64(2.0 / expm1(Float64(x * -4.0))), expm1(Float64(-2.0 * x)), -1.0); else tmp = expm1(Float64(-Float64(-x))); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.01], N[(N[(2.0 / N[(Exp[N[(x * -4.0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] * N[(Exp[N[(-2.0 * x), $MachinePrecision]] - 1), $MachinePrecision] + -1.0), $MachinePrecision], N[(Exp[(-(-x))] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -0.01:\\
\;\;\;\;\mathsf{fma}\left(\frac{2}{\mathsf{expm1}\left(x \cdot -4\right)}, \mathsf{expm1}\left(-2 \cdot x\right), -1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(-\left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -0.0100000000000000002Initial program 99.7%
lift--.f64N/A
sub-negN/A
lift-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
flip-+N/A
associate-/r/N/A
lower-fma.f64N/A
Applied rewrites99.8%
if -0.0100000000000000002 < (*.f64 #s(literal -2 binary64) x) Initial program 34.3%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval34.3
Applied rewrites34.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
(FPCore (x y)
:precision binary64
(if (<= (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 2e-42)
(+ (/ 2.0 (fma x (fma x (fma x -1.3333333333333333 2.0) -2.0) 2.0)) -1.0)
(fma
(fma (* x x) 0.13333333333333333 -0.3333333333333333)
(* x (* x x))
x)))
double code(double x, double y) {
double tmp;
if ((2.0 / (1.0 + exp((-2.0 * x)))) <= 2e-42) {
tmp = (2.0 / fma(x, fma(x, fma(x, -1.3333333333333333, 2.0), -2.0), 2.0)) + -1.0;
} else {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) <= 2e-42) tmp = Float64(Float64(2.0 / fma(x, fma(x, fma(x, -1.3333333333333333, 2.0), -2.0), 2.0)) + -1.0); else tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); end return tmp end
code[x_, y_] := If[LessEqual[N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-42], N[(N[(2.0 / N[(x * N[(x * N[(x * -1.3333333333333333 + 2.0), $MachinePrecision] + -2.0), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{2}{1 + e^{-2 \cdot x}} \leq 2 \cdot 10^{-42}:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \mathsf{fma}\left(x, -1.3333333333333333, 2\right), -2\right), 2\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, -0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)\\
\end{array}
\end{array}
if (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) < 2.00000000000000008e-42Initial 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.f6499.0
Applied rewrites99.0%
if 2.00000000000000008e-42 < (/.f64 #s(literal 2 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (*.f64 #s(literal -2 binary64) x)))) Initial program 36.2%
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-*.f6470.3
Applied rewrites70.3%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) -0.01) (+ (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) -1.0) (expm1 (- (- x)))))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = (2.0 / (1.0 + exp((-2.0 * x)))) + -1.0;
} else {
tmp = expm1(-(-x));
}
return tmp;
}
public static double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= -0.01) {
tmp = (2.0 / (1.0 + Math.exp((-2.0 * x)))) + -1.0;
} else {
tmp = Math.expm1(-(-x));
}
return tmp;
}
def code(x, y): tmp = 0 if (-2.0 * x) <= -0.01: tmp = (2.0 / (1.0 + math.exp((-2.0 * x)))) + -1.0 else: tmp = math.expm1(-(-x)) return tmp
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= -0.01) tmp = Float64(Float64(2.0 / Float64(1.0 + exp(Float64(-2.0 * x)))) + -1.0); else tmp = expm1(Float64(-Float64(-x))); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], -0.01], N[(N[(2.0 / N[(1.0 + N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(Exp[(-(-x))] - 1), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq -0.01:\\
\;\;\;\;\frac{2}{1 + e^{-2 \cdot x}} + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(-\left(-x\right)\right)\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < -0.0100000000000000002Initial program 99.7%
if -0.0100000000000000002 < (*.f64 #s(literal -2 binary64) x) Initial program 34.3%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval34.3
Applied rewrites34.3%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6499.7
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= (exp (* -2.0 x)) 2.0) (fma -0.3333333333333333 (* x (* x x)) x) (+ (/ 2.0 (- 2.0 (+ x x))) -1.0)))
double code(double x, double y) {
double tmp;
if (exp((-2.0 * x)) <= 2.0) {
tmp = fma(-0.3333333333333333, (x * (x * x)), x);
} else {
tmp = (2.0 / (2.0 - (x + x))) + -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (exp(Float64(-2.0 * x)) <= 2.0) tmp = fma(-0.3333333333333333, Float64(x * Float64(x * x)), x); else tmp = Float64(Float64(2.0 / Float64(2.0 - Float64(x + x))) + -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[Exp[N[(-2.0 * x), $MachinePrecision]], $MachinePrecision], 2.0], N[(-0.3333333333333333 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(2.0 - N[(x + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-2 \cdot x} \leq 2:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{2 - \left(x + x\right)} + -1\\
\end{array}
\end{array}
if (exp.f64 (*.f64 #s(literal -2 binary64) x)) < 2Initial program 36.2%
Taylor expanded in x around 0
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6469.3
Applied rewrites69.3%
if 2 < (exp.f64 (*.f64 #s(literal -2 binary64) x)) Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
cancel-sign-sub-invN/A
lower--.f64N/A
count-2N/A
lower-+.f6497.6
Applied rewrites97.6%
Final simplification75.6%
(FPCore (x y) :precision binary64 (expm1 (- (- x))))
double code(double x, double y) {
return expm1(-(-x));
}
public static double code(double x, double y) {
return Math.expm1(-(-x));
}
def code(x, y): return math.expm1(-(-x))
function code(x, y) return expm1(Float64(-Float64(-x))) end
code[x_, y_] := N[(Exp[(-(-x))] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(-\left(-x\right)\right)
\end{array}
Initial program 50.4%
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
metadata-evalN/A
pow-to-expN/A
lower-expm1.f64N/A
lower-*.f64N/A
lower-log.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval50.4
Applied rewrites50.4%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
lift-*.f64N/A
*-commutativeN/A
mul-1-negN/A
lower-neg.f6476.2
Applied rewrites76.2%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) 2e-13) (fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) (* x (* x x)) x) (+ (/ 2.0 (* x (fma x (fma x -1.3333333333333333 2.0) -2.0))) -1.0)))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 2e-13) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = (2.0 / (x * fma(x, fma(x, -1.3333333333333333, 2.0), -2.0))) + -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-13) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = Float64(Float64(2.0 / Float64(x * fma(x, fma(x, -1.3333333333333333, 2.0), -2.0))) + -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-13], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(x * N[(x * N[(x * -1.3333333333333333 + 2.0), $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{2}{x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, -1.3333333333333333, 2\right), -2\right)} + -1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2.0000000000000001e-13Initial program 36.2%
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-*.f6470.3
Applied rewrites70.3%
if 2.0000000000000001e-13 < (*.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.f6499.0
Applied rewrites99.0%
Taylor expanded in x around 0
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites99.0%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) 2e-13) (fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) (* x (* x x)) x) (+ (/ 2.0 (* x (* x (fma x -1.3333333333333333 2.0)))) -1.0)))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 2e-13) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = (2.0 / (x * (x * fma(x, -1.3333333333333333, 2.0)))) + -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-13) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = Float64(Float64(2.0 / Float64(x * Float64(x * fma(x, -1.3333333333333333, 2.0)))) + -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-13], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(x * N[(x * N[(x * -1.3333333333333333 + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{2}{x \cdot \left(x \cdot \mathsf{fma}\left(x, -1.3333333333333333, 2\right)\right)} + -1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2.0000000000000001e-13Initial program 36.2%
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-*.f6470.3
Applied rewrites70.3%
if 2.0000000000000001e-13 < (*.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.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
Applied rewrites99.0%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) 2e-13) (fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) (* x (* x x)) x) (+ (/ 2.0 (* x (* -1.3333333333333333 (* x x)))) -1.0)))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 2e-13) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = (2.0 / (x * (-1.3333333333333333 * (x * x)))) + -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-13) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = Float64(Float64(2.0 / Float64(x * Float64(-1.3333333333333333 * Float64(x * x)))) + -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-13], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(x * N[(-1.3333333333333333 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{2}{x \cdot \left(-1.3333333333333333 \cdot \left(x \cdot x\right)\right)} + -1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2.0000000000000001e-13Initial program 36.2%
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-*.f6470.3
Applied rewrites70.3%
if 2.0000000000000001e-13 < (*.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.f6499.0
Applied rewrites99.0%
Taylor expanded in x around inf
Applied rewrites99.0%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (<= (* -2.0 x) 2e-13) (fma (fma (* x x) 0.13333333333333333 -0.3333333333333333) (* x (* x x)) x) (+ (/ 2.0 (fma x (+ -2.0 (+ x x)) 2.0)) -1.0)))
double code(double x, double y) {
double tmp;
if ((-2.0 * x) <= 2e-13) {
tmp = fma(fma((x * x), 0.13333333333333333, -0.3333333333333333), (x * (x * x)), x);
} else {
tmp = (2.0 / fma(x, (-2.0 + (x + x)), 2.0)) + -1.0;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(-2.0 * x) <= 2e-13) tmp = fma(fma(Float64(x * x), 0.13333333333333333, -0.3333333333333333), Float64(x * Float64(x * x)), x); else tmp = Float64(Float64(2.0 / fma(x, Float64(-2.0 + Float64(x + x)), 2.0)) + -1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(-2.0 * x), $MachinePrecision], 2e-13], N[(N[(N[(x * x), $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $MachinePrecision] * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(2.0 / N[(x * N[(-2.0 + N[(x + x), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;-2 \cdot x \leq 2 \cdot 10^{-13}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(x, -2 + \left(x + x\right), 2\right)} + -1\\
\end{array}
\end{array}
if (*.f64 #s(literal -2 binary64) x) < 2.0000000000000001e-13Initial program 36.2%
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-*.f6470.3
Applied rewrites70.3%
if 2.0000000000000001e-13 < (*.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
+-commutativeN/A
lower-+.f64N/A
count-2N/A
lower-+.f6498.5
Applied rewrites98.5%
Final simplification76.6%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (+ (/ 2.0 (fma x (+ -2.0 (+ x x)) 2.0)) -1.0) (fma -0.3333333333333333 (* x (* x x)) x)))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (2.0 / fma(x, (-2.0 + (x + x)), 2.0)) + -1.0;
} else {
tmp = fma(-0.3333333333333333, (x * (x * x)), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(2.0 / fma(x, Float64(-2.0 + Float64(x + x)), 2.0)) + -1.0); else tmp = fma(-0.3333333333333333, Float64(x * Float64(x * x)), x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(2.0 / N[(x * N[(-2.0 + N[(x + x), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.3333333333333333 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(x, -2 + \left(x + x\right), 2\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
lower-+.f64N/A
count-2N/A
lower-+.f6498.5
Applied rewrites98.5%
if -1 < x Initial program 36.2%
Taylor expanded in x around 0
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6469.3
Applied rewrites69.3%
Final simplification75.8%
(FPCore (x y) :precision binary64 (if (<= x -1.2) (+ (/ 2.0 (* x (fma x 2.0 -2.0))) -1.0) (fma -0.3333333333333333 (* x (* x x)) x)))
double code(double x, double y) {
double tmp;
if (x <= -1.2) {
tmp = (2.0 / (x * fma(x, 2.0, -2.0))) + -1.0;
} else {
tmp = fma(-0.3333333333333333, (x * (x * x)), x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -1.2) tmp = Float64(Float64(2.0 / Float64(x * fma(x, 2.0, -2.0))) + -1.0); else tmp = fma(-0.3333333333333333, Float64(x * Float64(x * x)), x); end return tmp end
code[x_, y_] := If[LessEqual[x, -1.2], N[(N[(2.0 / N[(x * N[(x * 2.0 + -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(-0.3333333333333333 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2:\\
\;\;\;\;\frac{2}{x \cdot \mathsf{fma}\left(x, 2, -2\right)} + -1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)\\
\end{array}
\end{array}
if x < -1.19999999999999996Initial 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.f6499.0
Applied rewrites99.0%
Taylor expanded in x around 0
Applied rewrites97.6%
Taylor expanded in x around inf
Applied rewrites99.0%
Taylor expanded in x around 0
Applied rewrites98.5%
if -1.19999999999999996 < x Initial program 36.2%
Taylor expanded in x around 0
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6469.3
Applied rewrites69.3%
Final simplification75.8%
(FPCore (x y) :precision binary64 (fma -0.3333333333333333 (* x (* x x)) x))
double code(double x, double y) {
return fma(-0.3333333333333333, (x * (x * x)), x);
}
function code(x, y) return fma(-0.3333333333333333, Float64(x * Float64(x * x)), x) end
code[x_, y_] := N[(-0.3333333333333333 * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 50.4%
Taylor expanded in x around 0
distribute-lft-inN/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6454.0
Applied rewrites54.0%
(FPCore (x y) :precision binary64 (+ (+ x 1.0) -1.0))
double code(double x, double y) {
return (x + 1.0) + -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + 1.0d0) + (-1.0d0)
end function
public static double code(double x, double y) {
return (x + 1.0) + -1.0;
}
def code(x, y): return (x + 1.0) + -1.0
function code(x, y) return Float64(Float64(x + 1.0) + -1.0) end
function tmp = code(x, y) tmp = (x + 1.0) + -1.0; end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) + -1
\end{array}
Initial program 50.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f646.5
Applied rewrites6.5%
Final simplification6.5%
(FPCore (x y) :precision binary64 (+ 1.0 -1.0))
double code(double x, double y) {
return 1.0 + -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (-1.0d0)
end function
public static double code(double x, double y) {
return 1.0 + -1.0;
}
def code(x, y): return 1.0 + -1.0
function code(x, y) return Float64(1.0 + -1.0) end
function tmp = code(x, y) tmp = 1.0 + -1.0; end
code[x_, y_] := N[(1.0 + -1.0), $MachinePrecision]
\begin{array}{l}
\\
1 + -1
\end{array}
Initial program 50.4%
Taylor expanded in x around 0
Applied rewrites4.5%
Final simplification4.5%
herbie shell --seed 2024221
(FPCore (x y)
:name "Logistic function from Lakshay Garg"
:precision binary64
(- (/ 2.0 (+ 1.0 (exp (* -2.0 x)))) 1.0))