
(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 (* (+ -1.0 (+ 2.0 x)) (+ -1.0 x))))
double code(double x) {
return pow(((double) M_E), ((-1.0 + (2.0 + x)) * (-1.0 + x)));
}
public static double code(double x) {
return Math.pow(Math.E, ((-1.0 + (2.0 + x)) * (-1.0 + x)));
}
def code(x): return math.pow(math.e, ((-1.0 + (2.0 + x)) * (-1.0 + x)))
function code(x) return exp(1) ^ Float64(Float64(-1.0 + Float64(2.0 + x)) * Float64(-1.0 + x)) end
function tmp = code(x) tmp = 2.71828182845904523536 ^ ((-1.0 + (2.0 + x)) * (-1.0 + x)); end
code[x_] := N[Power[E, N[(N[(-1.0 + N[(2.0 + x), $MachinePrecision]), $MachinePrecision] * N[(-1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(\left(-1 + \left(2 + x\right)\right) \cdot \left(-1 + x\right)\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%
*-un-lft-identity100.0%
exp-prod100.0%
exp-1-e100.0%
fma-define100.0%
Applied egg-rr100.0%
fma-undefine100.0%
difference-of-sqr--1100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
expm1-log1p-u77.7%
expm1-undefine77.7%
Applied egg-rr77.7%
sub-neg77.7%
metadata-eval77.7%
+-commutative77.7%
log1p-undefine77.7%
rem-exp-log100.0%
+-commutative100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (pow E (* (+ -1.0 x) (+ x 1.0))))
double code(double x) {
return pow(((double) M_E), ((-1.0 + x) * (x + 1.0)));
}
public static double code(double x) {
return Math.pow(Math.E, ((-1.0 + x) * (x + 1.0)));
}
def code(x): return math.pow(math.e, ((-1.0 + x) * (x + 1.0)))
function code(x) return exp(1) ^ Float64(Float64(-1.0 + x) * Float64(x + 1.0)) end
function tmp = code(x) tmp = 2.71828182845904523536 ^ ((-1.0 + x) * (x + 1.0)); end
code[x_] := N[Power[E, N[(N[(-1.0 + x), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{e}^{\left(\left(-1 + x\right) \cdot \left(x + 1\right)\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%
*-un-lft-identity100.0%
exp-prod100.0%
exp-1-e100.0%
fma-define100.0%
Applied egg-rr100.0%
fma-undefine100.0%
difference-of-sqr--1100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification100.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%
sqr-neg100.0%
associate--r-100.0%
metadata-eval100.0%
+-commutative100.0%
sqr-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ 1.0 E))
double code(double x) {
return 1.0 / ((double) M_E);
}
public static double code(double x) {
return 1.0 / Math.E;
}
def code(x): return 1.0 / math.e
function code(x) return Float64(1.0 / exp(1)) end
function tmp = code(x) tmp = 1.0 / 2.71828182845904523536; end
code[x_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
\\
\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%
*-un-lft-identity100.0%
exp-prod100.0%
exp-1-e100.0%
fma-define100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 57.1%
herbie shell --seed 2024116
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))