
(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 5 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 (* 2.0 (+ 1.0 x_m))) (* 0.5 (+ x_m -1.0))))
x_m = fabs(x);
double code(double x_m) {
return pow(exp((2.0 * (1.0 + x_m))), (0.5 * (x_m + -1.0)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = exp((2.0d0 * (1.0d0 + x_m))) ** (0.5d0 * (x_m + (-1.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(Math.exp((2.0 * (1.0 + x_m))), (0.5 * (x_m + -1.0)));
}
x_m = math.fabs(x) def code(x_m): return math.pow(math.exp((2.0 * (1.0 + x_m))), (0.5 * (x_m + -1.0)))
x_m = abs(x) function code(x_m) return exp(Float64(2.0 * Float64(1.0 + x_m))) ^ Float64(0.5 * Float64(x_m + -1.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = exp((2.0 * (1.0 + x_m))) ^ (0.5 * (x_m + -1.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Power[N[Exp[N[(2.0 * N[(1.0 + x$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(e^{2 \cdot \left(1 + x\_m\right)}\right)}^{\left(0.5 \cdot \left(x\_m + -1\right)\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%
*-un-lft-identity100.0%
exp-prod100.0%
flip-+76.1%
metadata-eval76.1%
div-sub76.1%
pow-sub76.1%
exp-1-e76.1%
pow276.1%
pow276.1%
pow-prod-up76.2%
metadata-eval76.2%
fma-neg76.2%
metadata-eval76.2%
exp-1-e76.2%
fma-neg76.2%
metadata-eval76.2%
Applied egg-rr76.2%
pow-div76.1%
pow-to-exp76.1%
log-E76.1%
*-un-lft-identity76.1%
sub-div76.1%
metadata-eval76.1%
pow-prod-up76.1%
pow-prod-down76.1%
pow276.1%
metadata-eval76.1%
fma-udef76.1%
flip--100.0%
difference-of-sqr-199.9%
sub-neg99.9%
metadata-eval99.9%
pow-exp100.0%
exp-sum100.0%
e-exp-1100.0%
unpow-prod-down76.5%
Applied egg-rr76.6%
*-un-lft-identity76.6%
pow-exp76.5%
e-exp-176.5%
sqr-pow76.5%
sqr-pow76.5%
pow-prod-down76.5%
pow-prod-down76.5%
pow-prod-down100.0%
Applied egg-rr100.0%
pow-plus100.0%
*-commutative100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 100.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 -1.0)))
x_m = fabs(x);
double code(double x_m) {
return exp((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)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.exp((x_m + -1.0));
}
x_m = math.fabs(x) def code(x_m): return math.exp((x_m + -1.0))
x_m = abs(x) function code(x_m) return exp(Float64(x_m + -1.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = exp((x_m + -1.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[Exp[N[(x$95$m + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
e^{x\_m + -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%
difference-of-sqr--199.9%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 75.3%
exp-1-e75.3%
Simplified75.3%
e-exp-175.3%
pow-exp75.3%
*-un-lft-identity75.3%
Applied egg-rr75.3%
Final simplification75.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (+ 1.0 x_m) E))
x_m = fabs(x);
double code(double x_m) {
return (1.0 + x_m) / ((double) M_E);
}
x_m = Math.abs(x);
public static double code(double x_m) {
return (1.0 + x_m) / Math.E;
}
x_m = math.fabs(x) def code(x_m): return (1.0 + x_m) / math.e
x_m = abs(x) function code(x_m) return Float64(Float64(1.0 + x_m) / exp(1)) end
x_m = abs(x); function tmp = code(x_m) tmp = (1.0 + x_m) / 2.71828182845904523536; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(1.0 + x$95$m), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{1 + 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--199.9%
exp-prod100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 75.3%
exp-1-e75.3%
Simplified75.3%
e-exp-175.3%
pow-exp75.3%
*-un-lft-identity75.3%
Applied egg-rr75.3%
Taylor expanded in x around 0 52.0%
distribute-rgt1-in52.0%
metadata-eval52.0%
rec-exp52.0%
e-exp-152.0%
associate-*r/52.0%
distribute-rgt1-in52.0%
*-rgt-identity52.0%
Simplified52.0%
Final simplification52.0%
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%
*-un-lft-identity100.0%
exp-prod100.0%
flip-+76.1%
metadata-eval76.1%
div-sub76.1%
pow-sub76.1%
exp-1-e76.1%
pow276.1%
pow276.1%
pow-prod-up76.2%
metadata-eval76.2%
fma-neg76.2%
metadata-eval76.2%
exp-1-e76.2%
fma-neg76.2%
metadata-eval76.2%
Applied egg-rr76.2%
Taylor expanded in x around 0 52.6%
Final simplification52.6%
herbie shell --seed 2024026
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))