
(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 10 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 (- 1.0 y) x y))
double code(double x, double y) {
return fma((1.0 - y), x, y);
}
function code(x, y) return fma(Float64(1.0 - y), x, y) end
code[x_, y_] := N[(N[(1.0 - y), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1 - y, x, y\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
lower-fma.f64N/A
neg-mul-1N/A
lower-fma.f64100.0
Applied rewrites100.0%
lift-fma.f64N/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
lift--.f64100.0
Applied rewrites100.0%
(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+307) (fma 1.0 x y) t_1))))
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+307) {
tmp = fma(1.0, x, y);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(x + y) - Float64(x * y)) t_1 = Float64(Float64(-y) * x) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= 1e+307) tmp = fma(1.0, x, y); else tmp = t_1; end return tmp end
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+307], N[(1.0 * x + y), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + y\right) - x \cdot y\\
t_1 := \left(-y\right) \cdot x\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+307}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 9.99999999999999986e306 < (-.f64 (+.f64 x y) (*.f64 x y)) 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--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
Applied rewrites100.0%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 9.99999999999999986e306Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
lower-fma.f64N/A
neg-mul-1N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites86.0%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-221) (fma (- y) x x) (fma (- y) x y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-221) {
tmp = fma(-y, x, x);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-221) tmp = fma(Float64(-y), x, 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], -1e-221], N[((-y) * x + x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-221}:\\
\;\;\;\;\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.00000000000000002e-221Initial 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%
Applied rewrites64.1%
if -1.00000000000000002e-221 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
lower-fma.f64N/A
neg-mul-1N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around inf
mul-1-negN/A
lower-neg.f6461.2
Applied rewrites61.2%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-221) (fma (- y) x x) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-221) {
tmp = fma(-y, x, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-221) tmp = fma(Float64(-y), x, 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], -1e-221], N[((-y) * x + 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 -1 \cdot 10^{-221}:\\
\;\;\;\;\mathsf{fma}\left(-y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000002e-221Initial 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%
Applied rewrites64.1%
if -1.00000000000000002e-221 < (-.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--.f6461.1
Applied rewrites61.1%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-221) (* x (- 1.0 y)) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-221) {
tmp = x * (1.0 - y);
} 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)) <= (-1d-221)) then
tmp = x * (1.0d0 - y)
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)) <= -1e-221) {
tmp = x * (1.0 - y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -1e-221: tmp = x * (1.0 - y) else: tmp = (1.0 - x) * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-221) tmp = Float64(x * Float64(1.0 - y)); 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)) <= -1e-221) tmp = x * (1.0 - y); 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], -1e-221], N[(x * N[(1.0 - y), $MachinePrecision]), $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 -1 \cdot 10^{-221}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000002e-221Initial 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 -1.00000000000000002e-221 < (-.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--.f6461.1
Applied rewrites61.1%
Final simplification62.6%
(FPCore (x y) :precision binary64 (if (<= (- (+ x y) (* x y)) -1e-221) (* 1.0 x) (* 1.0 y)))
double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-221) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * 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)) <= (-1d-221)) then
tmp = 1.0d0 * x
else
tmp = 1.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((x + y) - (x * y)) <= -1e-221) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x + y) - (x * y)) <= -1e-221: tmp = 1.0 * x else: tmp = 1.0 * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(x + y) - Float64(x * y)) <= -1e-221) tmp = Float64(1.0 * x); else tmp = Float64(1.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x + y) - (x * y)) <= -1e-221) tmp = 1.0 * x; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], -1e-221], N[(1.0 * x), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) - x \cdot y \leq -1 \cdot 10^{-221}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -1.00000000000000002e-221Initial 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%
Taylor expanded in y around 0
Applied rewrites40.6%
if -1.00000000000000002e-221 < (-.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--.f6461.1
Applied rewrites61.1%
Taylor expanded in x around 0
Applied rewrites39.3%
(FPCore (x y) :precision binary64 (if (<= y -13000.0) (* (- y) x) (if (<= y 1.55e-8) (fma 1.0 x y) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (y <= -13000.0) {
tmp = -y * x;
} else if (y <= 1.55e-8) {
tmp = fma(1.0, x, y);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -13000.0) tmp = Float64(Float64(-y) * x); elseif (y <= 1.55e-8) tmp = fma(1.0, x, y); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -13000.0], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 1.55e-8], N[(1.0 * x + y), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -13000:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(1, x, y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -13000Initial 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--.f6457.4
Applied rewrites57.4%
Taylor expanded in y around inf
Applied rewrites55.7%
if -13000 < y < 1.55e-8Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
lower-fma.f64N/A
neg-mul-1N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites99.6%
if 1.55e-8 < 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--.f6498.0
Applied rewrites98.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 y 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%
(FPCore (x y) :precision binary64 (fma 1.0 x y))
double code(double x, double y) {
return fma(1.0, x, y);
}
function code(x, y) return fma(1.0, x, y) end
code[x_, y_] := N[(1.0 * x + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, x, y\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
distribute-rgt1-inN/A
lower-fma.f64N/A
neg-mul-1N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites77.1%
(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
sub-negN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f6461.5
Applied rewrites61.5%
Taylor expanded in x around 0
Applied rewrites38.9%
herbie shell --seed 2024244
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))