
(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%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (+ y 1.0) x)))
(if (<= x -1.4e-72)
t_0
(if (<= x -4.5e-84) y (if (<= x -2.85e-129) x (if (<= x 7e-8) y t_0))))))assert(x < y);
double code(double x, double y) {
double t_0 = (y + 1.0) * x;
double tmp;
if (x <= -1.4e-72) {
tmp = t_0;
} else if (x <= -4.5e-84) {
tmp = y;
} else if (x <= -2.85e-129) {
tmp = x;
} else if (x <= 7e-8) {
tmp = y;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = (y + 1.0d0) * x
if (x <= (-1.4d-72)) then
tmp = t_0
else if (x <= (-4.5d-84)) then
tmp = y
else if (x <= (-2.85d-129)) then
tmp = x
else if (x <= 7d-8) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = (y + 1.0) * x;
double tmp;
if (x <= -1.4e-72) {
tmp = t_0;
} else if (x <= -4.5e-84) {
tmp = y;
} else if (x <= -2.85e-129) {
tmp = x;
} else if (x <= 7e-8) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = (y + 1.0) * x tmp = 0 if x <= -1.4e-72: tmp = t_0 elif x <= -4.5e-84: tmp = y elif x <= -2.85e-129: tmp = x elif x <= 7e-8: tmp = y else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(y + 1.0) * x) tmp = 0.0 if (x <= -1.4e-72) tmp = t_0; elseif (x <= -4.5e-84) tmp = y; elseif (x <= -2.85e-129) tmp = x; elseif (x <= 7e-8) tmp = y; else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = (y + 1.0) * x;
tmp = 0.0;
if (x <= -1.4e-72)
tmp = t_0;
elseif (x <= -4.5e-84)
tmp = y;
elseif (x <= -2.85e-129)
tmp = x;
elseif (x <= 7e-8)
tmp = y;
else
tmp = t_0;
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := Block[{t$95$0 = N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.4e-72], t$95$0, If[LessEqual[x, -4.5e-84], y, If[LessEqual[x, -2.85e-129], x, If[LessEqual[x, 7e-8], y, t$95$0]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(y + 1\right) \cdot x\\
\mathbf{if}\;x \leq -1.4 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.5 \cdot 10^{-84}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -2.85 \cdot 10^{-129}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-8}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.3999999999999999e-72 or 7.00000000000000048e-8 < x Initial program 100.0%
Taylor expanded in x around inf 90.8%
+-commutative90.8%
Simplified90.8%
if -1.3999999999999999e-72 < x < -4.50000000000000016e-84 or -2.85e-129 < x < 7.00000000000000048e-8Initial program 100.0%
Taylor expanded in x around 0 81.2%
if -4.50000000000000016e-84 < x < -2.85e-129Initial program 100.0%
Taylor expanded in y around 0 72.3%
Final simplification86.3%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -6e+116)
x
(if (<= x -9.2e+82)
(* y x)
(if (<= x -3e-129) x (if (<= x 1.0) y (* y x))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -6e+116) {
tmp = x;
} else if (x <= -9.2e+82) {
tmp = y * x;
} else if (x <= -3e-129) {
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 <= (-6d+116)) then
tmp = x
else if (x <= (-9.2d+82)) then
tmp = y * x
else if (x <= (-3d-129)) 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 <= -6e+116) {
tmp = x;
} else if (x <= -9.2e+82) {
tmp = y * x;
} else if (x <= -3e-129) {
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 <= -6e+116: tmp = x elif x <= -9.2e+82: tmp = y * x elif x <= -3e-129: 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 <= -6e+116) tmp = x; elseif (x <= -9.2e+82) tmp = Float64(y * x); elseif (x <= -3e-129) 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 <= -6e+116)
tmp = x;
elseif (x <= -9.2e+82)
tmp = y * x;
elseif (x <= -3e-129)
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, -6e+116], x, If[LessEqual[x, -9.2e+82], N[(y * x), $MachinePrecision], If[LessEqual[x, -3e-129], 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 -6 \cdot 10^{+116}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -9.2 \cdot 10^{+82}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3 \cdot 10^{-129}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.9999999999999997e116 or -9.19999999999999953e82 < x < -2.9999999999999998e-129Initial program 100.0%
Taylor expanded in y around 0 53.3%
if -5.9999999999999997e116 < x < -9.19999999999999953e82 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 51.3%
*-commutative51.3%
Simplified51.3%
Taylor expanded in x around inf 50.6%
*-commutative50.6%
Simplified50.6%
if -2.9999999999999998e-129 < x < 1Initial program 100.0%
Taylor expanded in x around 0 81.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1.4e-72) (* (+ y 1.0) x) (if (<= x -4.5e-84) y (if (<= x -3e-129) x (* y (+ 1.0 x))))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.4e-72) {
tmp = (y + 1.0) * x;
} else if (x <= -4.5e-84) {
tmp = y;
} else if (x <= -3e-129) {
tmp = 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 (x <= (-1.4d-72)) then
tmp = (y + 1.0d0) * x
else if (x <= (-4.5d-84)) then
tmp = y
else if (x <= (-3d-129)) then
tmp = 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 (x <= -1.4e-72) {
tmp = (y + 1.0) * x;
} else if (x <= -4.5e-84) {
tmp = y;
} else if (x <= -3e-129) {
tmp = x;
} else {
tmp = y * (1.0 + x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.4e-72: tmp = (y + 1.0) * x elif x <= -4.5e-84: tmp = y elif x <= -3e-129: tmp = x else: tmp = y * (1.0 + x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.4e-72) tmp = Float64(Float64(y + 1.0) * x); elseif (x <= -4.5e-84) tmp = y; elseif (x <= -3e-129) tmp = 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 (x <= -1.4e-72)
tmp = (y + 1.0) * x;
elseif (x <= -4.5e-84)
tmp = y;
elseif (x <= -3e-129)
tmp = 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[x, -1.4e-72], N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, -4.5e-84], y, If[LessEqual[x, -3e-129], x, N[(y * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-72}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\
\mathbf{elif}\;x \leq -4.5 \cdot 10^{-84}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3 \cdot 10^{-129}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + x\right)\\
\end{array}
\end{array}
if x < -1.3999999999999999e-72Initial program 100.0%
Taylor expanded in x around inf 83.3%
+-commutative83.3%
Simplified83.3%
if -1.3999999999999999e-72 < x < -4.50000000000000016e-84Initial program 100.0%
Taylor expanded in x around 0 83.8%
if -4.50000000000000016e-84 < x < -2.9999999999999998e-129Initial program 100.0%
Taylor expanded in y around 0 72.3%
if -2.9999999999999998e-129 < x Initial program 100.0%
Taylor expanded in y around inf 69.0%
+-commutative69.0%
Simplified69.0%
Final simplification73.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 6.5e-194) x (if (<= y 2.6e-73) y (if (<= y 5e-39) x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 6.5e-194) {
tmp = x;
} else if (y <= 2.6e-73) {
tmp = y;
} else if (y <= 5e-39) {
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 <= 6.5d-194) then
tmp = x
else if (y <= 2.6d-73) then
tmp = y
else if (y <= 5d-39) 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 <= 6.5e-194) {
tmp = x;
} else if (y <= 2.6e-73) {
tmp = y;
} else if (y <= 5e-39) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 6.5e-194: tmp = x elif y <= 2.6e-73: tmp = y elif y <= 5e-39: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 6.5e-194) tmp = x; elseif (y <= 2.6e-73) tmp = y; elseif (y <= 5e-39) 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 <= 6.5e-194)
tmp = x;
elseif (y <= 2.6e-73)
tmp = y;
elseif (y <= 5e-39)
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, 6.5e-194], x, If[LessEqual[y, 2.6e-73], y, If[LessEqual[y, 5e-39], x, y]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{-194}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-73}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-39}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 6.50000000000000019e-194 or 2.6000000000000001e-73 < y < 4.9999999999999998e-39Initial program 100.0%
Taylor expanded in y around 0 53.8%
if 6.50000000000000019e-194 < y < 2.6000000000000001e-73 or 4.9999999999999998e-39 < y Initial program 100.0%
Taylor expanded in x around 0 56.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y (* (+ y 1.0) x)))
assert(x < y);
double code(double x, double y) {
return y + ((y + 1.0) * 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 + ((y + 1.0d0) * x)
end function
assert x < y;
public static double code(double x, double y) {
return y + ((y + 1.0) * x);
}
[x, y] = sort([x, y]) def code(x, y): return y + ((y + 1.0) * x)
x, y = sort([x, y]) function code(x, y) return Float64(y + Float64(Float64(y + 1.0) * x)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + ((y + 1.0) * x);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + \left(y + 1\right) \cdot x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
Applied egg-rr100.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%
Taylor expanded in y around 0 39.6%
herbie shell --seed 2024093
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))