
(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 9 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 (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-+r+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
(if (<= x -3.7e+185)
x
(if (<= x -1.55e+162)
(* x y)
(if (<= x -1.9e-22) x (if (<= x 1.0) y (* x y))))))assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -3.7e+185) {
tmp = x;
} else if (x <= -1.55e+162) {
tmp = x * y;
} else if (x <= -1.9e-22) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * 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.7d+185)) then
tmp = x
else if (x <= (-1.55d+162)) then
tmp = x * y
else if (x <= (-1.9d-22)) then
tmp = x
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -3.7e+185) {
tmp = x;
} else if (x <= -1.55e+162) {
tmp = x * y;
} else if (x <= -1.9e-22) {
tmp = x;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -3.7e+185: tmp = x elif x <= -1.55e+162: tmp = x * y elif x <= -1.9e-22: tmp = x elif x <= 1.0: tmp = y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -3.7e+185) tmp = x; elseif (x <= -1.55e+162) tmp = Float64(x * y); elseif (x <= -1.9e-22) tmp = x; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -3.7e+185)
tmp = x;
elseif (x <= -1.55e+162)
tmp = x * y;
elseif (x <= -1.9e-22)
tmp = x;
elseif (x <= 1.0)
tmp = y;
else
tmp = x * 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, -3.7e+185], x, If[LessEqual[x, -1.55e+162], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.9e-22], x, If[LessEqual[x, 1.0], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+185}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{+162}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.9 \cdot 10^{-22}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.6999999999999997e185 or -1.55e162 < x < -1.90000000000000012e-22Initial program 100.0%
Taylor expanded in y around 0 55.1%
if -3.6999999999999997e185 < x < -1.55e162 or 1 < x Initial program 100.0%
Taylor expanded in y around inf 56.4%
Taylor expanded in x around inf 55.4%
if -1.90000000000000012e-22 < x < 1Initial program 100.0%
Taylor expanded in x around 0 76.5%
Final simplification65.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -16000000.0) (* x y) (if (<= y 1.0) (+ x y) (* y (+ x 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -16000000.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} 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 (y <= (-16000000.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = x + y
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 (y <= -16000000.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -16000000.0: tmp = x * y elif y <= 1.0: tmp = x + y else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -16000000.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(x + y); 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 (y <= -16000000.0)
tmp = x * y;
elseif (y <= 1.0)
tmp = x + y;
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[y, -16000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], N[(x + y), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -1.6e7Initial program 100.0%
Taylor expanded in y around inf 99.7%
Taylor expanded in x around inf 48.0%
if -1.6e7 < y < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 97.7%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.0%
Final simplification86.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -19000.0) (* x (+ y 1.0)) (if (<= x 2e-274) (+ x y) (* y (+ x 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -19000.0) {
tmp = x * (y + 1.0);
} else if (x <= 2e-274) {
tmp = x + y;
} 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 <= (-19000.0d0)) then
tmp = x * (y + 1.0d0)
else if (x <= 2d-274) then
tmp = x + y
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 <= -19000.0) {
tmp = x * (y + 1.0);
} else if (x <= 2e-274) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -19000.0: tmp = x * (y + 1.0) elif x <= 2e-274: tmp = x + y else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -19000.0) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 2e-274) tmp = Float64(x + y); 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 <= -19000.0)
tmp = x * (y + 1.0);
elseif (x <= 2e-274)
tmp = x + y;
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, -19000.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2e-274], N[(x + y), $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 -19000:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 2 \cdot 10^{-274}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -19000Initial program 100.0%
Taylor expanded in x around inf 99.9%
if -19000 < x < 1.99999999999999993e-274Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 98.3%
if 1.99999999999999993e-274 < x Initial program 100.0%
Taylor expanded in y around inf 62.8%
Final simplification82.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -19000.0) (+ x (* x y)) (if (<= x 1.05e-259) (+ x y) (* y (+ x 1.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -19000.0) {
tmp = x + (x * y);
} else if (x <= 1.05e-259) {
tmp = x + y;
} 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 <= (-19000.0d0)) then
tmp = x + (x * y)
else if (x <= 1.05d-259) then
tmp = x + y
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 <= -19000.0) {
tmp = x + (x * y);
} else if (x <= 1.05e-259) {
tmp = x + y;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -19000.0: tmp = x + (x * y) elif x <= 1.05e-259: tmp = x + y else: tmp = y * (x + 1.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -19000.0) tmp = Float64(x + Float64(x * y)); elseif (x <= 1.05e-259) tmp = Float64(x + y); 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 <= -19000.0)
tmp = x + (x * y);
elseif (x <= 1.05e-259)
tmp = x + y;
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, -19000.0], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.05e-259], N[(x + y), $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 -19000:\\
\;\;\;\;x + x \cdot y\\
\mathbf{elif}\;x \leq 1.05 \cdot 10^{-259}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -19000Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around inf 99.9%
if -19000 < x < 1.04999999999999999e-259Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 98.5%
if 1.04999999999999999e-259 < x Initial program 100.0%
Taylor expanded in y around inf 63.6%
Final simplification83.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y -1800000.0) (* x y) (if (<= y 4.8e+129) (+ x y) (* x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1800000.0) {
tmp = x * y;
} else if (y <= 4.8e+129) {
tmp = x + y;
} else {
tmp = x * 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 <= (-1800000.0d0)) then
tmp = x * y
else if (y <= 4.8d+129) then
tmp = x + y
else
tmp = x * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= -1800000.0) {
tmp = x * y;
} else if (y <= 4.8e+129) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1800000.0: tmp = x * y elif y <= 4.8e+129: tmp = x + y else: tmp = x * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1800000.0) tmp = Float64(x * y); elseif (y <= 4.8e+129) tmp = Float64(x + y); else tmp = Float64(x * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= -1800000.0)
tmp = x * y;
elseif (y <= 4.8e+129)
tmp = x + y;
else
tmp = x * 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, -1800000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.8e+129], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1800000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+129}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.8e6 or 4.7999999999999997e129 < y Initial program 100.0%
Taylor expanded in y around inf 99.8%
Taylor expanded in x around inf 54.1%
if -1.8e6 < y < 4.7999999999999997e129Initial program 100.0%
Taylor expanded in y around 0 100.0%
Taylor expanded in x around 0 88.1%
Final simplification75.8%
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%
Taylor expanded in y around 0 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 -5.2e-22) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5.2e-22) {
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 <= (-5.2d-22)) 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 <= -5.2e-22) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5.2e-22: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5.2e-22) 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 <= -5.2e-22)
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, -5.2e-22], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{-22}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.2e-22Initial program 100.0%
Taylor expanded in y around 0 52.9%
if -5.2e-22 < x Initial program 100.0%
Taylor expanded in x around 0 51.0%
Final simplification51.6%
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 37.7%
Final simplification37.7%
herbie shell --seed 2023274
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))