@@ -855,31 +855,28 @@ def macaulay_matrix(self, degree,
855855 homogeneous = False ,
856856 variables = None ,
857857 return_indices = False ,
858- remove_zero = False ):
858+ remove_zero = False ,
859+ reverse_column_order = False ,
860+ row_order = None ):
859861 r"""
860- Return the Macaulay matrix of degree ``degree`` of this sequence
862+ Return the Macaulay matrix of degree ``degree`` for this sequence
861863 of polynomials.
862864
863865 INPUT:
864866
865- - ``remove_zero`` -- boolean (default: ``False``);
866- when ``False``, the columns of the Macaulay matrix are all the
867- monomials of the polynomial ring up to degree ``degree``, when
868- ``True``, the columns of the Macaulay matrix are only the monomials
869- that effectively appear in the sequence of polynomials
870-
871867 - ``homogeneous`` -- boolean (default: ``False``);
872- when ``False``, the polynomials in the sequence are not necessarily
873- homogeneous and the rows of the Macaulay matrix represent all
874- possible products between a polynomial of this sequence and the
875- monomials of the polynomial ring up to degree ``degree``;
876- when ``True``, the polynomials in the sequence must be homogeneous,
877- and the rows of the Macaulay matrix represent all possible products
878- between a polynomial of this sequence and a monomial of the
879- polynomial ring such that the product is homogeneous of degree equal
880- to the sum of ``degree`` and the maximum degree in the sequence
881-
882- - ``variables`` -- boolean (default: ``None``);
868+ when ``False``, the polynomials in the sequence do not need to be homogeneous
869+ the rows of the Macaulay matrix correspond to all possible products
870+ between a polynomial from the sequence and monomials of the polynomial
871+ ring up to degree ``degree``;
872+ when ``True``, all polynomials in the sequence must be homogeneous.
873+ the rows of the Macaulay matrix then represent all possible products
874+ between a polynomial in the sequence and a monomial of the polynomial
875+ ring such that the resulting product is homogeneous of degree
876+ ``degree + d_max``, where ``d_max`` is the maximum degree among the
877+ input polynomials
878+
879+ - ``variables`` -- list (default: ``None``);
883880 when ``None``, ``variables`` is interpreted as being the list of
884881 all variables of the ring of the polynomials in the sequence;
885882 otherwise ``variables`` is a list describing a subset of these
@@ -894,6 +891,28 @@ def macaulay_matrix(self, degree,
894891 index in the sequence of the input polynomial, whose product
895892 describes the corresponding row of the matrix; the second one is the
896893 list of monomials corresponding to the columns of the matrix
894+
895+ - ``remove_zero`` -- boolean (default: ``False``);
896+ when ``False``, all monomials of the polynomial ring up to
897+ degree ``degree``are included as columns in the Macaulay matrix;
898+ when ``True``, only the monomials that actually appear in the polynomial
899+ sequence are included
900+
901+ - ``reverse_column_order`` -- boolean (default: ``False``);
902+ when ``False``, by default the order for the columns is the same
903+ as the order of the polynomial ring;
904+ when ``True``, the order of the rows is the reverse of the order
905+ of the monomial of the polynomial ring
906+
907+ - ``row_order`` -- str (default: ``None``);
908+ determines the ordering of the columns in the matrix;
909+ when ``None`` (or ``"POT"``), a **position over term** (POT) order is used:
910+ columns are first ordered by the index of the corresponding polynomial
911+ in the sequence, and then by the (multiplicative) monomials;
912+ when set to ``"TOP"``, the columns follow a **term over position**
913+ (TOP) order: columns are firt ordered by the (multiplicative) monomials
914+ and then by the index of the corresponding polynomial
915+ in the sequence
897916
898917 EXAMPLES::
899918
@@ -978,6 +997,22 @@ def macaulay_matrix(self, degree,
978997 ...
979998 ValueError: the degree must be nonnegative
980999
1000+ sage: Sequence([y*z + z^2 - 1,f2=x*y - z^2 - x ]).macaulay_matrix(0, homogeneous=True)
1001+ Traceback (most recent call last):
1002+ ...
1003+ ValueError: all the polynomials of the sequence must be homogeneous
1004+
1005+ sage:Sequence([y*z + z^2 - 1,x*y - z^2 - x ]).macaulay_matrix(0, row_order="POP")
1006+ Traceback (most recent call last):
1007+ ...
1008+ ValueError: the argument of ``row_order`` must be ``None``, "TOP" or "POT"
1009+
1010+ sage: R1.<t>=PolynomialRing(GF(3))
1011+ sage: Sequence([y*z + z^2 - 1,x*y - z^2 - x ]).macaulay_matrix(1, variables=[t])
1012+ Traceback (most recent call last):
1013+ ...
1014+ ValueError: the variables must be in the polynomial ring
1015+
9811016 REFERENCES:
9821017
9831018 [Mac1902]_, Chapter 1 of [Mac1916]_
@@ -995,15 +1030,24 @@ def macaulay_matrix(self, degree,
9951030 for i in range (m ):
9961031 if not (self [i ].is_homogeneous ()):
9971032 raise ValueError ('all the polynomials of the sequence must be homogeneous' )
998-
1033+ if not (row_order is None or row_order == "TOP" or row_order == "POT" ) :
1034+ raise ValueError ('the argument of ``row_order`` must be ``None``, "TOP" or "POT" ' )
9991035
10001036 # handle subset of variables
10011037 S = self .ring ()
10021038 F = S .base_ring ()
10031039 if variables is None :
10041040 R = S
10051041 else :
1006- R = PolynomialRing (F , variables )
1042+ vars_names_base_ring = list (S .variable_names ())
1043+ for x in variables :
1044+ if str (x ) not in vars_names_base_ring :
1045+ raise ValueError ("the variables must be in the polynomial ring" )
1046+ try :
1047+ R = PolynomialRing (F , variables ,
1048+ order = S .term_order ())
1049+ except ValueError :
1050+ raise ValueError ("impossible to use the original term order (most likely because it was a block order). Please specify the term order for the subring" )
10071051
10081052 # maximum degree for monomials appearing in considered polynomial multiples
10091053 target_degree = self .maximal_degree () + degree
@@ -1036,13 +1080,35 @@ def macaulay_matrix(self, degree,
10361080 # that will be used to construct the rows
10371081 row_indices = []
10381082 if homogeneous :
1039- for i in range (m ):
1040- deg = target_degree - self [i ].degree ()
1041- row_indices += [(mon , i ) for mon in R_monomials_of_degree [deg ]]
1042- else :
1043- for i in range (m ):
1044- for deg in range (target_degree - self [i ].degree () + 1 ):
1083+ # order the rows with POT (or None)
1084+ if row_order is None or row_order == "TOP" :
1085+ for i in range (m ):
1086+ deg = target_degree - self [i ].degree ()
1087+ R_monomials_of_degree [deg ].sort ()
10451088 row_indices += [(mon , i ) for mon in R_monomials_of_degree [deg ]]
1089+ # order the rows with TOP
1090+ else :
1091+ R_monomials_of_degree [deg ].sort ()
1092+ for mon in R_monomials_of_degree [deg ]:
1093+ row_indices += [(mon , i ) for i in range (m )]
1094+ else :
1095+ #order the row with POT (or None)
1096+ if row_order is None or row_order == "TOP" :
1097+ for i in range (m ):
1098+ R_monomials_usefull = []
1099+ for deg in range (target_degree - self [i ].degree () + 1 ):
1100+ R_monomials_usefull += R_monomials_of_degree [deg ]
1101+ R_monomials_usefull .sort ()
1102+ row_indices += [(mon , i ) for mon in R_monomials_usefull ]
1103+ #order the row with TOP
1104+ else :
1105+ R_monomials_usefull = []
1106+ for deg in range (max_deg + 1 ):
1107+ R_monomials_usefull += R_monomials_of_degree [deg ]
1108+ R_monomials_usefull .sort ()
1109+ for mon in R_monomials_usefull :
1110+ row_indices += [(mon , i ) for i in range (m )
1111+ if mon .degree ()<= target_degree - self [i ].degree () + 1 ]
10461112
10471113 # compute sorted list of monomials that index the columns
10481114 if remove_zero :
@@ -1054,9 +1120,11 @@ def macaulay_matrix(self, degree,
10541120 else :
10551121 column_indices = [mon for deg in range (target_degree + 1 )
10561122 for mon in S_monomials_of_degree [deg ]]
1057- column_indices .sort (reverse = True )
1123+ column_indices .sort (reverse = not reverse_column_order )
10581124 dict_columns = {mon .exponents ()[0 ] : j for (j , mon ) in enumerate (column_indices )}
10591125
1126+
1127+
10601128 # actually build the Macaulay matrix
10611129 macaulay_mat = matrix (F , len (row_indices ), len (column_indices ))
10621130 for (ii , (mrow , i )) in enumerate (row_indices ):
0 commit comments