
(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 9 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 -1.0) (pow (exp x) (- x))))
double code(double x) {
return exp(-1.0) / pow(exp(x), -x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = exp((-1.0d0)) / (exp(x) ** -x)
end function
public static double code(double x) {
return Math.exp(-1.0) / Math.pow(Math.exp(x), -x);
}
def code(x): return math.exp(-1.0) / math.pow(math.exp(x), -x)
function code(x) return Float64(exp(-1.0) / (exp(x) ^ Float64(-x))) end
function tmp = code(x) tmp = exp(-1.0) / (exp(x) ^ -x); end
code[x_] := N[(N[Exp[-1.0], $MachinePrecision] / N[Power[N[Exp[x], $MachinePrecision], (-x)], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{-1}}{{\left(e^{x}\right)}^{\left(-x\right)}}
\end{array}
Initial program 100.0%
lift-exp.f64N/A
lift-neg.f64N/A
neg-sub0N/A
lift--.f64N/A
sub-negN/A
associate--r+N/A
metadata-evalN/A
exp-diffN/A
lower-/.f64N/A
lower-exp.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (exp (+ (* x x) -1.0)) 0.5) (/ 1.0 (E)) (/ (* x x) (E))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{x \cdot x + -1} \leq 0.5:\\
\;\;\;\;\frac{1}{\mathsf{E}\left(\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{E}\left(\right)}\\
\end{array}
\end{array}
if (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) < 0.5Initial program 100.0%
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%
Taylor expanded in x around 0
Applied rewrites98.9%
if 0.5 < (exp.f64 (neg.f64 (-.f64 #s(literal 1 binary64) (*.f64 x x)))) Initial program 100.0%
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%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6449.3
Applied rewrites49.3%
Taylor expanded in x around inf
Applied rewrites49.3%
Final simplification72.2%
(FPCore (x)
:precision binary64
(if (<= (* x x) 1e-6)
(/
1.0
(fma
(- (fma (* (fma (* 0.16666666666666666 x) x -0.5) (E)) (* x x) (E)))
(* x x)
(E)))
(exp (* x x))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{-6}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666 \cdot x, x, -0.5\right) \cdot \mathsf{E}\left(\right), x \cdot x, \mathsf{E}\left(\right)\right), x \cdot x, \mathsf{E}\left(\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 9.99999999999999955e-7Initial program 100.0%
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%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6499.8
Applied rewrites99.8%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites100.0%
if 9.99999999999999955e-7 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6499.4
Applied rewrites99.4%
Final simplification99.7%
(FPCore (x) :precision binary64 (exp (fma (- x 1.0) x (- x 1.0))))
double code(double x) {
return exp(fma((x - 1.0), x, (x - 1.0)));
}
function code(x) return exp(fma(Float64(x - 1.0), x, Float64(x - 1.0))) end
code[x_] := N[Exp[N[(N[(x - 1.0), $MachinePrecision] * x + N[(x - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\mathsf{fma}\left(x - 1, 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%
lift-fma.f64N/A
difference-of-sqr--1N/A
*-commutativeN/A
distribute-lft-inN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(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 (fma (* (* (/ x (E)) (* x x)) x) (fma (* 0.16666666666666666 x) x 0.5) (/ (fma x x 1.0) (E))))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\frac{x}{\mathsf{E}\left(\right)} \cdot \left(x \cdot x\right)\right) \cdot x, \mathsf{fma}\left(0.16666666666666666 \cdot x, x, 0.5\right), \frac{\mathsf{fma}\left(x, x, 1\right)}{\mathsf{E}\left(\right)}\right)
\end{array}
Initial program 100.0%
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%
Taylor expanded in x around 0
Applied rewrites89.7%
Applied rewrites89.7%
Applied rewrites89.7%
Final simplification89.7%
(FPCore (x) :precision binary64 (fma (* (/ (* x x) (E)) (* x x)) (fma (* 0.16666666666666666 x) x 0.5) (/ 1.0 (E))))
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{x \cdot x}{\mathsf{E}\left(\right)} \cdot \left(x \cdot x\right), \mathsf{fma}\left(0.16666666666666666 \cdot x, x, 0.5\right), \frac{1}{\mathsf{E}\left(\right)}\right)
\end{array}
Initial program 100.0%
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%
Taylor expanded in x around 0
Applied rewrites89.7%
Applied rewrites89.7%
Taylor expanded in x around 0
Applied rewrites89.2%
Final simplification89.2%
(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%
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%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6472.6
Applied rewrites72.6%
(FPCore (x) :precision binary64 (/ 1.0 (E)))
\begin{array}{l}
\\
\frac{1}{\mathsf{E}\left(\right)}
\end{array}
Initial program 100.0%
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%
Taylor expanded in x around 0
Applied rewrites47.3%
herbie shell --seed 2024270
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))