def rational_independent(terms, x):
 if (not terms):
  return []
 ind = terms[0:1]
 for t in terms[1:]:
  n = t.as_independent(x)[1]
  for (i, term) in enumerate(ind):
   d = term.as_independent(x)[1]
   q = (n / d).cancel()
   if q.is_rational_function(x):
    ind[i] += t
    break
  else:
   ind.append(t)
 return ind

def rational_independent ( terms , x ) : if ( not terms ) : return [ ] ind = terms [ 0 : 1 ] for t in terms [ 1 : ] : n = t . as_independent ( x ) [ 1 ] for ( i , term ) in enumerate ( ind ) : d = term . as_independent ( x ) [ 1 ] q = ( n / d ) . cancel ( ) if q . is_rational_function ( x ) : ind [ i ] += t break else : ind . append ( t ) return ind
returns a list of all the rationally independent terms .