
(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 (+ x (* y (+ x 1.0))))
assert(x < y);
double code(double x, double y) {
return x + (y * (x + 1.0));
}
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 + (y * (x + 1.0d0))
end function
assert x < y;
public static double code(double x, double y) {
return x + (y * (x + 1.0));
}
[x, y] = sort([x, y]) def code(x, y): return x + (y * (x + 1.0))
x, y = sort([x, y]) function code(x, y) return Float64(x + Float64(y * Float64(x + 1.0))) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x + (y * (x + 1.0));
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + y \cdot \left(x + 1\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.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
(if (<= x -4.6e+272)
(* y x)
(if (<= x -3.7e+242)
x
(if (<= x -3.2e+169)
(* y x)
(if (<= x -3.5e-110) x (if (<= x 1.0) y (* y x)))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -4.6e+272) {
tmp = y * x;
} else if (x <= -3.7e+242) {
tmp = x;
} else if (x <= -3.2e+169) {
tmp = y * x;
} else if (x <= -3.5e-110) {
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 <= (-4.6d+272)) then
tmp = y * x
else if (x <= (-3.7d+242)) then
tmp = x
else if (x <= (-3.2d+169)) then
tmp = y * x
else if (x <= (-3.5d-110)) 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 <= -4.6e+272) {
tmp = y * x;
} else if (x <= -3.7e+242) {
tmp = x;
} else if (x <= -3.2e+169) {
tmp = y * x;
} else if (x <= -3.5e-110) {
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 <= -4.6e+272: tmp = y * x elif x <= -3.7e+242: tmp = x elif x <= -3.2e+169: tmp = y * x elif x <= -3.5e-110: 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 <= -4.6e+272) tmp = Float64(y * x); elseif (x <= -3.7e+242) tmp = x; elseif (x <= -3.2e+169) tmp = Float64(y * x); elseif (x <= -3.5e-110) 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 <= -4.6e+272)
tmp = y * x;
elseif (x <= -3.7e+242)
tmp = x;
elseif (x <= -3.2e+169)
tmp = y * x;
elseif (x <= -3.5e-110)
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, -4.6e+272], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.7e+242], x, If[LessEqual[x, -3.2e+169], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.5e-110], 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 -4.6 \cdot 10^{+272}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.7 \cdot 10^{+242}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -3.2 \cdot 10^{+169}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.5 \cdot 10^{-110}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.5999999999999998e272 or -3.7e242 < x < -3.1999999999999998e169 or 1 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in y around inf 54.4%
if -4.5999999999999998e272 < x < -3.7e242 or -3.1999999999999998e169 < x < -3.49999999999999974e-110Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 53.1%
if -3.49999999999999974e-110 < x < 1Initial program 100.0%
Taylor expanded in x around 0 74.6%
Final simplification61.9%
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
:precision binary64
(if (<= x -3.5e+272)
(* y x)
(if (<= x -2.3e+241)
x
(if (or (<= x -1.45e+152) (not (<= x 600000.0))) (* y x) (+ y x)))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.5e+272) {
tmp = y * x;
} else if (x <= -2.3e+241) {
tmp = x;
} else if ((x <= -1.45e+152) || !(x <= 600000.0)) {
tmp = y * x;
} 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.5d+272)) then
tmp = y * x
else if (x <= (-2.3d+241)) then
tmp = x
else if ((x <= (-1.45d+152)) .or. (.not. (x <= 600000.0d0))) then
tmp = y * x
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.5e+272) {
tmp = y * x;
} else if (x <= -2.3e+241) {
tmp = x;
} else if ((x <= -1.45e+152) || !(x <= 600000.0)) {
tmp = y * x;
} else {
tmp = y + x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -3.5e+272: tmp = y * x elif x <= -2.3e+241: tmp = x elif (x <= -1.45e+152) or not (x <= 600000.0): tmp = y * x else: tmp = y + x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -3.5e+272) tmp = Float64(y * x); elseif (x <= -2.3e+241) tmp = x; elseif ((x <= -1.45e+152) || !(x <= 600000.0)) tmp = Float64(y * x); 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.5e+272)
tmp = y * x;
elseif (x <= -2.3e+241)
tmp = x;
elseif ((x <= -1.45e+152) || ~((x <= 600000.0)))
tmp = y * x;
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.5e+272], N[(y * x), $MachinePrecision], If[LessEqual[x, -2.3e+241], x, If[Or[LessEqual[x, -1.45e+152], N[Not[LessEqual[x, 600000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y + x), $MachinePrecision]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{+272}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{+241}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{+152} \lor \neg \left(x \leq 600000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if x < -3.50000000000000023e272 or -2.2999999999999999e241 < x < -1.4499999999999999e152 or 6e5 < x Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.4%
*-commutative99.4%
Simplified99.4%
Taylor expanded in y around inf 55.7%
if -3.50000000000000023e272 < x < -2.2999999999999999e241Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 50.1%
if -1.4499999999999999e152 < x < 6e5Initial program 100.0%
Taylor expanded in y around 0 91.6%
Final simplification77.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -12000000000.0) (* y x) (if (<= y 0.000155) (+ y x) (+ y (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -12000000000.0) {
tmp = y * x;
} else if (y <= 0.000155) {
tmp = y + x;
} 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 <= (-12000000000.0d0)) then
tmp = y * x
else if (y <= 0.000155d0) then
tmp = y + x
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 <= -12000000000.0) {
tmp = y * x;
} else if (y <= 0.000155) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -12000000000.0: tmp = y * x elif y <= 0.000155: tmp = y + x else: tmp = y + (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -12000000000.0) tmp = Float64(y * x); elseif (y <= 0.000155) tmp = Float64(y + x); 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 <= -12000000000.0)
tmp = y * x;
elseif (y <= 0.000155)
tmp = y + x;
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, -12000000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.000155], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -12000000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.000155:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1.2e10Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 62.4%
*-commutative62.4%
Simplified62.4%
Taylor expanded in y around inf 62.4%
if -1.2e10 < y < 1.55e-4Initial program 100.0%
Taylor expanded in y around 0 98.6%
if 1.55e-4 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
Final simplification91.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -38000.0) (+ x (* y x)) (if (<= x 4.2e-5) (+ y x) (+ y (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -38000.0) {
tmp = x + (y * x);
} else if (x <= 4.2e-5) {
tmp = y + x;
} 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 (x <= (-38000.0d0)) then
tmp = x + (y * x)
else if (x <= 4.2d-5) then
tmp = y + x
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 (x <= -38000.0) {
tmp = x + (y * x);
} else if (x <= 4.2e-5) {
tmp = y + x;
} else {
tmp = y + (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -38000.0: tmp = x + (y * x) elif x <= 4.2e-5: tmp = y + x else: tmp = y + (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -38000.0) tmp = Float64(x + Float64(y * x)); elseif (x <= 4.2e-5) tmp = Float64(y + x); 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 (x <= -38000.0)
tmp = x + (y * x);
elseif (x <= 4.2e-5)
tmp = y + x;
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[x, -38000.0], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.2e-5], N[(y + x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -38000:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-5}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if x < -38000Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 99.6%
*-commutative99.6%
Simplified99.6%
if -38000 < x < 4.19999999999999977e-5Initial program 100.0%
Taylor expanded in y around 0 98.8%
if 4.19999999999999977e-5 < x Initial program 100.0%
Taylor expanded in y around inf 49.5%
Final simplification85.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -4.5e-112) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -4.5e-112) {
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 <= (-4.5d-112)) 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 <= -4.5e-112) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -4.5e-112: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -4.5e-112) 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 <= -4.5e-112)
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, -4.5e-112], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{-112}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.50000000000000012e-112Initial program 100.0%
+-commutative100.0%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 46.6%
if -4.50000000000000012e-112 < x Initial program 100.0%
Taylor expanded in x around 0 45.8%
Final simplification46.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%
*-commutative100.0%
associate-+r+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
fma-def100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 39.7%
Final simplification39.7%
herbie shell --seed 2023336
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))