
(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
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (- (+ y x) (* y x))) (t_1 (- (* y x)))) (if (<= t_0 -1e+298) t_1 (if (<= t_0 2e+306) (+ 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 <= -1e+298) {
tmp = t_1;
} else if (t_0 <= 2e+306) {
tmp = y + x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (y + x) - (y * x)
t_1 = -(y * x)
if (t_0 <= (-1d+298)) then
tmp = t_1
else if (t_0 <= 2d+306) then
tmp = y + x
else
tmp = t_1
end if
code = tmp
end function
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 <= -1e+298) {
tmp = t_1;
} else if (t_0 <= 2e+306) {
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 <= -1e+298: tmp = t_1 elif t_0 <= 2e+306: 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 <= -1e+298) tmp = t_1; elseif (t_0 <= 2e+306) 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 <= -1e+298) tmp = t_1; elseif (t_0 <= 2e+306) 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, -1e+298], t$95$1, If[LessEqual[t$95$0, 2e+306], 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 -1 \cdot 10^{+298}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+306}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -9.9999999999999996e297 or 2.00000000000000003e306 < (-.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-*.f6497.5
Applied rewrites97.5%
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.f6497.5
Applied rewrites97.5%
if -9.9999999999999996e297 < (-.f64 (+.f64 x y) (*.f64 x y)) < 2.00000000000000003e306Initial 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
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites80.9%
*-rgt-identityN/A
lower-+.f6480.9
Applied rewrites80.9%
Final simplification83.3%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-279) (fma (- y) x x) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-279) {
tmp = fma(-y, x, x);
} else {
tmp = y - (y * x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-279) tmp = fma(Float64(-y), x, x); else tmp = Float64(y - Float64(y * x)); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-279], N[((-y) * x + x), $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^{-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)) < -2.00000000000000011e-279Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6465.2
Applied rewrites65.2%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6465.2
Applied rewrites65.2%
if -2.00000000000000011e-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-*.f6463.3
Applied rewrites63.3%
Final simplification64.3%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-279) (- x (* y x)) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-279) {
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-279)) 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-279) {
tmp = x - (y * x);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-279: 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-279) 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-279) 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-279], 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^{-279}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.00000000000000011e-279Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6465.2
Applied rewrites65.2%
if -2.00000000000000011e-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-*.f6463.3
Applied rewrites63.3%
Final simplification64.3%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- x (* y x)) (if (<= x 240000.0) (+ y x) (- (* y x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x - (y * x);
} else if (x <= 240000.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 <= (-1.0d0)) then
tmp = x - (y * x)
else if (x <= 240000.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 <= -1.0) {
tmp = x - (y * x);
} else if (x <= 240000.0) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x - (y * x) elif x <= 240000.0: tmp = y + x else: tmp = -(y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x - Float64(y * x)); elseif (x <= 240000.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 <= -1.0) tmp = x - (y * x); elseif (x <= 240000.0) tmp = y + x; else tmp = -(y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 240000.0], N[(y + x), $MachinePrecision], (-N[(y * x), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x - y \cdot x\\
\mathbf{elif}\;x \leq 240000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6496.9
Applied rewrites96.9%
if -1 < x < 2.4e5Initial 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
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.7%
*-rgt-identityN/A
lower-+.f6498.7
Applied rewrites98.7%
if 2.4e5 < 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-*.f6498.8
Applied rewrites98.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.f6450.0
Applied rewrites50.0%
Final simplification86.2%
(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
lower-fma.f64N/A
mul-1-negN/A
sub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites70.1%
*-rgt-identityN/A
lower-+.f6470.1
Applied rewrites70.1%
(FPCore (x y) :precision binary64 (- y))
double code(double x, double y) {
return -y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -y
end function
public static double code(double x, double y) {
return -y;
}
def code(x, y): return -y
function code(x, y) return Float64(-y) end
function tmp = code(x, y) tmp = -y; end
code[x_, y_] := (-y)
\begin{array}{l}
\\
-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
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites70.1%
*-rgt-identityN/A
+-commutativeN/A
unpow1N/A
metadata-evalN/A
pow-divN/A
pow2N/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
lift-neg.f64N/A
lift-neg.f64N/A
pow-prod-downN/A
sqr-powN/A
+-lft-identityN/A
+-commutativeN/A
distribute-rgt-outN/A
+-lft-identityN/A
metadata-evalN/A
lift-neg.f64N/A
cube-negN/A
sub0-negN/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
Applied rewrites38.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f642.7
Applied rewrites2.7%
herbie shell --seed 2024216
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))