
(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 7 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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma (+ x 1.0) y x))
assert(x < y);
double code(double x, double y) {
return fma((x + 1.0), y, x);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(x + 1.0), y, x) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\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%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -5.4e+240)
(* x y)
(if (<= x -2.2e+223)
x
(if (<= x -2.3e+200)
(* x y)
(if (<= x -7e-168) x (if (<= x 1.0) y (* x y)))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5.4e+240) {
tmp = x * y;
} else if (x <= -2.2e+223) {
tmp = x;
} else if (x <= -2.3e+200) {
tmp = x * y;
} else if (x <= -7e-168) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5.4d+240)) then
tmp = x * y
else if (x <= (-2.2d+223)) then
tmp = x
else if (x <= (-2.3d+200)) then
tmp = x * y
else if (x <= (-7d-168)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -5.4e+240) {
tmp = x * y;
} else if (x <= -2.2e+223) {
tmp = x;
} else if (x <= -2.3e+200) {
tmp = x * y;
} else if (x <= -7e-168) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5.4e+240: tmp = x * y elif x <= -2.2e+223: tmp = x elif x <= -2.3e+200: tmp = x * y elif x <= -7e-168: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5.4e+240) tmp = Float64(x * y); elseif (x <= -2.2e+223) tmp = x; elseif (x <= -2.3e+200) tmp = Float64(x * y); elseif (x <= -7e-168) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -5.4e+240)
tmp = x * y;
elseif (x <= -2.2e+223)
tmp = x;
elseif (x <= -2.3e+200)
tmp = x * y;
elseif (x <= -7e-168)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = x * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -5.4e+240], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.2e+223], x, If[LessEqual[x, -2.3e+200], N[(x * y), $MachinePrecision], If[LessEqual[x, -7e-168], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{+240}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.2 \cdot 10^{+223}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{+200}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -7 \cdot 10^{-168}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.3999999999999997e240 or -2.2e223 < x < -2.30000000000000003e200 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 58.2%
if -5.3999999999999997e240 < x < -2.2e223 or -2.30000000000000003e200 < x < -6.99999999999999964e-168Initial program 100.0%
Taylor expanded in y around 0 42.9%
if -6.99999999999999964e-168 < x < 1Initial program 100.0%
Taylor expanded in x around 0 84.5%
Final simplification62.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= x -7e-168) (not (<= x 0.026))) (* x (+ 1.0 y)) y))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((x <= -7e-168) || !(x <= 0.026)) {
tmp = x * (1.0 + y);
} else {
tmp = y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-7d-168)) .or. (.not. (x <= 0.026d0))) then
tmp = x * (1.0d0 + y)
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((x <= -7e-168) || !(x <= 0.026)) {
tmp = x * (1.0 + y);
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (x <= -7e-168) or not (x <= 0.026): tmp = x * (1.0 + y) else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((x <= -7e-168) || !(x <= 0.026)) tmp = Float64(x * Float64(1.0 + y)); else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((x <= -7e-168) || ~((x <= 0.026)))
tmp = x * (1.0 + y);
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[Or[LessEqual[x, -7e-168], N[Not[LessEqual[x, 0.026]], $MachinePrecision]], N[(x * N[(1.0 + y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-168} \lor \neg \left(x \leq 0.026\right):\\
\;\;\;\;x \cdot \left(1 + y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -6.99999999999999964e-168 or 0.0259999999999999988 < x Initial program 100.0%
Taylor expanded in x around inf 86.1%
+-commutative86.1%
Simplified86.1%
if -6.99999999999999964e-168 < x < 0.0259999999999999988Initial program 100.0%
Taylor expanded in x around 0 84.5%
Final simplification85.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 2.25e-120) (* x (+ 1.0 y)) (* (+ x 1.0) y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.25e-120) {
tmp = x * (1.0 + y);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.25d-120) then
tmp = x * (1.0d0 + y)
else
tmp = (x + 1.0d0) * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 2.25e-120) {
tmp = x * (1.0 + y);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 2.25e-120: tmp = x * (1.0 + y) else: tmp = (x + 1.0) * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.25e-120) tmp = Float64(x * Float64(1.0 + y)); else tmp = Float64(Float64(x + 1.0) * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 2.25e-120)
tmp = x * (1.0 + y);
else
tmp = (x + 1.0) * y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 2.25e-120], N[(x * N[(1.0 + y), $MachinePrecision]), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{-120}:\\
\;\;\;\;x \cdot \left(1 + y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if y < 2.25e-120Initial program 100.0%
Taylor expanded in x around inf 66.3%
+-commutative66.3%
Simplified66.3%
if 2.25e-120 < y Initial program 100.0%
Taylor expanded in y around inf 84.4%
+-commutative84.4%
Simplified84.4%
Final simplification72.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y (+ x (* x y))))
assert(x < y);
double code(double x, double y) {
return y + (x + (x * y));
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x + (x * y))
end function
assert x < y;
public static double code(double x, double y) {
return y + (x + (x * y));
}
[x, y] = sort([x, y]) def code(x, y): return y + (x + (x * y))
x, y = sort([x, y]) function code(x, y) return Float64(y + Float64(x + Float64(x * y))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + (x + (x * y));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \left(x + x \cdot y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 2.25e-120) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.25e-120) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.25d-120) then
tmp = x
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 2.25e-120) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 2.25e-120: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.25e-120) tmp = x; else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 2.25e-120)
tmp = x;
else
tmp = y;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 2.25e-120], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.25 \cdot 10^{-120}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.25e-120Initial program 100.0%
Taylor expanded in y around 0 43.6%
if 2.25e-120 < y Initial program 100.0%
Taylor expanded in x around 0 44.9%
Final simplification44.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 x)
assert(x < y);
double code(double x, double y) {
return x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
assert x < y;
public static double code(double x, double y) {
return x;
}
[x, y] = sort([x, y]) def code(x, y): return x
x, y = sort([x, y]) function code(x, y) return x end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := x
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 33.7%
Final simplification33.7%
herbie shell --seed 2023320
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))