
(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 15 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 (<= (exp (+ -1.0 (* x x))) 0.5) (/ (fma x (* x E) E) (* E E)) (/ (* 0.5 (* x (* x (* x x)))) E)))
double code(double x) {
double tmp;
if (exp((-1.0 + (x * x))) <= 0.5) {
tmp = fma(x, (x * ((double) M_E)), ((double) M_E)) / (((double) M_E) * ((double) M_E));
} else {
tmp = (0.5 * (x * (x * (x * x)))) / ((double) M_E);
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(Float64(-1.0 + Float64(x * x))) <= 0.5) tmp = Float64(fma(x, Float64(x * exp(1)), exp(1)) / Float64(exp(1) * exp(1))); else tmp = Float64(Float64(0.5 * Float64(x * Float64(x * Float64(x * x)))) / exp(1)); end return tmp end
code[x_] := If[LessEqual[N[Exp[N[(-1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.5], N[(N[(x * N[(x * E), $MachinePrecision] + E), $MachinePrecision] / N[(E * E), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / E), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-1 + x \cdot x} \leq 0.5:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x \cdot e, e\right)}{e \cdot e}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}{e}\\
\end{array}
\end{array}
if (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) < 0.5Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt1-inN/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f64N/A
unpow2N/A
lower-fma.f6499.7
Applied rewrites99.7%
Applied rewrites99.7%
Applied rewrites99.7%
if 0.5 < (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) Initial program 100.0%
Taylor expanded in x around 0
*-lft-identityN/A
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+l+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites75.8%
Taylor expanded in x around inf
Applied rewrites75.8%
Applied rewrites75.8%
Final simplification87.7%
herbie shell --seed 2024226
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))