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()
def sdm_from_dict(d, O): """ Create an sdm from a dictionary. Here ``O`` is the monomial order to use. >>> from sympy.polys.distributedmodules import sdm_from_dict >>> from sympy.polys import QQ, lex >>> dic = {(1, 1, 0): QQ(1), (1, 0, 0): QQ(2), (0, 1, 0): QQ(0)} >>> sdm_from_dict(dic, lex) [((1, 1, 0), 1/1), ((1, 0, 0), 2/1)] """ return sdp_strip(sdp_from_dict(d, O))
def test_sdp_strip(): assert sdp_strip([((2, 2), 0), ((1, 1), 1), ((0, 0), 0)]) == [((1, 1), 1)]
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()