
(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 (- (+ 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
(let* ((t_0 (* x (- y))))
(if (<= y -1.0)
t_0
(if (<= y 5.2e-84)
x
(if (<= y 2.5e-72)
y
(if (<= y 6e-50)
x
(if (or (<= y 6.5e+120) (and (not (<= y 4.8e+146)) (<= y 1.5e+243)))
y
t_0)))))))
double code(double x, double y) {
double t_0 = x * -y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.2e-84) {
tmp = x;
} else if (y <= 2.5e-72) {
tmp = y;
} else if (y <= 6e-50) {
tmp = x;
} else if ((y <= 6.5e+120) || (!(y <= 4.8e+146) && (y <= 1.5e+243))) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x * -y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 5.2d-84) then
tmp = x
else if (y <= 2.5d-72) then
tmp = y
else if (y <= 6d-50) then
tmp = x
else if ((y <= 6.5d+120) .or. (.not. (y <= 4.8d+146)) .and. (y <= 1.5d+243)) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * -y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.2e-84) {
tmp = x;
} else if (y <= 2.5e-72) {
tmp = y;
} else if (y <= 6e-50) {
tmp = x;
} else if ((y <= 6.5e+120) || (!(y <= 4.8e+146) && (y <= 1.5e+243))) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * -y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 5.2e-84: tmp = x elif y <= 2.5e-72: tmp = y elif y <= 6e-50: tmp = x elif (y <= 6.5e+120) or (not (y <= 4.8e+146) and (y <= 1.5e+243)): tmp = y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 5.2e-84) tmp = x; elseif (y <= 2.5e-72) tmp = y; elseif (y <= 6e-50) tmp = x; elseif ((y <= 6.5e+120) || (!(y <= 4.8e+146) && (y <= 1.5e+243))) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * -y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 5.2e-84) tmp = x; elseif (y <= 2.5e-72) tmp = y; elseif (y <= 6e-50) tmp = x; elseif ((y <= 6.5e+120) || (~((y <= 4.8e+146)) && (y <= 1.5e+243))) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 5.2e-84], x, If[LessEqual[y, 2.5e-72], y, If[LessEqual[y, 6e-50], x, If[Or[LessEqual[y, 6.5e+120], And[N[Not[LessEqual[y, 4.8e+146]], $MachinePrecision], LessEqual[y, 1.5e+243]]], y, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-72}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+120} \lor \neg \left(y \leq 4.8 \cdot 10^{+146}\right) \land y \leq 1.5 \cdot 10^{+243}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 6.4999999999999997e120 < y < 4.8000000000000004e146 or 1.49999999999999992e243 < y Initial program 100.0%
Taylor expanded in x around inf 58.4%
Taylor expanded in y around inf 58.3%
mul-1-neg58.3%
distribute-lft-neg-out58.3%
*-commutative58.3%
Simplified58.3%
if -1 < y < 5.2e-84 or 2.4999999999999998e-72 < y < 5.99999999999999981e-50Initial program 100.0%
Taylor expanded in y around 0 74.0%
if 5.2e-84 < y < 2.4999999999999998e-72 or 5.99999999999999981e-50 < y < 6.4999999999999997e120 or 4.8000000000000004e146 < y < 1.49999999999999992e243Initial program 100.0%
Taylor expanded in x around 0 50.1%
Final simplification63.2%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -1.35e-42)
t_0
(if (<= x -1.8e-66)
y
(if (<= x -3.9e-155) t_0 (if (<= x 1.0) y (* x (- y))))))))
double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -1.35e-42) {
tmp = t_0;
} else if (x <= -1.8e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - y)
if (x <= (-1.35d-42)) then
tmp = t_0
else if (x <= (-1.8d-66)) then
tmp = y
else if (x <= (-3.9d-155)) then
tmp = t_0
else if (x <= 1.0d0) then
tmp = y
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -1.35e-42) {
tmp = t_0;
} else if (x <= -1.8e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
tmp = t_0;
} else if (x <= 1.0) {
tmp = y;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - y) tmp = 0 if x <= -1.35e-42: tmp = t_0 elif x <= -1.8e-66: tmp = y elif x <= -3.9e-155: tmp = t_0 elif x <= 1.0: tmp = y else: tmp = x * -y return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -1.35e-42) tmp = t_0; elseif (x <= -1.8e-66) tmp = y; elseif (x <= -3.9e-155) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -1.35e-42) tmp = t_0; elseif (x <= -1.8e-66) tmp = y; elseif (x <= -3.9e-155) tmp = t_0; elseif (x <= 1.0) tmp = y; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e-42], t$95$0, If[LessEqual[x, -1.8e-66], y, If[LessEqual[x, -3.9e-155], t$95$0, If[LessEqual[x, 1.0], y, N[(x * (-y)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{-42}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-66}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3.9 \cdot 10^{-155}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -1.35e-42 or -1.80000000000000006e-66 < x < -3.9000000000000003e-155Initial program 100.0%
Taylor expanded in x around inf 82.3%
if -1.35e-42 < x < -1.80000000000000006e-66 or -3.9000000000000003e-155 < x < 1Initial program 100.0%
Taylor expanded in x around 0 78.4%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.6%
Taylor expanded in y around inf 51.8%
mul-1-neg51.8%
distribute-lft-neg-out51.8%
*-commutative51.8%
Simplified51.8%
Final simplification72.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (- 1.0 y))))
(if (<= x -5.2e-43)
t_0
(if (<= x -1.3e-66) y (if (<= x -3.9e-155) t_0 (* y (- 1.0 x)))))))
double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -5.2e-43) {
tmp = t_0;
} else if (x <= -1.3e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - y)
if (x <= (-5.2d-43)) then
tmp = t_0
else if (x <= (-1.3d-66)) then
tmp = y
else if (x <= (-3.9d-155)) then
tmp = t_0
else
tmp = y * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -5.2e-43) {
tmp = t_0;
} else if (x <= -1.3e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
tmp = t_0;
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): t_0 = x * (1.0 - y) tmp = 0 if x <= -5.2e-43: tmp = t_0 elif x <= -1.3e-66: tmp = y elif x <= -3.9e-155: tmp = t_0 else: tmp = y * (1.0 - x) return tmp
function code(x, y) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -5.2e-43) tmp = t_0; elseif (x <= -1.3e-66) tmp = y; elseif (x <= -3.9e-155) tmp = t_0; else tmp = Float64(y * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -5.2e-43) tmp = t_0; elseif (x <= -1.3e-66) tmp = y; elseif (x <= -3.9e-155) tmp = t_0; else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.2e-43], t$95$0, If[LessEqual[x, -1.3e-66], y, If[LessEqual[x, -3.9e-155], t$95$0, N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -5.2 \cdot 10^{-43}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-66}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3.9 \cdot 10^{-155}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -5.2e-43 or -1.2999999999999999e-66 < x < -3.9000000000000003e-155Initial program 100.0%
Taylor expanded in x around inf 82.3%
if -5.2e-43 < x < -1.2999999999999999e-66Initial program 100.0%
Taylor expanded in x around 0 94.9%
if -3.9000000000000003e-155 < x Initial program 100.0%
Taylor expanded in y around inf 67.3%
Final simplification72.8%
(FPCore (x y)
:precision binary64
(if (<= x -2.4e-48)
(- x (* x y))
(if (<= x -2.25e-66)
y
(if (<= x -3.9e-155) (* x (- 1.0 y)) (* y (- 1.0 x))))))
double code(double x, double y) {
double tmp;
if (x <= -2.4e-48) {
tmp = x - (x * y);
} else if (x <= -2.25e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
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 (x <= (-2.4d-48)) then
tmp = x - (x * y)
else if (x <= (-2.25d-66)) then
tmp = y
else if (x <= (-3.9d-155)) 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 (x <= -2.4e-48) {
tmp = x - (x * y);
} else if (x <= -2.25e-66) {
tmp = y;
} else if (x <= -3.9e-155) {
tmp = x * (1.0 - y);
} else {
tmp = y * (1.0 - x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.4e-48: tmp = x - (x * y) elif x <= -2.25e-66: tmp = y elif x <= -3.9e-155: tmp = x * (1.0 - y) else: tmp = y * (1.0 - x) return tmp
function code(x, y) tmp = 0.0 if (x <= -2.4e-48) tmp = Float64(x - Float64(x * y)); elseif (x <= -2.25e-66) tmp = y; elseif (x <= -3.9e-155) 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 (x <= -2.4e-48) tmp = x - (x * y); elseif (x <= -2.25e-66) tmp = y; elseif (x <= -3.9e-155) tmp = x * (1.0 - y); else tmp = y * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.4e-48], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.25e-66], y, If[LessEqual[x, -3.9e-155], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-48}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{elif}\;x \leq -2.25 \cdot 10^{-66}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -3.9 \cdot 10^{-155}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -2.4e-48Initial program 100.0%
Taylor expanded in x around inf 94.3%
sub-neg94.3%
distribute-rgt-in94.4%
*-un-lft-identity94.4%
Applied egg-rr94.4%
distribute-lft-neg-out94.4%
unsub-neg94.4%
*-commutative94.4%
Applied egg-rr94.4%
if -2.4e-48 < x < -2.2499999999999999e-66Initial program 100.0%
Taylor expanded in x around 0 94.9%
if -2.2499999999999999e-66 < x < -3.9000000000000003e-155Initial program 100.0%
Taylor expanded in x around inf 33.6%
if -3.9000000000000003e-155 < x Initial program 100.0%
Taylor expanded in y around inf 67.3%
Final simplification72.8%
(FPCore (x y) :precision binary64 (if (<= y 2.75e-85) x (if (<= y 2.5e-72) y (if (<= y 4.3e-50) x y))))
double code(double x, double y) {
double tmp;
if (y <= 2.75e-85) {
tmp = x;
} else if (y <= 2.5e-72) {
tmp = y;
} else if (y <= 4.3e-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 <= 2.75d-85) then
tmp = x
else if (y <= 2.5d-72) then
tmp = y
else if (y <= 4.3d-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 <= 2.75e-85) {
tmp = x;
} else if (y <= 2.5e-72) {
tmp = y;
} else if (y <= 4.3e-50) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.75e-85: tmp = x elif y <= 2.5e-72: tmp = y elif y <= 4.3e-50: tmp = x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= 2.75e-85) tmp = x; elseif (y <= 2.5e-72) tmp = y; elseif (y <= 4.3e-50) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.75e-85) tmp = x; elseif (y <= 2.5e-72) tmp = y; elseif (y <= 4.3e-50) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.75e-85], x, If[LessEqual[y, 2.5e-72], y, If[LessEqual[y, 4.3e-50], x, y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.75 \cdot 10^{-85}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{-72}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 2.7499999999999999e-85 or 2.4999999999999998e-72 < y < 4.29999999999999997e-50Initial program 100.0%
Taylor expanded in y around 0 47.5%
if 2.7499999999999999e-85 < y < 2.4999999999999998e-72 or 4.29999999999999997e-50 < y Initial program 100.0%
Taylor expanded in x around 0 41.6%
Final simplification45.7%
(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 35.5%
Final simplification35.5%
herbie shell --seed 2024089
(FPCore (x y)
:name "Data.Colour.RGBSpace.HSL:hsl from colour-2.3.3, A"
:precision binary64
(- (+ x y) (* x y)))