
(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}
(FPCore (x) :precision binary64 (pow E (fma x x -1.0)))
double code(double x) {
return pow(((double) M_E), fma(x, x, -1.0));
}
function code(x) return exp(1) ^ fma(x, x, -1.0) end
code[x_] := N[Power[E, N[(x * x + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(\mathsf{fma}\left(x, x, -1\right)\right)}
\end{array}
Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
*-un-lft-identity100.0%
exp-prod100.0%
fma-def100.0%
Applied egg-rr100.0%
exp-1-e100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= (* x x) 0.05) (exp -1.0) (* x (/ x E))))
double code(double x) {
double tmp;
if ((x * x) <= 0.05) {
tmp = exp(-1.0);
} else {
tmp = x * (x / ((double) M_E));
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((x * x) <= 0.05) {
tmp = Math.exp(-1.0);
} else {
tmp = x * (x / Math.E);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 0.05: tmp = math.exp(-1.0) else: tmp = x * (x / math.e) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 0.05) tmp = exp(-1.0); else tmp = Float64(x * Float64(x / exp(1))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 0.05) tmp = exp(-1.0); else tmp = x * (x / 2.71828182845904523536); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.05], N[Exp[-1.0], $MachinePrecision], N[(x * N[(x / E), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.05:\\
\;\;\;\;e^{-1}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{e}\\
\end{array}
\end{array}
if (*.f64 x x) < 0.050000000000000003Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 99.1%
if 0.050000000000000003 < (*.f64 x x) Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 54.5%
*-rgt-identity54.5%
distribute-lft-in54.5%
unpow254.5%
fma-def54.5%
Simplified54.5%
Taylor expanded in x around inf 54.5%
unpow254.5%
*-commutative54.5%
associate-*l*54.5%
metadata-eval54.5%
rec-exp54.5%
e-exp-154.5%
associate-*r/54.5%
*-rgt-identity54.5%
Simplified54.5%
Final simplification77.0%
(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%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (exp -1.0))
double code(double x) {
return exp(-1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((-1.0d0))
end function
public static double code(double x) {
return Math.exp(-1.0);
}
def code(x): return math.exp(-1.0)
function code(x) return exp(-1.0) end
function tmp = code(x) tmp = exp(-1.0); end
code[x_] := N[Exp[-1.0], $MachinePrecision]
\begin{array}{l}
\\
e^{-1}
\end{array}
Initial program 100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around 0 51.5%
Final simplification51.5%
herbie shell --seed 2023171
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))