title: Can Sympy simplify a rational expression by collecting multiple terms?
body: <p>Given a rational expression <code>E</code> such as the one below, I'm looking to use Sympy to simplify it to something that looks like <code>F</code> (defined in the second block of Python code below):</p>
  <pre><code>import sympy as sp
  
  a, b, c, d, n, t, A, B, C = sp.symbols('a, b, c, d, n, t, A, B, C', real = True)
  
  E = n/(c-b) * ( B - (c-b)/(c-a)*A - (b-a)/(c-a)*B ) * (c-t)/(c-b) + n/(c-b) * ( (d-c)/(d-b)*B + (c-b)/(d-b)*C - B ) * (t-b)/(c-b)
  
  print(sp.pretty( E ))
  print(sp.pretty( E.simplify() ))
  </code></pre>
  <p>This prints</p>
  <pre><code>           ⎛     B⋅(-c + d)   C⋅(-b + c)⎞             ⎛  A⋅(-b + c)   B⋅(-a + b)    ⎞
  n⋅(-b + t)⋅⎜-B + ────────── + ──────────⎟   n⋅(c - t)⋅⎜- ────────── - ────────── + B⎟
             ⎝       -b + d       -b + d  ⎠             ⎝    -a + c       -a + c      ⎠
  ───────────────────────────────────────── + ─────────────────────────────────────────
                          2                                           2                
                  (-b + c)                                    (-b + c)
                  
                  
  -n⋅((a - c)⋅(b - t)⋅(-B⋅(b - d) + B⋅(c - d) + C⋅(b - c)) + (b - d)⋅(c - t)⋅(A⋅(b - c) + B⋅(a - b) - B⋅(a - c))) 
  ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                             2                                                    
                                              (a - c)⋅(b - c) ⋅(b - d) 
  </code></pre>
  <p>However, the expression can be — manually — simplified further, the result of which I've labeled <code>F</code>:</p>
  <pre><code>F = n/(c-a) * (B - A) * (c-t)/(c-b) + n/(d-b) * (C - B) * (t-b)/(c-b)
  
  print(sp.pretty( F ))
  print((F-E).simplify())
  </code></pre>
  <p>This outputs</p>
  <pre><code>n⋅(-A + B)⋅(c - t)   n⋅(-B + C)⋅(-b + t)
  ────────────────── + ───────────────────
  (-a + c)⋅(-b + c)     (-b + c)⋅(-b + d) 
  
  
  0
  </code></pre>
  <p>I've looked into various options including <code>factor()</code>, <code>collect()</code> and <code>apart()</code>, but none of these seem to yield expressions that have the same structure as <code>F</code>. Any pointers on how to proceed?</p>
  <p>Additionally, I wondered whether Sympy's pretty print function can be tweaked somehow to</p>
  <ol>
  <li>Keep the original order of the variables in both the numerator and denominator (e.g. <code>B - A</code> instead of <code>-A + B</code>). Currently the order is flipped in most cases, which looks rather ugly with the leading minus signs.</li>
  <li>Show composite fractions as products of simple fractions (e.g. <code>a/b c/d</code> instead of <code>ac/bd</code>), though in certain cases it can of course be ambiguous where/how to &quot;split&quot; such composite fractions.</li>
  </ol>