def ratsimp(expr):
 (f, g) = cancel(expr).as_numer_denom()
 try:
  (Q, r) = reduced(f, [g], field=True, expand=False)
 except ComputationFailed:
  return (f / g)
 return (Add(*Q) + cancel((r / g)))

def ratsimp ( expr ) : ( f , g ) = cancel ( expr ) . as_numer_denom ( ) try : ( Q , r ) = reduced ( f , [ g ] , field = True , expand = False ) except ComputationFailed : return ( f / g ) return ( Add ( * Q ) + cancel ( ( r / g ) ) )
put an expression over a common denominator .