Not able to generate a simple list of polynomial. I am getting list of list.

asked 2021-01-09 22:35:37 -0600

Sri1729 gravatar image
 def quad_polynomial(field, n,m):
    Polynomial_Ring1=PolynomialRing(K,['x%s'%p for p in range(1,n+1)])
    x1=Polynomial_Ring1.gens()
    gen_Polynomial_Ring1 = matrix(x1)
    list_of_quadratic_part=[0 for i in range(m)]
    for i in range(m):
        list_of_quadratic_part[i]=gen_Polynomial_Ring1*(random_matrix(K,n))*gen_Polynomial_Ring1.transpose()
        #print(list_of_quadratic_part[i])

    return list_of_quadratic_part

The output I am getting is like this:

quad_polynomial(K,2,3)
[[x1*x2 + (a + 1)*x2^2], [x1^2 + (a + 1)*x1*x2], [x1^2 + (a + 1)*x2^2]]

It is giving me list of list. I want a output like

 [x1*x2 + (a + 1)*x2^2, x1^2 + (a + 1)*x1*x2, x1^2 + (a + 1)*x2^2]

How can I do it?

edit retag flag offensive close merge delete

Comments

1

You can use parent(t) to know in what t lives. In your case, each element of the list is a matrix.

FrédéricC gravatar imageFrédéricC ( 2021-01-10 04:32:13 -0600 )edit

not sure I understand the question , Sorry if I dont !.

K=GF(7)
def quad_polynomial(field, n,m):
    Polynomial_Ring1=PolynomialRing(K,['x%s'%p for p in range(1,n+1)])
    x1=Polynomial_Ring1.gens()
    gen_Polynomial_Ring1 = matrix(x1)
    list_of_quadratic_part=[0 for i in range(m)]
    for i in range(m):
        list_of_quadratic_part[i]=gen_Polynomial_Ring1*(random_matrix(K,n))*gen_Polynomial_Ring1.transpose()
        #print(list_of_quadratic_part[i])

    return list_of_quadratic_part

qpML= quad_polynomial(K,2,3)
show(qpML)
qpL=[]
for pol in qpML :
    show(pol[0][0])
    qpL.append(pol[0][0])
show(qpL)
ortollj gravatar imageortollj ( 2021-01-13 07:14:30 -0600 )edit