
(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 10 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 rewrites93.0%
Applied rewrites93.7%
(FPCore (x y) :precision binary64 (fma (* (fma (* (* y y) 0.16666666666666666) (* y y) 1.0) (* y y)) x x))
double code(double x, double y) {
return fma((fma(((y * y) * 0.16666666666666666), (y * y), 1.0) * (y * y)), x, x);
}
function code(x, y) return fma(Float64(fma(Float64(Float64(y * y) * 0.16666666666666666), Float64(y * y), 1.0) * Float64(y * y)), x, x) end
code[x_, y_] := N[(N[(N[(N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $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(\left(y \cdot y\right) \cdot 0.16666666666666666, 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 rewrites93.0%
Applied rewrites93.7%
Taylor expanded in y around inf
Applied rewrites93.5%
(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 rewrites93.0%
Applied rewrites93.0%
Taylor expanded in y around inf
Applied rewrites92.7%
(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(fma(0.5, Float64(y * y), 1.0) * Float64(y * y)), x, x) end
code[x_, y_] := N[(N[(N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision]), $MachinePrecision] * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.5, 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 rewrites93.0%
Applied rewrites93.7%
Taylor expanded in y around 0
Applied rewrites92.5%
(FPCore (x y) :precision binary64 (* (fma (fma 0.5 (* y y) 1.0) (* y y) 1.0) x))
double code(double x, double y) {
return fma(fma(0.5, (y * y), 1.0), (y * y), 1.0) * x;
}
function code(x, y) return Float64(fma(fma(0.5, Float64(y * y), 1.0), Float64(y * y), 1.0) * x) end
code[x_, y_] := N[(N[(N[(0.5 * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.5, y \cdot y, 1\right), y \cdot y, 1\right) \cdot x
\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 rewrites93.0%
Applied rewrites93.7%
Taylor expanded in y around 0
Applied rewrites92.5%
Applied rewrites92.5%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e-5) (* x 1.0) (* (* x y) y)))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e-5) {
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 * y) <= 5d-5) 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 * y) <= 5e-5) {
tmp = x * 1.0;
} else {
tmp = (x * y) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e-5: tmp = x * 1.0 else: tmp = (x * y) * y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e-5) 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 * y) <= 5e-5) tmp = x * 1.0; else tmp = (x * y) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e-5], N[(x * 1.0), $MachinePrecision], N[(N[(x * y), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{-5}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot y\\
\end{array}
\end{array}
if (*.f64 y y) < 5.00000000000000024e-5Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites98.3%
if 5.00000000000000024e-5 < (*.f64 y 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 rewrites85.7%
Applied rewrites87.2%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6445.1
Applied rewrites45.1%
Taylor expanded in y around inf
Applied rewrites45.1%
(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.f6480.8
Applied rewrites80.8%
(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 rewrites93.0%
Applied rewrites93.7%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6472.7
Applied rewrites72.7%
(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 rewrites51.7%
(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 2024326
(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))))