title: SymPy : Factorisation of a simple expression "a1*a2+a1*a3+a1*a4+a4*a2"
body: <p>I want to factorize/simply this expression f = &quot;a1<em>a2+a1</em>a3+a1<em>a4+a4</em>a2&quot; to a1*(a2+a3)+a4*(a1+a2) for example (minimize number of operators).</p>
  <p>I use sympy to do so :</p>
  <pre><code>import sympy
  a1,a2,a3,a4 = sympy.symbols('a1 a2 a3 a4')
  f = &quot;a1*a2+a1*a3+a1*a4+a4*a2&quot;
  sympy.init_printing(use_unicode=True)
  sympy.simplify(f, deep=True,gaussian = True)
  </code></pre>
  <p>I got this 'a1<em>a2 + a1</em>a3 + a1<em>a4 + a2</em>a4' (even with sympy.simplify)</p>
  <p>Do you know how I can get the result expected ?</p>
  <p>Thank you !</p>