
(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 9 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}
(FPCore (x y) :precision binary64 (fma (- y) x (+ y x)))
double code(double x, double y) {
return fma(-y, x, (y + x));
}
function code(x, y) return fma(Float64(-y), x, Float64(y + x)) end
code[x_, y_] := N[((-y) * x + N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y, x, y + x\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (+ x y) (* x y))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 1e+236)))
(* (- x) y)
(fma 1.0 y x))))
double code(double x, double y) {
double t_0 = (x + y) - (x * y);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 1e+236)) {
tmp = -x * y;
} else {
tmp = fma(1.0, y, x);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 1e+236)) tmp = Float64(Float64(-x) * y); else tmp = fma(1.0, y, x); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 1e+236]], $MachinePrecision]], N[((-x) * y), $MachinePrecision], N[(1.0 * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 10^{+236}\right):\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 1.00000000000000005e236 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6488.6
Applied rewrites88.6%
Taylor expanded in x around inf
Applied rewrites83.4%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 1.00000000000000005e236Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites88.7%
Final simplification87.4%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-195) (fma (- x) y x) (fma (- y) x y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-195) {
tmp = fma(-x, y, x);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-195) tmp = fma(Float64(-x), y, x); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-195], N[((-x) * y + x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-195}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, y\right)\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.0000000000000002e-195Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites66.0%
if -2.0000000000000002e-195 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.4
Applied rewrites63.4%
Taylor expanded in x around 0
Applied rewrites38.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites63.4%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-195) (fma (- x) y x) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-195) {
tmp = fma(-x, y, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-195) tmp = fma(Float64(-x), y, x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-195], N[((-x) * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-195}:\\
\;\;\;\;\mathsf{fma}\left(-x, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.0000000000000002e-195Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites66.0%
if -2.0000000000000002e-195 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.4
Applied rewrites63.4%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -2e-195) (* (- 1.0 y) x) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-195) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x + y) - (x * y)) <= (-2d-195)) then
tmp = (1.0d0 - y) * x
else
tmp = (1.0d0 - x) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -2e-195) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -2e-195: tmp = (1.0 - y) * x else: tmp = (1.0 - x) * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -2e-195) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x + y) - (x * y)) <= -2e-195) tmp = (1.0 - y) * x; else tmp = (1.0 - x) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -2e-195], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -2 \cdot 10^{-195}:\\
\;\;\;\;\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)) < -2.0000000000000002e-195Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6466.0
Applied rewrites66.0%
if -2.0000000000000002e-195 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.4
Applied rewrites63.4%
(FPCore (x y) :precision binary64 (if (<= y -9600000000000.0) (* (- x) y) (if (<= y 2.8e-17) (fma 1.0 y x) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (y <= -9600000000000.0) {
tmp = -x * y;
} else if (y <= 2.8e-17) {
tmp = fma(1.0, y, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -9600000000000.0) tmp = Float64(Float64(-x) * y); elseif (y <= 2.8e-17) tmp = fma(1.0, y, x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -9600000000000.0], N[((-x) * y), $MachinePrecision], If[LessEqual[y, 2.8e-17], N[(1.0 * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9600000000000:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -9.6e12Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites55.3%
if -9.6e12 < y < 2.7999999999999999e-17Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites99.1%
if 2.7999999999999999e-17 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6496.0
Applied rewrites96.0%
(FPCore (x y) :precision binary64 (fma (- 1.0 x) y x))
double code(double x, double y) {
return fma((1.0 - x), y, x);
}
function code(x, y) return fma(Float64(1.0 - x), y, x) end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1 - x, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (fma 1.0 y x))
double code(double x, double y) {
return fma(1.0, y, x);
}
function code(x, y) return fma(1.0, y, x) end
code[x_, y_] := N[(1.0 * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
distribute-lft-out--N/A
*-rgt-identityN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
+-commutativeN/A
associate-+r+N/A
+-commutativeN/A
distribute-lft1-inN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-fma.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites72.3%
(FPCore (x y) :precision binary64 (* 1.0 y))
double code(double x, double y) {
return 1.0 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 * y
end function
public static double code(double x, double y) {
return 1.0 * y;
}
def code(x, y): return 1.0 * y
function code(x, y) return Float64(1.0 * y) end
function tmp = code(x, y) tmp = 1.0 * y; end
code[x_, y_] := N[(1.0 * y), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6463.8
Applied rewrites63.8%
Taylor expanded in x around 0
Applied rewrites37.3%
herbie shell --seed 2024320
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))