
(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
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-300) (fma (- y) x x) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-300) {
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-300) 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-300], 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^{-300}:\\
\;\;\;\;\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.00000000000000005e-300Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.6
Simplified62.6%
cancel-sign-sub-invN/A
distribute-rgt1-inN/A
distribute-lft1-inN/A
lower-fma.f64N/A
lower-neg.f6462.7
Applied egg-rr62.7%
if -2.00000000000000005e-300 < (-.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-*.f6462.6
Simplified62.6%
Final simplification62.6%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-300) (- x (* y x)) (- y (* y x))))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-300) {
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-300)) 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-300) {
tmp = x - (y * x);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-300: 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-300) 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-300) 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-300], 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^{-300}:\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2.00000000000000005e-300Initial program 100.0%
Taylor expanded in x around inf
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6462.6
Simplified62.6%
if -2.00000000000000005e-300 < (-.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-*.f6462.6
Simplified62.6%
Final simplification62.6%
(FPCore (x y) :precision binary64 (if (<= x -1520000000000.0) (- x (* y x)) (if (<= x 13500000.0) (+ y x) (- (* y x)))))
double code(double x, double y) {
double tmp;
if (x <= -1520000000000.0) {
tmp = x - (y * x);
} else if (x <= 13500000.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 <= (-1520000000000.0d0)) then
tmp = x - (y * x)
else if (x <= 13500000.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 <= -1520000000000.0) {
tmp = x - (y * x);
} else if (x <= 13500000.0) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1520000000000.0: tmp = x - (y * x) elif x <= 13500000.0: tmp = y + x else: tmp = -(y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= -1520000000000.0) tmp = Float64(x - Float64(y * x)); elseif (x <= 13500000.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 <= -1520000000000.0) tmp = x - (y * x); elseif (x <= 13500000.0) tmp = y + x; else tmp = -(y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1520000000000.0], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 13500000.0], N[(y + x), $MachinePrecision], (-N[(y * x), $MachinePrecision])]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1520000000000:\\
\;\;\;\;x - y \cdot x\\
\mathbf{elif}\;x \leq 13500000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot x\\
\end{array}
\end{array}
if x < -1.52e12Initial 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%
if -1.52e12 < x < 1.35e7Initial 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
Simplified98.7%
*-rgt-identityN/A
lower-+.f6498.7
Applied egg-rr98.7%
if 1.35e7 < 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-*.f6499.7
Simplified99.7%
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.f6447.9
Simplified47.9%
Final simplification86.5%
(FPCore (x y) :precision binary64 (if (<= x 13500000.0) (+ y x) (- (* y x))))
double code(double x, double y) {
double tmp;
if (x <= 13500000.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 <= 13500000.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 <= 13500000.0) {
tmp = y + x;
} else {
tmp = -(y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 13500000.0: tmp = y + x else: tmp = -(y * x) return tmp
function code(x, y) tmp = 0.0 if (x <= 13500000.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 <= 13500000.0) tmp = y + x; else tmp = -(y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 13500000.0], N[(y + x), $MachinePrecision], (-N[(y * x), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 13500000:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot x\\
\end{array}
\end{array}
if x < 1.35e7Initial 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
Simplified87.1%
*-rgt-identityN/A
lower-+.f6487.1
Applied egg-rr87.1%
if 1.35e7 < 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-*.f6499.7
Simplified99.7%
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.f6447.9
Simplified47.9%
Final simplification77.5%
(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
Simplified100.0%
Taylor expanded in x around 0
Simplified78.8%
*-rgt-identityN/A
lower-+.f6478.8
Applied egg-rr78.8%
(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
Simplified100.0%
Taylor expanded in x around 0
Simplified78.8%
*-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--.f6441.6
Applied egg-rr41.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f642.8
Simplified2.8%
herbie shell --seed 2024207
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))