
(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 9 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 (exp (* 3.0 (fma x x -1.0))) 0.3333333333333333))
double code(double x) {
return pow(exp((3.0 * fma(x, x, -1.0))), 0.3333333333333333);
}
function code(x) return exp(Float64(3.0 * fma(x, x, -1.0))) ^ 0.3333333333333333 end
code[x_] := N[Power[N[Exp[N[(3.0 * N[(x * x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.3333333333333333], $MachinePrecision]
\begin{array}{l}
\\
{\left(e^{3 \cdot \mathsf{fma}\left(x, x, -1\right)}\right)}^{0.3333333333333333}
\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%
add-cbrt-cube100.0%
pow1/399.2%
add-exp-log100.0%
pow3100.0%
log-pow100.0%
add-log-exp100.0%
fma-define100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (exp (* (+ x -1.0) (+ x 1.0))))
double code(double x) {
return exp(((x + -1.0) * (x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp(((x + (-1.0d0)) * (x + 1.0d0)))
end function
public static double code(double x) {
return Math.exp(((x + -1.0) * (x + 1.0)));
}
def code(x): return math.exp(((x + -1.0) * (x + 1.0)))
function code(x) return exp(Float64(Float64(x + -1.0) * Float64(x + 1.0))) end
function tmp = code(x) tmp = exp(((x + -1.0) * (x + 1.0))); end
code[x_] := N[Exp[N[(N[(x + -1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x + -1\right) \cdot \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%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x 0.97) (/ 1.0 E) (exp x)))
double code(double x) {
double tmp;
if (x <= 0.97) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = exp(x);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 0.97) {
tmp = 1.0 / Math.E;
} else {
tmp = Math.exp(x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.97: tmp = 1.0 / math.e else: tmp = math.exp(x) return tmp
function code(x) tmp = 0.0 if (x <= 0.97) 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.97) tmp = 1.0 / 2.71828182845904523536; else tmp = exp(x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.97], N[(1.0 / E), $MachinePrecision], N[Exp[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.97:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;e^{x}\\
\end{array}
\end{array}
if x < 0.96999999999999997Initial 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 66.7%
exp-1-e66.7%
Simplified66.7%
Taylor expanded in x around 0 67.9%
if 0.96999999999999997 < 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 (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 (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 74.9%
exp-1-e74.9%
Simplified74.9%
(FPCore (x) :precision binary64 (if (<= x 0.95) (/ 1.0 E) (+ 1.0 (* x (+ 1.0 (* x 0.5))))))
double code(double x) {
double tmp;
if (x <= 0.95) {
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.95) {
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.95: 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.95) 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.95) 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.95], 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.95:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot \left(1 + x \cdot 0.5\right)\\
\end{array}
\end{array}
if x < 0.94999999999999996Initial 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 66.7%
exp-1-e66.7%
Simplified66.7%
Taylor expanded in x around 0 67.9%
if 0.94999999999999996 < 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.6%
log-E52.6%
log-E52.6%
metadata-eval52.6%
Simplified52.6%
Final simplification64.0%
(FPCore (x) :precision binary64 (- (/ x E) (/ -1.0 E)))
double code(double x) {
return (x / ((double) M_E)) - (-1.0 / ((double) M_E));
}
public static double code(double x) {
return (x / Math.E) - (-1.0 / Math.E);
}
def code(x): return (x / math.e) - (-1.0 / math.e)
function code(x) return Float64(Float64(x / exp(1)) - Float64(-1.0 / exp(1))) end
function tmp = code(x) tmp = (x / 2.71828182845904523536) - (-1.0 / 2.71828182845904523536); end
code[x_] := N[(N[(x / E), $MachinePrecision] - N[(-1.0 / E), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{e} - \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 74.9%
exp-1-e74.9%
Simplified74.9%
Taylor expanded in x around 0 50.6%
log-E50.6%
metadata-eval50.6%
log-E50.6%
associate-/l*50.6%
log-E50.6%
metadata-eval50.6%
/-rgt-identity50.6%
associate-*r/50.6%
associate-*l/50.6%
/-rgt-identity50.6%
Simplified50.6%
+-commutative50.6%
fma-define50.6%
frac-2neg50.6%
metadata-eval50.6%
distribute-frac-neg250.6%
fmm-undef50.6%
un-div-inv50.6%
Applied egg-rr50.6%
(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 74.9%
exp-1-e74.9%
Simplified74.9%
Taylor expanded in x around 0 50.6%
log-E50.6%
metadata-eval50.6%
log-E50.6%
associate-/l*50.6%
log-E50.6%
metadata-eval50.6%
/-rgt-identity50.6%
associate-*r/50.6%
associate-*l/50.6%
/-rgt-identity50.6%
distribute-rgt1-in50.6%
associate-*r/50.6%
*-rgt-identity50.6%
+-commutative50.6%
Simplified50.6%
Final simplification50.6%
(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 74.9%
exp-1-e74.9%
Simplified74.9%
Taylor expanded in x around 0 51.2%
herbie shell --seed 2024131
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))