def integer_powers(exprs):
 terms = {}
 for term in exprs:
  for j in terms:
   a = cancel((term / j))
   if a.is_Rational:
    terms[j].append((term, a))
    break
  else:
   terms[term] = [(term, S(1))]
 newterms = {}
 for term in terms:
  common_denom = reduce(ilcm, [i.as_numer_denom()[1] for (_, i) in terms[term]])
  newterm = (term / common_denom)
  newmults = [(i, (j * common_denom)) for (i, j) in terms[term]]
  newterms[newterm] = newmults
 return sorted(iter(newterms.items()), key=(lambda item: item[0].sort_key()))

def integer_powers ( exprs ) : terms = { } for term in exprs : for j in terms : a = cancel ( ( term / j ) ) if a . is_Rational : terms [ j ] . append ( ( term , a ) ) break else : terms [ term ] = [ ( term , S ( 1 ) ) ] newterms = { } for term in terms : common_denom = reduce ( ilcm , [ i . as_numer_denom ( ) [ 1 ] for ( _ , i ) in terms [ term ] ] ) newterm = ( term / common_denom ) newmults = [ ( i , ( j * common_denom ) ) for ( i , j ) in terms [ term ] ] newterms [ newterm ] = newmults return sorted ( iter ( newterms . items ( ) ) , key = ( lambda item : item [ 0 ] . sort_key ( ) ) )
rewrites a list of expressions as integer multiples of each other .