
(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 (+ y 1.0) x y))
assert(x < y);
double code(double x, double y) {
return fma((y + 1.0), x, y);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(y + 1.0), x, y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(y + 1.0), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(y + 1, x, y\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-define100.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 (<= y -1.0) (* y x) (if (<= y 1.3e-91) x (if (<= y 1.05e+58) y (if (<= y 4.6e+95) (* y x) y)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.3e-91) {
tmp = x;
} else if (y <= 1.05e+58) {
tmp = y;
} else if (y <= 4.6e+95) {
tmp = y * 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 <= (-1.0d0)) then
tmp = y * x
else if (y <= 1.3d-91) then
tmp = x
else if (y <= 1.05d+58) then
tmp = y
else if (y <= 4.6d+95) then
tmp = y * 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 <= -1.0) {
tmp = y * x;
} else if (y <= 1.3e-91) {
tmp = x;
} else if (y <= 1.05e+58) {
tmp = y;
} else if (y <= 4.6e+95) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 1.3e-91: tmp = x elif y <= 1.05e+58: tmp = y elif y <= 4.6e+95: tmp = y * x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 1.3e-91) tmp = x; elseif (y <= 1.05e+58) tmp = y; elseif (y <= 4.6e+95) tmp = Float64(y * 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 <= -1.0)
tmp = y * x;
elseif (y <= 1.3e-91)
tmp = x;
elseif (y <= 1.05e+58)
tmp = y;
elseif (y <= 4.6e+95)
tmp = y * 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, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.3e-91], x, If[LessEqual[y, 1.05e+58], y, If[LessEqual[y, 4.6e+95], N[(y * x), $MachinePrecision], y]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+58}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.6 \cdot 10^{+95}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 1.05000000000000006e58 < y < 4.59999999999999994e95Initial program 100.0%
Taylor expanded in y around inf 99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in x around inf 44.0%
*-commutative44.0%
Simplified44.0%
if -1 < y < 1.30000000000000007e-91Initial program 100.0%
Taylor expanded in y around 0 84.3%
if 1.30000000000000007e-91 < y < 1.05000000000000006e58 or 4.59999999999999994e95 < y Initial program 100.0%
Taylor expanded in x around 0 55.4%
Final simplification63.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.8e-120) (* (+ y 1.0) x) (if (<= x -1.8e-146) y (if (<= x -1.3e-195) x (if (<= x 1.0) y (* y x))))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.8e-120) {
tmp = (y + 1.0) * x;
} else if (x <= -1.8e-146) {
tmp = y;
} else if (x <= -1.3e-195) {
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 <= (-3.8d-120)) then
tmp = (y + 1.0d0) * x
else if (x <= (-1.8d-146)) then
tmp = y
else if (x <= (-1.3d-195)) 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 <= -3.8e-120) {
tmp = (y + 1.0) * x;
} else if (x <= -1.8e-146) {
tmp = y;
} else if (x <= -1.3e-195) {
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 <= -3.8e-120: tmp = (y + 1.0) * x elif x <= -1.8e-146: tmp = y elif x <= -1.3e-195: 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 <= -3.8e-120) tmp = Float64(Float64(y + 1.0) * x); elseif (x <= -1.8e-146) tmp = y; elseif (x <= -1.3e-195) 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 <= -3.8e-120)
tmp = (y + 1.0) * x;
elseif (x <= -1.8e-146)
tmp = y;
elseif (x <= -1.3e-195)
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, -3.8e-120], N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, -1.8e-146], y, If[LessEqual[x, -1.3e-195], 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 -3.8 \cdot 10^{-120}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-146}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-195}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.7999999999999997e-120Initial program 100.0%
Taylor expanded in x around inf 87.5%
+-commutative87.5%
Simplified87.5%
if -3.7999999999999997e-120 < x < -1.79999999999999989e-146 or -1.3000000000000001e-195 < x < 1Initial program 100.0%
Taylor expanded in x around 0 83.1%
if -1.79999999999999989e-146 < x < -1.3000000000000001e-195Initial program 100.0%
Taylor expanded in y around 0 45.5%
if 1 < x Initial program 99.9%
Taylor expanded in y around inf 51.8%
+-commutative51.8%
Simplified51.8%
Taylor expanded in x around inf 48.1%
*-commutative48.1%
Simplified48.1%
Final simplification76.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 6.2e-141) (* (+ y 1.0) x) (* y (+ 1.0 x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 6.2e-141) {
tmp = (y + 1.0) * x;
} else {
tmp = y * (1.0 + 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 <= 6.2d-141) then
tmp = (y + 1.0d0) * x
else
tmp = y * (1.0d0 + x)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 6.2e-141) {
tmp = (y + 1.0) * x;
} else {
tmp = y * (1.0 + x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 6.2e-141: tmp = (y + 1.0) * x else: tmp = y * (1.0 + x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 6.2e-141) tmp = Float64(Float64(y + 1.0) * x); else tmp = Float64(y * Float64(1.0 + x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 6.2e-141)
tmp = (y + 1.0) * x;
else
tmp = y * (1.0 + 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[y, 6.2e-141], N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision], N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.2 \cdot 10^{-141}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + x\right)\\
\end{array}
\end{array}
if y < 6.20000000000000055e-141Initial program 100.0%
Taylor expanded in x around inf 66.8%
+-commutative66.8%
Simplified66.8%
if 6.20000000000000055e-141 < y Initial program 100.0%
Taylor expanded in y around inf 83.3%
+-commutative83.3%
Simplified83.3%
Final simplification72.2%
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 (<= y 1.3e-91) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 1.3e-91) {
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 <= 1.3d-91) 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 <= 1.3e-91) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 1.3e-91: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 1.3e-91) 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 <= 1.3e-91)
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, 1.3e-91], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.30000000000000007e-91Initial program 100.0%
Taylor expanded in y around 0 50.7%
if 1.30000000000000007e-91 < y Initial program 100.0%
Taylor expanded in x around 0 53.7%
Final simplification51.6%
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 39.4%
Final simplification39.4%
herbie shell --seed 2024076
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))