
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
return exp(-(1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.exp(-(1.0 - (x * x)));
}
def code(x): return math.exp(-(1.0 - (x * x)))
function code(x) return exp(Float64(-Float64(1.0 - Float64(x * x)))) end
function tmp = code(x) tmp = exp(-(1.0 - (x * x))); end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\left(1 - x \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (exp (- (- 1.0 (* x x)))))
double code(double x) {
return exp(-(1.0 - (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(-(1.0d0 - (x * x)))
end function
public static double code(double x) {
return Math.exp(-(1.0 - (x * x)));
}
def code(x): return math.exp(-(1.0 - (x * x)))
function code(x) return exp(Float64(-Float64(1.0 - Float64(x * x)))) end
function tmp = code(x) tmp = exp(-(1.0 - (x * x))); end
code[x_] := N[Exp[(-N[(1.0 - N[(x * x), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]
\begin{array}{l}
\\
e^{-\left(1 - x \cdot x\right)}
\end{array}
(FPCore (x) :precision binary64 (pow E (fma x x -1.0)))
double code(double x) {
return pow(((double) M_E), fma(x, x, -1.0));
}
function code(x) return exp(1) ^ fma(x, x, -1.0) end
code[x_] := N[Power[E, N[(x * x + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(\mathsf{fma}\left(x, x, -1\right)\right)}
\end{array}
Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
*-un-lft-identity100.0%
exp-prod100.0%
exp-1-e100.0%
fma-define100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (exp (+ -1.0 (* x x))))
double code(double x) {
return exp((-1.0 + (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((-1.0d0) + (x * x)))
end function
public static double code(double x) {
return Math.exp((-1.0 + (x * x)));
}
def code(x): return math.exp((-1.0 + (x * x)))
function code(x) return exp(Float64(-1.0 + Float64(x * x))) end
function tmp = code(x) tmp = exp((-1.0 + (x * x))); end
code[x_] := N[Exp[N[(-1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{-1 + x \cdot x}
\end{array}
Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= (* x x) 1e-10) (/ 1.0 E) (* x (/ x E))))
double code(double x) {
double tmp;
if ((x * x) <= 1e-10) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = x * (x / ((double) M_E));
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((x * x) <= 1e-10) {
tmp = 1.0 / Math.E;
} else {
tmp = x * (x / Math.E);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 1e-10: tmp = 1.0 / math.e else: tmp = x * (x / math.e) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 1e-10) tmp = Float64(1.0 / exp(1)); else tmp = Float64(x * Float64(x / exp(1))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 1e-10) tmp = 1.0 / 2.71828182845904523536; else tmp = x * (x / 2.71828182845904523536); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e-10], N[(1.0 / E), $MachinePrecision], N[(x * N[(x / E), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-10}:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{e}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.00000000000000004e-10Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
distribute-rgt1-in100.0%
unpow2100.0%
fma-undefine100.0%
metadata-eval100.0%
rec-exp100.0%
e-exp-1100.0%
associate-*r/100.0%
metadata-eval100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 99.5%
if 1.00000000000000004e-10 < (*.f64 x x) Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 53.1%
distribute-rgt1-in53.1%
unpow253.1%
fma-undefine53.1%
metadata-eval53.1%
rec-exp53.1%
e-exp-153.1%
associate-*r/53.1%
metadata-eval53.1%
distribute-rgt-neg-in53.1%
*-commutative53.1%
neg-mul-153.1%
remove-double-neg53.1%
Simplified53.1%
Taylor expanded in x around inf 53.1%
unpow253.1%
associate-/l*53.1%
Applied egg-rr53.1%
(FPCore (x) :precision binary64 (/ (+ -1.0 (+ (* x x) 2.0)) E))
double code(double x) {
return (-1.0 + ((x * x) + 2.0)) / ((double) M_E);
}
public static double code(double x) {
return (-1.0 + ((x * x) + 2.0)) / Math.E;
}
def code(x): return (-1.0 + ((x * x) + 2.0)) / math.e
function code(x) return Float64(Float64(-1.0 + Float64(Float64(x * x) + 2.0)) / exp(1)) end
function tmp = code(x) tmp = (-1.0 + ((x * x) + 2.0)) / 2.71828182845904523536; end
code[x_] := N[(N[(-1.0 + N[(N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1 + \left(x \cdot x + 2\right)}{e}
\end{array}
Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 74.5%
distribute-rgt1-in74.5%
unpow274.5%
fma-undefine74.5%
metadata-eval74.5%
rec-exp74.5%
e-exp-174.5%
associate-*r/74.5%
metadata-eval74.5%
distribute-rgt-neg-in74.5%
*-commutative74.5%
neg-mul-174.5%
remove-double-neg74.5%
Simplified74.5%
expm1-log1p-u74.5%
expm1-undefine74.5%
Applied egg-rr74.5%
sub-neg74.5%
metadata-eval74.5%
+-commutative74.5%
log1p-undefine74.5%
rem-exp-log74.5%
fma-undefine74.5%
unpow274.5%
+-commutative74.5%
associate-+r+74.5%
metadata-eval74.5%
Simplified74.5%
unpow274.5%
Applied egg-rr74.5%
Final simplification74.5%
(FPCore (x) :precision binary64 (/ 1.0 E))
double code(double x) {
return 1.0 / ((double) M_E);
}
public static double code(double x) {
return 1.0 / Math.E;
}
def code(x): return 1.0 / math.e
function code(x) return Float64(1.0 / exp(1)) end
function tmp = code(x) tmp = 1.0 / 2.71828182845904523536; end
code[x_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e}
\end{array}
Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 74.5%
distribute-rgt1-in74.5%
unpow274.5%
fma-undefine74.5%
metadata-eval74.5%
rec-exp74.5%
e-exp-174.5%
associate-*r/74.5%
metadata-eval74.5%
distribute-rgt-neg-in74.5%
*-commutative74.5%
neg-mul-174.5%
remove-double-neg74.5%
Simplified74.5%
Taylor expanded in x around 0 47.2%
herbie shell --seed 2024139
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))