def is_zero_dimensional(self):
        """
        Checks if the ideal generated by a Groebner basis is zero-dimensional.

        The algorithm checks if the set of monomials not divisible by the
        leading monomial of any element of ``F`` is bounded.

        References
        ==========

        David A. Cox, John B. Little, Donal O'Shea. Ideals, Varieties and
        Algorithms, 3rd edition, p. 230

        """
        def single_var(monomial):
            return sum(map(bool, monomial)) == 1

        exponents = Monomial([0] * len(self.gens))
        order = self._options.order

        for poly in self.polys:
            monomial = poly.LM(order=order)

            if single_var(monomial):
                exponents *= monomial

        # If any element of the exponents vector is zero, then there's
        # a variable for which there's no degree bound and the ideal
        # generated by this Groebner basis isn't zero-dimensional.
        return all(exponents)
예제 #2
0
def test_pickling_polys_monomials():
    from sympy.polys.monomials import MonomialOps, Monomial
    x, y, z = symbols("x,y,z")

    for c in (MonomialOps, MonomialOps(3)):
        check(c)

    for c in (Monomial, Monomial((1, 2, 3), (x, y, z))):
        check(c)
예제 #3
0
    def staircase(n):
        """
        Compute all monomials with degree less than ``n`` that are
        not divisible by any element of ``leading_monomials``.
        """
        if n == 0:
            return [1]
        S = []
        for mi in combinations_with_replacement(range(len(opt.gens)), n):
            m = [0] * len(opt.gens)
            for i in mi:
                m[i] += 1
            if all(monomial_div(m, lmg) is None for lmg in leading_monomials):
                S.append(m)

        return [Monomial(s).as_expr(*opt.gens) for s in S] + staircase(n - 1)
예제 #4
0
def test_Monomial():
    m = Monomial((3, 4, 1), (x, y, z))
    n = Monomial((1, 2, 0), (x, y, z))

    assert m.as_expr() == x**3 * y**4 * z
    assert n.as_expr() == x**1 * y**2

    assert m.as_expr(a, b, c) == a**3 * b**4 * c
    assert n.as_expr(a, b, c) == a**1 * b**2

    assert m.exponents == (3, 4, 1)
    assert m.gens == (x, y, z)

    assert n.exponents == (1, 2, 0)
    assert n.gens == (x, y, z)

    assert m == (3, 4, 1)
    assert n != (3, 4, 1)
    assert m != (1, 2, 0)
    assert n == (1, 2, 0)
    assert (m == 1) is False

    assert m[0] == m[-3] == 3
    assert m[1] == m[-2] == 4
    assert m[2] == m[-1] == 1

    assert n[0] == n[-3] == 1
    assert n[1] == n[-2] == 2
    assert n[2] == n[-1] == 0

    assert m[:2] == (3, 4)
    assert n[:2] == (1, 2)

    assert m * n == Monomial((4, 6, 1))
    assert m / n == Monomial((2, 2, 1))

    assert m * (1, 2, 0) == Monomial((4, 6, 1))
    assert m / (1, 2, 0) == Monomial((2, 2, 1))

    assert m.gcd(n) == Monomial((1, 2, 0))
    assert m.lcm(n) == Monomial((3, 4, 1))

    assert m.gcd((1, 2, 0)) == Monomial((1, 2, 0))
    assert m.lcm((1, 2, 0)) == Monomial((3, 4, 1))

    assert m**0 == Monomial((0, 0, 0))
    assert m**1 == m
    assert m**2 == Monomial((6, 8, 2))
    assert m**3 == Monomial((9, 12, 3))

    raises(ExactQuotientFailed, lambda: m / Monomial((5, 2, 0)))

    mm = Monomial((1, 2, 3))
    raises(ValueError, lambda: mm.as_expr())
    assert str(mm) == 'Monomial((1, 2, 3))'
    assert str(m) == 'x**3*y**4*z**1'
    raises(NotImplementedError, lambda: m * 1)
    raises(NotImplementedError, lambda: m / 1)
    raises(ValueError, lambda: m**-1)
    raises(TypeError, lambda: m.gcd(3))
    raises(TypeError, lambda: m.lcm(3))
