
(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 16 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) (* (/ 1.0 E) (fma x (fma x (* x (* x 0.5)) x) 1.0)) (* x (/ (* x (* (* x x) (fma x (* x 0.16666666666666666) 0.5))) E))))
double code(double x) {
double tmp;
if (exp((-1.0 + (x * x))) <= 0.5) {
tmp = (1.0 / ((double) M_E)) * fma(x, fma(x, (x * (x * 0.5)), x), 1.0);
} else {
tmp = x * ((x * ((x * x) * fma(x, (x * 0.16666666666666666), 0.5))) / ((double) M_E));
}
return tmp;
}
function code(x) tmp = 0.0 if (exp(Float64(-1.0 + Float64(x * x))) <= 0.5) tmp = Float64(Float64(1.0 / exp(1)) * fma(x, fma(x, Float64(x * Float64(x * 0.5)), x), 1.0)); else tmp = Float64(x * Float64(Float64(x * Float64(Float64(x * x) * fma(x, Float64(x * 0.16666666666666666), 0.5))) / 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[(1.0 / E), $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / E), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-1 + x \cdot x} \leq 0.5:\\
\;\;\;\;\frac{1}{e} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \left(x \cdot 0.5\right), x\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x \cdot \left(\left(x \cdot x\right) \cdot \mathsf{fma}\left(x, x \cdot 0.16666666666666666, 0.5\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
*-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 rewrites100.0%
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
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 rewrites80.8%
Applied rewrites36.9%
Taylor expanded in x around inf
Applied rewrites80.8%
Final simplification90.8%
(FPCore (x) :precision binary64 (if (<= (exp (+ -1.0 (* x x))) 0.5) (* (/ 1.0 E) (fma x (fma x (* x (* x 0.5)) x) 1.0)) (* 0.16666666666666666 (/ (* (* x x) (* x (* x (* x x)))) E))))
double code(double x) {
double tmp;
if (exp((-1.0 + (x * x))) <= 0.5) {
tmp = (1.0 / ((double) M_E)) * fma(x, fma(x, (x * (x * 0.5)), x), 1.0);
} else {
tmp = 0.16666666666666666 * (((x * x) * (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(Float64(1.0 / exp(1)) * fma(x, fma(x, Float64(x * Float64(x * 0.5)), x), 1.0)); else tmp = Float64(0.16666666666666666 * Float64(Float64(Float64(x * x) * 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[(1.0 / E), $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(0.16666666666666666 * N[(N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / E), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{-1 + x \cdot x} \leq 0.5:\\
\;\;\;\;\frac{1}{e} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \left(x \cdot 0.5\right), x\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \frac{\left(x \cdot x\right) \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
*-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 rewrites100.0%
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
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 rewrites80.8%
Taylor expanded in x around inf
Applied rewrites80.8%
Final simplification90.8%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-7) (* (/ 1.0 E) (fma x (fma x (* x (* x 0.5)) x) 1.0)) (exp (* x x))))
double code(double x) {
double tmp;
if ((x * x) <= 2e-7) {
tmp = (1.0 / ((double) M_E)) * fma(x, fma(x, (x * (x * 0.5)), x), 1.0);
} else {
tmp = exp((x * x));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-7) tmp = Float64(Float64(1.0 / exp(1)) * fma(x, fma(x, Float64(x * Float64(x * 0.5)), x), 1.0)); else tmp = exp(Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-7], N[(N[(1.0 / E), $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{e} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \left(x \cdot 0.5\right), x\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;e^{x \cdot x}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.9999999999999999e-7Initial 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 rewrites100.0%
if 1.9999999999999999e-7 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6499.3
Applied rewrites99.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (fma x (* (* x x) 0.5) x)))
(if (<= (* x x) 4e+153)
(/ (fma x (* t_0 (* x t_0)) -1.0) (* E (fma x t_0 -1.0)))
(* x (* 0.5 (* x (/ (* x x) E)))))))
double code(double x) {
double t_0 = fma(x, ((x * x) * 0.5), x);
double tmp;
if ((x * x) <= 4e+153) {
tmp = fma(x, (t_0 * (x * t_0)), -1.0) / (((double) M_E) * fma(x, t_0, -1.0));
} else {
tmp = x * (0.5 * (x * ((x * x) / ((double) M_E))));
}
return tmp;
}
function code(x) t_0 = fma(x, Float64(Float64(x * x) * 0.5), x) tmp = 0.0 if (Float64(x * x) <= 4e+153) tmp = Float64(fma(x, Float64(t_0 * Float64(x * t_0)), -1.0) / Float64(exp(1) * fma(x, t_0, -1.0))); else tmp = Float64(x * Float64(0.5 * Float64(x * Float64(Float64(x * x) / exp(1))))); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[N[(x * x), $MachinePrecision], 4e+153], N[(N[(x * N[(t$95$0 * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / N[(E * N[(x * t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 * N[(x * N[(N[(x * x), $MachinePrecision] / E), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x, \left(x \cdot x\right) \cdot 0.5, x\right)\\
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, t\_0 \cdot \left(x \cdot t\_0\right), -1\right)}{e \cdot \mathsf{fma}\left(x, t\_0, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 \cdot \left(x \cdot \frac{x \cdot x}{e}\right)\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 4e153Initial 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 rewrites78.2%
Applied rewrites89.5%
if 4e153 < (*.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 rewrites100.0%
Taylor expanded in x around inf
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites100.0%
Final simplification92.9%
(FPCore (x) :precision binary64 (* (/ 1.0 E) (fma x (fma (* x (fma (* x x) 0.16666666666666666 0.5)) (* x x) x) 1.0)))
double code(double x) {
return (1.0 / ((double) M_E)) * fma(x, fma((x * fma((x * x), 0.16666666666666666, 0.5)), (x * x), x), 1.0);
}
function code(x) return Float64(Float64(1.0 / exp(1)) * fma(x, fma(Float64(x * fma(Float64(x * x), 0.16666666666666666, 0.5)), Float64(x * x), x), 1.0)) end
code[x_] := N[(N[(1.0 / E), $MachinePrecision] * N[(x * N[(N[(x * N[(N[(x * x), $MachinePrecision] * 0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot \mathsf{fma}\left(x \cdot x, 0.16666666666666666, 0.5\right), x \cdot x, x\right), 1\right)
\end{array}
Initial 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 rewrites90.8%
Applied rewrites90.8%
(FPCore (x) :precision binary64 (/ (fma x (fma (* x x) (* x (fma x (* x 0.16666666666666666) 0.5)) x) 1.0) E))
double code(double x) {
return fma(x, fma((x * x), (x * fma(x, (x * 0.16666666666666666), 0.5)), x), 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(x, fma(Float64(x * x), Float64(x * fma(x, Float64(x * 0.16666666666666666), 0.5)), x), 1.0) / exp(1)) end
code[x_] := N[(N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * N[(x * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x \cdot x, x \cdot \mathsf{fma}\left(x, x \cdot 0.16666666666666666, 0.5\right), x\right), 1\right)}{e}
\end{array}
Initial 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 rewrites90.8%
Applied rewrites69.7%
Applied rewrites90.8%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-7) (* (/ 1.0 E) (fma x x 1.0)) (* x (* (fma (* x x) 0.5 1.0) (/ x E)))))
double code(double x) {
double tmp;
if ((x * x) <= 2e-7) {
tmp = (1.0 / ((double) M_E)) * fma(x, x, 1.0);
} else {
tmp = x * (fma((x * x), 0.5, 1.0) * (x / ((double) M_E)));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-7) tmp = Float64(Float64(1.0 / exp(1)) * fma(x, x, 1.0)); else tmp = Float64(x * Float64(fma(Float64(x * x), 0.5, 1.0) * Float64(x / exp(1)))); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-7], N[(N[(1.0 / E), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(N[(x * x), $MachinePrecision] * 0.5 + 1.0), $MachinePrecision] * N[(x / E), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{e} \cdot \mathsf{fma}\left(x, x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\mathsf{fma}\left(x \cdot x, 0.5, 1\right) \cdot \frac{x}{e}\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1.9999999999999999e-7Initial 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.9
Applied rewrites99.9%
if 1.9999999999999999e-7 < (*.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 rewrites69.4%
Taylor expanded in x around inf
Applied rewrites69.4%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-7) (* (/ 1.0 E) (fma x x 1.0)) (* x (* 0.5 (* x (/ (* x x) E))))))
double code(double x) {
double tmp;
if ((x * x) <= 2e-7) {
tmp = (1.0 / ((double) M_E)) * fma(x, x, 1.0);
} else {
tmp = x * (0.5 * (x * ((x * x) / ((double) M_E))));
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-7) tmp = Float64(Float64(1.0 / exp(1)) * fma(x, x, 1.0)); else tmp = Float64(x * Float64(0.5 * Float64(x * Float64(Float64(x * x) / exp(1))))); end return tmp end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-7], N[(N[(1.0 / E), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 * N[(x * N[(N[(x * x), $MachinePrecision] / E), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{e} \cdot \mathsf{fma}\left(x, x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 \cdot \left(x \cdot \frac{x \cdot x}{e}\right)\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1.9999999999999999e-7Initial 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.9
Applied rewrites99.9%
if 1.9999999999999999e-7 < (*.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 rewrites69.4%
Taylor expanded in x around inf
Applied rewrites69.4%
Taylor expanded in x around inf
Applied rewrites69.4%
(FPCore (x) :precision binary64 (/ (fma x (* (* x (* x x)) (* (* x x) 0.16666666666666666)) 1.0) E))
double code(double x) {
return fma(x, ((x * (x * x)) * ((x * x) * 0.16666666666666666)), 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(x, Float64(Float64(x * Float64(x * x)) * Float64(Float64(x * x) * 0.16666666666666666)), 1.0) / exp(1)) end
code[x_] := N[(N[(x * N[(N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(\left(x \cdot x\right) \cdot 0.16666666666666666\right), 1\right)}{e}
\end{array}
Initial 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 rewrites90.8%
Taylor expanded in x around inf
Applied rewrites90.1%
Applied rewrites90.1%
(FPCore (x) :precision binary64 (* (/ 1.0 E) (fma x (fma x (* x (* x 0.5)) x) 1.0)))
double code(double x) {
return (1.0 / ((double) M_E)) * fma(x, fma(x, (x * (x * 0.5)), x), 1.0);
}
function code(x) return Float64(Float64(1.0 / exp(1)) * fma(x, fma(x, Float64(x * Float64(x * 0.5)), x), 1.0)) end
code[x_] := N[(N[(1.0 / E), $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e} \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, x \cdot \left(x \cdot 0.5\right), x\right), 1\right)
\end{array}
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 rewrites85.3%
(FPCore (x) :precision binary64 (/ (fma x (fma x (* (* x x) 0.5) x) 1.0) E))
double code(double x) {
return fma(x, fma(x, ((x * x) * 0.5), x), 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(x, fma(x, Float64(Float64(x * x) * 0.5), x), 1.0) / exp(1)) end
code[x_] := N[(N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.5), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, \mathsf{fma}\left(x, \left(x \cdot x\right) \cdot 0.5, x\right), 1\right)}{e}
\end{array}
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 rewrites85.3%
Applied rewrites85.3%
Final simplification85.3%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-7) (/ 1.0 E) (/ (* x x) E)))
double code(double x) {
double tmp;
if ((x * x) <= 2e-7) {
tmp = 1.0 / ((double) M_E);
} else {
tmp = (x * x) / ((double) M_E);
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((x * x) <= 2e-7) {
tmp = 1.0 / Math.E;
} else {
tmp = (x * x) / Math.E;
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 2e-7: tmp = 1.0 / math.e else: tmp = (x * x) / math.e return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-7) tmp = Float64(1.0 / exp(1)); else tmp = Float64(Float64(x * x) / exp(1)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 2e-7) tmp = 1.0 / 2.71828182845904523536; else tmp = (x * x) / 2.71828182845904523536; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-7], N[(1.0 / E), $MachinePrecision], N[(N[(x * x), $MachinePrecision] / E), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\frac{1}{e}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{e}\\
\end{array}
\end{array}
if (*.f64 x x) < 1.9999999999999999e-7Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6498.7
Applied rewrites98.7%
if 1.9999999999999999e-7 < (*.f64 x x) Initial 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.f6446.8
Applied rewrites46.8%
Taylor expanded in x around inf
Applied rewrites46.8%
(FPCore (x) :precision binary64 (* (/ 1.0 E) (fma x x 1.0)))
double code(double x) {
return (1.0 / ((double) M_E)) * fma(x, x, 1.0);
}
function code(x) return Float64(Float64(1.0 / exp(1)) * fma(x, x, 1.0)) end
code[x_] := N[(N[(1.0 / E), $MachinePrecision] * N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e} \cdot \mathsf{fma}\left(x, x, 1\right)
\end{array}
Initial 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.f6474.4
Applied rewrites74.4%
(FPCore (x) :precision binary64 (/ (fma x x 1.0) E))
double code(double x) {
return fma(x, x, 1.0) / ((double) M_E);
}
function code(x) return Float64(fma(x, x, 1.0) / exp(1)) end
code[x_] := N[(N[(x * x + 1.0), $MachinePrecision] / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, x, 1\right)}{e}
\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%
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.f6474.4
Applied rewrites74.4%
(FPCore (x) :precision binary64 (/ 1.0 E))
double code(double x) {
return 1.0 / ((double) M_E);
}
public static double code(double x) {
return 1.0 / Math.E;
}
def code(x): return 1.0 / math.e
function code(x) return Float64(1.0 / exp(1)) end
function tmp = code(x) tmp = 1.0 / 2.71828182845904523536; end
code[x_] := N[(1.0 / E), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{e}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
metadata-evalN/A
rec-expN/A
lower-/.f64N/A
exp-1-eN/A
lower-E.f6452.8
Applied rewrites52.8%
herbie shell --seed 2024216
(FPCore (x)
:name "exp neg sub"
:precision binary64
(exp (- (- 1.0 (* x x)))))