Update 2:
An alternative way to use TagSetDelayed
+define a function that works like Maple's collect using CoefficientRules
+ FromCoefficientRules
:
collectLikeMaple = FromCoefficientRules[CoefficientRules@##, #2] &;
{collectLikeMaple[eq, {x, y}] ==
Collect[eq, {x, y}, $distributed],
(collectLikeMaple[First@SubtractSides@eq2, {x, y}] == 0) ==
Collect[eq2, {x, y}, $distributed],
collectLikeMaple[eq3, {x, y, z}] ==
Collect[eq3, {x, y, z}, $distributed]}
{True, True, True}
Alternatively, use TagSetDelayed
to add an argument to make Collect
that makes it behave like Maple's collect
:
ClearAll[doItLikeMappleDoes]
doItLikeMappleDoes /:
Collect[p_Plus, vl_List, h_ : Identity, doItLikeMappleDoes] :=
FromCoefficientRules[MapAt[h, {All, 2}] @ CoefficientRules[p, vl], vl]
doItLikeMappleDoes /:
Collect[e_Equal, vl_List, h_ : Identity, doItLikeMappleDoes] :=
Collect[First @ SubtractSides @ e, vl, h, doItLikeMappleDoes] == 0
Examples:
{Collect[eq, {x, y}, doItLikeMappleDoes] ==
Collect[eq, {x, y}, $distributed],
Collect[eq2, {x, y}, doItLikeMappleDoes] ==
Collect[eq2, {x, y}, $distributed],
Collect[eq3, {x, y, z}, Simplify, doItLikeMappleDoes] ==
Collect[eq3, {x, y, z}, Simplify, $distributed]}
{True, True, True}
Update:
Use TagSetDelayed
to add an argument to Collect
to make it behave like Maple collect
$distributed /: Collect[e_, vl_List, h___, $distributed] :=
Collect[e,
{Splice @ MapApply[Times] @ Reverse @ Subsets[#, {2, Length @ #}],
Splice @ #} & @ Map[#^_. &] @ vl, h]
Examples:
Collect[eq, {x, y}, $distributed]
Collect[eq2, {x, y}, $distributed]
eq3 = Expand[(a + b x + c y + d z + e y x + y z + y^2)^2]
Collect[eq3, {x, y, z}, Simplify, $distributed]
Original answer:
Use a pattern in the second argument of Collect
:
Collect[eq, {x^_. y^_., x^_., y^_.}]
Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]