Skip to content

Commit a4107d3

Browse files
committed
Some fixes for corner case. Adding some systemmatic tests.
1 parent da45bef commit a4107d3

File tree

3 files changed

+60
-13
lines changed

3 files changed

+60
-13
lines changed

src/sage/combinat/diagram.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,15 +1011,28 @@ def peelable_tableaux(self):
10111011
10121012
This implementation uses the algorithm suggested in Remark 25
10131013
of [RS1995]_.
1014+
1015+
TESTS:
1016+
1017+
Corner case::
1018+
1019+
sage: from sage.combinat.diagram import NorthwestDiagram
1020+
sage: D = NorthwestDiagram([])
1021+
sage: D.peelable_tableaux()
1022+
{[]}
10141023
"""
10151024
# TODO: There is a condition on the first column (if the rows in Dhat
10161025
# are a subset of the rows in the first column) which simplifies the
10171026
# description without performing JDT, so we should implement that
10181027

1028+
# empty diagram case
1029+
if not self:
1030+
return set([Tableau([])])
1031+
10191032
# if there is a single column in the diagram then there is only
10201033
# one posslbe peelable tableau.
10211034
if self._n_nonempty_cols == 1:
1022-
return {Tableau([[i+1] for i, j in self.cells()])}
1035+
return set([Tableau([[i+1] for i, j in self.cells()])])
10231036

10241037
first_col = min(j for i, j in self._cells)
10251038

src/sage/combinat/key_polynomial.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _coerce_map_from_(self, R):
501501

502502
from sage.combinat.schubert_polynomial import SchubertPolynomialRing_xbasis
503503
if isinstance(R, SchubertPolynomialRing_xbasis):
504-
return CallableConvertMap(R, self, self.from_schubert_polynomial)
504+
return self.from_schubert_polynomial
505505

506506
phi = P.coerce_map_from(R)
507507
if phi is not None:
@@ -660,41 +660,65 @@ def from_schubert_polynomial(self, x):
660660
661661
EXAMPLES::
662662
663-
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
664-
sage: k = KeyPolynomialBasis(ZZ)
663+
sage: k = KeyPolynomials(ZZ)
665664
sage: X = SchubertPolynomialRing(ZZ)
666665
sage: f = X([2,1,5,4,3])
667666
sage: k.from_schubert_polynomial(f)
668667
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
669668
sage: k.from_schubert_polynomial(2)
670669
2*k[]
671-
sage: k(f) #indirect doctest
670+
sage: k(f)
672671
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
673672
673+
sage: k = KeyPolynomials(GF(7), 4)
674+
sage: k.from_schubert_polynomial(f)
675+
k[1, 0, 2, 1] + k[2, 0, 2, 0] + k[3, 0, 0, 1]
676+
674677
TESTS::
675678
676-
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
677-
sage: k = KeyPolynomialBasis(ZZ)
679+
sage: k = KeyPolynomials(ZZ)
678680
sage: k.from_schubert_polynomial(k([3,2]))
679681
Traceback (most recent call last):
680682
...
681-
ValueError: Please provide a Schubert polynomial
683+
ValueError: not a Schubert polynomial
684+
685+
sage: k = KeyPolynomials(ZZ)
686+
sage: X = SchubertPolynomialRing(ZZ)
687+
sage: it = iter(Compositions())
688+
sage: for _ in range(50):
689+
....: C = next(it)
690+
....: assert k.from_schubert_polynomial(X(k[C])) == k[C], C
691+
692+
sage: k = KeyPolynomials(ZZ, 4)
693+
sage: X = SchubertPolynomialRing(ZZ)
694+
sage: it = iter(k.basis().keys())
695+
sage: for _ in range(50):
696+
....: C = next(it)
697+
....: assert k.from_schubert_polynomial(X(k[C])) == k[C], C
682698
"""
683699
if x in self.base_ring():
684700
return self(x)
701+
685702
from sage.combinat.schubert_polynomial import SchubertPolynomial_class
686703
if not isinstance(x, SchubertPolynomial_class):
687-
raise ValueError('Please provide a Schubert polynomial')
704+
raise ValueError('not a Schubert polynomial')
688705

689706
from sage.combinat.diagram import RotheDiagram
690-
R = KeyPolynomialBasis(self.base_ring())
691-
out = R.zero()
707+
out = self.zero()
708+
if self._k is not None:
709+
def build_elt(wt):
710+
wt = list(wt)
711+
wt += [0] * (self._k - len(wt))
712+
return self[wt]
713+
else:
714+
def build_elt(wt):
715+
return self[wt]
692716

693717
for m, c in x.monomial_coefficients().items():
694718
D = RotheDiagram(m)
695-
a = R.zero()
719+
a = self.zero()
696720
for d in D.peelable_tableaux():
697-
a += R(d.left_key_tableau().weight())
721+
a += build_elt(d.left_key_tableau().weight())
698722
out += c * a
699723

700724
return out

src/sage/combinat/schubert_polynomial.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,15 @@ def _element_constructor_(self, x):
443443
444444
sage: X([])
445445
X[1]
446+
447+
Check the round trip from key polynomials::
448+
449+
sage: k = KeyPolynomials(ZZ)
450+
sage: X = SchubertPolynomialRing(ZZ)
451+
sage: it = iter(Permutations())
452+
sage: for _ in range(50):
453+
....: P = next(it)
454+
....: assert X(k(X(P))) == X(P), P
446455
"""
447456
if isinstance(x, list):
448457
# checking the input to avoid symmetrica crashing Sage, see trac 12924
@@ -490,3 +499,4 @@ def product_on_basis(self, left, right):
490499
X[4, 2, 1, 3]
491500
"""
492501
return symmetrica.mult_schubert_schubert(left, right)
502+

0 commit comments

Comments
 (0)