
(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%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* x y))))
(if (<= (* y y) 2e+54)
(+ x t_0)
(if (<= (* y y) 2e+262)
(/ (- (* t_0 t_0) (* x x)) (- t_0 x))
(* x (* y y))))))
double code(double x, double y) {
double t_0 = y * (x * y);
double tmp;
if ((y * y) <= 2e+54) {
tmp = x + t_0;
} else if ((y * y) <= 2e+262) {
tmp = ((t_0 * t_0) - (x * x)) / (t_0 - x);
} 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) :: t_0
real(8) :: tmp
t_0 = y * (x * y)
if ((y * y) <= 2d+54) then
tmp = x + t_0
else if ((y * y) <= 2d+262) then
tmp = ((t_0 * t_0) - (x * x)) / (t_0 - x)
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (x * y);
double tmp;
if ((y * y) <= 2e+54) {
tmp = x + t_0;
} else if ((y * y) <= 2e+262) {
tmp = ((t_0 * t_0) - (x * x)) / (t_0 - x);
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): t_0 = y * (x * y) tmp = 0 if (y * y) <= 2e+54: tmp = x + t_0 elif (y * y) <= 2e+262: tmp = ((t_0 * t_0) - (x * x)) / (t_0 - x) else: tmp = x * (y * y) return tmp
function code(x, y) t_0 = Float64(y * Float64(x * y)) tmp = 0.0 if (Float64(y * y) <= 2e+54) tmp = Float64(x + t_0); elseif (Float64(y * y) <= 2e+262) tmp = Float64(Float64(Float64(t_0 * t_0) - Float64(x * x)) / Float64(t_0 - x)); else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (x * y); tmp = 0.0; if ((y * y) <= 2e+54) tmp = x + t_0; elseif ((y * y) <= 2e+262) tmp = ((t_0 * t_0) - (x * x)) / (t_0 - x); else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y * y), $MachinePrecision], 2e+54], N[(x + t$95$0), $MachinePrecision], If[LessEqual[N[(y * y), $MachinePrecision], 2e+262], N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+54}:\\
\;\;\;\;x + t_0\\
\mathbf{elif}\;y \cdot y \leq 2 \cdot 10^{+262}:\\
\;\;\;\;\frac{t_0 \cdot t_0 - x \cdot x}{t_0 - x}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 2.0000000000000002e54Initial program 100.0%
Taylor expanded in y around 0 93.5%
fma-def93.5%
unpow293.5%
Simplified93.5%
fma-udef93.5%
associate-*l*93.5%
Applied egg-rr93.5%
if 2.0000000000000002e54 < (*.f64 y y) < 2e262Initial program 100.0%
Taylor expanded in y around 0 21.7%
fma-def21.7%
unpow221.7%
Simplified21.7%
fma-udef21.7%
flip-+45.3%
associate-*l*45.3%
associate-*l*45.3%
associate-*l*45.3%
Applied egg-rr45.3%
if 2e262 < (*.f64 y y) Initial program 100.0%
Taylor expanded in y around 0 95.3%
fma-def95.3%
unpow295.3%
Simplified95.3%
Taylor expanded in y around inf 95.3%
*-commutative95.3%
unpow295.3%
Simplified95.3%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 0.0005) x (* x (* y y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 0.0005) {
tmp = x;
} 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) <= 0.0005d0) then
tmp = x
else
tmp = x * (y * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 0.0005) {
tmp = x;
} else {
tmp = x * (y * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 0.0005: tmp = x else: tmp = x * (y * y) return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 0.0005) tmp = x; else tmp = Float64(x * Float64(y * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 0.0005) tmp = x; else tmp = x * (y * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 0.0005], x, N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 0.0005:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 99.1%
if 5.0000000000000001e-4 < (*.f64 y y) Initial program 100.0%
Taylor expanded in y around 0 68.7%
fma-def68.7%
unpow268.7%
Simplified68.7%
Taylor expanded in y around inf 68.7%
*-commutative68.7%
unpow268.7%
Simplified68.7%
Final simplification84.3%
(FPCore (x y) :precision binary64 (* x (+ (* y y) 1.0)))
double code(double x, double y) {
return x * ((y * y) + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * ((y * y) + 1.0d0)
end function
public static double code(double x, double y) {
return x * ((y * y) + 1.0);
}
def code(x, y): return x * ((y * y) + 1.0)
function code(x, y) return Float64(x * Float64(Float64(y * y) + 1.0)) end
function tmp = code(x, y) tmp = x * ((y * y) + 1.0); end
code[x_, y_] := N[(x * N[(N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y \cdot y + 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 84.6%
fma-def84.6%
unpow284.6%
Simplified84.6%
fma-udef84.6%
distribute-lft1-in84.5%
Applied egg-rr84.5%
Final simplification84.5%
(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 52.6%
Final simplification52.6%
(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 2023268
(FPCore (x y)
:name "Data.Number.Erf:$dmerfcx from erf-2.0.0.0"
:precision binary64
:herbie-target
(* x (pow (exp y) y))
(* x (exp (* y y))))