
(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}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (pow (exp (+ x_m 1.0)) (+ x_m -1.0)))
x_m = fabs(x);
double code(double x_m) {
return pow(exp((x_m + 1.0)), (x_m + -1.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp((x_m + 1.0d0)) ** (x_m + (-1.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(Math.exp((x_m + 1.0)), (x_m + -1.0));
}
x_m = math.fabs(x) def code(x_m): return math.pow(math.exp((x_m + 1.0)), (x_m + -1.0))
x_m = abs(x) function code(x_m) return exp(Float64(x_m + 1.0)) ^ Float64(x_m + -1.0) end
x_m = abs(x); function tmp = code(x_m) tmp = exp((x_m + 1.0)) ^ (x_m + -1.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[N[Exp[N[(x$95$m + 1.0), $MachinePrecision]], $MachinePrecision], N[(x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(e^{x_m + 1}\right)}^{\left(x_m + -1\right)}
\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%
difference-of-sqr--1100.0%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (exp (+ -1.0 (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
return exp((-1.0 + (x_m * x_m)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp(((-1.0d0) + (x_m * x_m)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.exp((-1.0 + (x_m * x_m)));
}
x_m = math.fabs(x) def code(x_m): return math.exp((-1.0 + (x_m * x_m)))
x_m = abs(x) function code(x_m) return exp(Float64(-1.0 + Float64(x_m * x_m))) end
x_m = abs(x); function tmp = code(x_m) tmp = exp((-1.0 + (x_m * x_m))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[N[(-1.0 + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{-1 + x_m \cdot x_m}
\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%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (exp x_m) E))
x_m = fabs(x);
double code(double x_m) {
return exp(x_m) / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.exp(x_m) / Math.E;
}
x_m = math.fabs(x) def code(x_m): return math.exp(x_m) / math.e
x_m = abs(x) function code(x_m) return Float64(exp(x_m) / exp(1)) end
x_m = abs(x); function tmp = code(x_m) tmp = exp(x_m) / 2.71828182845904523536; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Exp[x$95$m], $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{e^{x_m}}{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%
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.8%
exp-1-e70.8%
Simplified70.8%
e-exp-170.8%
pow-exp70.8%
*-un-lft-identity70.8%
expm1-log1p-u69.5%
expm1-udef69.5%
exp-diff69.5%
Applied egg-rr70.8%
Final simplification70.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (+ E (* x_m E)) (* E E)))
x_m = fabs(x);
double code(double x_m) {
return (((double) M_E) + (x_m * ((double) M_E))) / (((double) M_E) * ((double) M_E));
}
x_m = Math.abs(x);
public static double code(double x_m) {
return (Math.E + (x_m * Math.E)) / (Math.E * Math.E);
}
x_m = math.fabs(x) def code(x_m): return (math.e + (x_m * math.e)) / (math.e * math.e)
x_m = abs(x) function code(x_m) return Float64(Float64(exp(1) + Float64(x_m * exp(1))) / Float64(exp(1) * exp(1))) end
x_m = abs(x); function tmp = code(x_m) tmp = (2.71828182845904523536 + (x_m * 2.71828182845904523536)) / (2.71828182845904523536 * 2.71828182845904523536); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(E + N[(x$95$m * E), $MachinePrecision]), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{e + x_m \cdot e}{e \cdot 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%
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.8%
exp-1-e70.8%
Simplified70.8%
Taylor expanded in x around 0 50.9%
log-E50.9%
associate-/l*50.9%
Simplified50.9%
frac-2neg50.9%
metadata-eval50.9%
frac-2neg50.9%
/-rgt-identity50.9%
frac-add50.9%
metadata-eval50.9%
associate-/r/50.9%
metadata-eval50.9%
frac-2neg50.9%
remove-double-div50.9%
Applied egg-rr50.9%
Final simplification50.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (+ (/ x_m E) (/ 1.0 E)))
x_m = fabs(x);
double code(double x_m) {
return (x_m / ((double) M_E)) + (1.0 / ((double) M_E));
}
x_m = Math.abs(x);
public static double code(double x_m) {
return (x_m / Math.E) + (1.0 / Math.E);
}
x_m = math.fabs(x) def code(x_m): return (x_m / math.e) + (1.0 / math.e)
x_m = abs(x) function code(x_m) return Float64(Float64(x_m / exp(1)) + Float64(1.0 / exp(1))) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m / 2.71828182845904523536) + (1.0 / 2.71828182845904523536); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(x$95$m / E), $MachinePrecision] + N[(1.0 / E), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{x_m}{e} + \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%
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.8%
exp-1-e70.8%
Simplified70.8%
Taylor expanded in x around 0 50.9%
log-E50.9%
associate-/l*50.9%
Simplified50.9%
Taylor expanded in x around 0 50.9%
+-commutative50.9%
Simplified50.9%
Final simplification50.9%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ 1.0 E))
x_m = fabs(x);
double code(double x_m) {
return 1.0 / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
return 1.0 / Math.E;
}
x_m = math.fabs(x) def code(x_m): return 1.0 / math.e
x_m = abs(x) function code(x_m) return Float64(1.0 / exp(1)) end
x_m = abs(x); function tmp = code(x_m) tmp = 1.0 / 2.71828182845904523536; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\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%
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.8%
exp-1-e70.8%
Simplified70.8%
Taylor expanded in x around 0 51.5%
Final simplification51.5%
herbie shell --seed 2024023
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))