1515# https://www.gnu.org/licenses/
1616# ****************************************************************************
1717
18- from sage .rings .polynomial .multi_polynomial_ideal import MPolynomialIdeal
18+ from itertools import product
19+
20+ from sage .combinat .posets .posets import Poset
1921from sage .matroids .utilities import cmp_elements_key
20- from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
22+ from sage .rings .polynomial .multi_polynomial_ideal import MPolynomialIdeal
2123from sage .rings .polynomial .multi_polynomial_sequence import PolynomialSequence
22- from sage .combinat .posets .posets import Poset
23- from itertools import product
24+ from sage .rings .polynomial .polynomial_ring_constructor import PolynomialRing
2425
2526
2627class ChowRingIdeal (MPolynomialIdeal ):
@@ -37,7 +38,7 @@ def matroid(self):
3738 """
3839 return self ._matroid
3940
40- def _lattice_flats (self ):
41+ def _lattice_flats (self ) -> tuple :
4142 r"""
4243 Return the ranks and chains of lattice of flats of the matroid.
4344
@@ -65,7 +66,7 @@ def _lattice_flats(self):
6566 chains = lattice_flats .chains () # Only chains
6667 return (ranks , chains )
6768
68- def flats_to_generator_dict (self ):
69+ def flats_to_generator_dict (self ) -> dict :
6970 r"""
7071 Return the corresponding generators of flats/groundset elements of
7172 Chow ring ideal.
@@ -146,7 +147,7 @@ class ChowRingIdeal_nonaug(ChowRingIdeal):
146147 Chow ring ideal of Fano: Binary matroid of rank 3 on 7 elements,
147148 type (3, 0) - non augmented
148149 """
149- def __init__ (self , M , R ):
150+ def __init__ (self , M , R ) -> None :
150151 r"""
151152 Initialize ``self``.
152153
@@ -167,7 +168,7 @@ def __init__(self, M, R):
167168 self ._flats_generator = dict (zip (flats , gens ))
168169 MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
169170
170- def _gens_constructor (self , poly_ring ):
171+ def _gens_constructor (self , poly_ring ) -> list :
171172 r"""
172173 Return the generators of ``self``.
173174
@@ -215,7 +216,7 @@ def _gens_constructor(self, poly_ring):
215216 J = list (atoms_gen .values ()) # Linear generators
216217 return I + J
217218
218- def _repr_ (self ):
219+ def _repr_ (self ) -> str :
219220 r"""
220221 Return a string representation of ``self``.
221222
@@ -228,7 +229,7 @@ def _repr_(self):
228229 """
229230 return "Chow ring ideal of {} - non augmented" .format (self ._matroid )
230231
231- def _latex_ (self ):
232+ def _latex_ (self ) -> str :
232233 r"""
233234 Return a LaTeX representation of ``self``.
234235
@@ -289,7 +290,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
289290 term += flats_gen [G ]
290291 for G in lattice_flats .order_ideal ([F ]):
291292 if G != F :
292- gb .append (flats_gen [G ]* (term ) ** (ranks [F ] - ranks [G ]))
293+ gb .append (flats_gen [G ] * (term ) ** (ranks [F ] - ranks [G ]))
293294
294295 gb .append (term ** ranks [F ])
295296
@@ -420,7 +421,7 @@ class AugmentedChowRingIdeal_fy(ChowRingIdeal):
420421 Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
421422 elements with 16 bases of Feitchner-Yuzvinsky presentation
422423 """
423- def __init__ (self , M , R ):
424+ def __init__ (self , M , R ) -> None :
424425 r"""
425426 Initialize ``self``.
426427
@@ -450,7 +451,7 @@ def __init__(self, M, R):
450451 self ._flats_containing [x ].append (F )
451452 MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
452453
453- def _gens_constructor (self , poly_ring ):
454+ def _gens_constructor (self , poly_ring ) -> list :
454455 r"""
455456 Return the generators of ``self``.
456457
@@ -488,12 +489,13 @@ def _gens_constructor(self, poly_ring):
488489 A4*B, A3*B, A2*B, A1*B, A0*B]
489490 """
490491 E = list (self ._matroid .groundset ())
491- Q = []
492492 L = []
493493 lattice_flats = Poset ((self ._flats , lambda x , y : x <= y ))
494494 antichains = lattice_flats .antichains ().elements_of_depth_iterator (2 )
495- for F , G in antichains :
496- Q .append (self ._flats_generator [F ] * self ._flats_generator [G ]) # Quadratic generators
495+
496+ # Quadratic generators
497+ Q = [self ._flats_generator [F ] * self ._flats_generator [G ]
498+ for F , G in antichains ]
497499
498500 for x in E :
499501 term = poly_ring .zero ()
@@ -508,7 +510,7 @@ def _gens_constructor(self, poly_ring):
508510 L .append (term1 )
509511 return Q + L
510512
511- def _repr_ (self ):
513+ def _repr_ (self ) -> str :
512514 r"""
513515 EXAMPLES::
514516
@@ -519,7 +521,7 @@ def _repr_(self):
519521 """
520522 return "Augmented Chow ring ideal of {} of Feitchner-Yuzvinsky presentation" .format (self ._matroid )
521523
522- def _latex_ (self ):
524+ def _latex_ (self ) -> str :
523525 r"""
524526 Return a LaTeX representation of ``self``.
525527
@@ -554,11 +556,12 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
554556 gb = [] # reduced groebner basis with two eliminated cases
555557 E = list (self ._matroid .groundset ())
556558 poly_ring = self .ring ()
557- reln = lambda x , y : x <= y
558- lattice_flats = Poset ((self ._flats , reln ))
559+
560+ lattice_flats = Poset ((self ._flats , lambda x , y : x <= y ))
559561 antichains = lattice_flats .antichains ().elements_of_depth_iterator (2 )
560562 for F , G in antichains :
561- gb .append (self ._flats_generator [F ] * self ._flats_generator [G ]) # non-nested flats
563+ # non-nested flats
564+ gb .append (self ._flats_generator [F ] * self ._flats_generator [G ])
562565 for i in E :
563566 term = poly_ring .zero ()
564567 for H in self ._flats_containing [i ]:
@@ -575,7 +578,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
575578 order_ideal_modified = lattice_flats .order_ideal ([F ])
576579 order_ideal_modified .remove (F )
577580 for G in order_ideal_modified : # nested flats
578- gb .append (self ._flats_generator [G ]* term1 ** (self ._matroid .rank (F ) - self ._matroid .rank (G )))
581+ gb .append (self ._flats_generator [G ] * term1 ** (self ._matroid .rank (F ) - self ._matroid .rank (G )))
579582
580583 return PolynomialSequence (poly_ring , [gb ])
581584
@@ -611,10 +614,9 @@ def normal_basis(self, algorithm='', *args, **kwargs):
611614 monomial_basis .append (R .one ())
612615 else :
613616 k = len (subset )
614- max_powers = []
615- max_powers .append (ranks [subset [0 ]])
616- for i in range (1 , k ):
617- max_powers .append (ranks [subset [i ]] - ranks [subset [i - 1 ]])
617+ max_powers = [ranks [subset [0 ]]]
618+ max_powers .extend (ranks [subset [i ]] - ranks [subset [i - 1 ]]
619+ for i in range (1 , k ))
618620 ranges = [range (1 , p ) for p in max_powers ]
619621 ranges [0 ] = range (1 , max_powers [0 ] + 1 )
620622 for combination in product (* (r for r in ranges )):
@@ -674,7 +676,7 @@ class AugmentedChowRingIdeal_atom_free(ChowRingIdeal):
674676 Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
675677 elements with 16 bases in the atom-free presentation
676678 """
677- def __init__ (self , M , R ):
679+ def __init__ (self , M , R ) -> None :
678680 r"""
679681 Initialize ``self``.
680682
@@ -695,7 +697,7 @@ def __init__(self, M, R):
695697 self ._flats_generator = dict (zip (self ._flats , gens ))
696698 MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
697699
698- def _gens_constructor (self , poly_ring ):
700+ def _gens_constructor (self , poly_ring ) -> list :
699701 r"""
700702 Return the generators of ``self``.
701703
@@ -714,8 +716,7 @@ def _gens_constructor(self, poly_ring):
714716 for F in self ._flats :
715717 for x in F :
716718 flats_containing [x ].append (F )
717- reln = lambda x ,y : x <= y
718- lattice_flats = Poset ((self ._flats , reln ))
719+ lattice_flats = Poset ((self ._flats , lambda x , y : x <= y ))
719720 antichains = lattice_flats .antichains ().elements_of_depth_iterator (2 )
720721 for F , G in antichains :
721722 Q .append (self ._flats_generator [F ] * self ._flats_generator [G ])
@@ -727,11 +728,12 @@ def _gens_constructor(self, poly_ring):
727728 if term ** 2 not in Q :
728729 Q .append (term ** 2 )
729730
730- if F not in flats_containing [x ]: # generators for every set of flats not containing element
731- Q .append (self ._flats_generator [F ]* term )
731+ if F not in flats_containing [x ]:
732+ # generators for every set of flats not containing element
733+ Q .append (self ._flats_generator [F ] * term )
732734 return Q
733735
734- def _repr_ (self ):
736+ def _repr_ (self ) -> str :
735737 r"""
736738 EXAMPLES::
737739
@@ -742,7 +744,7 @@ def _repr_(self):
742744 """
743745 return "Augmented Chow ring ideal of {} in the atom-free presentation" .format (self ._matroid )
744746
745- def _latex_ (self ):
747+ def _latex_ (self ) -> str :
746748 r"""
747749 Return the LaTeX output of the ring and generators of ``self``.
748750
0 commit comments