Macaulay2 » Documentation
Packages » Macaulay2Doc > matrices > determinants and minors
next | previous | forward | backward | up | index | toc

determinants and minors

The command det can be used to compute the determinant of a square matrix.
i1 : R = ZZ[a..i];
i2 : det matrix{{a,b},{c,d}}

o2 = - b*c + a*d

o2 : R
Macaulay2 can use three different algorithms to compute determinants: the Cofactor method, which expands a determinant using the standard cofactor approach, and Bareiss which uses a fraction-free variant of Gaussian elimination to compute a determinant. The Dynamic algorithm implements a version of cofactor expansion, with caching of intermediate results. The algorithm to use may be chosen using the optional Strategy argument:
i3 : m = matrix{{0,a,b},{a+b,a,d},{e,f,g}}

o3 = | 0   a b |
     | a+b a d |
     | e   f g |

             3      3
o3 : Matrix R  <-- R
i4 : det(m, Strategy => Cofactor)

                                2     2
o4 = - a*b*e + a*d*e + a*b*f + b f - a g - a*b*g

o4 : R
i5 : minors(2,m, Strategy => Bareiss)

               2                                          2
o5 = ideal (- a  - a*b, -a*e, - a*e + a*f + b*f, - a*b - b , -b*e, - d*e +
     ------------------------------------------------------------------------
     a*g + b*g, - a*b + a*d, - b*f + a*g, - d*f + a*g)

o5 : Ideal of R
i6 : exteriorPower(2,m, Strategy => Dynamic)

o6 = | -a2-ab    -ab-b2    -ab+ad |
     | -ae       -be       -bf+ag |
     | -ae+af+bf -de+ag+bg -df+ag |

             3      3
o6 : Matrix R  <-- R
One warning is in order here: the Bareiss algorithm requires division in the base ring, and so can yield the INCORRECT answer if the base ring contains zero divisors. However, the Bareiss algorithm is often dramatically faster than the cofactor method, unless the matrix is particularly sparse. Consequently, the default strategy for rings which are fields or are not quotients of polynomial rings is Bareiss, while the default for quotients of polynomial rings that are not (declared to be) fields is Cofactor. The Dynamic algorithm can sometimes also result in significant speedups compared to Cofactor and Bareiss, at the cost of a slight memory overhead.

The command minors can be used to construct the ideal generated by the n by n minors of a matrix. Recall that the n by n minors of a matrix are the determinants of the n by n submatrices of a matrix.
i7 : R = QQ[x,y,z];
i8 : f = matrix{{x,y,z},{y,z,x^2}}

o8 = | x y z  |
     | y z x2 |

             2      3
o8 : Matrix R  <-- R
i9 : I = minors(2,f)

               2         3         2     2
o9 = ideal (- y  + x*z, x  - y*z, x y - z )

o9 : Ideal of R
Sometimes finer control is needed when one is computing the ideal of minors of a larger matrix. Compute the ideal of some determinants using minors with optional arguments as in
i10 : R = ZZ[a..i];
i11 : M = genericMatrix(R,a,3,3);

              3      3
o11 : Matrix R  <-- R
i12 : minors(2,M,First => {{0,1},{1,2}}, Limit => 3)

o12 = ideal (- e*g + d*h, - f*g + d*i, - f*h + e*i)

o12 : Ideal of R
The argument to the optional argument First is the list of row and column positions to use for the first minor. Starting at this first minor, we then compute three minors.