Exemple #1
0
 def __cmp__(self, other):
     """
     Compare two coefficient lists of the same height.
     """
     if other is not None:
         assert self.height == other.height, "comparing unequal heights"
     if self.height == 0:
         if other is None:
             val = Integer(0)
         else:
             val = other.val
         d = SR(self.val - val)
         if d.is_constant():
             d = numerical_approx(d)
             if isinstance(d, ComplexNumber):
                 p = (d.real_part(), d.imag_part())
             else:
                 p = (d, 0)
             if p > (0, 0):
                 return 1
             elif p < (0, 0):
                 return -1
         elif checkPos(self.val - val):
             return 1
         elif checkPos(val - self.val):
             return -1
         return 0
     if other is None:
         keys = set()
     else:
         keys = set(six.iterkeys(other.val))
     for k in sorted(keys.union(six.iterkeys(self.val)), reverse=True):
         if k not in keys:
             c = self.val[k].__cmp__(None)
         elif k not in self.val:
             c = -other.val[k].__cmp__(None)
         else:
             c = self.val[k].__cmp__(other.val[k])
         if c != 0:
             return c
     return 0