15
15
# https://www.gnu.org/licenses/
16
16
# ****************************************************************************
17
17
18
- from sage .rings .polynomial .multi_polynomial_ideal import MPolynomialIdeal
18
+ from itertools import product
19
+
20
+ from sage .combinat .posets .posets import Poset
19
21
from 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
21
23
from 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
24
25
25
26
26
27
class ChowRingIdeal (MPolynomialIdeal ):
@@ -37,7 +38,7 @@ def matroid(self):
37
38
"""
38
39
return self ._matroid
39
40
40
- def _lattice_flats (self ):
41
+ def _lattice_flats (self ) -> tuple :
41
42
r"""
42
43
Return the ranks and chains of lattice of flats of the matroid.
43
44
@@ -65,7 +66,7 @@ def _lattice_flats(self):
65
66
chains = lattice_flats .chains () # Only chains
66
67
return (ranks , chains )
67
68
68
- def flats_to_generator_dict (self ):
69
+ def flats_to_generator_dict (self ) -> dict :
69
70
r"""
70
71
Return the corresponding generators of flats/groundset elements of
71
72
Chow ring ideal.
@@ -146,7 +147,7 @@ class ChowRingIdeal_nonaug(ChowRingIdeal):
146
147
Chow ring ideal of Fano: Binary matroid of rank 3 on 7 elements,
147
148
type (3, 0) - non augmented
148
149
"""
149
- def __init__ (self , M , R ):
150
+ def __init__ (self , M , R ) -> None :
150
151
r"""
151
152
Initialize ``self``.
152
153
@@ -167,7 +168,7 @@ def __init__(self, M, R):
167
168
self ._flats_generator = dict (zip (flats , gens ))
168
169
MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
169
170
170
- def _gens_constructor (self , poly_ring ):
171
+ def _gens_constructor (self , poly_ring ) -> list :
171
172
r"""
172
173
Return the generators of ``self``.
173
174
@@ -215,7 +216,7 @@ def _gens_constructor(self, poly_ring):
215
216
J = list (atoms_gen .values ()) # Linear generators
216
217
return I + J
217
218
218
- def _repr_ (self ):
219
+ def _repr_ (self ) -> str :
219
220
r"""
220
221
Return a string representation of ``self``.
221
222
@@ -228,7 +229,7 @@ def _repr_(self):
228
229
"""
229
230
return "Chow ring ideal of {} - non augmented" .format (self ._matroid )
230
231
231
- def _latex_ (self ):
232
+ def _latex_ (self ) -> str :
232
233
r"""
233
234
Return a LaTeX representation of ``self``.
234
235
@@ -289,7 +290,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
289
290
term += flats_gen [G ]
290
291
for G in lattice_flats .order_ideal ([F ]):
291
292
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 ]))
293
294
294
295
gb .append (term ** ranks [F ])
295
296
@@ -420,7 +421,7 @@ class AugmentedChowRingIdeal_fy(ChowRingIdeal):
420
421
Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
421
422
elements with 16 bases of Feitchner-Yuzvinsky presentation
422
423
"""
423
- def __init__ (self , M , R ):
424
+ def __init__ (self , M , R ) -> None :
424
425
r"""
425
426
Initialize ``self``.
426
427
@@ -450,7 +451,7 @@ def __init__(self, M, R):
450
451
self ._flats_containing [x ].append (F )
451
452
MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
452
453
453
- def _gens_constructor (self , poly_ring ):
454
+ def _gens_constructor (self , poly_ring ) -> list :
454
455
r"""
455
456
Return the generators of ``self``.
456
457
@@ -488,12 +489,13 @@ def _gens_constructor(self, poly_ring):
488
489
A4*B, A3*B, A2*B, A1*B, A0*B]
489
490
"""
490
491
E = list (self ._matroid .groundset ())
491
- Q = []
492
492
L = []
493
493
lattice_flats = Poset ((self ._flats , lambda x , y : x <= y ))
494
494
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 ]
497
499
498
500
for x in E :
499
501
term = poly_ring .zero ()
@@ -508,7 +510,7 @@ def _gens_constructor(self, poly_ring):
508
510
L .append (term1 )
509
511
return Q + L
510
512
511
- def _repr_ (self ):
513
+ def _repr_ (self ) -> str :
512
514
r"""
513
515
EXAMPLES::
514
516
@@ -519,7 +521,7 @@ def _repr_(self):
519
521
"""
520
522
return "Augmented Chow ring ideal of {} of Feitchner-Yuzvinsky presentation" .format (self ._matroid )
521
523
522
- def _latex_ (self ):
524
+ def _latex_ (self ) -> str :
523
525
r"""
524
526
Return a LaTeX representation of ``self``.
525
527
@@ -554,11 +556,12 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
554
556
gb = [] # reduced groebner basis with two eliminated cases
555
557
E = list (self ._matroid .groundset ())
556
558
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 ))
559
561
antichains = lattice_flats .antichains ().elements_of_depth_iterator (2 )
560
562
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 ])
562
565
for i in E :
563
566
term = poly_ring .zero ()
564
567
for H in self ._flats_containing [i ]:
@@ -575,7 +578,7 @@ def groebner_basis(self, algorithm='', *args, **kwargs):
575
578
order_ideal_modified = lattice_flats .order_ideal ([F ])
576
579
order_ideal_modified .remove (F )
577
580
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 )))
579
582
580
583
return PolynomialSequence (poly_ring , [gb ])
581
584
@@ -611,10 +614,9 @@ def normal_basis(self, algorithm='', *args, **kwargs):
611
614
monomial_basis .append (R .one ())
612
615
else :
613
616
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 ))
618
620
ranges = [range (1 , p ) for p in max_powers ]
619
621
ranges [0 ] = range (1 , max_powers [0 ] + 1 )
620
622
for combination in product (* (r for r in ranges )):
@@ -674,7 +676,7 @@ class AugmentedChowRingIdeal_atom_free(ChowRingIdeal):
674
676
Augmented Chow ring ideal of Wheel(3): Regular matroid of rank 3 on 6
675
677
elements with 16 bases in the atom-free presentation
676
678
"""
677
- def __init__ (self , M , R ):
679
+ def __init__ (self , M , R ) -> None :
678
680
r"""
679
681
Initialize ``self``.
680
682
@@ -695,7 +697,7 @@ def __init__(self, M, R):
695
697
self ._flats_generator = dict (zip (self ._flats , gens ))
696
698
MPolynomialIdeal .__init__ (self , poly_ring , self ._gens_constructor (poly_ring ))
697
699
698
- def _gens_constructor (self , poly_ring ):
700
+ def _gens_constructor (self , poly_ring ) -> list :
699
701
r"""
700
702
Return the generators of ``self``.
701
703
@@ -714,8 +716,7 @@ def _gens_constructor(self, poly_ring):
714
716
for F in self ._flats :
715
717
for x in F :
716
718
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 ))
719
720
antichains = lattice_flats .antichains ().elements_of_depth_iterator (2 )
720
721
for F , G in antichains :
721
722
Q .append (self ._flats_generator [F ] * self ._flats_generator [G ])
@@ -727,11 +728,12 @@ def _gens_constructor(self, poly_ring):
727
728
if term ** 2 not in Q :
728
729
Q .append (term ** 2 )
729
730
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 )
732
734
return Q
733
735
734
- def _repr_ (self ):
736
+ def _repr_ (self ) -> str :
735
737
r"""
736
738
EXAMPLES::
737
739
@@ -742,7 +744,7 @@ def _repr_(self):
742
744
"""
743
745
return "Augmented Chow ring ideal of {} in the atom-free presentation" .format (self ._matroid )
744
746
745
- def _latex_ (self ):
747
+ def _latex_ (self ) -> str :
746
748
r"""
747
749
Return the LaTeX output of the ring and generators of ``self``.
748
750
0 commit comments