
(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 12 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 (* 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}
Initial program 100.0%
(FPCore (x y) :precision binary64 (fma (* (fma (fma 0.16666666666666666 (* y y) 0.5) (* y y) 1.0) (* y y)) x x))
double code(double x, double y) {
return fma((fma(fma(0.16666666666666666, (y * y), 0.5), (y * y), 1.0) * (y * y)), x, x);
}
function code(x, y) return fma(Float64(fma(fma(0.16666666666666666, Float64(y * y), 0.5), Float64(y * y), 1.0) * Float64(y * y)), x, x) end
code[x_, y_] := N[(N[(N[(N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + 0.5), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, y \cdot y, 0.5\right), y \cdot y, 1\right) \cdot \left(y \cdot y\right), x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Applied rewrites95.5%
(FPCore (x y) :precision binary64 (fma (* (* (fma (* (* y 0.16666666666666666) y) (* y y) 1.0) y) y) x x))
double code(double x, double y) {
return fma(((fma(((y * 0.16666666666666666) * y), (y * y), 1.0) * y) * y), x, x);
}
function code(x, y) return fma(Float64(Float64(fma(Float64(Float64(y * 0.16666666666666666) * y), Float64(y * y), 1.0) * y) * y), x, x) end
code[x_, y_] := N[(N[(N[(N[(N[(N[(y * 0.16666666666666666), $MachinePrecision] * y), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(\left(y \cdot 0.16666666666666666\right) \cdot y, y \cdot y, 1\right) \cdot y\right) \cdot y, x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Applied rewrites95.5%
Taylor expanded in y around inf
Applied rewrites95.3%
Applied rewrites95.3%
(FPCore (x y) :precision binary64 (fma (* x y) (fma (* (* (* (* y y) 0.16666666666666666) y) y) y y) x))
double code(double x, double y) {
return fma((x * y), fma(((((y * y) * 0.16666666666666666) * y) * y), y, y), x);
}
function code(x, y) return fma(Float64(x * y), fma(Float64(Float64(Float64(Float64(y * y) * 0.16666666666666666) * y) * y), y, y), x) end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * N[(N[(N[(N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * y + y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, \mathsf{fma}\left(\left(\left(\left(y \cdot y\right) \cdot 0.16666666666666666\right) \cdot y\right) \cdot y, y, y\right), x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Applied rewrites94.7%
Taylor expanded in y around inf
Applied rewrites94.6%
(FPCore (x y) :precision binary64 (fma y (* y (* (fma (* (* y y) 0.16666666666666666) (* y y) 1.0) x)) x))
double code(double x, double y) {
return fma(y, (y * (fma(((y * y) * 0.16666666666666666), (y * y), 1.0) * x)), x);
}
function code(x, y) return fma(y, Float64(y * Float64(fma(Float64(Float64(y * y) * 0.16666666666666666), Float64(y * y), 1.0) * x)), x) end
code[x_, y_] := N[(y * N[(y * N[(N[(N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, y \cdot \left(\mathsf{fma}\left(\left(y \cdot y\right) \cdot 0.16666666666666666, y \cdot y, 1\right) \cdot x\right), x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Applied rewrites94.4%
Taylor expanded in y around inf
Applied rewrites94.2%
(FPCore (x y) :precision binary64 (fma (* (* (fma 0.5 (* y y) 1.0) y) y) x x))
double code(double x, double y) {
return fma(((fma(0.5, (y * y), 1.0) * y) * y), x, x);
}
function code(x, y) return fma(Float64(Float64(fma(0.5, Float64(y * y), 1.0) * y) * y), x, x) end
code[x_, y_] := N[(N[(N[(N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * y), $MachinePrecision] * y), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(0.5, y \cdot y, 1\right) \cdot y\right) \cdot y, x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Taylor expanded in y around 0
Applied rewrites88.3%
Applied rewrites89.1%
Applied rewrites91.6%
(FPCore (x y) :precision binary64 (fma (* (* (fma 0.5 (* y y) 1.0) y) x) y x))
double code(double x, double y) {
return fma(((fma(0.5, (y * y), 1.0) * y) * x), y, x);
}
function code(x, y) return fma(Float64(Float64(fma(0.5, Float64(y * y), 1.0) * y) * x), y, x) end
code[x_, y_] := N[(N[(N[(N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * y), $MachinePrecision] * x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(0.5, y \cdot y, 1\right) \cdot y\right) \cdot x, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Taylor expanded in y around 0
Applied rewrites88.3%
Applied rewrites89.1%
Applied rewrites89.1%
(FPCore (x y) :precision binary64 (fma y (* (* x y) (fma 0.5 (* y y) 1.0)) x))
double code(double x, double y) {
return fma(y, ((x * y) * fma(0.5, (y * y), 1.0)), x);
}
function code(x, y) return fma(y, Float64(Float64(x * y) * fma(0.5, Float64(y * y), 1.0)), x) end
code[x_, y_] := N[(y * N[(N[(x * y), $MachinePrecision] * N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \left(x \cdot y\right) \cdot \mathsf{fma}\left(0.5, y \cdot y, 1\right), x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Taylor expanded in y around 0
Applied rewrites88.3%
Applied rewrites88.3%
(FPCore (x y) :precision binary64 (if (<= y 1.0) (* x 1.0) (* (* x y) y)))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x * 1.0;
} else {
tmp = (x * y) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 1.0d0) then
tmp = x * 1.0d0
else
tmp = (x * y) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x * 1.0;
} else {
tmp = (x * y) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x * 1.0 else: tmp = (x * y) * y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = Float64(x * 1.0); else tmp = Float64(Float64(x * y) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = x * 1.0; else tmp = (x * y) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], N[(x * 1.0), $MachinePrecision], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\end{array}
\end{array}
if y < 1Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites68.5%
if 1 < y Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites92.2%
Applied rewrites93.7%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6451.7
Applied rewrites51.7%
Taylor expanded in y around inf
Applied rewrites51.7%
(FPCore (x y) :precision binary64 (* x (fma y y 1.0)))
double code(double x, double y) {
return x * fma(y, y, 1.0);
}
function code(x, y) return Float64(x * fma(y, y, 1.0)) end
code[x_, y_] := N[(x * N[(y * y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(y, y, 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
lower-fma.f6482.6
Applied rewrites82.6%
(FPCore (x y) :precision binary64 (fma (* x y) y x))
double code(double x, double y) {
return fma((x * y), y, x);
}
function code(x, y) return fma(Float64(x * y), y, x) end
code[x_, y_] := N[(N[(x * y), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot y, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
associate-+r+N/A
distribute-lft-inN/A
+-commutativeN/A
Applied rewrites94.4%
Applied rewrites95.5%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6474.6
Applied rewrites74.6%
(FPCore (x y) :precision binary64 (* x 1.0))
double code(double x, double y) {
return x * 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * 1.0d0
end function
public static double code(double x, double y) {
return x * 1.0;
}
def code(x, y): return x * 1.0
function code(x, y) return Float64(x * 1.0) end
function tmp = code(x, y) tmp = x * 1.0; end
code[x_, y_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites53.1%
(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 2024339
(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))))