コード例 #1
0
ファイル: findNewtPoly.py プロジェクト: nbliss/polyDiv
"""
For the polynomial p, finds the leading monomial for a
bunch of different weight vectors to check that they are
the Newton polygon vertices (they are, at least for this polygon)
"""
import newLT
from sympy import symbols,Poly
x,y = symbols('x,y')
symbolList = [x,y]
p = Poly(y**4+1+x**4+x**4*y**2+x**3*y**3+y+y**2+y**3+x*y+x**2*y+x*y**2+x**2*y**2+x*y**3+x**4*y)
ltFunct = lambda v:newLT.monomialOrdering(symbolList,ordering='weighted',weightVector=v).LT(p)
vertices = []
for i in xrange(40):
	for j in xrange(40):
		for sgn in [(1,1),(-1,1),(1,-1),(-1,-1)]:
			newguy = ltFunct((sgn[0]*i/40.0,sgn[1]*j/39.0))
			if newguy not in vertices: 
				vertices.append(newguy)
for vertex in vertices:
	print vertex.as_expr()
コード例 #2
0
ファイル: buchberger-moller.py プロジェクト: nbliss/polyDiv
def buchMol(points, ordering, weightVector=(1, 1, 1)):
    """
	Given X = [(c11,c12,...,c1n),...,(cs1,cs2,...,csn)] affine point set
	and ordering 'lex','grlex','grevlex', or 'weighted' (plus a weight vector)
	computes reduced Groebner basis and Q-basis of the ring mod the ideal
	"""
    from sympy import symbols, Poly, div, Rational, Matrix
    from newLT import monomialOrdering

    dim = len(points[0])
    for pt in points:  # check that all pts have same dimension
        assert len(pt) == dim
    if dim in [1, 2, 3]:
        l = ["x", "x,y", "x,y,z"]
        varlist = symbols(l[dim - 1])
    else:
        varstring = "x0"
        for i in xrange(1, dim):
            varstring += ",x" + str(i)
        varlist = symbols(varstring)
    monClass = monomialOrdering(varlist, ordering, weightVector)
    counter = 0  # keep track of number of rows of matrix & size of S
    G, normalSet, S = [], [], []
    L = [Poly(1, varlist, domain="QQ")]
    M = Matrix(0, len(points), [])
    pivots = {}  # {column:row}
    while L != []:
        # step 2:
        t = L[0]
        for elmt in L:
            if monClass.compare(t.as_dict().keys()[0], elmt.as_dict().keys()[0]):
                t = elmt
        L.remove(t)
        evalVector = Matrix(1, len(points), [t.eval(pt) for pt in points])
        print "hi"
        print M
        print evalVector
        v, a = vecReduce(evalVector, M, pivots)
        print v
        viszero = False
        if firstNonzero(v) == -1:
            viszero = True
        toAdd = t
        for i in xrange(counter):
            toAdd += Poly(-1, varlist) * Poly(a[i], varlist) * S[i]
        if viszero:
            G.append(toAdd)
            for mon in L:
                if div(t, mon)[1] == 0:
                    L.remove(mon)
        else:
            pivSpot = firstNonzero(v)
            pivots[pivSpot] = M.shape[0]
            M = M.col_join(v)
            S.append(toAdd)
            counter += 1
            normalSet.append(t)
            for variable in varlist:
                toCheck = Poly(variable, varlist) * t
                isMultiple = False
                for elmt in L:
                    if div(elmt, toCheck)[1] == 0:
                        isMultiple = True
                        break
                if isMultiple:
                    continue
                for elmt in G:
                    if div(monClass.LT(elmt), toCheck)[1] == 0:
                        isMultiple = True
                        break
                if isMultiple == False:
                    L.append(toCheck)
    return G, normalSet