
(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 6 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 (- (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x (- y)) (if (<= y 9e-71) x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 9e-71) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = x * -y
else if (y <= 9d-71) then
tmp = x
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 9e-71) {
tmp = x;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * -y elif y <= 9e-71: tmp = x else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * Float64(-y)); elseif (y <= 9e-71) tmp = x; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * -y; elseif (y <= 9e-71) tmp = x; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * (-y)), $MachinePrecision], If[LessEqual[y, 9e-71], x, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-71}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 53.4%
associate-*r*53.4%
mul-1-neg53.4%
*-commutative53.4%
Simplified53.4%
if -1 < y < 9.0000000000000004e-71Initial program 100.0%
Taylor expanded in y around 0 80.1%
if 9.0000000000000004e-71 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y 6e-70) (- x (* x y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 6e-70) {
tmp = x - (x * y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 6d-70) then
tmp = x - (x * y)
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 6e-70) {
tmp = x - (x * y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 6e-70: tmp = x - (x * y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 6e-70) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 6e-70) tmp = x - (x * y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 6e-70], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6 \cdot 10^{-70}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 6.0000000000000003e-70Initial program 100.0%
Taylor expanded in x around inf 70.3%
sub-neg70.3%
distribute-rgt-in70.3%
*-lft-identity70.3%
cancel-sign-sub-inv70.3%
Simplified70.3%
if 6.0000000000000003e-70 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x (- y)) (if (<= y 3e-69) x y)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 3e-69) {
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 <= (-1.0d0)) then
tmp = x * -y
else if (y <= 3d-69) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * -y;
} else if (y <= 3e-69) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * -y elif y <= 3e-69: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * Float64(-y)); elseif (y <= 3e-69) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * -y; elseif (y <= 3e-69) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * (-y)), $MachinePrecision], If[LessEqual[y, 3e-69], x, y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot \left(-y\right)\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-69}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 53.4%
associate-*r*53.4%
mul-1-neg53.4%
*-commutative53.4%
Simplified53.4%
if -1 < y < 2.99999999999999989e-69Initial program 100.0%
Taylor expanded in y around 0 80.1%
if 2.99999999999999989e-69 < y Initial program 100.0%
Taylor expanded in x around 0 68.5%
Final simplification69.7%
(FPCore (x y) :precision binary64 (if (<= y 3.6e-70) x y))
double code(double x, double y) {
double tmp;
if (y <= 3.6e-70) {
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 <= 3.6d-70) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.6e-70) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.6e-70: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.6e-70) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.6e-70) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.6e-70], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.6 \cdot 10^{-70}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.6000000000000002e-70Initial program 100.0%
Taylor expanded in y around 0 52.4%
if 3.6000000000000002e-70 < y Initial program 100.0%
Taylor expanded in x around 0 68.5%
Final simplification57.0%
(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 39.3%
Final simplification39.3%
herbie shell --seed 2023297
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))