Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macaulay matrix for Sequence Multivariate Polynomials #39511

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b34f019
Test
MercedesHaiech Feb 10, 2025
832682b
Implement monomial_of_degree for Univariate Polynomials
MercedesHaiech Feb 13, 2025
30e8a0c
A method for computing the Macaulay Matrix
MercedesHaiech Feb 13, 2025
0ac2c2c
Merge branch 'macaulay' of github.com:MercedesHaiech/sage into macaulay
Feb 13, 2025
8804553
fix doctests
Feb 13, 2025
cd87cc2
biblio
Feb 13, 2025
21ee9bd
Fix lint
MercedesHaiech Feb 13, 2025
ed6a34e
Add TESTS for macaulay_matrix in multi_polynomial_sequence.py
MercedesHaiech Feb 14, 2025
757e461
Fix Lint
MercedesHaiech Feb 14, 2025
a2ac5ac
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 16, 2025
3074462
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
fdeda71
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
9de773b
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
9f9b955
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
b81703a
Update src/doc/en/reference/references/index.rst
MercedesHaiech Feb 26, 2025
8e9ebeb
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
f5ec7fa
Merge branch 'sagemath:develop' into macaulay
MercedesHaiech Feb 26, 2025
56b0170
Improvement in the documentation for macaulay matrix
MercedesHaiech Feb 26, 2025
9bd4116
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
fcd31f9
Update src/sage/rings/polynomial/multi_polynomial_sequence.py
MercedesHaiech Feb 26, 2025
61023af
Update src/sage/rings/polynomial/polynomial_ring.py
MercedesHaiech Feb 26, 2025
0bc2513
Update src/sage/rings/polynomial/polynomial_ring.py
MercedesHaiech Feb 26, 2025
260ab35
small fix in documentation
vneiger Feb 26, 2025
a4b8c9f
documentation, until (excluding) examples
vneiger Feb 26, 2025
e7d39b3
blank space
vneiger Feb 26, 2025
e2f4e5f
descriptions of examples + break long line of optional arguments
vneiger Feb 26, 2025
821343f
change the long output from (mon, poly) to (mon, i)
vneiger Feb 27, 2025
374e8be
change the long output from (mon, poly) to (mon, i): remove useless l…
vneiger Feb 27, 2025
8b030cf
change name to row_indices / column_indices
vneiger Feb 27, 2025
9a95aef
precompute the monomials of degree, to save some computation time
vneiger Feb 27, 2025
9dcd5e7
added some comments
vneiger Feb 27, 2025
19e4e2d
compute the monomial multiplications once for all
vneiger Feb 27, 2025
8496a77
improve performance: store the position of column monomials and use i…
vneiger Feb 27, 2025
d8f4de4
Merge pull request #1 from vneiger/macaulay_matrix
MercedesHaiech Feb 27, 2025
d1144ef
modify macaulay function
MercedesHaiech Feb 27, 2025
4ba7f3d
New feature for macaulay matrix: ordering for rows and colums
MercedesHaiech Feb 28, 2025
1b63dcf
Fixed LINT bug
MercedesHaiech Feb 28, 2025
50c83b7
Fixed new lint issues
MercedesHaiech Feb 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/doc/en/reference/references/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4744,7 +4744,10 @@ REFERENCES:

**M**

.. [Mac1916] \F.S. Macaulay. The algebraic theory of modular systems
.. [Mac1902] \F.S. Macaulay. *On some formula in elimination.*
London Mathematical Society, 33, 1902, 3--27

.. [Mac1916] \F.S. Macaulay. *The algebraic theory of modular systems*
Cambridge university press, 1916.

.. [Mac1995] \I. G. Macdonald, Symmetric functions and Hall
Expand Down
171 changes: 171 additions & 0 deletions src/sage/rings/polynomial/multi_polynomial_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,177 @@ def coefficient_matrix(self, sparse=True):
A, v = self.coefficients_monomials(sparse=sparse)
return A, matrix(R,len(v),1,v)

