
(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.32e-93)
x
(if (<= y 3.4e+93) y (if (<= y 3.2e+154) (* 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.32e-93) {
tmp = x;
} else if (y <= 3.4e+93) {
tmp = y;
} else if (y <= 3.2e+154) {
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.32d-93) then
tmp = x
else if (y <= 3.4d+93) then
tmp = y
else if (y <= 3.2d+154) 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.32e-93) {
tmp = x;
} else if (y <= 3.4e+93) {
tmp = y;
} else if (y <= 3.2e+154) {
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.32e-93: tmp = x elif y <= 3.4e+93: tmp = y elif y <= 3.2e+154: 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.32e-93) tmp = x; elseif (y <= 3.4e+93) tmp = y; elseif (y <= 3.2e+154) 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.32e-93)
tmp = x;
elseif (y <= 3.4e+93)
tmp = y;
elseif (y <= 3.2e+154)
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.32e-93], x, If[LessEqual[y, 3.4e+93], y, If[LessEqual[y, 3.2e+154], 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.32 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+93}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{+154}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.4e93 < y < 3.2e154Initial program 100.0%
Taylor expanded in y around inf 99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in x around inf 53.8%
*-commutative53.8%
Simplified53.8%
if -1 < y < 1.3200000000000001e-93Initial program 100.0%
Taylor expanded in y around 0 78.6%
if 1.3200000000000001e-93 < y < 3.4e93 or 3.2e154 < y Initial program 100.0%
Taylor expanded in x around 0 55.6%
Final simplification64.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -5.5e-209) (* (+ y 1.0) x) (if (<= x 1.0) y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5.5e-209) {
tmp = (y + 1.0) * 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 <= (-5.5d-209)) then
tmp = (y + 1.0d0) * 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 <= -5.5e-209) {
tmp = (y + 1.0) * 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 <= -5.5e-209: tmp = (y + 1.0) * 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 <= -5.5e-209) tmp = Float64(Float64(y + 1.0) * 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 <= -5.5e-209)
tmp = (y + 1.0) * 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, -5.5e-209], N[(N[(y + 1.0), $MachinePrecision] * x), $MachinePrecision], 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 -5.5 \cdot 10^{-209}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.5000000000000001e-209Initial program 100.0%
Taylor expanded in x around inf 71.0%
+-commutative71.0%
Simplified71.0%
if -5.5000000000000001e-209 < x < 1Initial program 100.0%
Taylor expanded in x around 0 82.2%
if 1 < x Initial program 100.0%
Taylor expanded in y around inf 45.0%
+-commutative45.0%
Simplified45.0%
Taylor expanded in x around inf 42.9%
*-commutative42.9%
Simplified42.9%
Final simplification66.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 2.5e-109) (* (+ y 1.0) x) (* y (+ 1.0 x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.5e-109) {
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 <= 2.5d-109) 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 <= 2.5e-109) {
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 <= 2.5e-109: 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 <= 2.5e-109) 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 <= 2.5e-109)
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, 2.5e-109], 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 2.5 \cdot 10^{-109}:\\
\;\;\;\;\left(y + 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 + x\right)\\
\end{array}
\end{array}
if y < 2.5000000000000001e-109Initial program 100.0%
Taylor expanded in x around inf 67.8%
+-commutative67.8%
Simplified67.8%
if 2.5000000000000001e-109 < y Initial program 100.0%
Taylor expanded in y around inf 83.8%
+-commutative83.8%
Simplified83.8%
Final simplification72.7%
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.82e-93) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 1.82e-93) {
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.82d-93) 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.82e-93) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 1.82e-93: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 1.82e-93) 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.82e-93)
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.82e-93], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.82 \cdot 10^{-93}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.82000000000000001e-93Initial program 100.0%
Taylor expanded in y around 0 48.2%
if 1.82000000000000001e-93 < y Initial program 100.0%
Taylor expanded in x around 0 51.1%
Final simplification49.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 38.6%
Final simplification38.6%
herbie shell --seed 2024077
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))