コード例 #1
0
def dmp_list_terms(f, u, K, order=None):
    """
    List all non-zero terms from ``f`` in the given order ``order``.

    Examples
    ========

    >>> from sympy.polys.domains import ZZ
    >>> from sympy.polys.densebasic import dmp_list_terms

    >>> f = ZZ.map([[1, 1], [2, 3]])

    >>> dmp_list_terms(f, 1, ZZ)
    [((1, 1), 1), ((1, 0), 1), ((0, 1), 2), ((0, 0), 3)]
    >>> dmp_list_terms(f, 1, ZZ, order='grevlex')
    [((1, 1), 1), ((1, 0), 1), ((0, 1), 2), ((0, 0), 3)]

    """
    terms = _rec_list_terms(f, u, ())

    if not terms:
        return [((0,)*(u + 1), K.zero)]

    if order is None:
        return terms
    else:
        return sdp_sort(terms, monomial_key(order))
コード例 #2
0
ファイル: groebnertools.py プロジェクト: nvlrules/sympy
def matrix_fglm(F, u, O_from, O_to, K):
    """
    Converts the reduced Groebner basis ``F`` of a zero-dimensional
    ideal w.r.t. ``O_from`` to a reduced Groebner basis
    w.r.t. ``O_to``.

    **References**
    J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient
    Computation of Zero-dimensional Groebner Bases by Change of
    Ordering

    J.C. Faugere's lecture notes:
    http://www-salsa.lip6.fr/~jcf/Papers/2010_MPRI5e.pdf
    """
    old_basis = _basis(F, u, O_from, K)
    M = _representing_matrices(old_basis, F, u, O_from, K)

    # V contains the normalforms (wrt O_from) of S
    S = [(0,) * (u + 1)]
    V = [[K.one] + [K.zero] * (len(old_basis) - 1)]
    G = []

    L = [(i, 0) for i in xrange(u + 1)]  # (i, j) corresponds to x_i * S[j]
    L.sort(key=lambda (k, l): O_to(_incr_k(S[l], k)), reverse=True)
    t = L.pop()

    P = _identity_matrix(len(old_basis), K)

    while True:
        s = len(S)
        v = _matrix_mul(M[t[0]], V[t[1]], K)
        _lambda = _matrix_mul(P, v, K)

        if all(_lambda[i] == K.zero for i in xrange(s, len(old_basis))):
            # there is a linear combination of v by V

            lt = [(_incr_k(S[t[1]], t[0]), K.one)]
            rest = sdp_strip(sdp_sort([(S[i], _lambda[i]) for i in xrange(s)], O_to))
            g = sdp_sub(lt, rest, u, O_to, K)

            if g != []:
                G.append(g)

        else:
            # v is linearly independant from V
            P = _update(s, _lambda, P, K)
            S.append(_incr_k(S[t[1]], t[0]))
            V.append(v)

            L.extend([(i, s) for i in xrange(u + 1)])
            L = list(set(L))
            L.sort(key=lambda (k, l): O_to(_incr_k(S[l], k)), reverse=True)

        L = [(k, l) for (k, l) in L if all(monomial_div(_incr_k(S[l], k), sdp_LM(g, u)) is None for g in G)]

        if not L:
            G = [sdp_monic(g, K) for g in G]
            return sorted(G, key=lambda g: O_to(sdp_LM(g, u)), reverse=True)

        t = L.pop()
コード例 #3
0
ファイル: groebnertools.py プロジェクト: lazovich/sympy
def matrix_fglm(F, u, O_from, O_to, K):
    """
    Converts the reduced Groebner basis ``F`` of a zero-dimensional
    ideal w.r.t. ``O_from`` to a reduced Groebner basis
    w.r.t. ``O_to``.

    **References**
    J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient
    Computation of Zero-dimensional Groebner Bases by Change of
    Ordering

    J.C. Faugere's lecture notes:
    http://www-salsa.lip6.fr/~jcf/Papers/2010_MPRI5e.pdf
    """
    old_basis = _basis(F, u, O_from, K)
    M = _representing_matrices(old_basis, F, u, O_from, K)

    # V contains the normalforms (wrt O_from) of S
    S = [(0, ) * (u + 1)]
    V = [[K.one] + [K.zero] * (len(old_basis) - 1)]
    G = []

    L = [(i, 0) for i in xrange(u + 1)]  # (i, j) corresponds to x_i * S[j]
    L.sort(key=lambda (k, l): O_to(_incr_k(S[l], k)), reverse=True)
    t = L.pop()

    P = _identity_matrix(len(old_basis), K)

    while True:
        s = len(S)
        v = _matrix_mul(M[t[0]], V[t[1]], K)
        _lambda = _matrix_mul(P, v, K)

        if all([_lambda[i] == K.zero for i in xrange(s, len(old_basis))]):
            # there is a linear combination of v by V

            lt = [(_incr_k(S[t[1]], t[0]), K.one)]
            rest = sdp_strip(
                sdp_sort([(S[i], _lambda[i]) for i in xrange(s)], O_to))
            g = sdp_sub(lt, rest, u, O_to, K)

            if g != []:
                G.append(g)

        else:
            # v is linearly independant from V
            P = _update(s, _lambda, P, K)
            S.append(_incr_k(S[t[1]], t[0]))
            V.append(v)

            L.extend([(i, s) for i in xrange(u + 1)])
            L = list(set(L))
            L.sort(key=lambda (k, l): O_to(_incr_k(S[l], k)), reverse=True)

        L = [(k, l) for (k, l) in L if \
            all([monomial_div(_incr_k(S[l], k), sdp_LM(g, u)) is None for g in G])]

        if L == []:
            return sorted(G, key=lambda g: O_to(sdp_LM(g, u)), reverse=True)

        t = L.pop()