
(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 5 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 y (- 1.0 x) x))
assert(x < y);
double code(double x, double y) {
return fma(y, (1.0 - x), x);
}
x, y = sort([x, y]) function code(x, y) return fma(y, Float64(1.0 - x), x) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(y, 1 - x, x\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%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (let* ((t_0 (- (+ y x) (* y x))) (t_1 (* x (- y)))) (if (<= t_0 -1e+297) t_1 (if (<= t_0 5e+297) (+ y x) t_1))))
assert(x < y);
double code(double x, double y) {
double t_0 = (y + x) - (y * x);
double t_1 = x * -y;
double tmp;
if (t_0 <= -1e+297) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = y + x;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = (y + x) - (y * x)
t_1 = x * -y
if (t_0 <= (-1d+297)) then
tmp = t_1
else if (t_0 <= 5d+297) then
tmp = y + x
else
tmp = t_1
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = (y + x) - (y * x);
double t_1 = x * -y;
double tmp;
if (t_0 <= -1e+297) {
tmp = t_1;
} else if (t_0 <= 5e+297) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = (y + x) - (y * x) t_1 = x * -y tmp = 0 if t_0 <= -1e+297: tmp = t_1 elif t_0 <= 5e+297: tmp = y + x else: tmp = t_1 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(y + x) - Float64(y * x)) t_1 = Float64(x * Float64(-y)) tmp = 0.0 if (t_0 <= -1e+297) tmp = t_1; elseif (t_0 <= 5e+297) tmp = Float64(y + x); else tmp = t_1; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = (y + x) - (y * x);
t_1 = x * -y;
tmp = 0.0;
if (t_0 <= -1e+297)
tmp = t_1;
elseif (t_0 <= 5e+297)
tmp = y + x;
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[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+297], t$95$1, If[LessEqual[t$95$0, 5e+297], N[(y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(y + x\right) - y \cdot x\\
t_1 := x \cdot \left(-y\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+297}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+297}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1e297 or 4.9999999999999998e297 < (-.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.f6494.9
Applied rewrites94.9%
if -1e297 < (-.f64 (+.f64 x y) (*.f64 x y)) < 4.9999999999999998e297Initial 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 rewrites87.6%
*-rgt-identityN/A
lower-+.f6487.6
Applied rewrites87.6%
Final simplification88.7%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -1e-249) (- x (* y x)) (- y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -1e-249) {
tmp = x - (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 + x) - (y * x)) <= (-1d-249)) then
tmp = x - (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 + x) - (y * x)) <= -1e-249) {
tmp = x - (y * x);
} else {
tmp = y - (y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -1e-249: tmp = x - (y * x) else: tmp = y - (y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -1e-249) tmp = Float64(x - 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 + x) - (y * x)) <= -1e-249)
tmp = x - (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[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -1e-249], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -1 \cdot 10^{-249}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000005e-249Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6466.9
Applied rewrites66.9%
if -1.00000000000000005e-249 < (-.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-*.f6465.4
Applied rewrites65.4%
Final simplification66.1%
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)))) (if (<= x -59.0) t_0 (if (<= x 1.0) (+ y x) t_0))))
assert(x < y);
double code(double x, double y) {
double t_0 = x - (y * x);
double tmp;
if (x <= -59.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y + x;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = x - (y * x)
if (x <= (-59.0d0)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = y + x
else
tmp = t_0
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double t_0 = x - (y * x);
double tmp;
if (x <= -59.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y + x;
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = x - (y * x) tmp = 0 if x <= -59.0: tmp = t_0 elif x <= 1.0: tmp = y + x else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(x - Float64(y * x)) tmp = 0.0 if (x <= -59.0) tmp = t_0; elseif (x <= 1.0) tmp = Float64(y + x); else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = x - (y * x);
tmp = 0.0;
if (x <= -59.0)
tmp = t_0;
elseif (x <= 1.0)
tmp = y + x;
else
tmp = t_0;
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[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -59.0], t$95$0, If[LessEqual[x, 1.0], N[(y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := x - y \cdot x\\
\mathbf{if}\;x \leq -59:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -59 or 1 < 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-*.f6499.6
Applied rewrites99.6%
if -59 < x < 1Initial 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 rewrites98.2%
*-rgt-identityN/A
lower-+.f6498.2
Applied rewrites98.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ y x))
assert(x < y);
double code(double x, double y) {
return y + 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 = y + x
end function
assert x < y;
public static double code(double x, double y) {
return y + x;
}
[x, y] = sort([x, y]) def code(x, y): return y + x
x, y = sort([x, y]) function code(x, y) return Float64(y + x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y + x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
y + x
\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 rewrites75.7%
*-rgt-identityN/A
lower-+.f6475.7
Applied rewrites75.7%
herbie shell --seed 2024219
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))