Skip to content

typing annotation in Chow ring ideal #39799

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Changes from all commits
Commits
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
70 changes: 36 additions & 34 deletions src/sage/matroids/chow_ring_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
from itertools import product

from sage.combinat.posets.posets import Poset
from sage.matroids.utilities import cmp_elements_key
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
from sage.combinat.posets.posets import Poset
from itertools import product
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing


class ChowRingIdeal(MPolynomialIdeal):
Expand All @@ -37,7 +38,7 @@ def matroid(self):
"""
return self._matroid

def _lattice_flats(self):
def _lattice_flats(self) -> tuple:
r"""
Return the ranks and chains of lattice of flats of the matroid.

Expand Down Expand Up @@ -65,7 +66,7 @@ def _lattice_flats(self):
chains = lattice_flats.chains() # Only chains
return (ranks, chains)

def flats_to_generator_dict(self):
def flats_to_generator_dict(self) -> dict:
r"""
Return the corresponding generators of flats/groundset elements of
Chow ring ideal.
Expand Down Expand Up @@ -146,7 +147,7 @@ class ChowRingIdeal_nonaug(ChowRingIdeal):
Chow ring ideal of Fano: Binary matroid of rank 3 on 7 elements,
type (3, 0) - non augmented
"""
def __init__(self, M, R):
def __init__(self, M, R) -> None:
r"""
Initialize ``self``.

Expand All @@ -167,7 +168,7 @@ def __init__(self, M, R):
self._flats_generator = dict(zip(flats, gens))
MPolynomialIdeal.__init__(self, poly_ring, self._gens_constructor(poly_ring))

def _gens_constructor(self, poly_ring):
def _gens_constructor(self, poly_ring) -> list:
r"""
Return the generators of ``self``.

Expand Down Expand Up @@ -215,7 +216,7 @@ def _gens_constructor(self, poly_ring):
J = list(atoms_gen.values()) # Linear generators
return I + J

def _repr_(self):
def _repr_(self) -> str:
r"""
Return a string representation of ``self``.

Expand All @@ -228,7 +229,7 @@ def _repr_(self):
"""
return "Chow ring ideal of {} - non augmented".format(self._matroid)

def _latex_(self):
def _latex_(self) -> str:
r"""
Return a LaTeX representation of ``self``.

Expand Down Expand Up @@ -289,7 +290,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
term += flats_gen[G]
for G in lattice_flats.order_ideal([F]):
if G != F:
gb.append(flats_gen[G]*(term) ** (ranks[F] - ranks[G]))
gb.append(flats_gen[G] * (term) ** (ranks[F] - ranks[G]))

gb.append(term ** ranks[F])

Expand Down Expand Up @@ -420,7 +421,7 @@ class AugmentedChowRingIdeal_fy(ChowRingIdeal):
Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
elements with 16 bases of Feitchner-Yuzvinsky presentation
"""
def __init__(self, M, R):
def __init__(self, M, R) -> None:
r"""
Initialize ``self``.

Expand Down Expand Up @@ -450,7 +451,7 @@ def __init__(self, M, R):
self._flats_containing[x].append(F)
MPolynomialIdeal.__init__(self, poly_ring, self._gens_constructor(poly_ring))

def _gens_constructor(self, poly_ring):
def _gens_constructor(self, poly_ring) -> list:
r"""
Return the generators of ``self``.

Expand Down Expand Up @@ -488,12 +489,13 @@ def _gens_constructor(self, poly_ring):
A4*B, A3*B, A2*B, A1*B, A0*B]
"""
E = list(self._matroid.groundset())
Q = []
L = []
lattice_flats = Poset((self._flats, lambda x, y: x <= y))
antichains = lattice_flats.antichains().elements_of_depth_iterator(2)
for F, G in antichains:
Q.append(self._flats_generator[F] * self._flats_generator[G]) # Quadratic generators

# Quadratic generators
Q = [self._flats_generator[F] * self._flats_generator[G]
for F, G in antichains]

for x in E:
term = poly_ring.zero()
Expand All @@ -508,7 +510,7 @@ def _gens_constructor(self, poly_ring):
L.append(term1)
return Q + L

def _repr_(self):
def _repr_(self) -> str:
r"""
EXAMPLES::

