
(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 6 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%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
(FPCore (x) :precision binary64 (if (<= x 0.98) (/ 1.0 E) (exp x)))
double code(double x) {
double tmp;
if (x <= 0.98) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = exp(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 0.98) {
tmp = 1.0 / Math.E;
} else {
tmp = Math.exp(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.98: tmp = 1.0 / math.e else: tmp = math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.98) tmp = Float64(1.0 / exp(1)); else tmp = exp(x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.98) tmp = 1.0 / 2.71828182845904523536; else tmp = exp(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.98], N[(1.0 / E), $MachinePrecision], N[Exp[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.98:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;e^{x}\\
\end{array}
\end{array}
if x < 0.97999999999999998Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 70.6%
exp-1-e70.6%
Simplified70.6%
Taylor expanded in x around 0 72.1%
if 0.97999999999999998 < x Initial program 99.9%
neg-sub099.9%
sqr-neg99.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
sqr-neg99.9%
Simplified99.9%
difference-of-sqr--199.9%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.6%
exp-1-e98.6%
Simplified98.6%
Taylor expanded in x around inf 98.6%
add-log-exp98.6%
*-un-lft-identity98.6%
log-prod98.6%
metadata-eval98.6%
add-log-exp98.6%
e-exp-198.6%
pow-exp98.6%
*-un-lft-identity98.6%
Applied egg-rr98.6%
+-lft-identity98.6%
Simplified98.6%
(FPCore (x) :precision binary64 (pow E (+ x -1.0)))
double code(double x) {
return pow(((double) M_E), (x + -1.0));
}
public static double code(double x) {
return Math.pow(Math.E, (x + -1.0));
}
def code(x): return math.pow(math.e, (x + -1.0))
function code(x) return exp(1) ^ Float64(x + -1.0) end
function tmp = code(x) tmp = 2.71828182845904523536 ^ (x + -1.0); end
code[x_] := N[Power[E, N[(x + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(x + -1\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%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.6%
exp-1-e77.6%
Simplified77.6%
(FPCore (x) :precision binary64 (if (<= x 0.96) (/ 1.0 E) (+ 1.0 (* x (+ 1.0 (* x 0.5))))))
double code(double x) {
double tmp;
if (x <= 0.96) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = 1.0 + (x * (1.0 + (x * 0.5)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 0.96) {
tmp = 1.0 / Math.E;
} else {
tmp = 1.0 + (x * (1.0 + (x * 0.5)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.96: tmp = 1.0 / math.e else: tmp = 1.0 + (x * (1.0 + (x * 0.5))) return tmp
function code(x) tmp = 0.0 if (x <= 0.96) tmp = Float64(1.0 / exp(1)); else tmp = Float64(1.0 + Float64(x * Float64(1.0 + Float64(x * 0.5)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.96) tmp = 1.0 / 2.71828182845904523536; else tmp = 1.0 + (x * (1.0 + (x * 0.5))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.96], N[(1.0 / E), $MachinePrecision], N[(1.0 + N[(x * N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.96:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(1 + x \cdot 0.5\right)\\
\end{array}
\end{array}
if x < 0.95999999999999996Initial program 100.0%
neg-sub0100.0%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 70.6%
exp-1-e70.6%
Simplified70.6%
Taylor expanded in x around 0 72.1%
if 0.95999999999999996 < x Initial program 99.9%
neg-sub099.9%
sqr-neg99.9%
associate--r-99.9%
metadata-eval99.9%
+-commutative99.9%
sqr-neg99.9%
Simplified99.9%
difference-of-sqr--199.9%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.6%
exp-1-e98.6%
Simplified98.6%
Taylor expanded in x around inf 98.6%
Taylor expanded in x around 0 52.5%
log-E52.5%
associate-*r*52.5%
log-E52.5%
metadata-eval52.5%
associate-*r*52.5%
*-commutative52.5%
Simplified52.5%
Final simplification67.2%
(FPCore (x) :precision binary64 (/ (+ x 1.0) E))
double code(double x) {
return (x + 1.0) / ((double) M_E);
}
public static double code(double x) {
return (x + 1.0) / Math.E;
}
def code(x): return (x + 1.0) / math.e
function code(x) return Float64(Float64(x + 1.0) / exp(1)) end
function tmp = code(x) tmp = (x + 1.0) / 2.71828182845904523536; end
code[x_] := N[(N[(x + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + 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%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.6%
exp-1-e77.6%
Simplified77.6%
Taylor expanded in x around 0 54.1%
log-E54.1%
metadata-eval54.1%
log-E54.1%
associate-/l*54.1%
log-E54.1%
metadata-eval54.1%
/-rgt-identity54.1%
associate-*r/54.1%
associate-*l/54.1%
/-rgt-identity54.1%
distribute-rgt1-in54.1%
associate-*r/54.1%
*-rgt-identity54.1%
+-commutative54.1%
Simplified54.1%
Final simplification54.1%
(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%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.6%
exp-1-e77.6%
Simplified77.6%
Taylor expanded in x around 0 54.9%
herbie shell --seed 2024132
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))