
(FPCore (x y) :precision binary64 (exp (* (* x y) y)))
double code(double x, double y) {
return exp(((x * y) * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp(((x * y) * y))
end function
public static double code(double x, double y) {
return Math.exp(((x * y) * y));
}
def code(x, y): return math.exp(((x * y) * y))
function code(x, y) return exp(Float64(Float64(x * y) * y)) end
function tmp = code(x, y) tmp = exp(((x * y) * y)); end
code[x_, y_] := N[Exp[N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x \cdot y\right) \cdot y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (exp (* (* x y) y)))
double code(double x, double y) {
return exp(((x * y) * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp(((x * y) * y))
end function
public static double code(double x, double y) {
return Math.exp(((x * y) * y));
}
def code(x, y): return math.exp(((x * y) * y))
function code(x, y) return exp(Float64(Float64(x * y) * y)) end
function tmp = code(x, y) tmp = exp(((x * y) * y)); end
code[x_, y_] := N[Exp[N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(x \cdot y\right) \cdot y}
\end{array}
(FPCore (x y) :precision binary64 (exp (* (* y x) y)))
double code(double x, double y) {
return exp(((y * x) * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = exp(((y * x) * y))
end function
public static double code(double x, double y) {
return Math.exp(((y * x) * y));
}
def code(x, y): return math.exp(((y * x) * y))
function code(x, y) return exp(Float64(Float64(y * x) * y)) end
function tmp = code(x, y) tmp = exp(((y * x) * y)); end
code[x_, y_] := N[Exp[N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\left(y \cdot x\right) \cdot y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (exp (* (* y x) y))))
(if (<= t_0 4e-153)
(exp (* y x))
(if (<= t_0 2.0)
(fma (* y x) y 1.0)
(* (* (* (* (* (* y y) 0.16666666666666666) y) x) x) x)))))
double code(double x, double y) {
double t_0 = exp(((y * x) * y));
double tmp;
if (t_0 <= 4e-153) {
tmp = exp((y * x));
} else if (t_0 <= 2.0) {
tmp = fma((y * x), y, 1.0);
} else {
tmp = (((((y * y) * 0.16666666666666666) * y) * x) * x) * x;
}
return tmp;
}
function code(x, y) t_0 = exp(Float64(Float64(y * x) * y)) tmp = 0.0 if (t_0 <= 4e-153) tmp = exp(Float64(y * x)); elseif (t_0 <= 2.0) tmp = fma(Float64(y * x), y, 1.0); else tmp = Float64(Float64(Float64(Float64(Float64(Float64(y * y) * 0.16666666666666666) * y) * x) * x) * x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[Exp[N[(N[(y * x), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 4e-153], N[Exp[N[(y * x), $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, 2.0], N[(N[(y * x), $MachinePrecision] * y + 1.0), $MachinePrecision], N[(N[(N[(N[(N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * y), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\left(y \cdot x\right) \cdot y}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{-153}:\\
\;\;\;\;e^{y \cdot x}\\
\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\mathsf{fma}\left(y \cdot x, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(\left(y \cdot y\right) \cdot 0.16666666666666666\right) \cdot y\right) \cdot x\right) \cdot x\right) \cdot x\\
\end{array}
\end{array}
if (exp.f64 (*.f64 (*.f64 x y) y)) < 4.00000000000000016e-153Initial program 100.0%
Applied rewrites42.1%
if 4.00000000000000016e-153 < (exp.f64 (*.f64 (*.f64 x y) y)) < 2Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
if 2 < (exp.f64 (*.f64 (*.f64 x y) y)) Initial program 100.0%
Applied rewrites44.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites35.6%
Taylor expanded in x around inf
Applied rewrites35.4%
Applied rewrites44.4%
Final simplification71.3%
herbie shell --seed 2024230
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalF from random-fu-0.2.6.2"
:precision binary64
(exp (* (* x y) y)))