
(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(y * Float64(x * y))) end
function tmp = code(x, y) tmp = exp((y * (x * y))); end
code[x_, y_] := N[Exp[N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{y \cdot \left(x \cdot y\right)}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= (* y (* x y)) -400000.0)
(exp (* x y))
(fma
(* y y)
(fma (* x (* x (* y y))) (fma x (* (* y y) 0.16666666666666666) 0.5) x)
1.0)))
double code(double x, double y) {
double tmp;
if ((y * (x * y)) <= -400000.0) {
tmp = exp((x * y));
} else {
tmp = fma((y * y), fma((x * (x * (y * y))), fma(x, ((y * y) * 0.16666666666666666), 0.5), x), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * Float64(x * y)) <= -400000.0) tmp = exp(Float64(x * y)); else tmp = fma(Float64(y * y), fma(Float64(x * Float64(x * Float64(y * y))), fma(x, Float64(Float64(y * y) * 0.16666666666666666), 0.5), x), 1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], -400000.0], N[Exp[N[(x * y), $MachinePrecision]], $MachinePrecision], N[(N[(y * y), $MachinePrecision] * N[(N[(x * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(x \cdot y\right) \leq -400000:\\
\;\;\;\;e^{x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(x \cdot \left(x \cdot \left(y \cdot y\right)\right), \mathsf{fma}\left(x, \left(y \cdot y\right) \cdot 0.16666666666666666, 0.5\right), x\right), 1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x y) y) < -4e5Initial program 100.0%
Applied rewrites43.6%
if -4e5 < (*.f64 (*.f64 x y) y) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites93.7%
Final simplification78.1%
(FPCore (x y)
:precision binary64
(if (<= (* y (* x y)) -400000.0)
(exp x)
(fma
(* y y)
(fma (* x (* x (* y y))) (fma x (* (* y y) 0.16666666666666666) 0.5) x)
1.0)))
double code(double x, double y) {
double tmp;
if ((y * (x * y)) <= -400000.0) {
tmp = exp(x);
} else {
tmp = fma((y * y), fma((x * (x * (y * y))), fma(x, ((y * y) * 0.16666666666666666), 0.5), x), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * Float64(x * y)) <= -400000.0) tmp = exp(x); else tmp = fma(Float64(y * y), fma(Float64(x * Float64(x * Float64(y * y))), fma(x, Float64(Float64(y * y) * 0.16666666666666666), 0.5), x), 1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], -400000.0], N[Exp[x], $MachinePrecision], N[(N[(y * y), $MachinePrecision] * N[(N[(x * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(x \cdot y\right) \leq -400000:\\
\;\;\;\;e^{x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(x \cdot \left(x \cdot \left(y \cdot y\right)\right), \mathsf{fma}\left(x, \left(y \cdot y\right) \cdot 0.16666666666666666, 0.5\right), x\right), 1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x y) y) < -4e5Initial program 100.0%
Applied rewrites67.3%
if -4e5 < (*.f64 (*.f64 x y) y) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites93.7%
Final simplification85.5%
(FPCore (x y) :precision binary64 (fma (* y y) (fma (* x (* x (* y y))) (fma x (* (* y y) 0.16666666666666666) 0.5) x) 1.0))
double code(double x, double y) {
return fma((y * y), fma((x * (x * (y * y))), fma(x, ((y * y) * 0.16666666666666666), 0.5), x), 1.0);
}
function code(x, y) return fma(Float64(y * y), fma(Float64(x * Float64(x * Float64(y * y))), fma(x, Float64(Float64(y * y) * 0.16666666666666666), 0.5), x), 1.0) end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] * N[(N[(x * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x * N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] + 0.5), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(x \cdot \left(x \cdot \left(y \cdot y\right)\right), \mathsf{fma}\left(x, \left(y \cdot y\right) \cdot 0.16666666666666666, 0.5\right), x\right), 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites65.0%
(FPCore (x y) :precision binary64 (if (<= (* y (* x y)) 0.1) (fma x (* y y) 1.0) (* x (* 0.5 (* x (* (* y y) (* y y)))))))
double code(double x, double y) {
double tmp;
if ((y * (x * y)) <= 0.1) {
tmp = fma(x, (y * y), 1.0);
} else {
tmp = x * (0.5 * (x * ((y * y) * (y * y))));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * Float64(x * y)) <= 0.1) tmp = fma(x, Float64(y * y), 1.0); else tmp = Float64(x * Float64(0.5 * Float64(x * Float64(Float64(y * y) * Float64(y * y))))); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], 0.1], N[(x * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision], N[(x * N[(0.5 * N[(x * N[(N[(y * y), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(x \cdot y\right) \leq 0.1:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.5 \cdot \left(x \cdot \left(\left(y \cdot y\right) \cdot \left(y \cdot y\right)\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x y) y) < 0.10000000000000001Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6457.7
Applied rewrites57.7%
if 0.10000000000000001 < (*.f64 (*.f64 x y) y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites80.9%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
rem-exp-logN/A
log-prodN/A
exp-sumN/A
rem-exp-logN/A
lower-fma.f64N/A
lower-exp.f64N/A
lower-log.f6480.9
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6480.9
Applied rewrites80.9%
Taylor expanded in y around inf
*-commutativeN/A
unpow2N/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
metadata-evalN/A
pow-sqrN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6483.9
Applied rewrites83.9%
Final simplification64.3%
(FPCore (x y)
:precision binary64
(if (<= y 2.3e-92)
(fma x (* y y) 1.0)
(if (<= y 1.56e+98)
(fma y (fma y (* x (* x 0.5)) x) 1.0)
(fma y (fma y (fma y 0.16666666666666666 0.5) 1.0) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= 2.3e-92) {
tmp = fma(x, (y * y), 1.0);
} else if (y <= 1.56e+98) {
tmp = fma(y, fma(y, (x * (x * 0.5)), x), 1.0);
} else {
tmp = fma(y, fma(y, fma(y, 0.16666666666666666, 0.5), 1.0), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 2.3e-92) tmp = fma(x, Float64(y * y), 1.0); elseif (y <= 1.56e+98) tmp = fma(y, fma(y, Float64(x * Float64(x * 0.5)), x), 1.0); else tmp = fma(y, fma(y, fma(y, 0.16666666666666666, 0.5), 1.0), 1.0); end return tmp end
code[x_, y_] := If[LessEqual[y, 2.3e-92], N[(x * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[y, 1.56e+98], N[(y * N[(y * N[(x * N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision], N[(y * N[(y * N[(y * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.3 \cdot 10^{-92}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, 1\right)\\
\mathbf{elif}\;y \leq 1.56 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, x \cdot \left(x \cdot 0.5\right), x\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, 0.16666666666666666, 0.5\right), 1\right), 1\right)\\
\end{array}
\end{array}
if y < 2.30000000000000016e-92Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6468.5
Applied rewrites68.5%
if 2.30000000000000016e-92 < y < 1.56e98Initial program 100.0%
Applied rewrites92.1%
*-commutativeN/A
exp-prodN/A
lift-exp.f64N/A
lower-pow.f6467.6
Applied rewrites67.6%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6467.6
Applied rewrites67.6%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6452.8
Applied rewrites52.8%
if 1.56e98 < y Initial program 100.0%
Applied rewrites46.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6446.8
Applied rewrites46.8%
(FPCore (x y) :precision binary64 (fma (* y y) (fma x (* (* x (* y y)) 0.5) x) 1.0))
double code(double x, double y) {
return fma((y * y), fma(x, ((x * (y * y)) * 0.5), x), 1.0);
}
function code(x, y) return fma(Float64(y * y), fma(x, Float64(Float64(x * Float64(y * y)) * 0.5), x), 1.0) end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] * N[(x * N[(N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(x, \left(x \cdot \left(y \cdot y\right)\right) \cdot 0.5, x\right), 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
Applied rewrites63.7%
(FPCore (x y) :precision binary64 (if (<= y 1.56e+98) (fma x (* y y) 1.0) (fma y (fma y (fma y 0.16666666666666666 0.5) 1.0) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= 1.56e+98) {
tmp = fma(x, (y * y), 1.0);
} else {
tmp = fma(y, fma(y, fma(y, 0.16666666666666666, 0.5), 1.0), 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= 1.56e+98) tmp = fma(x, Float64(y * y), 1.0); else tmp = fma(y, fma(y, fma(y, 0.16666666666666666, 0.5), 1.0), 1.0); end return tmp end
code[x_, y_] := If[LessEqual[y, 1.56e+98], N[(x * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision], N[(y * N[(y * N[(y * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.56 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(y, 0.16666666666666666, 0.5\right), 1\right), 1\right)\\
\end{array}
\end{array}
if y < 1.56e98Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 1.56e98 < y Initial program 100.0%
Applied rewrites46.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6446.8
Applied rewrites46.8%
(FPCore (x y) :precision binary64 (if (<= (* y (* x y)) 0.1) 1.0 (fma x y 1.0)))
double code(double x, double y) {
double tmp;
if ((y * (x * y)) <= 0.1) {
tmp = 1.0;
} else {
tmp = fma(x, y, 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(y * Float64(x * y)) <= 0.1) tmp = 1.0; else tmp = fma(x, y, 1.0); end return tmp end
code[x_, y_] := If[LessEqual[N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], 0.1], 1.0, N[(x * y + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot \left(x \cdot y\right) \leq 0.1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, y, 1\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x y) y) < 0.10000000000000001Initial program 100.0%
Applied rewrites57.5%
if 0.10000000000000001 < (*.f64 (*.f64 x y) y) Initial program 100.0%
Applied rewrites51.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6414.7
Applied rewrites14.7%
Final simplification46.7%
(FPCore (x y) :precision binary64 (fma x (* y y) 1.0))
double code(double x, double y) {
return fma(x, (y * y), 1.0);
}
function code(x, y) return fma(x, Float64(y * y), 1.0) end
code[x_, y_] := N[(x * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y \cdot y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6459.1
Applied rewrites59.1%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Applied rewrites43.7%
herbie shell --seed 2024220
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalF from random-fu-0.2.6.2"
:precision binary64
(exp (* (* x y) y)))