Skip to main content
added 491 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

Update 2:

An alternative way to use TagSetDelayed + CoefficientRules + FromCoefficientRules to make Collect 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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

Update 2:

An alternative way to 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 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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

added 1103 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update 2:

An alternative way to use TagSetDelayed + CoefficientRules + FromCoefficientRules to make Collect 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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

Update 2:

An alternative way to use TagSetDelayed + CoefficientRules + FromCoefficientRules to make Collect 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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

added 207 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update:

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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

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:enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

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] 

enter image description here

Collect[eq2, {x, y}, $distributed] 

enter image description here

eq3 = Expand[(a + b x + c y + d  z + e y x + y z + y^2)^2]

Collect[eq3, {x, y, z}, Simplify, $distributed]

enter image description here

Original answer:

Use a pattern in the second argument of Collect:

Collect[eq, {x^_. y^_., x^_., y^_.}]

![enter image description here

Collect[ExpandAll @ eq2, {x^_. y^_., x^_., y^_.}]

enter image description here

added 591 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 12 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 6 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 12 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 12 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading