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 sdp_spoly(p1, p2, u, O, K): """ Compute LCM(LM(p1), LM(p2))/LM(p1)*p1 - LCM(LM(p1), LM(p2))/LM(p2)*p2 This is the S-poly provided p1 and p2 are monic """ LM1 = sdp_LM(p1, u) LM2 = sdp_LM(p2, u) LCM12 = monomial_lcm(LM1, LM2) m1 = monomial_div(LCM12, LM1) m2 = monomial_div(LCM12, LM2) s1 = sdp_mul_term(p1, (m1, K.one), u, O, K) s2 = sdp_mul_term(p2, (m2, K.one), u, O, K) s = sdp_sub(s1, s2, u, O, K) return s
def lbp_sub(f, g, u, O, K): """ Subtract labeled polynomial g from f. The signature and number of the difference of f and g are signature and number of the maximum of f and g, w.r.t. lbp_cmp. """ if sig_cmp(Sign(f), Sign(g), O) < 0: max_poly = g else: max_poly = f ret = sdp_sub(Polyn(f), Polyn(g), u, O, K) return lbp(Sign(max_poly), ret, Num(max_poly))
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()