(p1, p2, tolerance=None)
Approximate equality test for polynomials.
Approximate equality test for polynomials.
Approximate equality test for polynomials .
def almosteq(p1, p2, tolerance=None):
        """Approximate equality test for polynomials. """
        ring = p1.ring

        if isinstance(p2, ring.dtype):
            if list(p1.keys()) != list(p2.keys()):
                return False

            almosteq = ring.domain.almosteq

            for c1, c2 in zip(p1.itercoeffs(), p2.itercoeffs()):
                if not almosteq(c1, c2, tolerance):
                    return False
            else:
                return True
        elif len(p1) > 1:
            return False
        else:
            try:
                p2 = ring.domain.convert(p2)
            except CoercionFailed:
                return False
            else:
                return ring.domain.almosteq(p1.const(), p2, tolerance)
def almosteq ( p1 , p2 , tolerance = None ) : ring = p1 . ring if isinstance ( p2 , ring . dtype ) : if list ( p1 . keys ( ) ) != list ( p2 . keys ( ) ) : return False almosteq = ring . domain . almosteq for c1 , c2 in zip ( p1 . itercoeffs ( ) , p2 . itercoeffs ( ) ) : if not almosteq ( c1 , c2 , tolerance ) : return False else : return True elif len ( p1 ) > 1 : return False else : try : p2 = ring . domain . convert ( p2 ) except CoercionFailed : return False else : return ring . domain . almosteq ( p1 . const ( ) , p2 , tolerance )