def test_dmp_div(): f, g, q, r = [5,4,3,2,1], [1,2,3], [5,-6,0], [20,1] assert dmp_div(f, g, 0, ZZ) == (q, r) assert dmp_quo(f, g, 0, ZZ) == q assert dmp_rem(f, g, 0, ZZ) == r raises(ExactQuotientFailed, lambda: dmp_exquo(f, g, 0, ZZ)) f, g, q, r = [[[1]]], [[[2]],[1]], [[[]]], [[[1]]] assert dmp_div(f, g, 2, ZZ) == (q, r) assert dmp_quo(f, g, 2, ZZ) == q assert dmp_rem(f, g, 2, ZZ) == r raises(ExactQuotientFailed, lambda: dmp_exquo(f, g, 2, ZZ))
def dmp_trunc(f, p, u, K): """ Reduce ``K[X]`` polynomial modulo a polynomial ``p`` in ``K[Y]``. **Examples** >>> from sympy.polys.domains import ZZ >>> from sympy.polys.densetools import dmp_trunc >>> f = ZZ.map([[3, 8], [5, 6], [2, 3]]) >>> g = ZZ.map([1, -1]) >>> dmp_trunc(f, g, 1, ZZ) [[11], [11], [5]] """ return dmp_strip([dmp_rem(c, p, u - 1, K) for c in f], u)
def dmp_trunc(f, p, u, K): """ Reduce ``K[X]`` polynomial modulo a polynomial ``p`` in ``K[Y]``. **Examples** >>> from sympy.polys.domains import ZZ >>> from sympy.polys.densetools import dmp_trunc >>> f = ZZ.map([[3, 8], [5, 6], [2, 3]]) >>> g = ZZ.map([1, -1]) >>> dmp_trunc(f, g, 1, ZZ) [[11], [11], [5]] """ return dmp_strip([ dmp_rem(c, p, u-1, K) for c in f ], u)
def dmp_trunc(f, p, u, K): """ Reduce a ``K[X]`` polynomial modulo a polynomial ``p`` in ``K[Y]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3 >>> g = (y - 1).drop(x) >>> R.dmp_trunc(f, g) 11*x**2 + 11*x + 5 """ return dmp_strip([dmp_rem(c, p, u - 1, K) for c in f], u)
def dmp_trunc(f, p, u, K): """ Reduce a ``K[X]`` polynomial modulo a polynomial ``p`` in ``K[Y]``. Examples ======== >>> from sympy.polys import ring, ZZ >>> R, x,y = ring("x,y", ZZ) >>> f = 3*x**2*y + 8*x**2 + 5*x*y + 6*x + 2*y + 3 >>> g = (y - 1).drop(x) >>> R.dmp_trunc(f, g) 11*x**2 + 11*x + 5 """ return dmp_strip([ dmp_rem(c, p, u - 1, K) for c in f ], u)
def rem(f, g): """Computes polynomial remainder of `f` and `g`. """ lev, dom, per, F, G = f.unify(g) return per(dmp_rem(F, G, lev, dom))