Ask Your Question

Revision history [back]

In the code you added, the ideal ends up in a univariate polynomial ring over a multivariate polynomial ring, rather than a multivariate polynomial ring with an extra variable.

Here is a version (avoiding the symbolic ring) where the ideal ends up in the correct ring:

mu1, mu2, mu = [1,1],[1,1],[2,2]

def mu_vars(mu):
    svs = [] 
    for i in range(1,2):
        for j in range(i+1,2+1):
            for k in range(0,mu[j-1]):
                svs.append('x_{}_{}_{}'.format(i,j,k+1))
    return svs

svs = mu_vars(mu) 
R = PolynomialRing(GF(101), ['s'] + svs, order='degrevlex')
s = R.gen(0)

def insert_row(mat,row):
    return matrix(R, mat.rows()[:mat.nrows()]+[row]+mat.rows()[mat.nrows():])

def upper_row_matrix(row):
    symbMat = []
    for i in range(row,2):
        mat = matrix(R, mu[row-1]-1,mu[i])
        v = [v for v in svs if v.startswith('x_{}_{}'.format(row,i+1))]
        d = insert_row(mat,v)
        symbMat.append(d)
    return symbMat

def mu_matrix(mu1,mu2):
    x = polygen(R)
    symbMat = []
    for i in range(0,2):
        row = [] + [0]*i
        p = x**(mu1[i])*(x-s)**(mu2[i])
        row.append(companion_matrix(p.coefficients(sparse=False),format='bottom'))
        row += upper_row_matrix(i+1)
        symbMat.append(row)
    return block_matrix(R,symbMat)

m = mu_matrix(mu1,mu2)

R.ideal(m.minors(2)[29]).groebner_basis()

You may want to adapt the monomial ordering.

A good rule of thumb is that it is better to be explicit than implicit: when defining matrices and ideals, specify the ring that they are to be defined over. And avoid the symbolic ring when possible.

(The above could also be adapted so that the extra variable s is not in R but in a second polynomial ring.)