
(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 (- (+ y x) (* y x)))
double code(double x, double y) {
return (y + x) - (y * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) - (y * x)
end function
public static double code(double x, double y) {
return (y + x) - (y * x);
}
def code(x, y): return (y + x) - (y * x)
function code(x, y) return Float64(Float64(y + x) - Float64(y * x)) end
function tmp = code(x, y) tmp = (y + x) - (y * x); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-264) (fma (- y) x x) (fma (- y) x y)))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-264) {
tmp = fma(-y, x, x);
} else {
tmp = fma(-y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-264) tmp = fma(Float64(-y), x, x); else tmp = fma(Float64(-y), x, y); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-264], N[((-y) * x + x), $MachinePrecision], N[((-y) * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-264}:\\
\;\;\;\;\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)) < -2e-264Initial 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.9
Applied rewrites64.9%
Applied rewrites64.9%
if -2e-264 < (-.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--.f6459.2
Applied rewrites59.2%
Applied rewrites59.2%
Final simplification62.3%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-264) (fma (- y) x x) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-264) {
tmp = fma(-y, x, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-264) 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[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-264], N[((-y) * x + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-264}:\\
\;\;\;\;\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)) < -2e-264Initial 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.9
Applied rewrites64.9%
Applied rewrites64.9%
if -2e-264 < (-.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--.f6459.2
Applied rewrites59.2%
Final simplification62.3%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-264) (* (- 1.0 y) x) (* (- 1.0 x) y)))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-264) {
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 (((y + x) - (y * x)) <= (-2d-264)) 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 (((y + x) - (y * x)) <= -2e-264) {
tmp = (1.0 - y) * x;
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-264: tmp = (1.0 - y) * x else: tmp = (1.0 - x) * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-264) 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 (((y + x) - (y * x)) <= -2e-264) tmp = (1.0 - y) * x; else tmp = (1.0 - x) * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-264], 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(y + x\right) - y \cdot x \leq -2 \cdot 10^{-264}:\\
\;\;\;\;\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)) < -2e-264Initial 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.9
Applied rewrites64.9%
if -2e-264 < (-.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--.f6459.2
Applied rewrites59.2%
Final simplification62.3%
(FPCore (x y) :precision binary64 (if (<= (- (+ y x) (* y x)) -2e-264) (* 1.0 x) (* 1.0 y)))
double code(double x, double y) {
double tmp;
if (((y + x) - (y * x)) <= -2e-264) {
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 (((y + x) - (y * x)) <= (-2d-264)) 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 (((y + x) - (y * x)) <= -2e-264) {
tmp = 1.0 * x;
} else {
tmp = 1.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if ((y + x) - (y * x)) <= -2e-264: tmp = 1.0 * x else: tmp = 1.0 * y return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(y + x) - Float64(y * x)) <= -2e-264) 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 (((y + x) - (y * x)) <= -2e-264) tmp = 1.0 * x; else tmp = 1.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(y + x), $MachinePrecision] - N[(y * x), $MachinePrecision]), $MachinePrecision], -2e-264], N[(1.0 * x), $MachinePrecision], N[(1.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(y + x\right) - y \cdot x \leq -2 \cdot 10^{-264}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x y) (*.f64 x y)) < -2e-264Initial 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.9
Applied rewrites64.9%
Taylor expanded in y around 0
Applied rewrites38.5%
if -2e-264 < (-.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--.f6459.2
Applied rewrites59.2%
Taylor expanded in x around 0
Applied rewrites36.5%
Final simplification37.6%
(FPCore (x y) :precision binary64 (if (<= y -580000000000.0) (* (- y) x) (if (<= y 0.00165) (fma 1.0 y x) (* (- 1.0 x) y))))
double code(double x, double y) {
double tmp;
if (y <= -580000000000.0) {
tmp = -y * x;
} else if (y <= 0.00165) {
tmp = fma(1.0, y, x);
} else {
tmp = (1.0 - x) * y;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -580000000000.0) tmp = Float64(Float64(-y) * x); elseif (y <= 0.00165) tmp = fma(1.0, y, x); else tmp = Float64(Float64(1.0 - x) * y); end return tmp end
code[x_, y_] := If[LessEqual[y, -580000000000.0], N[((-y) * x), $MachinePrecision], If[LessEqual[y, 0.00165], N[(1.0 * y + x), $MachinePrecision], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -580000000000:\\
\;\;\;\;\left(-y\right) \cdot x\\
\mathbf{elif}\;y \leq 0.00165:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\end{array}
\end{array}
if y < -5.8e11Initial 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--.f6444.3
Applied rewrites44.3%
Taylor expanded in y around inf
Applied rewrites44.3%
if -5.8e11 < y < 0.00165Initial 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%
Taylor expanded in x around 0
Applied rewrites98.0%
if 0.00165 < 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--.f6499.0
Applied rewrites99.0%
(FPCore (x y) :precision binary64 (if (<= x 85.0) (fma 1.0 y x) (* (- y) x)))
double code(double x, double y) {
double tmp;
if (x <= 85.0) {
tmp = fma(1.0, y, x);
} else {
tmp = -y * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 85.0) tmp = fma(1.0, y, x); else tmp = Float64(Float64(-y) * x); end return tmp end
code[x_, y_] := If[LessEqual[x, 85.0], N[(1.0 * y + x), $MachinePrecision], N[((-y) * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 85:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-y\right) \cdot x\\
\end{array}
\end{array}
if x < 85Initial 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%
Taylor expanded in x around 0
Applied rewrites86.2%
if 85 < x 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--.f6499.8
Applied rewrites99.8%
Taylor expanded in y around inf
Applied rewrites57.4%
(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 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 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%
Taylor expanded in x around 0
Applied rewrites74.5%
(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.2
Applied rewrites61.2%
Taylor expanded in x around 0
Applied rewrites36.3%
herbie shell --seed 2024235
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))