title: Use pattern to collect terms in Mathematica
body: <p>With Mathematica I would like collect terms <code>from (1 + a + x + y)^4</code> according to the exponents of <code>x</code> and <code>y</code>, so</p>
  
  <pre><code>(1 + a + x + y)^4 = (...)x^0 y^0 + (...)x^1 y^0 + (...)x^0 y^1 + ...
  </code></pre>
  
  <p>The <a href="http://reference.wolfram.com/mathematica/ref/Collect.html?q=Collect&amp;lang=en" rel="noreferrer">Mathematica help</a> has a nice example which I tried to imitate:</p>
  
  <pre><code>D[f[Sqrt[ x^2 + 1 ]], {x, 3}]
  Collect[%, Derivative[ _ ][ f ][ _ ], Together]
  </code></pre>
  
  <p>This collects derivative terms of the same order (and the same argument for f)</p>
  
  <p>Can anyone explain why the following imitation does not work?</p>
  
  <pre><code>Collect[(1 + a + x + y)^4, x^_ y^_]
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>(1 + a + x + y)^4
  </code></pre>
  
  <p>Any suggestions for a solution?</p>