
(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 8 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%
(FPCore (x y) :precision binary64 (if (or (<= x -3.4e-190) (not (<= x 0.42))) (* x (- 1.0 y)) y))
double code(double x, double y) {
double tmp;
if ((x <= -3.4e-190) || !(x <= 0.42)) {
tmp = x * (1.0 - y);
} 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 ((x <= (-3.4d-190)) .or. (.not. (x <= 0.42d0))) then
tmp = x * (1.0d0 - y)
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -3.4e-190) || !(x <= 0.42)) {
tmp = x * (1.0 - y);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.4e-190) or not (x <= 0.42): tmp = x * (1.0 - y) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.4e-190) || !(x <= 0.42)) tmp = Float64(x * Float64(1.0 - y)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -3.4e-190) || ~((x <= 0.42))) tmp = x * (1.0 - y); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.4e-190], N[Not[LessEqual[x, 0.42]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{-190} \lor \neg \left(x \leq 0.42\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -3.39999999999999981e-190 or 0.419999999999999984 < x Initial program 100.0%
Taylor expanded in x around inf 88.5%
if -3.39999999999999981e-190 < x < 0.419999999999999984Initial program 100.0%
Taylor expanded in x around 0 75.9%
Final simplification84.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* y (- x)) (if (<= y 6e-50) x y)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = y * -x;
} else if (y <= 6e-50) {
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 = y * -x
else if (y <= 6d-50) 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 = y * -x;
} else if (y <= 6e-50) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = y * -x elif y <= 6e-50: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * Float64(-x)); elseif (y <= 6e-50) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = y * -x; elseif (y <= 6e-50) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(y * (-x)), $MachinePrecision], If[LessEqual[y, 6e-50], x, y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1Initial program 100.0%
Taylor expanded in y around inf 96.7%
Taylor expanded in x around inf 55.8%
neg-mul-155.8%
Simplified55.8%
if -1 < y < 5.99999999999999981e-50Initial program 100.0%
Taylor expanded in y around 0 84.2%
if 5.99999999999999981e-50 < y Initial program 100.0%
Taylor expanded in x around 0 48.4%
(FPCore (x y) :precision binary64 (if (<= y 8.8e-54) (- x (* x y)) (- y (* x y))))
double code(double x, double y) {
double tmp;
if (y <= 8.8e-54) {
tmp = x - (x * y);
} else {
tmp = y - (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 <= 8.8d-54) then
tmp = x - (x * y)
else
tmp = y - (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.8e-54) {
tmp = x - (x * y);
} else {
tmp = y - (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.8e-54: tmp = x - (x * y) else: tmp = y - (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= 8.8e-54) tmp = Float64(x - Float64(x * y)); else tmp = Float64(y - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.8e-54) tmp = x - (x * y); else tmp = y - (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.8e-54], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.8 \cdot 10^{-54}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x \cdot y\\
\end{array}
\end{array}
if y < 8.7999999999999998e-54Initial program 100.0%
Taylor expanded in x around inf 76.9%
sub-neg76.9%
distribute-rgt-in77.0%
*-un-lft-identity77.0%
Applied egg-rr77.0%
distribute-lft-neg-out77.0%
unsub-neg77.0%
*-commutative77.0%
Applied egg-rr77.0%
if 8.7999999999999998e-54 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
sub-neg92.8%
distribute-rgt-in92.8%
*-un-lft-identity92.8%
Applied egg-rr92.8%
distribute-lft-neg-out92.8%
unsub-neg92.8%
Applied egg-rr92.8%
(FPCore (x y) :precision binary64 (if (<= y 5.5e-50) (- x (* x y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 5.5e-50) {
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 <= 5.5d-50) 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 <= 5.5e-50) {
tmp = x - (x * y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5.5e-50: tmp = x - (x * y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 5.5e-50) 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 <= 5.5e-50) tmp = x - (x * y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5.5e-50], 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 5.5 \cdot 10^{-50}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 5.49999999999999975e-50Initial program 100.0%
Taylor expanded in x around inf 76.9%
sub-neg76.9%
distribute-rgt-in77.0%
*-un-lft-identity77.0%
Applied egg-rr77.0%
distribute-lft-neg-out77.0%
unsub-neg77.0%
*-commutative77.0%
Applied egg-rr77.0%
if 5.49999999999999975e-50 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
(FPCore (x y) :precision binary64 (if (<= y 2.9e-50) (* x (- 1.0 y)) (* y (- 1.0 x))))
double code(double x, double y) {
double tmp;
if (y <= 2.9e-50) {
tmp = x * (1.0 - 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 <= 2.9d-50) then
tmp = x * (1.0d0 - 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 <= 2.9e-50) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.9e-50: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.9e-50) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.9e-50) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.9e-50], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.9 \cdot 10^{-50}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < 2.90000000000000008e-50Initial program 100.0%
Taylor expanded in x around inf 76.9%
if 2.90000000000000008e-50 < y Initial program 100.0%
Taylor expanded in y around inf 92.8%
(FPCore (x y) :precision binary64 (if (<= y 1.1e-53) x y))
double code(double x, double y) {
double tmp;
if (y <= 1.1e-53) {
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.1d-53) 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.1e-53) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 1.1e-53: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 1.1e-53) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 1.1e-53) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 1.1e-53], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.1 \cdot 10^{-53}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 1.10000000000000009e-53Initial program 100.0%
Taylor expanded in y around 0 60.9%
if 1.10000000000000009e-53 < y Initial program 100.0%
Taylor expanded in x around 0 48.4%
(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 45.8%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))