def macaulay_matrix(self, degree, remove_zero=False, homogeneous=False, set_variables=None, long_output=False) :
r"""
Return the Macaulay matrix of degree ``degree`` of this sequence
of polynomials.

INPUT:

- ``remove_zero`` -- boolean (default: ``False``);
when ``False``, the columns of
the Macaulay matrix are all the monomials of the polynomial
ring up to degree ``degree``,
when ``True``, the columns of the Macaulay matrix are only
the monomials that appears effectively in the system of
polynomials equations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and below in the documentation, there is "system of equations", "system of polynomial equations", etc. I think it would be better to just talk about "sequence of polynomials" (one does not have to view them specifically as equations), like in the main description of the method.


- ``homogeneous`` -- boolean (default: ``False``);
when ``False``, the system of equations is not supposed to be
homogeneous and the rows of the Macaulay matrix of degree
``degree`` contain all the equations of this system of
polynomials and all the products between the element of
this system and the monomials of the polynomial ring up
to degree ``degree``
when ``True``, the given system of equations
must be homogeneous, and the rows of the Macaulay matrix
are the elements of the input sequence of polynomials multiplied by monomials, such that
the product is homogeneous of degree ``degree`` + maximum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the documentation we usually avoid shortcut notations like "+", but use complete sentences (with math notation introduced for this maximum degree if needed).

degree in this system.

- ``set_variables`` -- boolean (default: ``None``);
when ``None`` the Macaulay matrix is constructed
using all the variables of the base ring of polynomials.
when ``set_variables`` is a list of variables, it is
used instead of all the variables of the base ring of polynomials.
Copy link
Contributor

@vneiger vneiger Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be an input restriction to indicate here (this set must consist of variables from the parent of the input polynomials). More importantly: it is not very clear what this set is impacting. Is this about variables for the monomials that are constructed to multiply the input polynomials? or is this also about monomials that index the columns and appear in the input polynomials?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for all the suggestions. I modified the word 'system' in 'sequence' and specified that set_variables was used to multiply the polynomials of the starting system by this set.
I hope I got the push right.
I'll have a look at your other suggestions.
Thanks again!


- ``long_output`` -- boolean (default: ``False``);
when ``False``, only return the Macaulay matrix
when ``True``, return the Macaulay matrix and two list,
the first one is the list of monomials corresponding
to the rows of the matrix,
the second one is a list of tuples, each tuple is the
data of a monomial and a polynomial of the system.
the product of the elements of a given tuple is the equation
describing each row of the matrix

EXAMPLES::

sage: R.<x,y,z> = PolynomialRing(GF(7), order='deglex')
sage: L = Sequence([2*x*z - y*z + 2*z^2 + 3*x - 1,
....: 2*x^2 - 3*y*z + z^2 - 3*y + 3,
....: -x^2 - 2*x*z - 3*y*z + 3*x])
sage: L.macaulay_matrix(0)
[0 0 2 0 6 2 3 0 0 6]
[2 0 0 0 4 1 0 4 0 3]
[6 0 5 0 4 0 3 0 0 0]

Example with the option homogeneous::

sage: R.<x,y,z> = PolynomialRing(QQ)
sage: L = Sequence([x*y^2 + y^3 + x*y*z + y*z^2,
....: x^2*y + x*y^2 + x*y*z + 3*x*z^2 + z^3,
....: x^3 + 2*y^3 + x^2*z + 2*x*y*z + 2*z^3])
sage: L.macaulay_matrix(1, homogeneous=True)
[0 0 0 0 0 0 0 1 1 0 1 0 0 1 0]
[0 0 0 1 1 0 0 1 0 0 0 1 0 0 0]
[0 0 1 1 0 0 1 0 0 0 1 0 0 0 0]
[0 0 0 0 0 0 1 1 0 0 1 0 3 0 1]
[0 0 1 1 0 0 0 1 0 0 3 0 0 1 0]
[0 1 1 0 0 0 1 0 0 3 0 0 1 0 0]
[0 0 0 0 0 1 0 0 2 1 2 0 0 0 2]
[0 1 0 0 2 0 1 2 0 0 0 0 0 2 0]
[1 0 0 2 0 1 2 0 0 0 0 0 2 0 0]

Same example as before but with all options
activated excepted the ``set_variables`` option::

sage: R.<x,y,z> = PolynomialRing(QQ)
sage: L = Sequence([x*y + 2*z^2, y^2 + y*z, x*z])
sage: L.macaulay_matrix(1, homogeneous=True, remove_zero=True, long_output=True)
[
[0 0 0 0 1 0 0 0 2]
[0 1 0 0 0 0 0 2 0]
[1 0 0 0 0 0 2 0 0]
[0 0 0 0 0 1 0 1 0]
[0 0 1 0 0 1 0 0 0]
[0 1 0 0 1 0 0 0 0]
[0 0 0 0 0 0 1 0 0]
[0 0 0 0 1 0 0 0 0]
[0 0 0 1 0 0 0 0 0],
[(z, x*y + 2*z^2), (y, x*y + 2*z^2), (x, x*y + 2*z^2), (z, y^2 + y*z),
(y, y^2 + y*z), (x, y^2 + y*z), (z, x*z), (y, x*z), (x, x*z)],
[x^2*y, x*y^2, y^3, x^2*z, x*y*z, y^2*z, x*z^2, y*z^2, z^3]
]

Example with the ``set_variables`` option::

sage: R.<x,y,z> = PolynomialRing(QQ)
sage: L = Sequence([2*y*z - 2*z^2 - 3*x + z - 3,
....: -3*y^2 + 3*y*z + 2*z^2 - 2*x - 2*y,
....: -2*y - z - 3])
sage: L.macaulay_matrix(1, set_variables=['x'], remove_zero=True, long_output=True)
[
[ 0 0 0 0 0 0 0 0 0 2 -2 -3 0 1 -3]
[ 0 0 0 2 -2 -3 0 0 1 0 0 -3 0 0 0]
[ 0 0 0 0 0 0 0 -3 0 3 2 -2 -2 0 0]
[ 0 -3 0 3 2 -2 -2 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0 0 0 -2 -1 -3]
[ 0 0 0 0 0 0 -2 0 -1 0 0 -3 0 0 0]
[-2 0 -1 0 0 -3 0 0 0 0 0 0 0 0 0],
[(1, 2*y*z - 2*z^2 - 3*x + z - 3), (x, 2*y*z - 2*z^2 - 3*x + z - 3),
(1, -3*y^2 + 3*y*z + 2*z^2 - 2*x - 2*y), (x, -3*y^2 + 3*y*z + 2*z^2 - 2*x - 2*y),
(1, -2*y - z - 3), (x, -2*y - z - 3), (x^2, -2*y - z - 3)],
[x^2*y, x*y^2, x^2*z, x*y*z, x*z^2, x^2, x*y, y^2, x*z, y*z, z^2, x, y, z, 1]
]

TESTS::

sage: R.<x,y,z> = PolynomialRing(GF(7),order='deglex')
sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence_generic
sage: PolynomialSequence_generic([], R).macaulay_matrix(1)
Traceback (most recent call last):
...
TypeError: the list of polynomials must be non empty

sage: Sequence([x*y, x**2]).macaulay_matrix(-1)
Traceback (most recent call last):
...
ValueError: the degree must be a non negative number

REFERENCES:

[Mac1902]_, Chapter 1 of [Mac1916]_
"""
from sage.matrix.constructor import matrix

