
(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-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 -1.7e+240)
(* y x)
(if (<= x -7.8e+164)
x
(if (<= x -8.8e+130)
(* y x)
(if (<= x -3.2e-62)
x
(if (<= x -7.2e-118)
y
(if (<= x -1.25e-153) x (if (<= x 1.0) y (* y x)))))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.7e+240) {
tmp = y * x;
} else if (x <= -7.8e+164) {
tmp = x;
} else if (x <= -8.8e+130) {
tmp = y * x;
} else if (x <= -3.2e-62) {
tmp = x;
} else if (x <= -7.2e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
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 <= (-1.7d+240)) then
tmp = y * x
else if (x <= (-7.8d+164)) then
tmp = x
else if (x <= (-8.8d+130)) then
tmp = y * x
else if (x <= (-3.2d-62)) then
tmp = x
else if (x <= (-7.2d-118)) then
tmp = y
else if (x <= (-1.25d-153)) 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 <= -1.7e+240) {
tmp = y * x;
} else if (x <= -7.8e+164) {
tmp = x;
} else if (x <= -8.8e+130) {
tmp = y * x;
} else if (x <= -3.2e-62) {
tmp = x;
} else if (x <= -7.2e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
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 <= -1.7e+240: tmp = y * x elif x <= -7.8e+164: tmp = x elif x <= -8.8e+130: tmp = y * x elif x <= -3.2e-62: tmp = x elif x <= -7.2e-118: tmp = y elif x <= -1.25e-153: 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 <= -1.7e+240) tmp = Float64(y * x); elseif (x <= -7.8e+164) tmp = x; elseif (x <= -8.8e+130) tmp = Float64(y * x); elseif (x <= -3.2e-62) tmp = x; elseif (x <= -7.2e-118) tmp = y; elseif (x <= -1.25e-153) 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 <= -1.7e+240)
tmp = y * x;
elseif (x <= -7.8e+164)
tmp = x;
elseif (x <= -8.8e+130)
tmp = y * x;
elseif (x <= -3.2e-62)
tmp = x;
elseif (x <= -7.2e-118)
tmp = y;
elseif (x <= -1.25e-153)
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, -1.7e+240], N[(y * x), $MachinePrecision], If[LessEqual[x, -7.8e+164], x, If[LessEqual[x, -8.8e+130], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.2e-62], x, If[LessEqual[x, -7.2e-118], y, If[LessEqual[x, -1.25e-153], 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 -1.7 \cdot 10^{+240}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -7.8 \cdot 10^{+164}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -8.8 \cdot 10^{+130}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{-62}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{-118}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-153}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.70000000000000004e240 or -7.79999999999999971e164 < x < -8.79999999999999974e130 or 1 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 57.9%
if -1.70000000000000004e240 < x < -7.79999999999999971e164 or -8.79999999999999974e130 < x < -3.20000000000000021e-62 or -7.2000000000000004e-118 < x < -1.25000000000000008e-153Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 61.9%
if -3.20000000000000021e-62 < x < -7.2000000000000004e-118 or -1.25000000000000008e-153 < x < 1Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 88.3%
Final simplification69.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.45e-62) (* x (+ y 1.0)) (if (<= x -7.2e-118) y (if (<= x -1.25e-153) x (if (<= x 1.0) y (* y x))))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.45e-62) {
tmp = x * (y + 1.0);
} else if (x <= -7.2e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
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.45d-62)) then
tmp = x * (y + 1.0d0)
else if (x <= (-7.2d-118)) then
tmp = y
else if (x <= (-1.25d-153)) 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.45e-62) {
tmp = x * (y + 1.0);
} else if (x <= -7.2e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
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.45e-62: tmp = x * (y + 1.0) elif x <= -7.2e-118: tmp = y elif x <= -1.25e-153: 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.45e-62) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= -7.2e-118) tmp = y; elseif (x <= -1.25e-153) 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.45e-62)
tmp = x * (y + 1.0);
elseif (x <= -7.2e-118)
tmp = y;
elseif (x <= -1.25e-153)
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.45e-62], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7.2e-118], y, If[LessEqual[x, -1.25e-153], 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.45 \cdot 10^{-62}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{-118}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-153}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -3.44999999999999979e-62Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 96.0%
+-commutative96.0%
Simplified96.0%
if -3.44999999999999979e-62 < x < -7.2000000000000004e-118 or -1.25000000000000008e-153 < x < 1Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 88.3%
if -7.2000000000000004e-118 < x < -1.25000000000000008e-153Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 51.4%
if 1 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 53.8%
Final simplification79.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.3e-62) x (if (<= x -9e-118) y (if (<= x -1.25e-153) x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.3e-62) {
tmp = x;
} else if (x <= -9e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
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 <= (-2.3d-62)) then
tmp = x
else if (x <= (-9d-118)) then
tmp = y
else if (x <= (-1.25d-153)) 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 <= -2.3e-62) {
tmp = x;
} else if (x <= -9e-118) {
tmp = y;
} else if (x <= -1.25e-153) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.3e-62: tmp = x elif x <= -9e-118: tmp = y elif x <= -1.25e-153: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.3e-62) tmp = x; elseif (x <= -9e-118) tmp = y; elseif (x <= -1.25e-153) 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 <= -2.3e-62)
tmp = x;
elseif (x <= -9e-118)
tmp = y;
elseif (x <= -1.25e-153)
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, -2.3e-62], x, If[LessEqual[x, -9e-118], y, If[LessEqual[x, -1.25e-153], x, y]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-62}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -9 \cdot 10^{-118}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{-153}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.3e-62 or -9.0000000000000001e-118 < x < -1.25000000000000008e-153Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 54.1%
if -2.3e-62 < x < -9.0000000000000001e-118 or -1.25000000000000008e-153 < x Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 52.2%
Final simplification52.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 1.4e-12) (* x (+ y 1.0)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 1.4e-12) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
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.4d-12) then
tmp = x * (y + 1.0d0)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 1.4e-12) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 1.4e-12: tmp = x * (y + 1.0) else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 1.4e-12) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 1.4e-12)
tmp = x * (y + 1.0);
else
tmp = y * (x + 1.0);
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.4e-12], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.4 \cdot 10^{-12}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 1.4000000000000001e-12Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 70.1%
+-commutative70.1%
Simplified70.1%
if 1.4000000000000001e-12 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 98.1%
+-commutative98.1%
Simplified98.1%
Final simplification78.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 2.4e-12) (+ x (* y x)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.4e-12) {
tmp = x + (y * x);
} else {
tmp = y * (x + 1.0);
}
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.4d-12) then
tmp = x + (y * x)
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 2.4e-12) {
tmp = x + (y * x);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 2.4e-12: tmp = x + (y * x) else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.4e-12) tmp = Float64(x + Float64(y * x)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 2.4e-12)
tmp = x + (y * x);
else
tmp = y * (x + 1.0);
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.4e-12], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.4 \cdot 10^{-12}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < 2.39999999999999987e-12Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 70.1%
+-commutative70.1%
Simplified70.1%
distribute-lft-in70.1%
*-rgt-identity70.1%
Applied egg-rr70.1%
if 2.39999999999999987e-12 < y Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 98.1%
+-commutative98.1%
Simplified98.1%
Final simplification78.4%
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 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-def100.0%
Simplified100.0%
Taylor expanded in y around 0 37.9%
Final simplification37.9%
herbie shell --seed 2024010
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))