
(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%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
cancel-sign-sub-invN/A
+-commutativeN/A
associate-+r+N/A
*-rgt-identityN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
distribute-lft-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
unsub-negN/A
mul-1-negN/A
+-commutativeN/A
associate-+l+N/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
*-rgt-identityN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
distribute-lft-inN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (let* ((t_0 (- (+ x y) (* x y))) (t_1 (* y (- x)))) (if (<= t_0 (- INFINITY)) t_1 (if (<= t_0 1e+308) (+ x y) t_1))))
assert(x < y);
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = y * -x;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= 1e+308) {
tmp = x + y;
} else {
tmp = t_1;
}
return tmp;
}
assert x < y;
public static double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double t_1 = y * -x;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= 1e+308) {
tmp = x + y;
} else {
tmp = t_1;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = (x + y) - (x * y) t_1 = y * -x tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= 1e+308: tmp = x + y else: tmp = t_1 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) t_1 = Float64(y * Float64(-x)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= 1e+308) tmp = Float64(x + y); else tmp = t_1; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = (x + y) - (x * y);
t_1 = y * -x;
tmp = 0.0;
if (t_0 <= -Inf)
tmp = t_1;
elseif (t_0 <= 1e+308)
tmp = x + y;
else
tmp = t_1;
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[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, 1e+308], N[(x + y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := y \cdot \left(-x\right)\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+308}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 1e308 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1e308Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
cancel-sign-sub-invN/A
+-commutativeN/A
associate-+r+N/A
*-rgt-identityN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
distribute-lft-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites88.5%
*-rgt-identityN/A
lower-+.f6488.5
Applied rewrites88.5%
Final simplification90.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-279) (fma (- y) x x) (fma (- y) x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-279) {
tmp = fma(-y, x, x);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279) tmp = fma(Float64(-y), x, x); else tmp = fma(Float64(-y), x, y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], N[((-y) * x + x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.1
Applied rewrites62.1%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6462.1
Applied rewrites62.1%
if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6460.8
Applied rewrites60.8%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6460.8
Applied rewrites60.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-279) (fma (- y) x x) (- y (* x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-279) {
tmp = fma(-y, x, x);
} else {
tmp = y - (x * y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279) tmp = fma(Float64(-y), x, x); else tmp = Float64(y - Float64(x * y)); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], N[((-y) * x + x), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.1
Applied rewrites62.1%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6462.1
Applied rewrites62.1%
if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6460.8
Applied rewrites60.8%
Final simplification61.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-279) (- x (* x y)) (- y (* x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-279) {
tmp = x - (x * y);
} else {
tmp = y - (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 + y) - (x * y)) <= (-1d-279)) then
tmp = x - (x * y)
else
tmp = y - (x * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-279) {
tmp = x - (x * y);
} else {
tmp = y - (x * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -1e-279: tmp = x - (x * y) else: tmp = y - (x * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-279) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (((x + y) - (x * y)) <= -1e-279)
tmp = x - (x * y);
else
tmp = y - (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[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-279], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-279}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000006e-279Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.1
Applied rewrites62.1%
if -1.00000000000000006e-279 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6460.8
Applied rewrites60.8%
Final simplification61.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1.0) (- x (* x y)) (if (<= x 9.2e+17) (+ x y) (* y (- x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x - (x * y);
} else if (x <= 9.2e+17) {
tmp = x + 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 <= (-1.0d0)) then
tmp = x - (x * y)
else if (x <= 9.2d+17) then
tmp = x + 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 <= -1.0) {
tmp = x - (x * y);
} else if (x <= 9.2e+17) {
tmp = x + y;
} else {
tmp = y * -x;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -1.0: tmp = x - (x * y) elif x <= 9.2e+17: tmp = x + y else: tmp = y * -x return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x - Float64(x * y)); elseif (x <= 9.2e+17) tmp = Float64(x + y); else tmp = Float64(y * Float64(-x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -1.0)
tmp = x - (x * y);
elseif (x <= 9.2e+17)
tmp = x + 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, -1.0], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 9.2e+17], N[(x + y), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{+17}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if x < -1Initial program 99.9%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.8
Applied rewrites98.8%
if -1 < x < 9.2e17Initial program 100.0%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
cancel-sign-sub-invN/A
+-commutativeN/A
associate-+r+N/A
*-rgt-identityN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
distribute-lft-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.2%
*-rgt-identityN/A
lower-+.f6499.2
Applied rewrites99.2%
if 9.2e17 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6448.7
Applied rewrites48.7%
Final simplification89.3%
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%
Taylor expanded in x around 0
distribute-rgt-out--N/A
*-lft-identityN/A
cancel-sign-sub-invN/A
+-commutativeN/A
associate-+r+N/A
*-rgt-identityN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-outN/A
distribute-lft-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites77.7%
*-rgt-identityN/A
lower-+.f6477.7
Applied rewrites77.7%
Final simplification77.7%
herbie shell --seed 2024214
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))