(f, g)
Unify a multivariate fraction and a polynomial.
Unify a multivariate fraction and a polynomial.
Unify a multivariate fraction and a polynomial .
def poly_unify(f, g):
        """Unify a multivariate fraction and a polynomial. """
        if not isinstance(g, DMP) or f.lev != g.lev:
            raise UnificationFailed("can't unify %s with %s" % (f, g))

        if f.dom == g.dom and f.ring == g.ring:
            return (f.lev, f.dom, f.per, (f.num, f.den), g.rep)
        else:
            lev, dom = f.lev, f.dom.unify(g.dom)
            ring = f.ring
            if g.ring is not None:
                if ring is not None:
                    ring = ring.unify(g.ring)
                else:
                    ring = g.ring

            F = (dmp_convert(f.num, lev, f.dom, dom),
                 dmp_convert(f.den, lev, f.dom, dom))

            G = dmp_convert(g.rep, lev, g.dom, dom)

            def per(num, den, cancel=True, kill=False, lev=lev):
                if kill:
                    if not lev:
                        return num/den
                    else:
                        lev = lev - 1

                if cancel:
                    num, den = dmp_cancel(num, den, lev, dom)

                return f.__class__.new((num, den), dom, lev, ring=ring)

            return lev, dom, per, F, G
def poly_unify ( f , g ) : if not isinstance ( g , DMP ) or f . lev != g . lev : raise UnificationFailed ( "can't unify %s with %s" % ( f , g ) ) if f . dom == g . dom and f . ring == g . ring : return ( f . lev , f . dom , f . per , ( f . num , f . den ) , g . rep ) else : lev , dom = f . lev , f . dom . unify ( g . dom ) ring = f . ring if g . ring is not None : if ring is not None : ring = ring . unify ( g . ring ) else : ring = g . ring F = ( dmp_convert ( f . num , lev , f . dom , dom ) , dmp_convert ( f . den , lev , f . dom , dom ) ) G = dmp_convert ( g . rep , lev , g . dom , dom ) def per ( num , den , cancel = True , kill = False , lev = lev ) : if kill : if not lev : return num / den else : lev = lev - 1 if cancel : num , den = dmp_cancel ( num , den , lev , dom ) return f . __class__ . new ( ( num , den ) , dom , lev , ring = ring ) return lev , dom , per , F , G