
(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(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot 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(x + y) - Float64(x * y)) end
function tmp = code(x, y) tmp = (x + y) - (x * y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - x \cdot y
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma x (- 1.0 y) y))
assert(x < y);
double code(double x, double y) {
return fma(x, (1.0 - y), y);
}
x, y = sort([x, y]) function code(x, y) return fma(x, Float64(1.0 - y), y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x * N[(1.0 - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(x, 1 - y, y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
associate--l+100.0%
+-commutative100.0%
*-rgt-identity100.0%
distribute-lft-out--100.0%
unsub-neg100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.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))))
(if (<= y -1.0)
t_0
(if (<= y 3.8e-114)
x
(if (<= y 3.3e+14)
y
(if (or (<= y 7.6e+33)
(not
(or (<= y 1.6e+94)
(and (not (<= y 5.8e+140)) (<= y 4.8e+196)))))
t_0
y))))))assert(x < y);
double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.8e-114) {
tmp = x;
} else if (y <= 3.3e+14) {
tmp = y;
} else if ((y <= 7.6e+33) || !((y <= 1.6e+94) || (!(y <= 5.8e+140) && (y <= 4.8e+196)))) {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 3.8d-114) then
tmp = x
else if (y <= 3.3d+14) then
tmp = y
else if ((y <= 7.6d+33) .or. (.not. (y <= 1.6d+94) .or. (.not. (y <= 5.8d+140)) .and. (y <= 4.8d+196))) then
tmp = t_0
else
tmp = y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = y * -x;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.8e-114) {
tmp = x;
} else if (y <= 3.3e+14) {
tmp = y;
} else if ((y <= 7.6e+33) || !((y <= 1.6e+94) || (!(y <= 5.8e+140) && (y <= 4.8e+196)))) {
tmp = t_0;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = y * -x tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 3.8e-114: tmp = x elif y <= 3.3e+14: tmp = y elif (y <= 7.6e+33) or not ((y <= 1.6e+94) or (not (y <= 5.8e+140) and (y <= 4.8e+196))): tmp = t_0 else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 3.8e-114) tmp = x; elseif (y <= 3.3e+14) tmp = y; elseif ((y <= 7.6e+33) || !((y <= 1.6e+94) || (!(y <= 5.8e+140) && (y <= 4.8e+196)))) tmp = t_0; else tmp = y; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = y * -x;
tmp = 0.0;
if (y <= -1.0)
tmp = t_0;
elseif (y <= 3.8e-114)
tmp = x;
elseif (y <= 3.3e+14)
tmp = y;
elseif ((y <= 7.6e+33) || ~(((y <= 1.6e+94) || (~((y <= 5.8e+140)) && (y <= 4.8e+196)))))
tmp = t_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_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 3.8e-114], x, If[LessEqual[y, 3.3e+14], y, If[Or[LessEqual[y, 7.6e+33], N[Not[Or[LessEqual[y, 1.6e+94], And[N[Not[LessEqual[y, 5.8e+140]], $MachinePrecision], LessEqual[y, 4.8e+196]]]], $MachinePrecision]], t$95$0, y]]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{+14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+33} \lor \neg \left(y \leq 1.6 \cdot 10^{+94} \lor \neg \left(y \leq 5.8 \cdot 10^{+140}\right) \land y \leq 4.8 \cdot 10^{+196}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 3.3e14 < y < 7.60000000000000005e33 or 1.60000000000000007e94 < y < 5.7999999999999998e140 or 4.8000000000000001e196 < y Initial program 100.0%
Taylor expanded in y around inf 98.1%
Taylor expanded in x around inf 52.4%
mul-1-neg52.4%
distribute-rgt-neg-out52.4%
Simplified52.4%
if -1 < y < 3.7999999999999998e-114Initial program 100.0%
Taylor expanded in y around 0 78.2%
if 3.7999999999999998e-114 < y < 3.3e14 or 7.60000000000000005e33 < y < 1.60000000000000007e94 or 5.7999999999999998e140 < y < 4.8000000000000001e196Initial program 100.0%
Taylor expanded in x around 0 55.4%
Final simplification62.9%
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 3.8e-114) x (* y (- 1.0 x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * -x;
} else if (y <= 3.8e-114) {
tmp = 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 <= (-1.0d0)) then
tmp = y * -x
else if (y <= 3.8d-114) then
tmp = 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 <= -1.0) {
tmp = y * -x;
} else if (y <= 3.8e-114) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= -1.0: tmp = y * -x elif y <= 3.8e-114: tmp = x else: tmp = y * (1.0 - x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(-x)); elseif (y <= 3.8e-114) tmp = 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 <= -1.0)
tmp = y * -x;
elseif (y <= 3.8e-114)
tmp = 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, -1.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 3.8e-114], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -1Initial program 99.9%
Taylor expanded in y around inf 97.1%
Taylor expanded in x around inf 43.4%
mul-1-neg43.4%
distribute-rgt-neg-out43.4%
Simplified43.4%
if -1 < y < 3.7999999999999998e-114Initial program 100.0%
Taylor expanded in y around 0 78.2%
if 3.7999999999999998e-114 < y Initial program 100.0%
Taylor expanded in y around inf 89.0%
Final simplification72.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 3.8e-114) (* x (- 1.0 y)) (* y (- 1.0 x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3.8e-114) {
tmp = x * (1.0 - y);
} 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 <= 3.8d-114) then
tmp = x * (1.0d0 - y)
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 <= 3.8e-114) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 3.8e-114: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3.8e-114) tmp = Float64(x * Float64(1.0 - y)); 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 <= 3.8e-114)
tmp = x * (1.0 - y);
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, 3.8e-114], N[(x * N[(1.0 - y), $MachinePrecision]), $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 3.8 \cdot 10^{-114}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 3.7999999999999998e-114Initial program 100.0%
Taylor expanded in x around inf 64.5%
if 3.7999999999999998e-114 < y Initial program 100.0%
Taylor expanded in y around inf 89.0%
Final simplification72.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (- (+ x y) (* x y)))
assert(x < y);
double code(double x, double y) {
return (x + y) - (x * y);
}
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 * y)
end function
assert x < y;
public static double code(double x, double y) {
return (x + y) - (x * y);
}
[x, y] = sort([x, y]) def code(x, y): return (x + y) - (x * y)
x, y = sort([x, y]) function code(x, y) return Float64(Float64(x + y) - Float64(x * y)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = (x + y) - (x * y);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\left(x + y\right) - x \cdot y
\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 3.6e-114) x y))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 3.6e-114) {
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 <= 3.6d-114) 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 <= 3.6e-114) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 3.6e-114: tmp = x else: tmp = y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 3.6e-114) 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 <= 3.6e-114)
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, 3.6e-114], x, y]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{-114}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.60000000000000018e-114Initial program 100.0%
Taylor expanded in y around 0 47.1%
if 3.60000000000000018e-114 < y Initial program 100.0%
Taylor expanded in x around 0 46.3%
Final simplification46.8%
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 34.9%
Final simplification34.9%
herbie shell --seed 2023257
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))