
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 21 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (exp (* y y))))
double code(double x, double y) {
return x * exp((y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * exp((y * y))
end function
public static double code(double x, double y) {
return x * Math.exp((y * y));
}
def code(x, y): return x * math.exp((y * y))
function code(x, y) return Float64(x * exp(Float64(y * y))) end
function tmp = code(x, y) tmp = x * exp((y * y)); end
code[x_, y_] := N[(x * N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot e^{y \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (* (exp (* y y)) x))
double code(double x, double y) {
return exp((y * y)) * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp((y * y)) * x
end function
public static double code(double x, double y) {
return Math.exp((y * y)) * x;
}
def code(x, y): return math.exp((y * y)) * x
function code(x, y) return Float64(exp(Float64(y * y)) * x) end
function tmp = code(x, y) tmp = exp((y * y)) * x; end
code[x_, y_] := N[(N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
e^{y \cdot y} \cdot x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (* y y) y)))
(if (<= (exp (* y y)) 2.0)
(fma (* y x) (fma t_0 0.5 y) x)
(* (* (* (* (* t_0 y) y) y) 0.16666666666666666) x))))
double code(double x, double y) {
double t_0 = (y * y) * y;
double tmp;
if (exp((y * y)) <= 2.0) {
tmp = fma((y * x), fma(t_0, 0.5, y), x);
} else {
tmp = ((((t_0 * y) * y) * y) * 0.16666666666666666) * x;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(y * y) * y) tmp = 0.0 if (exp(Float64(y * y)) <= 2.0) tmp = fma(Float64(y * x), fma(t_0, 0.5, y), x); else tmp = Float64(Float64(Float64(Float64(Float64(t_0 * y) * y) * y) * 0.16666666666666666) * x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(y * y), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[N[Exp[N[(y * y), $MachinePrecision]], $MachinePrecision], 2.0], N[(N[(y * x), $MachinePrecision] * N[(t$95$0 * 0.5 + y), $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(N[(N[(t$95$0 * y), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot y\right) \cdot y\\
\mathbf{if}\;e^{y \cdot y} \leq 2:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, \mathsf{fma}\left(t\_0, 0.5, y\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(t\_0 \cdot y\right) \cdot y\right) \cdot y\right) \cdot 0.16666666666666666\right) \cdot x\\
\end{array}
\end{array}
if (exp.f64 (*.f64 y y)) < 2Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
*-lft-identityN/A
distribute-rgt-inN/A
lower-fma.f64N/A
Applied rewrites99.7%
if 2 < (exp.f64 (*.f64 y y)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites88.7%
Taylor expanded in y around inf
Applied rewrites88.7%
Final simplification94.2%
(FPCore (x y) :precision binary64 (* x (pow (exp y) y)))
double code(double x, double y) {
return x * pow(exp(y), y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (exp(y) ** y)
end function
public static double code(double x, double y) {
return x * Math.pow(Math.exp(y), y);
}
def code(x, y): return x * math.pow(math.exp(y), y)
function code(x, y) return Float64(x * (exp(y) ^ y)) end
function tmp = code(x, y) tmp = x * (exp(y) ^ y); end
code[x_, y_] := N[(x * N[Power[N[Exp[y], $MachinePrecision], y], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot {\left(e^{y}\right)}^{y}
\end{array}
herbie shell --seed 2024230
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:alt
(! :herbie-platform default (* x (pow (exp y) y)))
(* x (exp (* y y))))