
(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 8 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 2.0) -1.0)) (+ -0.5 (* x_m 0.5))) (exp (* 0.5 (+ x_m -1.0)))))
x_m = fabs(x);
double code(double x_m) {
return pow(exp(((x_m * 2.0) - -1.0)), (-0.5 + (x_m * 0.5))) * exp((0.5 * (x_m + -1.0)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (exp(((x_m * 2.0d0) - (-1.0d0))) ** ((-0.5d0) + (x_m * 0.5d0))) * exp((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(((x_m * 2.0) - -1.0)), (-0.5 + (x_m * 0.5))) * Math.exp((0.5 * (x_m + -1.0)));
}
x_m = math.fabs(x) def code(x_m): return math.pow(math.exp(((x_m * 2.0) - -1.0)), (-0.5 + (x_m * 0.5))) * math.exp((0.5 * (x_m + -1.0)))
x_m = abs(x) function code(x_m) return Float64((exp(Float64(Float64(x_m * 2.0) - -1.0)) ^ Float64(-0.5 + Float64(x_m * 0.5))) * exp(Float64(0.5 * Float64(x_m + -1.0)))) end
x_m = abs(x); function tmp = code(x_m) tmp = (exp(((x_m * 2.0) - -1.0)) ^ (-0.5 + (x_m * 0.5))) * exp((0.5 * (x_m + -1.0))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[N[Exp[N[(N[(x$95$m * 2.0), $MachinePrecision] - -1.0), $MachinePrecision]], $MachinePrecision], N[(-0.5 + N[(x$95$m * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(0.5 * N[(x$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{\left(e^{x\_m \cdot 2 - -1}\right)}^{\left(-0.5 + x\_m \cdot 0.5\right)} \cdot e^{0.5 \cdot \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--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
sqr-pow100.0%
pow-prod-down99.9%
exp-sum99.9%
associate-*r*99.9%
unpow-prod-down79.7%
div-inv79.7%
+-commutative79.7%
metadata-eval79.7%
div-inv79.7%
metadata-eval79.7%
pow-unpow79.7%
exp-prod79.7%
*-un-lft-identity79.7%
+-commutative79.7%
Applied egg-rr79.7%
metadata-eval79.7%
sub-neg79.7%
div-exp79.6%
associate-*l/79.6%
prod-exp79.6%
count-279.6%
div-exp79.7%
*-commutative79.7%
*-commutative79.7%
distribute-rgt-in79.7%
metadata-eval79.7%
unpow1/279.7%
+-commutative79.7%
Simplified79.7%
pow1/279.7%
pow-exp79.7%
Applied egg-rr79.7%
Final simplification79.7%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.98) (/ 1.0 E) (exp x_m)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.98) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = exp(x_m);
}
return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.98) {
tmp = 1.0 / Math.E;
} else {
tmp = Math.exp(x_m);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.98: tmp = 1.0 / math.e else: tmp = math.exp(x_m) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.98) tmp = Float64(1.0 / exp(1)); else tmp = exp(x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.98) tmp = 1.0 / 2.71828182845904523536; else tmp = exp(x_m); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.98], N[(1.0 / E), $MachinePrecision], N[Exp[x$95$m], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.98:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;e^{x\_m}\\
\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--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 68.3%
exp-1-e68.3%
Simplified68.3%
Taylor expanded in x around 0 70.8%
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.7%
exp-1-e98.7%
Simplified98.7%
Taylor expanded in x around inf 98.7%
*-un-lft-identity98.7%
e-exp-198.7%
pow-exp98.7%
*-un-lft-identity98.7%
Applied egg-rr98.7%
*-lft-identity98.7%
Simplified98.7%
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%
neg-sub0100.0%
sqr-neg100.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 (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--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 77.0%
exp-1-e77.0%
Simplified77.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.95) (/ 1.0 E) (+ 1.0 (* x_m (+ (* x_m 0.5) 1.0)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.95) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = 1.0 + (x_m * ((x_m * 0.5) + 1.0));
}
return tmp;
}
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.95) {
tmp = 1.0 / Math.E;
} else {
tmp = 1.0 + (x_m * ((x_m * 0.5) + 1.0));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.95: tmp = 1.0 / math.e else: tmp = 1.0 + (x_m * ((x_m * 0.5) + 1.0)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.95) tmp = Float64(1.0 / exp(1)); else tmp = Float64(1.0 + Float64(x_m * Float64(Float64(x_m * 0.5) + 1.0))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.95) tmp = 1.0 / 2.71828182845904523536; else tmp = 1.0 + (x_m * ((x_m * 0.5) + 1.0)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.95], N[(1.0 / E), $MachinePrecision], N[(1.0 + N[(x$95$m * N[(N[(x$95$m * 0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.95:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;1 + x\_m \cdot \left(x\_m \cdot 0.5 + 1\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--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 68.3%
exp-1-e68.3%
Simplified68.3%
Taylor expanded in x around 0 70.8%
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.7%
exp-1-e98.7%
Simplified98.7%
Taylor expanded in x around inf 98.7%
Taylor expanded in x around 0 44.4%
log-E44.4%
associate-*r*44.4%
log-E44.4%
metadata-eval44.4%
associate-*r*44.4%
Simplified44.4%
Final simplification63.3%
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--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 77.0%
exp-1-e77.0%
Simplified77.0%
Taylor expanded in x around 0 51.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (+ x_m 1.0))
x_m = fabs(x);
double code(double x_m) {
return x_m + 1.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m + 1.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m + 1.0;
}
x_m = math.fabs(x) def code(x_m): return x_m + 1.0
x_m = abs(x) function code(x_m) return Float64(x_m + 1.0) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m + 1.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m + 1.0), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
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%
difference-of-sqr--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 77.0%
exp-1-e77.0%
Simplified77.0%
Taylor expanded in x around inf 37.6%
Taylor expanded in x around 0 10.6%
+-commutative10.6%
log-E10.6%
*-rgt-identity10.6%
Simplified10.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 1.0)
x_m = fabs(x);
double code(double x_m) {
return 1.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 1.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 1.0;
}
x_m = math.fabs(x) def code(x_m): return 1.0
x_m = abs(x) function code(x_m) return 1.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 1.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 1.0
\begin{array}{l}
x_m = \left|x\right|
\\
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%
difference-of-sqr--199.9%
exp-prod99.9%
sub-neg99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 77.0%
exp-1-e77.0%
Simplified77.0%
Taylor expanded in x around inf 37.6%
Taylor expanded in x around 0 10.6%
herbie shell --seed 2024137
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))