def removeDoubles(begin): # "remove doubles means keeping only one of Eq and -Eq on the list, to get 270." # toTreat keeps a list of eqns that are yet to be treated. In the beginning, it is just a copy of the singleton list of equations. equationsNoDoubles = set([]) toTreat = begin.copy() #Treated keeps a list of the equations that have been treated. treated = set([]) while len(toTreat) > 0: # Pick the first equation to be treated eq = SR(expand(toTreat.pop())) # Add to equations the (previously unseen) equations unless it is obtained by multiplying by -1 newEq = SR(expand(-1*eq)) if newEq not in equationsNoDoubles and eq not in equationsNoDoubles: equationsNoDoubles.add(eq) treated.add(eq) print "Found: " + str(len(equationsNoDoubles)) print "To treat: " + str(len(toTreat)) print "Treated: " + str(len(treated)) print " " return(equationsNoDoubles)