
(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 8 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
Simplified100.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 (- (* y x)))) (if (<= t_0 -2e+272) t_1 (if (<= t_0 INFINITY) (+ y x) t_1))))
assert(x < y);
double code(double x, double y) {
double t_0 = (y + x) - (y * x);
double t_1 = -(y * x);
double tmp;
if (t_0 <= -2e+272) {
tmp = t_1;
} else if (t_0 <= ((double) INFINITY)) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
assert x < y;
public static double code(double x, double y) {
double t_0 = (y + x) - (y * x);
double t_1 = -(y * x);
double tmp;
if (t_0 <= -2e+272) {
tmp = t_1;
} else if (t_0 <= Double.POSITIVE_INFINITY) {
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 = -(y * x) tmp = 0 if t_0 <= -2e+272: tmp = t_1 elif t_0 <= math.inf: 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(-Float64(y * x)) tmp = 0.0 if (t_0 <= -2e+272) tmp = t_1; elseif (t_0 <= Inf) 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 = -(y * x);
tmp = 0.0;
if (t_0 <= -2e+272)
tmp = t_1;
elseif (t_0 <= Inf)
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[(y * x), $MachinePrecision])}, If[LessEqual[t$95$0, -2e+272], t$95$1, If[LessEqual[t$95$0, Infinity], 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 := -y \cdot x\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+272}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.0000000000000001e272 or +inf.0 < (-.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
Simplified100.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.f6496.4
Simplified96.4%
if -2.0000000000000001e272 < (-.f64 (+.f64 x y) (*.f64 x y)) < +inf.0Initial 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
Simplified100.0%
Taylor expanded in x around 0
Simplified80.4%
*-rgt-identityN/A
lower-+.f6480.4
Applied egg-rr80.4%
Final simplification82.1%
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-279) (fma (- y) x x) (fma (- y) x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -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(y + x) - Float64(y * x)) <= -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[(y + x), $MachinePrecision] - N[(y * x), $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(y + x\right) - y \cdot x \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-*.f6461.9
Simplified61.9%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6462.0
Applied egg-rr62.0%
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.4
Simplified60.4%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6460.4
Applied egg-rr60.4%
Final simplification61.2%
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-279) (fma (- y) x x) (- y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -1e-279) {
tmp = fma(-y, x, 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-279) tmp = fma(Float64(-y), x, x); else tmp = Float64(y - Float64(y * x)); 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], -1e-279], N[((-y) * x + x), $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^{-279}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\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-*.f6461.9
Simplified61.9%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6462.0
Applied egg-rr62.0%
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.4
Simplified60.4%
Final simplification61.2%
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-279) (- x (* y x)) (- y (* y x))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -1e-279) {
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-279)) 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-279) {
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-279: 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-279) 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-279)
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-279], 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^{-279}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\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-*.f6461.9
Simplified61.9%
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.4
Simplified60.4%
Final simplification61.2%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -5.4) (- x (* y x)) (if (<= x 7.9) (+ y x) (- (* y x)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -5.4) {
tmp = x - (y * x);
} else if (x <= 7.9) {
tmp = y + x;
} 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 <= (-5.4d0)) then
tmp = x - (y * x)
else if (x <= 7.9d0) then
tmp = y + x
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 <= -5.4) {
tmp = x - (y * x);
} else if (x <= 7.9) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -5.4: tmp = x - (y * x) elif x <= 7.9: tmp = y + x else: tmp = -(y * x) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -5.4) tmp = Float64(x - Float64(y * x)); elseif (x <= 7.9) tmp = Float64(y + x); else tmp = Float64(-Float64(y * x)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -5.4)
tmp = x - (y * x);
elseif (x <= 7.9)
tmp = y + x;
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, -5.4], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.9], N[(y + x), $MachinePrecision], (-N[(y * x), $MachinePrecision])]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4:\\
\;\;\;\;x - y \cdot x\\
\mathbf{elif}\;x \leq 7.9:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot x\\
\end{array}
\end{array}
if x < -5.4000000000000004Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.8
Simplified98.8%
if -5.4000000000000004 < x < 7.9000000000000004Initial 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--.f6499.9
Simplified99.9%
Taylor expanded in x around 0
Simplified98.8%
*-rgt-identityN/A
lower-+.f6498.8
Applied egg-rr98.8%
if 7.9000000000000004 < 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-*.f6497.8
Simplified97.8%
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.f6446.3
Simplified46.3%
Final simplification84.9%
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
Simplified100.0%
Taylor expanded in x around 0
Simplified73.0%
*-rgt-identityN/A
lower-+.f6473.0
Applied egg-rr73.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (- y))
assert(x < y);
double code(double x, double y) {
return -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 = -y
end function
assert x < y;
public static double code(double x, double y) {
return -y;
}
[x, y] = sort([x, y]) def code(x, y): return -y
x, y = sort([x, y]) function code(x, y) return Float64(-y) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = -y;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := (-y)
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
-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
Simplified100.0%
Taylor expanded in x around 0
Simplified73.0%
*-rgt-identityN/A
+-commutativeN/A
unpow1N/A
metadata-evalN/A
pow-divN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
unpow-prod-downN/A
sqr-powN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
pow2N/A
+-lft-identityN/A
+-commutativeN/A
distribute-rgt-outN/A
+-lft-identityN/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
sub-negN/A
lower--.f6437.7
Applied egg-rr37.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f643.0
Simplified3.0%
herbie shell --seed 2024208
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))