--==================================================================-- -- Tutorial 4: Hilbert Functions and Counting Monomials -- --==================================================================-- -- Use C-x 2 to get a horizontally split window or -- Use C-x 3 to get a vertically split window. -- Select the lower (or right) window and Hit F12 to start M2. -- Hit F11 to send code from this screen to M2. -- for help with M2 type (works in version 1.1) viewHelp ---------------------------------------------------------------------- -- Gradings and Degrees -- ---------------------------------------------------------------------- -- Unless otherwise stated, Macaulay 2 will view a polynomial ring or -- a quotient ring, as being standard graded. Check it out: A = ZZ/101[x] basis(1,A) -- the ZZ/101 generator of degree 1 basis(2,A) -- the ZZ/101 generator of degree 2 basis(16,A) -- the ZZ/101 generator of degree 16 -- How do you change the degree of x? -- Change the degree of x to 3, and do a similar computation with -- "basis" as we did above to verify that your ring is graded -- correctly. -- Now let's work with two variables. A = ZZ/101[x,y] basis(1,A) -- the ZZ/101 generators of degree 1 basis(2,A) -- the ZZ/101 generators of degree 2 basis(3,A) -- the ZZ/101 generators of degree 3 -- Change the degree of x to 2 and the degree of y to 3, just like -- Glenn did in class. -- Check out those generators of the n-graded part, where n is a -- natural number of your choosing. Pick some natural numbers that -- show something interesting--the degree 2 part is rather boring. -- Time for a multigrading. Consider A = ZZ/101[x,y] -- Set the degree of x to be (1,0), and the degree of y to be (0,1). -- Big tip: include the option "Heft=>{1,1}" or else Macaulay 2 won't -- be very happy. A = ZZ/101[x,y] -- Finally, consider A = ZZ/101[x,y,z] -- with the degree of x being 3, the degree of y being 4, and the -- degree of z being 5. Compute some generators of homogeneous graded -- components! ---------------------------------------------------------------------- -- Hilbert Functions and Hilbert Series -- ---------------------------------------------------------------------- -- Macaulay 2 loves to compute Hilbert functions and Hilbert series. -- Compute the Hilbert series and a few values of the Hilbert -- functions for the above examples. -- Consider the following graded rings. A=ZZ/101[x,y]/(x^3,y^7) B=ZZ/101[x,y]/(x^4) -- Work the following four problems for both of the above rings. -- Compute the Hilbert series. Observe that the numerator is a -- polynomial that has T=1 as a zero. Can you find a way to reduce -- this to an expression like the one in exercise 4.13 from your -- homework? -- What is the polynomial that is guaranteed to exist by exercise -- 4.13? Note: This polynomial is called the Hilbert polynomial. -- For what values of T is the Hilbert polynomial equal to the Hilbert -- function? -- Macaulay 2 can also compute Hilbert polynomials. viewHelp hilbertPolynomial -- Compute the Hilbert polynomials of the above rings using this -- command, and compare to your previous answer. ---------------------------------------------------------------------- -- Counting Monomials -- ---------------------------------------------------------------------- -- Now we're going to implement the queens problem from Section 2 of -- Counting Monomials. restart n = 3; -- we'll start with the 3x3 chess board toList((n^2:{1,0})|(n^2:{0,1})) -- this makes a list that you may want -- to know. -- Now take the ring below, and use the list above, to help you assign -- the correct degrees to the elements. R = ZZ/2[x_{1,1}..x_{n,n},y_{1,1}..y_{n,n}] -- Now we want a function to determine whether or not a queen can -- attack a square. The parameters x and y will be x_{i,j} and -- y_{l,m}. The number d will be difference of the indices {i,j} and -- {l,m}. -- Macaulay 2 knows about logical conditionals: 1 == 0 and 1 == 1 1 == 0 or 1 == 1 -- Insert the correct conditional in the code below so that the -- function will return true if a queen can move from square {i,j} to -- square {l,m} and false otherwise. isMove = (x,y) -> ( d := (baseName x)#1 - (baseName y)#1; -- insert conditional here ); -- Give your isMove function a test run! -- We will use the isMove function to construct the ideal generated by -- the squares of the variables together with the products -- x_{i,j}y_{l,m} such that a queen can move from square {i,j} to -- square {l,m}. The following function will create the ideal -- generated by the above products. toMonomials = L -> x_{L_0,L_1}*y_{L_2,L_3}; movementSet = apply(select({1,1,1,1}..{n,n,n,n},i -> isMove(x_{i_0,i_1},y_{i_2,i_3})),toMonomials) -- Construct the ideal I generate by the aforementioned products -- together with the squares of the variables. I = ideal(movementSet) + -- insert the rest of the ideal -- Next we need the Hilbert function of R/I. Unfortunately the -- hilbertFunction command is slow, and we need lots of values of the -- function. So we will construct our own hilbFunc command. We first -- compute the Hilbert series and reduce it. In this case the Hilbert -- series is a polynomial as the graded components of R/I are all zero -- for large enough indices. HS=numerator reduceHilbert hilbertSeries I; -- The lengths of the graded components of R/I are the coefficients of -- the Hilbert series HS. Let's make a function to obtain those -- coefficients. hilbFunc = (k,u) -> ( coefficient((ring HS)_0^k*(ring HS)_1^u,HS) ) -- Now we need mu(k) from the paper. mu = k -> ( u:=0; while hilbFunc(k,u)!=0 do u=u+1; u-1 ); -- Evaluate mu(k) for k=1,...,n^2 -- Next we need the Psi function from the paper. -- Here is a naive Psi function: NaivePsi = (k,u) -> hilbFunc(k,u) - sum(u+1..mu(k),v -> binomial(v,u)*NaivePsi(k,v)); -- Here is another version of Psi. Psi = (k,u) -> ( muk:=mu(k); PsiActual(k,u,muk) ) PsiActual = (k,u,muk) -> hilbFunc(k,u)-sum(u+1..muk,v->binomial(v,u)*PsiActual(k,v,muk)) -- Why is the second version of Psi faster? -- Now we will make a table of values of Psi. Replace range1 and -- range2 below with appropriate ranges to see the important values of -- Psi. (These values depend on the values of mu(k) obtained before) matrix table(toList(range1),toList(range2),(k,u)->Psi(k,u)) --==================================================================-- -- FIN -- --==================================================================--