
(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 (pow (exp -2.0) (* (fma x x -1.0) -0.5)))
double code(double x) {
return pow(exp(-2.0), (fma(x, x, -1.0) * -0.5));
}
function code(x) return exp(-2.0) ^ Float64(fma(x, x, -1.0) * -0.5) end
code[x_] := N[Power[N[Exp[-2.0], $MachinePrecision], N[(N[(x * x + -1.0), $MachinePrecision] * -0.5), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
{\left(e^{-2}\right)}^{\left(\mathsf{fma}\left(x, x, -1\right) \cdot -0.5\right)}
\end{array}
Initial program 99.9%
Applied rewrites100.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-exp.f64100.0
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (/ (pow (exp x) x) (E)))
\begin{array}{l}
\\
\frac{{\left(e^{x}\right)}^{x}}{\mathsf{E}\left(\right)}
\end{array}
Initial program 99.9%
lift-exp.f64N/A
lift-neg.f64N/A
exp-negN/A
lift--.f64N/A
exp-diffN/A
clear-numN/A
lower-/.f64N/A
lift-*.f64N/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
exp-1-eN/A
lower-E.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (pow (* (E) (E)) (* 0.5 (fma x x -1.0))))
\begin{array}{l}
\\
{\left(\mathsf{E}\left(\right) \cdot \mathsf{E}\left(\right)\right)}^{\left(0.5 \cdot \mathsf{fma}\left(x, x, -1\right)\right)}
\end{array}
Initial program 99.9%
Applied rewrites100.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-exp.f64100.0
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-pow.f64N/A
lift-*.f64N/A
pow-unpowN/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
sqr-powN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
div-invN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites99.9%
(FPCore (x) :precision binary64 (if (<= (* x x) 0.005) (/ (fma x x 1.0) (E)) (exp (* x x))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.005:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{E}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 0.0050000000000000001Initial program 100.0%
Applied rewrites100.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-exp.f64100.0
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-pow.f64N/A
lift-*.f64N/A
pow-unpowN/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
sqr-powN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
div-invN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
rem-log-expN/A
metadata-evalN/A
log-EN/A
log-EN/A
prod-expN/A
log-EN/A
e-exp-1N/A
log-EN/A
e-exp-1N/A
unpow2N/A
associate-*r/N/A
associate-/l*N/A
associate-*r*N/A
Applied rewrites99.0%
if 0.0050000000000000001 < (*.f64 x x) Initial program 99.9%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6499.3
Applied rewrites99.3%
(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 99.9%
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
Applied rewrites99.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 99.9%
Applied rewrites100.0%
lift-*.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
metadata-evalN/A
lower-exp.f64100.0
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval100.0
Applied rewrites100.0%
lift-pow.f64N/A
lift-*.f64N/A
pow-unpowN/A
lift-fma.f64N/A
metadata-evalN/A
sub-negN/A
metadata-evalN/A
sqr-powN/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
lift-exp.f64N/A
pow-expN/A
metadata-evalN/A
exp-1-eN/A
lower-E.f64N/A
div-invN/A
metadata-evalN/A
metadata-evalN/A
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
metadata-evalN/A
rem-log-expN/A
metadata-evalN/A
log-EN/A
log-EN/A
prod-expN/A
log-EN/A
e-exp-1N/A
log-EN/A
e-exp-1N/A
unpow2N/A
associate-*r/N/A
associate-/l*N/A
associate-*r*N/A
Applied rewrites75.4%
herbie shell --seed 2024254
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))