if len(self) == 0:
raise TypeError('the list of polynomials must be non empty')
if degree < 0:
raise ValueError('the degree must be a non negative number')

S = self.ring()
F = S.base_ring()
if set_variables is None:
R = S
else:
R = PolynomialRing(F, set_variables)

degree_system = self.maximal_degree()

augmented_system = []
if homogeneous:
for poly in self:
augmented_system += [(mon, poly) for mon in R.monomials_of_degree(degree_system - poly.degree() + degree)]
else:
for poly in self:
for deg in range(degree_system - poly.degree() + degree + 1):
augmented_system += [(mon, poly) for mon in R.monomials_of_degree(deg)]

if remove_zero:
monomials_sys = list(set(sum(((mon*poly).monomials() for mon, poly in augmented_system), [])))
else:
if homogeneous :
monomials_sys = S.monomials_of_degree(degree_system+degree)
else:
monomials_sys = sum((S.monomials_of_degree(i) for i in range(degree_system + degree + 1)), [])

monomials_sys = list(monomials_sys)
monomials_sys.sort(reverse=True)
macaulay = matrix(F, [[(mon*poly).monomial_coefficient(m) for m in monomials_sys] for mon, poly in augmented_system])

return [macaulay, augmented_system, monomials_sys] if long_output else macaulay

def subs(self, *args, **kwargs):
"""
Substitute variables for every polynomial in this system and
Expand Down
19 changes: 19 additions & 0 deletions src/sage/rings/polynomial/polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,25 @@ def some_elements(self):
self([2*one,0,2*one]), # an element with non-trivial content
]

def monomials_of_degree(self, degree):
r"""
Return the list of all monomials of the given total
degree in this univariate polynomial ring.

.. NOTE::

This method extends a method with the same name
used for multivariate polynomials rings.

EXAMPLES::

sage: R.<x> = ZZ[]
sage: mons = R.monomials_of_degree(2)
sage: mons
[x^2]
"""
return [self.gen()**degree]

@cached_method
def flattening_morphism(self):
r"""
Expand Down
Loading