
(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 4 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 (exp (+ (* x x) -1.0)))
double code(double x) {
return exp(((x * x) + -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((x * x) + (-1.0d0)))
end function
public static double code(double x) {
return Math.exp(((x * x) + -1.0));
}
def code(x): return math.exp(((x * x) + -1.0))
function code(x) return exp(Float64(Float64(x * x) + -1.0)) end
function tmp = code(x) tmp = exp(((x * x) + -1.0)); end
code[x_] := N[Exp[N[(N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{x \cdot x + -1}
\end{array}
Initial program 100.0%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ 1.0 E) (* x (/ x E))))
double code(double x) {
double tmp;
if (x <= 1.0) {
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 <= 1.0) {
tmp = 1.0 / Math.E;
} else {
tmp = x * (x / Math.E);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 1.0 / math.e else: tmp = x * (x / math.e) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) 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 <= 1.0) tmp = 1.0 / 2.71828182845904523536; else tmp = x * (x / 2.71828182845904523536); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(1.0 / E), $MachinePrecision], N[(x * N[(x / E), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{e}\\
\end{array}
\end{array}
if x < 1Initial program 100.0%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 86.6%
distribute-rgt1-in86.6%
unpow286.6%
fma-undefine86.6%
*-commutative86.6%
metadata-eval86.6%
rec-exp86.6%
e-exp-186.6%
associate-*l/86.6%
*-lft-identity86.6%
Simplified86.6%
Taylor expanded in x around 0 67.8%
if 1 < x Initial program 100.0%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 55.0%
distribute-rgt1-in55.0%
unpow255.0%
fma-undefine55.0%
*-commutative55.0%
metadata-eval55.0%
rec-exp55.0%
e-exp-155.0%
associate-*l/55.0%
*-lft-identity55.0%
Simplified55.0%
Taylor expanded in x around inf 55.0%
unpow255.0%
associate-/l*53.7%
Applied egg-rr53.7%
Final simplification64.2%
(FPCore (x) :precision binary64 (if (<= x 1.0) (/ 1.0 E) (/ (* x x) E)))
double code(double x) {
double tmp;
if (x <= 1.0) {
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 <= 1.0) {
tmp = 1.0 / Math.E;
} else {
tmp = (x * x) / Math.E;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = 1.0 / math.e else: tmp = (x * x) / math.e return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(1.0 / exp(1)); else tmp = Float64(Float64(x * x) / exp(1)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = 1.0 / 2.71828182845904523536; else tmp = (x * x) / 2.71828182845904523536; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(1.0 / E), $MachinePrecision], N[(N[(x * x), $MachinePrecision] / E), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{e}\\
\end{array}
\end{array}
if x < 1Initial program 100.0%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 86.6%
distribute-rgt1-in86.6%
unpow286.6%
fma-undefine86.6%
*-commutative86.6%
metadata-eval86.6%
rec-exp86.6%
e-exp-186.6%
associate-*l/86.6%
*-lft-identity86.6%
Simplified86.6%
Taylor expanded in x around 0 67.8%
if 1 < x Initial program 100.0%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 55.0%
distribute-rgt1-in55.0%
unpow255.0%
fma-undefine55.0%
*-commutative55.0%
metadata-eval55.0%
rec-exp55.0%
e-exp-155.0%
associate-*l/55.0%
*-lft-identity55.0%
Simplified55.0%
Taylor expanded in x around inf 55.0%
unpow255.0%
associate-/l*53.7%
Applied egg-rr53.7%
*-commutative53.7%
frac-2neg53.7%
associate-*l/55.0%
Applied egg-rr55.0%
Final simplification64.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%
sqr-neg100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 78.6%
distribute-rgt1-in78.6%
unpow278.6%
fma-undefine78.6%
*-commutative78.6%
metadata-eval78.6%
rec-exp78.6%
e-exp-178.6%
associate-*l/78.6%
*-lft-identity78.6%
Simplified78.6%
Taylor expanded in x around 0 51.4%
Final simplification51.4%
herbie shell --seed 2024047
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))