
(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 (+ x (fma x y y)))
assert(x < y);
double code(double x, double y) {
return x + fma(x, y, y);
}
x, y = sort([x, y]) function code(x, y) return Float64(x + fma(x, y, y)) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + N[(x * y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + \mathsf{fma}\left(x, y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate-+l+100.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
(let* ((t_0 (* y (+ x 1.0))))
(if (<= y -1.0)
(* y x)
(if (<= y 2.05e-182)
x
(if (<= y 3.8e-166)
t_0
(if (<= y 3e-130)
x
(if (<= y 6.6e-114) y (if (<= y 7.6e-52) x t_0))))))))assert(x < y);
double code(double x, double y) {
double t_0 = y * (x + 1.0);
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 2.05e-182) {
tmp = x;
} else if (y <= 3.8e-166) {
tmp = t_0;
} else if (y <= 3e-130) {
tmp = x;
} else if (y <= 6.6e-114) {
tmp = y;
} else if (y <= 7.6e-52) {
tmp = x;
} 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 * (x + 1.0d0)
if (y <= (-1.0d0)) then
tmp = y * x
else if (y <= 2.05d-182) then
tmp = x
else if (y <= 3.8d-166) then
tmp = t_0
else if (y <= 3d-130) then
tmp = x
else if (y <= 6.6d-114) then
tmp = y
else if (y <= 7.6d-52) then
tmp = x
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 * (x + 1.0);
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 2.05e-182) {
tmp = x;
} else if (y <= 3.8e-166) {
tmp = t_0;
} else if (y <= 3e-130) {
tmp = x;
} else if (y <= 6.6e-114) {
tmp = y;
} else if (y <= 7.6e-52) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = y * (x + 1.0) tmp = 0 if y <= -1.0: tmp = y * x elif y <= 2.05e-182: tmp = x elif y <= 3.8e-166: tmp = t_0 elif y <= 3e-130: tmp = x elif y <= 6.6e-114: tmp = y elif y <= 7.6e-52: tmp = x else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(y * Float64(x + 1.0)) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 2.05e-182) tmp = x; elseif (y <= 3.8e-166) tmp = t_0; elseif (y <= 3e-130) tmp = x; elseif (y <= 6.6e-114) tmp = y; elseif (y <= 7.6e-52) tmp = x; else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = y * (x + 1.0);
tmp = 0.0;
if (y <= -1.0)
tmp = y * x;
elseif (y <= 2.05e-182)
tmp = x;
elseif (y <= 3.8e-166)
tmp = t_0;
elseif (y <= 3e-130)
tmp = x;
elseif (y <= 6.6e-114)
tmp = y;
elseif (y <= 7.6e-52)
tmp = x;
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[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.05e-182], x, If[LessEqual[y, 3.8e-166], t$95$0, If[LessEqual[y, 3e-130], x, If[LessEqual[y, 6.6e-114], y, If[LessEqual[y, 7.6e-52], x, t$95$0]]]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(x + 1\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-182}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-166}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-130}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{-114}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 98.9%
Taylor expanded in x around inf 54.8%
if -1 < y < 2.0500000000000001e-182 or 3.79999999999999982e-166 < y < 2.99999999999999986e-130 or 6.60000000000000069e-114 < y < 7.6000000000000007e-52Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 83.4%
if 2.0500000000000001e-182 < y < 3.79999999999999982e-166 or 7.6000000000000007e-52 < y Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 91.8%
if 2.99999999999999986e-130 < y < 6.60000000000000069e-114Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 68.5%
Final simplification78.7%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -7.2e+78)
x
(if (<= x -2.15e+62)
(* y x)
(if (<= x -1.22e-46) x (if (<= x 1.0) y (* y x))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -7.2e+78) {
tmp = x;
} else if (x <= -2.15e+62) {
tmp = y * x;
} else if (x <= -1.22e-46) {
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 <= (-7.2d+78)) then
tmp = x
else if (x <= (-2.15d+62)) then
tmp = y * x
else if (x <= (-1.22d-46)) 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 <= -7.2e+78) {
tmp = x;
} else if (x <= -2.15e+62) {
tmp = y * x;
} else if (x <= -1.22e-46) {
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 <= -7.2e+78: tmp = x elif x <= -2.15e+62: tmp = y * x elif x <= -1.22e-46: 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 <= -7.2e+78) tmp = x; elseif (x <= -2.15e+62) tmp = Float64(y * x); elseif (x <= -1.22e-46) 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 <= -7.2e+78)
tmp = x;
elseif (x <= -2.15e+62)
tmp = y * x;
elseif (x <= -1.22e-46)
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, -7.2e+78], x, If[LessEqual[x, -2.15e+62], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.22e-46], 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 -7.2 \cdot 10^{+78}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -2.15 \cdot 10^{+62}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.22 \cdot 10^{-46}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7.20000000000000039e78 or -2.1499999999999998e62 < x < -1.22e-46Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 52.9%
if -7.20000000000000039e78 < x < -2.1499999999999998e62 or 1 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 61.8%
Taylor expanded in x around inf 61.0%
if -1.22e-46 < x < 1Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 73.4%
Final simplification64.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -4.6e-47) (* x (+ y 1.0)) (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -4.6e-47) {
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 (x <= (-4.6d-47)) 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 (x <= -4.6e-47) {
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 x <= -4.6e-47: 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 (x <= -4.6e-47) 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 (x <= -4.6e-47)
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[x, -4.6e-47], 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}\;x \leq -4.6 \cdot 10^{-47}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -4.59999999999999964e-47Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around inf 94.3%
if -4.59999999999999964e-47 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around inf 69.2%
Final simplification76.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 (<= x -1.12e-45) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.12e-45) {
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 <= (-1.12d-45)) 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 <= -1.12e-45) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.12e-45: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.12e-45) 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 <= -1.12e-45)
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, -1.12e-45], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.12 \cdot 10^{-45}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.1199999999999999e-45Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 50.3%
if -1.1199999999999999e-45 < x Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in x around 0 49.9%
Final simplification50.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%
associate-+l+100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in y around 0 37.2%
Final simplification37.2%
herbie shell --seed 2023181
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))