
(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 (<= y -1.0)
(* y x)
(if (<= y 2.6e-128)
x
(if (<= y 2.7e+262) y (if (<= y 1.15e+276) (* y x) y)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 2.6e-128) {
tmp = x;
} else if (y <= 2.7e+262) {
tmp = y;
} else if (y <= 1.15e+276) {
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 <= 2.6d-128) then
tmp = x
else if (y <= 2.7d+262) then
tmp = y
else if (y <= 1.15d+276) 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 <= 2.6e-128) {
tmp = x;
} else if (y <= 2.7e+262) {
tmp = y;
} else if (y <= 1.15e+276) {
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 <= 2.6e-128: tmp = x elif y <= 2.7e+262: tmp = y elif y <= 1.15e+276: 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 <= 2.6e-128) tmp = x; elseif (y <= 2.7e+262) tmp = y; elseif (y <= 1.15e+276) 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 <= 2.6e-128)
tmp = x;
elseif (y <= 2.7e+262)
tmp = y;
elseif (y <= 1.15e+276)
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, 2.6e-128], x, If[LessEqual[y, 2.7e+262], y, If[LessEqual[y, 1.15e+276], 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 2.6 \cdot 10^{-128}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+262}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+276}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 2.7000000000000001e262 < y < 1.15000000000000002e276Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 47.6%
+-commutative47.6%
Simplified47.6%
Taylor expanded in y around inf 47.6%
if -1 < y < 2.59999999999999981e-128Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 76.4%
if 2.59999999999999981e-128 < y < 2.7000000000000001e262 or 1.15000000000000002e276 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 50.0%
Final simplification61.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= x -3.3e-137) (not (<= x 1.52e-27))) (* x (+ y 1.0)) y))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((x <= -3.3e-137) || !(x <= 1.52e-27)) {
tmp = x * (y + 1.0);
} 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 <= (-3.3d-137)) .or. (.not. (x <= 1.52d-27))) then
tmp = x * (y + 1.0d0)
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((x <= -3.3e-137) || !(x <= 1.52e-27)) {
tmp = x * (y + 1.0);
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (x <= -3.3e-137) or not (x <= 1.52e-27): tmp = x * (y + 1.0) else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((x <= -3.3e-137) || !(x <= 1.52e-27)) tmp = Float64(x * Float64(y + 1.0)); else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((x <= -3.3e-137) || ~((x <= 1.52e-27)))
tmp = x * (y + 1.0);
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[Or[LessEqual[x, -3.3e-137], N[Not[LessEqual[x, 1.52e-27]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-137} \lor \neg \left(x \leq 1.52 \cdot 10^{-27}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.3000000000000002e-137 or 1.52000000000000004e-27 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 81.4%
+-commutative81.4%
Simplified81.4%
if -3.3000000000000002e-137 < x < 1.52000000000000004e-27Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 77.6%
Final simplification80.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -3.3e-137) (+ x (* y x)) (if (<= x 3.2e-11) y (* x (+ y 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.3e-137) {
tmp = x + (y * x);
} else if (x <= 3.2e-11) {
tmp = y;
} else {
tmp = x * (y + 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 (x <= (-3.3d-137)) then
tmp = x + (y * x)
else if (x <= 3.2d-11) then
tmp = y
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -3.3e-137) {
tmp = x + (y * x);
} else if (x <= 3.2e-11) {
tmp = y;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -3.3e-137: tmp = x + (y * x) elif x <= 3.2e-11: tmp = y else: tmp = x * (y + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -3.3e-137) tmp = Float64(x + Float64(y * x)); elseif (x <= 3.2e-11) tmp = y; else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -3.3e-137)
tmp = x + (y * x);
elseif (x <= 3.2e-11)
tmp = y;
else
tmp = x * (y + 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[x, -3.3e-137], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.2e-11], y, N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{-137}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-11}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if x < -3.3000000000000002e-137Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 72.6%
+-commutative72.6%
Simplified72.6%
distribute-lft-in72.6%
*-rgt-identity72.6%
Applied egg-rr72.6%
if -3.3000000000000002e-137 < x < 3.19999999999999994e-11Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 75.4%
if 3.19999999999999994e-11 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 94.0%
+-commutative94.0%
Simplified94.0%
Final simplification79.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 2.05e-128) (* x (+ y 1.0)) (+ y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.05e-128) {
tmp = x * (y + 1.0);
} 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 (y <= 2.05d-128) then
tmp = x * (y + 1.0d0)
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 (y <= 2.05e-128) {
tmp = x * (y + 1.0);
} else {
tmp = y + (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 2.05e-128: tmp = x * (y + 1.0) else: tmp = y + (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.05e-128) tmp = Float64(x * Float64(y + 1.0)); 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 (y <= 2.05e-128)
tmp = x * (y + 1.0);
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[y, 2.05e-128], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.05 \cdot 10^{-128}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < 2.05e-128Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around inf 67.0%
+-commutative67.0%
Simplified67.0%
if 2.05e-128 < y Initial program 100.0%
Taylor expanded in y around inf 84.1%
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 2.6e-128) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 2.6e-128) {
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 <= 2.6d-128) 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 <= 2.6e-128) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 2.6e-128: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 2.6e-128) 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 <= 2.6e-128)
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, 2.6e-128], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{-128}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.59999999999999981e-128Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 50.4%
if 2.59999999999999981e-128 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in x around 0 48.7%
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 41.0%
herbie shell --seed 2024086
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))