
(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 7 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 (- 1.0 x) x))
double code(double x, double y) {
return fma(y, (1.0 - x), x);
}
function code(x, y) return fma(y, Float64(1.0 - x), x) end
code[x_, y_] := N[(y * N[(1.0 - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\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
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64100.0
Simplified100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (+ y x) (* y x))) (t_1 (- (* y x)))) (if (<= t_0 (- INFINITY)) t_1 (if (<= t_0 1e+304) (+ y x) t_1))))
double code(double x, double y) {
double t_0 = (y + x) - (y * x);
double t_1 = -(y * x);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= 1e+304) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
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 <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if (t_0 <= 1e+304) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = (y + x) - (y * x) t_1 = -(y * x) tmp = 0 if t_0 <= -math.inf: tmp = t_1 elif t_0 <= 1e+304: tmp = y + x else: tmp = t_1 return tmp
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 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= 1e+304) tmp = Float64(y + x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = (y + x) - (y * x); t_1 = -(y * x); tmp = 0.0; if (t_0 <= -Inf) tmp = t_1; elseif (t_0 <= 1e+304) tmp = y + x; else tmp = t_1; end tmp_2 = tmp; end
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, (-Infinity)], t$95$1, If[LessEqual[t$95$0, 1e+304], N[(y + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y + x\right) - y \cdot x\\
t_1 := -y \cdot x\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{+304}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -inf.0 or 9.9999999999999994e303 < (-.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
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Simplified100.0%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f64100.0
Simplified100.0%
if -inf.0 < (-.f64 (+.f64 x y) (*.f64 x y)) < 9.9999999999999994e303Initial 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
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in x around 0
Simplified82.4%
+-lowering-+.f64N/A
*-rgt-identity82.4
Applied egg-rr82.4%
Final simplification85.0%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-257) (- x (* y x)) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-257) {
tmp = x - (y * x);
} else {
tmp = y - (y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((y + x) - (y * x)) <= (-2d-257)) then
tmp = x - (y * x)
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-257) {
tmp = x - (y * x);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-257: tmp = x - (y * x) else: tmp = y - (y * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-257) tmp = Float64(x - Float64(y * x)); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((y + x) - (y * x)) <= -2e-257) tmp = x - (y * x); else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-257], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-257}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2e-257Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6467.5
Simplified67.5%
if -2e-257 < (-.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
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6463.7
Simplified63.7%
Final simplification65.4%
(FPCore (x y) :precision binary64 (if (<= x -9500.0) (- x (* y x)) (if (<= x 8000000.0) (+ y x) (- (* y x)))))
double code(double x, double y) {
double tmp;
if (x <= -9500.0) {
tmp = x - (y * x);
} else if (x <= 8000000.0) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-9500.0d0)) then
tmp = x - (y * x)
else if (x <= 8000000.0d0) then
tmp = y + x
else
tmp = -(y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9500.0) {
tmp = x - (y * x);
} else if (x <= 8000000.0) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9500.0: tmp = x - (y * x) elif x <= 8000000.0: tmp = y + x else: tmp = -(y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= -9500.0) tmp = Float64(x - Float64(y * x)); elseif (x <= 8000000.0) tmp = Float64(y + x); else tmp = Float64(-Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9500.0) tmp = x - (y * x); elseif (x <= 8000000.0) tmp = y + x; else tmp = -(y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9500.0], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8000000.0], N[(y + x), $MachinePrecision], (-N[(y * x), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9500:\\
\;\;\;\;x - y \cdot x\\
\mathbf{elif}\;x \leq 8000000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot x\\
\end{array}
\end{array}
if x < -9500Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6499.0
Simplified99.0%
if -9500 < x < 8e6Initial 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
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in x around 0
Simplified99.0%
+-lowering-+.f64N/A
*-rgt-identity99.0
Applied egg-rr99.0%
if 8e6 < x Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6499.9
Simplified99.9%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-lowering-*.f64N/A
mul-1-negN/A
neg-lowering-neg.f6448.0
Simplified48.0%
Final simplification88.5%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-257) x y))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-257) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((y + x) - (y * x)) <= (-2d-257)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-257) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-257: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-257) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((y + x) - (y * x)) <= -2e-257) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-257], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-257}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2e-257Initial program 100.0%
Taylor expanded in y around 0
Simplified37.9%
if -2e-257 < (-.f64 (+.f64 x y) (*.f64 x y)) Initial program 100.0%
Taylor expanded in x around 0
Simplified36.9%
Final simplification37.4%
(FPCore (x y) :precision binary64 (+ y x))
double code(double x, double y) {
return y + x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + x
end function
public static double code(double x, double y) {
return y + x;
}
def code(x, y): return y + x
function code(x, y) return Float64(y + x) end
function tmp = code(x, y) tmp = y + x; end
code[x_, y_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
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
accelerator-lowering-fma.f64N/A
mul-1-negN/A
sub-negN/A
--lowering--.f64100.0
Simplified100.0%
Taylor expanded in x around 0
Simplified71.1%
+-lowering-+.f64N/A
*-rgt-identity71.1
Applied egg-rr71.1%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Simplified37.6%
herbie shell --seed 2024199
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))