-- This is code related to lectures from Feb 27 -- Math 615, Winter 2013 -- By: Daniel Erman -- How to define functions in M2. -- The following function uses the Koszul complex to compute -- the depth on an ideal on a module. -- Input: an ideal I and a module M. -- (I amd M must be defined over the same ring.) -- Output: depth(I,M). depthKoszul = (I,M) ->( n := numgens I; K := (koszul gens I)**M; scan(n+1,i-> if HH_(n-i)(K) != 0 then break i) ) -- Examples: S = QQ[x,y,z] m = ideal(x,y,z) M = S^1/(x^2,x*y) depthKoszul(m,M) I = ideal(y^2,x+y) depthKoszul(I,M) -- The following function computes the projective dimension -- of an R-module over a ring where there might exist infinite -- resolutions. It relies on the Auslander--Buchsbaum -- theorem, which implies that if pdim M>dim R then -- pdim M = infinity. -- -- Input: a module M -- Output: the projective dimension of M (possibly infinity) improvedPDim = (M)->( R := ring M; d := dim R; r := res(M, LengthLimit => d+1); if length r == d+1 then return infinity; length r ) R = QQ[x]/ideal(x^2); M = R^1/ideal(x) improvedPDim(M) -- The following function uses the Auslander--Buchsbaum -- theorem to compute the depth of the maximal ideal -- on a module. -- Input: a module M. -- Output: depth(m,M), where m=maximal ideal depthAB = (M) ->( R := ring M; p := improvedPDim M; if p == infinity then return( "M does not have finite projective dimension"); dim R - p ) R = QQ[x]/ideal(x^2); M = R^1/ideal(x) depthAB(M) m = ideal(x) depthKoszul(m,M) -- Input: M a module over a polynomial ring S -- Output: whether M is a Cohen-Macaulay S-module or not. isCohenMacaulay = (M) ->( pdim M == codim M )