
(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 (- 1.0 y) x y))
assert(x < y);
double code(double x, double y) {
return fma((1.0 - y), x, y);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(1.0 - y), x, y) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(1 - y, x, y\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/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 (if (<= (- (+ y x) (* y x)) -5e-229) (* (- 1.0 y) x) (fma (- y) x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -5e-229) {
tmp = (1.0 - y) * x;
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -5e-229) tmp = Float64(Float64(1.0 - y) * 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[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -5e-229], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -5 \cdot 10^{-229}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -5.00000000000000016e-229Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6464.1
Applied rewrites64.1%
if -5.00000000000000016e-229 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6463.8
Applied rewrites63.8%
Applied rewrites63.8%
Final simplification63.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -5e-229) (* (- 1.0 y) x) (* (- 1.0 x) y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -5e-229) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - 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 + x) - (y * x)) <= (-5d-229)) then
tmp = (1.0d0 - y) * x
else
tmp = (1.0d0 - x) * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -5e-229) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -5e-229: tmp = (1.0 - y) * x else: tmp = (1.0 - x) * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -5e-229) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (((y + x) - (y * x)) <= -5e-229)
tmp = (1.0 - y) * x;
else
tmp = (1.0 - 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[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -5e-229], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -5 \cdot 10^{-229}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -5.00000000000000016e-229Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6464.1
Applied rewrites64.1%
if -5.00000000000000016e-229 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6463.8
Applied rewrites63.8%
Final simplification63.9%
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 (<= x -1.0) t_0 (if (<= x 1.0) (* 1.0 y) t_0))))
assert(x < y);
double code(double x, double y) {
double t_0 = -y * x;
double tmp;
if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = 1.0 * y;
} 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 = -y * x
if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = 1.0d0 * y
else
tmp = t_0
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 (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = 1.0 * y;
} else {
tmp = t_0;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): t_0 = -y * x tmp = 0 if x <= -1.0: tmp = t_0 elif x <= 1.0: tmp = 1.0 * y else: tmp = t_0 return tmp
x, y = sort([x, y]) function code(x, y) t_0 = Float64(Float64(-y) * x) tmp = 0.0 if (x <= -1.0) tmp = t_0; elseif (x <= 1.0) tmp = Float64(1.0 * y); else tmp = t_0; end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
t_0 = -y * x;
tmp = 0.0;
if (x <= -1.0)
tmp = t_0;
elseif (x <= 1.0)
tmp = 1.0 * y;
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[((-y) * x), $MachinePrecision]}, If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.0], N[(1.0 * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
t_0 := \left(-y\right) \cdot x\\
\mathbf{if}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;1 \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6498.7
Applied rewrites98.7%
Taylor expanded in y around inf
Applied rewrites43.5%
if -1 < x < 1Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6479.0
Applied rewrites79.0%
Taylor expanded in x around 0
Applied rewrites76.9%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (* (- 1.0 x) y))
assert(x < y);
double code(double x, double y) {
return (1.0 - 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 = (1.0d0 - x) * y
end function
assert x < y;
public static double code(double x, double y) {
return (1.0 - x) * y;
}
[x, y] = sort([x, y]) def code(x, y): return (1.0 - x) * y
x, y = sort([x, y]) function code(x, y) return Float64(Float64(1.0 - x) * y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = (1.0 - x) * y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\left(1 - x\right) \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6462.3
Applied rewrites62.3%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (* 1.0 y))
assert(x < y);
double code(double x, double y) {
return 1.0 * 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 = 1.0d0 * y
end function
assert x < y;
public static double code(double x, double y) {
return 1.0 * y;
}
[x, y] = sort([x, y]) def code(x, y): return 1.0 * y
x, y = sort([x, y]) function code(x, y) return Float64(1.0 * y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = 1.0 * y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(1.0 * y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
1 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6462.3
Applied rewrites62.3%
Taylor expanded in x around 0
Applied rewrites40.8%
herbie shell --seed 2024308
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))