
(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 6 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
(if (or (<= y -440000.0)
(not (or (<= y 1.8e+144) (and (not (<= y 8e+159)) (<= y 2.1e+298)))))
(* x (- y))
(+ x y)))assert(x < y);
double code(double x, double y) {
double tmp;
if ((y <= -440000.0) || !((y <= 1.8e+144) || (!(y <= 8e+159) && (y <= 2.1e+298)))) {
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 <= (-440000.0d0)) .or. (.not. (y <= 1.8d+144) .or. (.not. (y <= 8d+159)) .and. (y <= 2.1d+298))) 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 <= -440000.0) || !((y <= 1.8e+144) || (!(y <= 8e+159) && (y <= 2.1e+298)))) {
tmp = x * -y;
} else {
tmp = x + y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (y <= -440000.0) or not ((y <= 1.8e+144) or (not (y <= 8e+159) and (y <= 2.1e+298))): tmp = x * -y else: tmp = x + y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((y <= -440000.0) || !((y <= 1.8e+144) || (!(y <= 8e+159) && (y <= 2.1e+298)))) tmp = Float64(x * Float64(-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 <= -440000.0) || ~(((y <= 1.8e+144) || (~((y <= 8e+159)) && (y <= 2.1e+298)))))
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[Or[LessEqual[y, -440000.0], N[Not[Or[LessEqual[y, 1.8e+144], And[N[Not[LessEqual[y, 8e+159]], $MachinePrecision], LessEqual[y, 2.1e+298]]]], $MachinePrecision]], N[(x * (-y)), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -440000 \lor \neg \left(y \leq 1.8 \cdot 10^{+144} \lor \neg \left(y \leq 8 \cdot 10^{+159}\right) \land y \leq 2.1 \cdot 10^{+298}\right):\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -4.4e5 or 1.7999999999999999e144 < y < 7.9999999999999994e159 or 2.0999999999999998e298 < y Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 54.9%
Taylor expanded in y around inf 54.9%
mul-1-neg54.9%
*-commutative54.9%
distribute-rgt-neg-in54.9%
Simplified54.9%
if -4.4e5 < y < 1.7999999999999999e144 or 7.9999999999999994e159 < y < 2.0999999999999998e298Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around 0 86.3%
Final simplification77.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= x -32.0) (not (<= x 1.0))) (* x (- 1.0 y)) (+ x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((x <= -32.0) || !(x <= 1.0)) {
tmp = x * (1.0 - 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 <= (-32.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (1.0d0 - 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 <= -32.0) || !(x <= 1.0)) {
tmp = x * (1.0 - y);
} else {
tmp = x + y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (x <= -32.0) or not (x <= 1.0): tmp = x * (1.0 - y) else: tmp = x + y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((x <= -32.0) || !(x <= 1.0)) tmp = Float64(x * Float64(1.0 - 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 <= -32.0) || ~((x <= 1.0)))
tmp = x * (1.0 - 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[Or[LessEqual[x, -32.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -32 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if x < -32 or 1 < x Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around inf 99.1%
if -32 < x < 1Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around 0 99.3%
Final simplification99.2%
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(x + Float64(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[(x + N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + \left(y - x \cdot y\right)
\end{array}
Initial program 100.0%
associate--l+100.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 y))
assert(x < y);
double code(double x, double y) {
return 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
end function
assert x < y;
public static double code(double x, double y) {
return x + y;
}
[x, y] = sort([x, y]) def code(x, y): return x + y
x, y = sort([x, y]) function code(x, y) return Float64(x + y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x + y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x + y
\end{array}
Initial program 100.0%
associate--l+100.0%
Simplified100.0%
Taylor expanded in x around 0 75.2%
Final simplification75.2%
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%
associate--l+100.0%
Simplified100.0%
Taylor expanded in y around 0 40.3%
Final simplification40.3%
herbie shell --seed 2023230
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))