def dup_exquo(f, g, K):
    """
    Returns polynomial quotient in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> R.dup_exquo(x**2 - 1, x - 1)
    x + 1

    >>> R.dup_exquo(x**2 + 1, 2*x - 4)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]

    """
    q, r = dup_div(f, g, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed(f, g)
Exemplo n.º 2
0
def dmp_exquo(f, g, u, K):
    """
    Returns polynomial quotient in ``K[X]``.

    **Examples**

    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.densearith import dmp_exquo

    >>> f = ZZ.map([[1], [1, 0], []])
    >>> g = ZZ.map([[1], [1, 0]])
    >>> h = ZZ.map([[2], [2]])

    >>> dmp_exquo(f, g, 1, ZZ)
    [[1], []]

    >>> dmp_exquo(f, h, 1, ZZ)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]

    """
    q, r = dmp_div(f, g, u, K)

    if dmp_zero_p(r, u):
        return q
    else:
        raise ExactQuotientFailed(f, g)
def dmp_exquo(f, g, u, K):
    """
    Returns polynomial quotient in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> f = x**2 + x*y
    >>> g = x + y
    >>> h = 2*x + 2

    >>> R.dmp_exquo(f, g)
    x

    >>> R.dmp_exquo(f, h)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [[2], [2]] does not divide [[1], [1, 0], []]

    """
    q, r = dmp_div(f, g, u, K)

    if dmp_zero_p(r, u):
        return q
    else:
        raise ExactQuotientFailed(f, g)
Exemplo n.º 4
0
def dup_exquo(f, g, K):
    """
    Returns polynomial quotient in ``K[x]``.

    **Examples**

    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.densearith import dup_exquo

    >>> f = ZZ.map([1, 0, -1])
    >>> g = ZZ.map([1, -1])

    >>> dup_exquo(f, g, ZZ)
    [1, 1]

    >>> f = ZZ.map([1, 0, 1])
    >>> g = ZZ.map([2, -4])

    >>> dup_exquo(f, g, ZZ)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [2, -4] does not divide [1, 0, 1]

    """
    q, r = dup_div(f, g, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed(f, g)
Exemplo n.º 5
0
def gf_exquo(f, g, p, K):
    """
    Compute polynomial quotient in ``GF(p)[x]``.

    Examples
    ========

    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.galoistools import gf_exquo

    >>> gf_exquo(ZZ.map([1, 0, 3, 2, 3]), ZZ.map([2, 2, 2]), 5, ZZ)
    [3, 2, 4]

    >>> gf_exquo(ZZ.map([1, 0, 1, 1]), ZZ.map([1, 1, 0]), 2, ZZ)
    Traceback (most recent call last):
    ...
    ExactQuotientFailed: [1, 1, 0] does not divide [1, 0, 1, 1]

    """
    q, r = gf_div(f, g, p, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed(f, g)
Exemplo n.º 6
0
def sdp_exquo(f, g, u, O, K):
    """Returns exact polynomial quotient in `K[X]`. """
    q, r = sdp_div(f, g, u, O, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed(f, g)
Exemplo n.º 7
0
def dup_pquo(f, g, K):
    """Polynomial pseudo-quotient in `K[x]`. """
    q, r = dup_pdiv(f, g, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed('%s does not divide %s' % (g, f))
Exemplo n.º 8
0
 def exquo(f, g):
     """Computes polynomial exact quotient of ``f`` and ``g``. """
     lev, dom, per, F, G = f.unify(g)
     res = per(dmp_exquo(F, G, lev, dom))
     if f.ring and res not in f.ring:
         from sympy.polys.polyerrors import ExactQuotientFailed
         raise ExactQuotientFailed(f, g, f.ring)
     return res
Exemplo n.º 9
0
def sdp_quo(f, g, u, O, K):
    """Returns polynomial quotient in `K[X]`. """
    q, r = sdp_div(f, g, u, O, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed('%s does not divide %s' % (g, f))
Exemplo n.º 10
0
def dmp_quo(f, g, u, K):
    """Returns polynomial quotient in `K[X]`. """
    q, r = dmp_div(f, g, u, K)

    if dmp_zero_p(r, u):
        return q
    else:
        raise ExactQuotientFailed('%s does not divide %s' % (g, f))
Exemplo n.º 11
0
def gf_quo(f, g, p, K):
    """Returns polynomial quotient in `GF(p)[x]`. """
    q, r = gf_div(f, g, p, K)

    if not r:
        return q
    else:
        raise ExactQuotientFailed('%s does not divide %s' % (g, f))
Exemplo n.º 12
0
    def __div__(self, other):
        if isinstance(other, Monomial):
            result = monomial_div(self.data, other.data)

            if result is not None:
                return Monomial(*result)
            else:
                raise ExactQuotientFailed(self, other)
        else:
            raise TypeError("an instance of Monomial class expected, got %s" %
                            other)
Exemplo n.º 13
0
    def __div__(self, other):
        if isinstance(other, Monomial):
            exponents = other.exponents
        elif isinstance(other, (tuple, Tuple)):
            exponents = other
        else:
            return NotImplementedError

        result = monomial_div(self.exponents, exponents)

        if result is not None:
            return self.rebuild(result)
        else:
            raise ExactQuotientFailed(self, Monomial(other))
Exemplo n.º 14
0
    def quo(f, g):
        """Computes quotient of fractions ``f`` and ``g``. """
        if isinstance(g, DMP):
            lev, dom, per, (F_num, F_den), G = f.poly_unify(g)
            num, den = F_num, dmp_mul(F_den, G, lev, dom)
        else:
            lev, dom, per, F, G = f.frac_unify(g)
            (F_num, F_den), (G_num, G_den) = F, G

            num = dmp_mul(F_num, G_den, lev, dom)
            den = dmp_mul(F_den, G_num, lev, dom)

        res = per(num, den)
        if f.ring is not None and res not in f.ring:
            from sympy.polys.polyerrors import ExactQuotientFailed
            raise ExactQuotientFailed(f, g, f.ring)
        return res
Exemplo n.º 15
0
 def exquo(self, a, b):
     """Exact quotient of ``a`` and ``b``, implies ``__floordiv__``.  """
     if a % b:
         raise ExactQuotientFailed(a, b, self)
     else:
         return a // b
Exemplo n.º 16
0
 def quo(self, a, b):
     """Quotient of `a` and `b`, implies `__floordiv__`. """
     if a % b:
         raise ExactQuotientFailed(a, b, self)
     else:
         return a // b
Exemplo n.º 17
0
 def __rdiv__(self, g):
     r = self.invert(check=False)*g
     if self.ring and r not in self.ring:
         from sympy.polys.polyerrors import ExactQuotientFailed
         raise ExactQuotientFailed(g, self, self.ring)
     return r