Mathematica has lots of tools for polynomials, but few for Laurent polynomials (Series
will return a truncated Laurent series) and none really for treating monomials in multivariate polynomials as a flat sum. To get at the monomials of a polynomial (not a Laurent polynomial), one can use CoefficientList
or CoefficientArrays
. I used Series
to find the lowest degree (if below zero) of each variable; maybe there's a better way (e.g. Exponent[p /. x -> 1/x, x]
). This is needed to convert Laurent polynomial to a ordinary polynomial so that we can apply CoefficientList
.
ClearAll[minExponent];
minExponent::laurent = "`` is not a Laurent polynomial.";
minExponent[p_, x_] := Module[{res},
res = Series[p, {x, 0, 0}];
If[Head[res] === SeriesData,
res = res[[4]];
If[PolynomialQ[x^-res p, x],
Message[minExponent::laurent, p];
res = $Failed],
Message[minExponent::poly, x^-res p];
res = $Failed];
res /; FreeQ[res, $Failed]
]
Block[{p = u[x, y] u1[1/x, 1/y]},
With[{xd = minExponent[p, x], yd = minExponent[p, y]},
With[{c = CoefficientList[x^-xd y^-yd p, {x, y}]},
Total[
c*
Transpose[{x^Range[xd, xd + Dimensions[c][[1]] - 1]}].
y^{Range[xd, yd + Dimensions[c][[2]] - 1]},
2
]
]]
]
a x/y+b x/y
, while I need terms as(a+b) x/y
, but using collect it will have terms like(ax+b)y
etc. $\endgroup$Collect
, but I don't have an example to be able to know if that would work. $\endgroup$Collect[#, x] & /@ Collect[u[x, y] u1[1/x, 1/y], y]
? $\endgroup$Collect[#, y] & /@ Collect[u[x, y] u1[1/x, 1/y], {x, y}]
$\endgroup$