Determinant of large symbolic matrix in Sage

79 Views Asked by At

I have a 12-by-12 matrix whose entries are elements of a polynomial ring in 24 variables over the real numbers.

Short version: It seems Sage is computing the determinant incorrectly (or I am misunderstanding something)

Long version: The full code is pasted at the end, for reference.

Most entries of the matrix are zero, but each non-zero entry of the matrix is a random real number times one of the variables. So there are several lines of code that all look like this:

K[0,0] = x1 * random()

etc.

I want to determine the number of terms in the determinant. The last line of my code is:

print(K.det().number_of_terms())

The weird thing is that I get a different result every time I run the code. I would expect the determinant to have the same number of terms every time, even with the random numbers, since the variables are always in the same positions.

Also, if I print the determinant, I get terms that are nonsense. For example, I get terms where some of the variables are cubed (to the third power), but each variable appears at most in a 2x2 block of the matrix, so there should be no exponents more than 2.

Question: Why is Sage seemingly computing the determinant incorrectly, and why is the result different every time I run the code?

The full code is pasted below:

R = PolynomialRing(RR, ('x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10', 'x11', 'x12', 'x13', 'x14', 'x15', 'x16', 'x17', 'x18', 'x19', 'x20', 'x21', 'x22', 'x23', 'x24'))
R.inject_variables()

K = Matrix(R, 12,12)
K[0,0]   = x1*random()
K[0,1]   = x2*random()
K[0,2]   = x2*random()
K[1,1]   = x3*random()
K[1,2]   = x3*random()
K[1,3]   = x4*random()
K[2,0]   = x5*random()
K[3,0]   = x5*random()
K[2,1]   = x6*random()
K[2,2]   = x6*random()
K[3,1]   = x6*random()
K[3,2]   = x6*random()
K[2,4]   = x21*random()
K[3,4]   = x21*random()
K[2,5]   = x22*random()
K[2,6]   = x22*random()
K[3,5]   = x22*random()
K[3,6]   = x22*random()
K[4,1]   = x7*random()
K[4,2]   = x7*random()
K[5,1]   = x7*random()
K[5,2]   = x7*random()
K[4,3]   = x8*random()
K[5,3]   = x8*random()
K[4,5]   = x23*random()
K[4,6]   = x23*random()
K[5,5]   = x23*random()
K[5,6]   = x23*random()
K[4,7]   = x24*random()
K[5,7]   = x24*random()
K[6,4]   = x9*random()
K[7,4]   = x9*random()
K[6,5]   = x10*random()
K[6,6]   = x10*random()
K[7,5]   = x10*random()
K[7,6]   = x10*random()
K[6,8]   = x13*random()
K[7,8]   = x13*random()
K[6,9]   = x14*random()
K[6,10]  = x14*random()
K[7,9]   = x14*random()
K[7,10]  = x14*random()
K[8,5]   = x11*random()
K[8,6]   = x11*random()
K[9,5]   = x11*random()
K[9,6]   = x11*random()
K[8,7]   = x12*random()
K[9,7]   = x12*random()
K[8,9]   = x15*random()
K[8,10]  = x15*random()
K[9,9]   = x15*random()
K[9,10]  = x15*random()
K[8,11]  = x16*random()
K[9,11]  = x16*random()
K[10,8]  = x17*random()
K[10,9]  = x18*random()
K[10,10] = x18*random()
K[11,9]  = x19*random()
K[11,10] = x19*random()
K[11,11] = x20*random()

print(K.det().number_of_terms())
0

There are 0 best solutions below