Expand All @@ -519,7 +521,7 @@ def _repr_(self):
"""
return "Augmented Chow ring ideal of {} of Feitchner-Yuzvinsky presentation".format(self._matroid)

def _latex_(self):
def _latex_(self) -> str:
r"""
Return a LaTeX representation of ``self``.

Expand Down Expand Up @@ -554,11 +556,12 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
gb = [] # reduced groebner basis with two eliminated cases
E = list(self._matroid.groundset())
poly_ring = self.ring()
reln = lambda x,y: x <= y
lattice_flats = Poset((self._flats, reln))

lattice_flats = Poset((self._flats, lambda x, y: x <= y))
antichains = lattice_flats.antichains().elements_of_depth_iterator(2)
for F, G in antichains:
gb.append(self._flats_generator[F] * self._flats_generator[G]) # non-nested flats
# non-nested flats
gb.append(self._flats_generator[F] * self._flats_generator[G])
for i in E:
term = poly_ring.zero()
for H in self._flats_containing[i]:
Expand All @@ -575,7 +578,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
order_ideal_modified = lattice_flats.order_ideal([F])
order_ideal_modified.remove(F)
for G in order_ideal_modified: # nested flats
gb.append(self._flats_generator[G]*term1**(self._matroid.rank(F) - self._matroid.rank(G)))
gb.append(self._flats_generator[G] * term1**(self._matroid.rank(F) - self._matroid.rank(G)))

return PolynomialSequence(poly_ring, [gb])

Expand Down Expand Up @@ -611,10 +614,9 @@ def normal_basis(self, algorithm='', *args, **kwargs):
monomial_basis.append(R.one())
else:
k = len(subset)
max_powers = []
max_powers.append(ranks[subset[0]])
for i in range(1, k):
max_powers.append(ranks[subset[i]] - ranks[subset[i-1]])
max_powers = [ranks[subset[0]]]
max_powers.extend(ranks[subset[i]] - ranks[subset[i - 1]]
for i in range(1, k))
ranges = [range(1, p) for p in max_powers]
ranges[0] = range(1, max_powers[0] + 1)
for combination in product(*(r for r in ranges)):
Expand Down Expand Up @@ -674,7 +676,7 @@ class AugmentedChowRingIdeal_atom_free(ChowRingIdeal):
Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
elements with 16 bases in the atom-free presentation
"""
def __init__(self, M, R):
def __init__(self, M, R) -> None:
r"""
Initialize ``self``.

Expand All @@ -695,7 +697,7 @@ def __init__(self, M, R):
self._flats_generator = dict(zip(self._flats, gens))
MPolynomialIdeal.__init__(self, poly_ring, self._gens_constructor(poly_ring))

def _gens_constructor(self, poly_ring):
def _gens_constructor(self, poly_ring) -> list:
r"""
Return the generators of ``self``.

Expand All @@ -714,8 +716,7 @@ def _gens_constructor(self, poly_ring):
for F in self._flats:
for x in F:
flats_containing[x].append(F)
reln = lambda x,y: x <= y
lattice_flats = Poset((self._flats, reln))
lattice_flats = Poset((self._flats, lambda x, y: x <= y))
antichains = lattice_flats.antichains().elements_of_depth_iterator(2)
for F, G in antichains:
Q.append(self._flats_generator[F] * self._flats_generator[G])
Expand All @@ -727,11 +728,12 @@ def _gens_constructor(self, poly_ring):
if term**2 not in Q:
Q.append(term**2)

if F not in flats_containing[x]: # generators for every set of flats not containing element
Q.append(self._flats_generator[F]*term)
if F not in flats_containing[x]:
# generators for every set of flats not containing element
Q.append(self._flats_generator[F] * term)
return Q

def _repr_(self):
def _repr_(self) -> str:
r"""
EXAMPLES::

Expand All @@ -742,7 +744,7 @@ def _repr_(self):
"""
return "Augmented Chow ring ideal of {} in the atom-free presentation".format(self._matroid)

def _latex_(self):
def _latex_(self) -> str:
r"""
Return the LaTeX output of the ring and generators of ``self``.

Expand Down
Loading