예제 #5
0
def test_Monomial():
    m = Monomial((3, 4, 1), (x, y, z))
    n = Monomial((1, 2, 0), (x, y, z))

    assert m.as_expr() == x**3 * y**4 * z
    assert n.as_expr() == x**1 * y**2

    assert m.as_expr(a, b, c) == a**3 * b**4 * c
    assert n.as_expr(a, b, c) == a**1 * b**2

    assert m.exponents == (3, 4, 1)
    assert m.gens == (x, y, z)

    assert n.exponents == (1, 2, 0)
    assert n.gens == (x, y, z)

    assert m == (3, 4, 1)
    assert n != (3, 4, 1)
    assert m != (1, 2, 0)
    assert n == (1, 2, 0)

    assert m[0] == m[-3] == 3
    assert m[1] == m[-2] == 4
    assert m[2] == m[-1] == 1

    assert n[0] == n[-3] == 1
    assert n[1] == n[-2] == 2
    assert n[2] == n[-1] == 0

    assert m[:2] == (3, 4)
    assert n[:2] == (1, 2)

    assert m * n == Monomial((4, 6, 1))
    assert m / n == Monomial((2, 2, 1))

    assert m * (1, 2, 0) == Monomial((4, 6, 1))
    assert m / (1, 2, 0) == Monomial((2, 2, 1))

    assert m.gcd(n) == Monomial((1, 2, 0))
    assert m.lcm(n) == Monomial((3, 4, 1))

    assert m.gcd((1, 2, 0)) == Monomial((1, 2, 0))
    assert m.lcm((1, 2, 0)) == Monomial((3, 4, 1))

    assert m**0 == Monomial((0, 0, 0))
    assert m**1 == m
    assert m**2 == Monomial((6, 8, 2))
    assert m**3 == Monomial((9, 12, 3))

    raises(ExactQuotientFailed, lambda: m / Monomial((5, 2, 0)))
예제 #6
0
def itermonomials_degree_list_AGA(variables, max_degrees, min_degrees):
    """
    Returns a list of all monomials such that
    min_degrees[i] <= degree_list(monom)[i] <= max_degrees[i]
    for all monom in the list and all i.
    
    If max_degrees = [d_1, ..., d_n] and min_degrees = [e_1, ..., e_n],
    the number of monomials in the list is:
    
                (d_1 - e_1 + 1) * ... * (d_n - e_n + 1)
    """
    # input lists of same length?
    if len(variables) != len(max_degrees) or len(variables) != len(
            min_degrees):
        raise ValueError('all three input lists should be of same length')

    # length of each row to be formed
    columns = len(variables)

    # divider of row j while filling a column k.
    div_by = [1]

    # min_degrees = [0, ..., 0]?
    if sum(min_degrees) == 0:

        # compute the number of rows (monomials)
        rows = 1
        rows = Mul(*[rows * (max_degrees[i] + 1) for i in range(columns)])

        # initialize table m having 'rows' rows, where
        # each row is filled with 'columns' zeros.
        m = [[0 for i in range(columns)] for i in range(rows)]

        # copy list max_degrees
        temp = max_degrees[:]

        # update table m
        while sum(temp) != 0:

            # pick k-th column to fill
            k = temp.index(max(temp))
            temp[k] = 0

            # fill in k-th column
            for j in range(rows):
                m[j][k] = floor(j / Mul(*div_by)) % (max_degrees[k] + 1)

            # update div_by for next column
            div_by.append(max_degrees[k] + 1)

    # min_degrees != [0, ..., 0]
    else:

        # here diff_degrees in the role of max_degrees
        diff_degrees = [
            max_degrees[i] - min_degrees[i] for i in range(columns)
        ]

        if any(x < 0 for x in diff_degrees):
            raise ValueError(
                'min_degrees[i] should be <= max_degrees[i] for all i.')

        # compute the number of rows (monomials)
        rows = 1
        rows = Mul(*[rows * (diff_degrees[i] + 1) for i in range(columns)])

        # initialize table m having 'rows' rows, where
        # each row is filled with 'columns' zeros.
        m = [[0 for i in range(columns)] for i in range(rows)]

        # copy the list diff_degrees
        temp = diff_degrees[:]

        # update table m
        while sum(temp) != 0:

            # pick k-th column to fill
            k = temp.index(max(temp))
            temp[k] = 0

            # fill in k-th column
            for j in range(rows):
                m[j][k] = floor(j / Mul(*div_by)) % (diff_degrees[k] + 1)

            # update div_by for next column
            div_by.append(diff_degrees[k] + 1)

        # add min_degrees to each row
        m = [[m[j][k] + min_degrees[k] for k in range(columns)]
             for j in range(rows)]

    return [Monomial(m[j]).as_expr(*variables) for j in range(rows)]