
(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}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (let* ((t_0 (+ -0.5 (* x_m 0.5)))) (* (pow (exp (* x_m 2.0)) t_0) (pow (exp 2.0) t_0))))
x_m = fabs(x);
double code(double x_m) {
double t_0 = -0.5 + (x_m * 0.5);
return pow(exp((x_m * 2.0)), t_0) * pow(exp(2.0), t_0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: t_0
t_0 = (-0.5d0) + (x_m * 0.5d0)
code = (exp((x_m * 2.0d0)) ** t_0) * (exp(2.0d0) ** t_0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double t_0 = -0.5 + (x_m * 0.5);
return Math.pow(Math.exp((x_m * 2.0)), t_0) * Math.pow(Math.exp(2.0), t_0);
}
x_m = math.fabs(x) def code(x_m): t_0 = -0.5 + (x_m * 0.5) return math.pow(math.exp((x_m * 2.0)), t_0) * math.pow(math.exp(2.0), t_0)
x_m = abs(x) function code(x_m) t_0 = Float64(-0.5 + Float64(x_m * 0.5)) return Float64((exp(Float64(x_m * 2.0)) ^ t_0) * (exp(2.0) ^ t_0)) end
x_m = abs(x); function tmp = code(x_m) t_0 = -0.5 + (x_m * 0.5); tmp = (exp((x_m * 2.0)) ^ t_0) * (exp(2.0) ^ t_0); end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_] := Block[{t$95$0 = N[(-0.5 + N[(x$95$m * 0.5), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision], t$95$0], $MachinePrecision] * N[Power[N[Exp[2.0], $MachinePrecision], t$95$0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
t_0 := -0.5 + x\_m \cdot 0.5\\
{\left(e^{x\_m \cdot 2}\right)}^{t\_0} \cdot {\left(e^{2}\right)}^{t\_0}
\end{array}
\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%
sqr-pow100.0%
pow-prod-down100.0%
exp-sum100.0%
exp-sum99.9%
swap-sqr100.0%
unpow-prod-down74.2%
div-inv74.2%
+-commutative74.2%
metadata-eval74.2%
exp-1-e74.2%
exp-1-e74.2%
div-inv74.2%
+-commutative74.2%
metadata-eval74.2%
Applied egg-rr74.2%
exp-lft-sqr74.2%
*-commutative74.2%
distribute-rgt-in74.2%
metadata-eval74.2%
exp-1-e74.2%
exp-1-e74.2%
prod-exp74.2%
metadata-eval74.2%
*-commutative74.2%
distribute-rgt-in74.2%
metadata-eval74.2%
Simplified74.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (exp (+ (* x_m x_m) -1.0)))
x_m = fabs(x);
double code(double x_m) {
return exp(((x_m * x_m) + -1.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp(((x_m * x_m) + (-1.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.exp(((x_m * x_m) + -1.0));
}
x_m = math.fabs(x) def code(x_m): return math.exp(((x_m * x_m) + -1.0))
x_m = abs(x) function code(x_m) return exp(Float64(Float64(x_m * x_m) + -1.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = exp(((x_m * x_m) + -1.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[N[(N[(x$95$m * x$95$m), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{x\_m \cdot x\_m + -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%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (pow E (+ x_m -1.0)))
x_m = fabs(x);
double code(double x_m) {
return pow(((double) M_E), (x_m + -1.0));
}
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(Math.E, (x_m + -1.0));
}
x_m = math.fabs(x) def code(x_m): return math.pow(math.e, (x_m + -1.0))
x_m = abs(x) function code(x_m) return exp(1) ^ Float64(x_m + -1.0) end
x_m = abs(x); function tmp = code(x_m) tmp = 2.71828182845904523536 ^ (x_m + -1.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[E, N[(x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{e}^{\left(x\_m + -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 72.6%
exp-1-e72.6%
Simplified72.6%
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%
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 72.6%
exp-1-e72.6%
Simplified72.6%
Taylor expanded in x around 0 50.6%
herbie shell --seed 2024185
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))