
(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 5 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 (if (<= y 2.1e+14) (+ x (* y (* x y))) (* x (pow y 2.0))))
double code(double x, double y) {
double tmp;
if (y <= 2.1e+14) {
tmp = x + (y * (x * y));
} else {
tmp = x * pow(y, 2.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.1d+14) then
tmp = x + (y * (x * y))
else
tmp = x * (y ** 2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.1e+14) {
tmp = x + (y * (x * y));
} else {
tmp = x * Math.pow(y, 2.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.1e+14: tmp = x + (y * (x * y)) else: tmp = x * math.pow(y, 2.0) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.1e+14) tmp = Float64(x + Float64(y * Float64(x * y))); else tmp = Float64(x * (y ^ 2.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.1e+14) tmp = x + (y * (x * y)); else tmp = x * (y ^ 2.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.1e+14], N[(x + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{+14}:\\
\;\;\;\;x + y \cdot \left(x \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot {y}^{2}\\
\end{array}
\end{array}
if y < 2.1e14Initial program 100.0%
Taylor expanded in y around 0 88.1%
unpow288.1%
associate-*r*82.3%
Applied egg-rr82.3%
if 2.1e14 < y Initial program 100.0%
Taylor expanded in y around 0 60.6%
Taylor expanded in y around inf 60.6%
Final simplification77.1%
(FPCore (x y) :precision binary64 (if (<= y 1.0) x (* y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x;
} else {
tmp = y * (x * 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
else
tmp = y * (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 1.0) {
tmp = x;
} else {
tmp = y * (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.0: tmp = x else: tmp = y * (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 1.0) tmp = x; else tmp = Float64(y * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.0) tmp = x; else tmp = y * (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.0], x, N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < 1Initial program 100.0%
Taylor expanded in y around 0 67.5%
if 1 < y Initial program 100.0%
Taylor expanded in y around 0 58.8%
Taylor expanded in y around inf 58.8%
unpow258.8%
associate-*r*48.3%
Applied egg-rr48.3%
Final simplification62.8%
(FPCore (x y) :precision binary64 (+ x (* y (* x y))))
double code(double x, double y) {
return x + (y * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (y * (x * y))
end function
public static double code(double x, double y) {
return x + (y * (x * y));
}
def code(x, y): return x + (y * (x * y))
function code(x, y) return Float64(x + Float64(y * Float64(x * y))) end
function tmp = code(x, y) tmp = x + (y * (x * y)); end
code[x_, y_] := N[(x + N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x \cdot y\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 81.5%
unpow281.5%
associate-*r*74.6%
Applied egg-rr74.6%
Final simplification74.6%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 51.8%
(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 2024096
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:alt
(* x (pow (exp y) y))
(* x (exp (* y y))))