
(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 6 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) 4.0) (* (/ 1.0 (E)) (fma (* x x) (* 0.5 (* x x)) (fma x x 1.0))) (exp (* x x))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4:\\
\;\;\;\;\frac{1}{\mathsf{E}\left(\right)} \cdot \mathsf{fma}\left(x \cdot x, 0.5 \cdot \left(x \cdot x\right), \mathsf{fma}\left(x, x, 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 4Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites99.2%
Applied rewrites99.2%
Applied rewrites99.2%
Applied rewrites99.2%
if 4 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites3.1%
Taylor expanded in x around inf
unpow2N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification99.6%
(FPCore (x) :precision binary64 (* (/ 1.0 (E)) (fma (* x x) (* 0.5 (* x x)) (fma x x 1.0))))
\begin{array}{l}
\\
\frac{1}{\mathsf{E}\left(\right)} \cdot \mathsf{fma}\left(x \cdot x, 0.5 \cdot \left(x \cdot x\right), \mathsf{fma}\left(x, x, 1\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites88.5%
Applied rewrites88.5%
Applied rewrites88.5%
Applied rewrites88.5%
Final simplification88.5%
(FPCore (x) :precision binary64 (* (fma (fma (* x x) 0.5 1.0) (* x x) 1.0) (/ 1.0 (E))))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.5, 1\right), x \cdot x, 1\right) \cdot \frac{1}{\mathsf{E}\left(\right)}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites88.5%
Applied rewrites88.5%
Applied rewrites88.5%
(FPCore (x) :precision binary64 (* (fma (* 0.5 (* x x)) (* x x) 1.0) (/ 1.0 (E))))
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 \cdot \left(x \cdot x\right), x \cdot x, 1\right) \cdot \frac{1}{\mathsf{E}\left(\right)}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites88.5%
Applied rewrites88.5%
Applied rewrites88.5%
Taylor expanded in x around inf
Applied rewrites87.9%
(FPCore (x) :precision binary64 (/ (fma x x 1.0) (E)))
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{E}\left(\right)}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
associate-*r*N/A
distribute-rgt1-inN/A
associate-*r*N/A
distribute-rgt1-inN/A
distribute-lft-inN/A
*-rgt-identityN/A
associate-+r+N/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites88.5%
Applied rewrites88.5%
Applied rewrites88.5%
Taylor expanded in x around 0
distribute-rgt1-inN/A
metadata-evalN/A
rec-expN/A
e-exp-1N/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
lower-E.f6477.5
Applied rewrites77.5%
herbie shell --seed 2024308
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))