
(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 6 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 (fma (+ x 1.0) y x))
double code(double x, double y) {
return fma((x + 1.0), y, x);
}
function code(x, y) return fma(Float64(x + 1.0), y, x) end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + 1, y, x\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
associate-+r+100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -16.5) (* x y) (if (<= y 1.0) (+ x y) (* (+ x 1.0) y))))
double code(double x, double y) {
double tmp;
if (y <= -16.5) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-16.5d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = x + y
else
tmp = (x + 1.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -16.5) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -16.5: tmp = x * y elif y <= 1.0: tmp = x + y else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if (y <= -16.5) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(x + y); else tmp = Float64(Float64(x + 1.0) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -16.5) tmp = x * y; elseif (y <= 1.0) tmp = x + y; else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -16.5], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + y), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16.5:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if y < -16.5Initial program 100.0%
Taylor expanded in y around inf 98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in x around inf 55.1%
*-commutative55.1%
Simplified55.1%
if -16.5 < y < 1Initial program 100.0%
Taylor expanded in y around 0 97.9%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Final simplification87.7%
(FPCore (x y) :precision binary64 (if (or (<= x -3.5) (not (<= x 1.0))) (* x y) y))
double code(double x, double y) {
double tmp;
if ((x <= -3.5) || !(x <= 1.0)) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-3.5d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * y
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.5) || !(x <= 1.0)) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.5) or not (x <= 1.0): tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.5) || !(x <= 1.0)) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.5) || ~((x <= 1.0))) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.5], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.5 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 53.6%
+-commutative53.6%
Simplified53.6%
Taylor expanded in x around inf 52.6%
*-commutative52.6%
Simplified52.6%
if -3.5 < x < 1Initial program 100.0%
Taylor expanded in x around 0 75.3%
Final simplification64.2%
(FPCore (x y) :precision binary64 (if (or (<= x -2.9e+222) (not (<= x 650000000000.0))) (* x y) (+ x y)))
double code(double x, double y) {
double tmp;
if ((x <= -2.9e+222) || !(x <= 650000000000.0)) {
tmp = x * y;
} else {
tmp = x + y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.9d+222)) .or. (.not. (x <= 650000000000.0d0))) then
tmp = x * y
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.9e+222) || !(x <= 650000000000.0)) {
tmp = x * y;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.9e+222) or not (x <= 650000000000.0): tmp = x * y else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.9e+222) || !(x <= 650000000000.0)) tmp = Float64(x * y); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.9e+222) || ~((x <= 650000000000.0))) tmp = x * y; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.9e+222], N[Not[LessEqual[x, 650000000000.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+222} \lor \neg \left(x \leq 650000000000\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if x < -2.89999999999999981e222 or 6.5e11 < x Initial program 100.0%
Taylor expanded in y around inf 56.1%
+-commutative56.1%
Simplified56.1%
Taylor expanded in x around inf 56.1%
*-commutative56.1%
Simplified56.1%
if -2.89999999999999981e222 < x < 6.5e11Initial program 100.0%
Taylor expanded in y around 0 88.4%
Final simplification77.6%
(FPCore (x y) :precision binary64 (+ y (* x (+ 1.0 y))))
double code(double x, double y) {
return y + (x * (1.0 + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (1.0d0 + y))
end function
public static double code(double x, double y) {
return y + (x * (1.0 + y));
}
def code(x, y): return y + (x * (1.0 + y))
function code(x, y) return Float64(y + Float64(x * Float64(1.0 + y))) end
function tmp = code(x, y) tmp = y + (x * (1.0 + y)); end
code[x_, y_] := N[(y + N[(x * N[(1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(1 + y\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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 x around 0 40.1%
Final simplification40.1%
herbie shell --seed 2023311
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))