
(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 14 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 (exp (fma x x -1.0)))
double code(double x) {
return exp(fma(x, x, -1.0));
}
function code(x) return exp(fma(x, x, -1.0)) end
code[x_] := N[Exp[N[(x * x + -1.0), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Initial program 100.0%
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x)
:precision binary64
(if (<= (* x x) 0.0002)
(/
(fma x (fma (* x (* x (fma (* x x) 0.16666666666666666 0.5))) x x) 1.0)
E)
(exp (* x x))))
double code(double x) {
double tmp;
if ((x * x) <= 0.0002) {
tmp = fma(x, fma((x * (x * fma((x * x), 0.16666666666666666, 0.5))), x, x), 1.0) / ((double) M_E);
} else {
tmp = exp((x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 0.0002) tmp = Float64(fma(x, fma(Float64(x * Float64(x * fma(Float64(x * x), 0.16666666666666666, 0.5))), x, x), 1.0) / exp(1)); else tmp = exp(Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.0002], N[(N[(x * N[(N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision], N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.0002:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, 0.16666666666666666, 0.5\right)\right), x, x\right), 1\right)}{e}\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 2.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-commutativeN/A
associate-+r+N/A
distribute-rgt1-inN/A
*-commutativeN/A
associate-*l*N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 2.0000000000000001e-4 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6498.9
Applied rewrites98.9%
herbie shell --seed 2024222
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))