
(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(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
(FPCore (x y) :precision binary64 (+ y (* (+ y 1.0) x)))
double code(double x, double y) {
return y + ((y + 1.0) * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + ((y + 1.0d0) * x)
end function
public static double code(double x, double y) {
return y + ((y + 1.0) * x);
}
def code(x, y): return y + ((y + 1.0) * x)
function code(x, y) return Float64(y + Float64(Float64(y + 1.0) * x)) end
function tmp = code(x, y) tmp = y + ((y + 1.0) * x); end
code[x_, y_] := N[(y + N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(y + 1\right) \cdot x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -460000.0) (and (not (<= y 3.7e+254)) (<= y 3.6e+259))) (* y x) (+ y x)))
double code(double x, double y) {
double tmp;
if ((y <= -460000.0) || (!(y <= 3.7e+254) && (y <= 3.6e+259))) {
tmp = y * x;
} else {
tmp = y + x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-460000.0d0)) .or. (.not. (y <= 3.7d+254)) .and. (y <= 3.6d+259)) then
tmp = y * x
else
tmp = y + x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -460000.0) || (!(y <= 3.7e+254) && (y <= 3.6e+259))) {
tmp = y * x;
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -460000.0) or (not (y <= 3.7e+254) and (y <= 3.6e+259)): tmp = y * x else: tmp = y + x return tmp
function code(x, y) tmp = 0.0 if ((y <= -460000.0) || (!(y <= 3.7e+254) && (y <= 3.6e+259))) tmp = Float64(y * x); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -460000.0) || (~((y <= 3.7e+254)) && (y <= 3.6e+259))) tmp = y * x; else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -460000.0], And[N[Not[LessEqual[y, 3.7e+254]], $MachinePrecision], LessEqual[y, 3.6e+259]]], N[(y * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -460000 \lor \neg \left(y \leq 3.7 \cdot 10^{+254}\right) \land y \leq 3.6 \cdot 10^{+259}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if y < -4.6e5 or 3.6999999999999999e254 < y < 3.6000000000000003e259Initial program 100.0%
Taylor expanded in y around inf 98.9%
Taylor expanded in x around inf 51.3%
if -4.6e5 < y < 3.6999999999999999e254 or 3.6000000000000003e259 < y Initial program 100.0%
Taylor expanded in y around 0 85.0%
Final simplification76.4%
(FPCore (x y) :precision binary64 (if (<= y -18000000.0) (* y x) (if (<= y 0.0021) (+ y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -18000000.0) {
tmp = y * x;
} else if (y <= 0.0021) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-18000000.0d0)) then
tmp = y * x
else if (y <= 0.0021d0) then
tmp = y + x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -18000000.0) {
tmp = y * x;
} else if (y <= 0.0021) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -18000000.0: tmp = y * x elif y <= 0.0021: tmp = y + x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -18000000.0) tmp = Float64(y * x); elseif (y <= 0.0021) tmp = Float64(y + x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -18000000.0) tmp = y * x; elseif (y <= 0.0021) tmp = y + x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -18000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.0021], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -18000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.0021:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1.8e7Initial program 100.0%
Taylor expanded in y around inf 98.9%
Taylor expanded in x around inf 49.8%
if -1.8e7 < y < 0.00209999999999999987Initial program 100.0%
Taylor expanded in y around 0 99.0%
if 0.00209999999999999987 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Final simplification87.2%
(FPCore (x y) :precision binary64 (if (<= x -2.1e+16) (* y x) (if (<= x 1.0) y (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -2.1e+16) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.1d+16)) then
tmp = y * x
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.1e+16) {
tmp = y * x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.1e+16: tmp = y * x elif x <= 1.0: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.1e+16) tmp = Float64(y * x); elseif (x <= 1.0) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.1e+16) tmp = y * x; elseif (x <= 1.0) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.1e+16], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+16}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.1e16 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 48.2%
Taylor expanded in x around inf 48.2%
if -2.1e16 < x < 1Initial program 100.0%
Taylor expanded in y around inf 77.2%
Taylor expanded in x around 0 75.6%
Final simplification61.8%
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 62.6%
Taylor expanded in x around 0 38.9%
Final simplification38.9%
herbie shell --seed 2023227
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))