
(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 8 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 (+ y (fma x y x)))
assert(x < y);
double code(double x, double y) {
return y + fma(x, y, x);
}
x, y = sort([x, y]) function code(x, y) return Float64(y + fma(x, y, x)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(x * y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \mathsf{fma}\left(x, y, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.8e+120) (* y x) (if (<= x -1.1e-94) x (if (<= x 1.0) y (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.8e+120) {
tmp = y * x;
} else if (x <= -1.1e-94) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
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 <= (-2.8d+120)) then
tmp = y * x
else if (x <= (-1.1d-94)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.8e+120) {
tmp = y * x;
} else if (x <= -1.1e-94) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.8e+120: tmp = y * x elif x <= -1.1e-94: tmp = x elif x <= 1.0: tmp = y else: tmp = y * x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.8e+120) tmp = Float64(y * x); elseif (x <= -1.1e-94) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(y * x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.8e+120)
tmp = y * x;
elseif (x <= -1.1e-94)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = y * x;
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, -2.8e+120], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.1e-94], x, If[LessEqual[x, 1.0], y, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+120}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{-94}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.8000000000000001e120 or 1 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
distribute-rgt-in99.0%
*-un-lft-identity99.0%
Applied egg-rr99.0%
Taylor expanded in y around inf 61.0%
if -2.8000000000000001e120 < x < -1.10000000000000001e-94Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 42.7%
if -1.10000000000000001e-94 < x < 1Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 79.8%
Final simplification66.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= x -1150000000.0) (not (<= x 1.0))) (* x (+ y 1.0)) (+ y x)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((x <= -1150000000.0) || !(x <= 1.0)) {
tmp = x * (y + 1.0);
} else {
tmp = y + x;
}
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 <= (-1150000000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y + 1.0d0)
else
tmp = y + x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((x <= -1150000000.0) || !(x <= 1.0)) {
tmp = x * (y + 1.0);
} else {
tmp = y + x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (x <= -1150000000.0) or not (x <= 1.0): tmp = x * (y + 1.0) else: tmp = y + x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((x <= -1150000000.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y + x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((x <= -1150000000.0) || ~((x <= 1.0)))
tmp = x * (y + 1.0);
else
tmp = y + x;
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, -1150000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1150000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if x < -1.15e9 or 1 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 99.1%
if -1.15e9 < x < 1Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around 0 98.6%
Final simplification98.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1150000000.0) (* x (+ y 1.0)) (if (<= x 5e-146) (+ y x) (+ y (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1150000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 5e-146) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
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 <= (-1150000000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 5d-146) then
tmp = y + x
else
tmp = y + (y * x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -1150000000.0) {
tmp = x * (y + 1.0);
} else if (x <= 5e-146) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1150000000.0: tmp = x * (y + 1.0) elif x <= 5e-146: tmp = y + x else: tmp = y + (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1150000000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 5e-146) tmp = Float64(y + x); else tmp = Float64(y + Float64(y * x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -1150000000.0)
tmp = x * (y + 1.0);
elseif (x <= 5e-146)
tmp = y + x;
else
tmp = y + (y * x);
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, -1150000000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5e-146], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1150000000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 5 \cdot 10^{-146}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if x < -1.15e9Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
if -1.15e9 < x < 4.99999999999999957e-146Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around 0 98.5%
if 4.99999999999999957e-146 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 63.5%
Final simplification85.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= y -49000000.0) (not (<= y 9e+139))) (* y x) (+ y x)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((y <= -49000000.0) || !(y <= 9e+139)) {
tmp = y * x;
} else {
tmp = y + x;
}
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 <= (-49000000.0d0)) .or. (.not. (y <= 9d+139))) then
tmp = y * x
else
tmp = y + x
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((y <= -49000000.0) || !(y <= 9e+139)) {
tmp = y * x;
} else {
tmp = y + x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (y <= -49000000.0) or not (y <= 9e+139): tmp = y * x else: tmp = y + x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((y <= -49000000.0) || !(y <= 9e+139)) tmp = Float64(y * x); else tmp = Float64(y + x); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((y <= -49000000.0) || ~((y <= 9e+139)))
tmp = y * x;
else
tmp = y + x;
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[y, -49000000.0], N[Not[LessEqual[y, 9e+139]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -49000000 \lor \neg \left(y \leq 9 \cdot 10^{+139}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if y < -4.9e7 or 8.9999999999999999e139 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 55.7%
+-commutative55.7%
distribute-rgt-in55.7%
*-un-lft-identity55.7%
Applied egg-rr55.7%
Taylor expanded in y around inf 55.7%
if -4.9e7 < y < 8.9999999999999999e139Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around inf 84.8%
Taylor expanded in y around 0 88.9%
Final simplification74.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y (+ x (* y x))))
assert(x < y);
double code(double x, double y) {
return y + (x + (y * 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 = y + (x + (y * x))
end function
assert x < y;
public static double code(double x, double y) {
return y + (x + (y * x));
}
[x, y] = sort([x, y]) def code(x, y): return y + (x + (y * x))
x, y = sort([x, y]) function code(x, y) return Float64(y + Float64(x + Float64(y * x))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + (x + (y * x));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \left(x + y \cdot x\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 (<= x -1.42e-95) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.42e-95) {
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 (x <= (-1.42d-95)) 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 (x <= -1.42e-95) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.42e-95: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.42e-95) 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 (x <= -1.42e-95)
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[x, -1.42e-95], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.42 \cdot 10^{-95}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.42000000000000007e-95Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 39.4%
if -1.42000000000000007e-95 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 53.3%
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%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 32.5%
herbie shell --seed 2024131
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))