Skip to content

Commit 3a2999b

Browse files
committed
Add coercion from Schubert to Key
1 parent f657815 commit 3a2999b

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/sage/combinat/key_polynomial.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _coerce_map_from_(self, R):
440440
441441
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
442442
sage: k = KeyPolynomialBasis(QQ)
443-
sage: m1 = k([3,2,4,0]); m1
443+
sage: m1 = k([3, 2, 4, 0]); m1
444444
k[3, 2, 4]
445445
sage: m2 = k(Composition([3, 2, 4])); m2
446446
k[3, 2, 4]
@@ -451,11 +451,21 @@ def _coerce_map_from_(self, R):
451451
sage: z = R.gen()
452452
sage: z[0] * k([4, 3, 3, 2])
453453
k[5, 3, 3, 2]
454+
455+
sage: X = SchubertPolynomialRing(QQ)
456+
sage: k(X([4, 3, 2, 1]))
457+
k[3, 2, 1]
454458
"""
455-
P = self._polynomial_ring
456459
from sage.structure.coerce_maps import CallableConvertMap
460+
461+
P = self._polynomial_ring
457462
if R is P:
458463
return CallableConvertMap(R, self, self.from_polynomial)
464+
465+
from sage.combinat.schubert_polynomial import SchubertPolynomialRing_xbasis
466+
if isinstance(R, SchubertPolynomialRing_xbasis):
467+
return CallableConvertMap(R, self, self.from_schubert_polynomial)
468+
459469
phi = P.coerce_map_from(R)
460470
if phi is not None:
461471
return self.coerce_map_from(P) * phi
@@ -578,6 +588,51 @@ def from_polynomial(self, f):
578588

579589
return out
580590

591+
def from_schubert_polynomial(self, x):
592+
r"""
593+
Expand a Schubert polynomial in the key basis.
594+
595+
EXAMPLES::
596+
597+
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
598+
sage: k = KeyPolynomialBasis(ZZ)
599+
sage: X = SchubertPolynomialRing(ZZ)
600+
sage: f = X([2,1,5,4,3])
601+
sage: k.from_schubert_polynomial(f)
602+
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
603+
sage: k.from_schubert_polynomial(2)
604+
2*k[]
605+
sage: k(f) #indirect doctest
606+
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
607+
608+
TESTS::
609+
610+
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
611+
sage: k = KeyPolynomialBasis(ZZ)
612+
sage: k.from_schubert_polynomial(k([3,2]))
613+
Traceback (most recent call last):
614+
...
615+
ValueError: Please provide a Schubert polynomial
616+
"""
617+
if x in self.base_ring():
618+
return self(x)
619+
from sage.combinat.schubert_polynomial import SchubertPolynomial_class
620+
if not isinstance(x, SchubertPolynomial_class):
621+
raise ValueError('Please provide a Schubert polynomial')
622+
623+
from sage.combinat.diagram import RotheDiagram
624+
R = KeyPolynomialBasis(self.base_ring())
625+
out = R.zero()
626+
627+
for m, c in x.monomial_coefficients().items():
628+
D = RotheDiagram(m)
629+
a = R.zero()
630+
for d in D.peelable_tableaux():
631+
a += R(d.left_key_tableau().weight())
632+
out += c * a
633+
634+
return out
635+
581636

582637
def _divided_difference(P, i, f):
583638
r"""

src/sage/combinat/schubert_polynomial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
import sage.libs.symmetrica.all as symmetrica
8888

89+
8990
def SchubertPolynomialRing(R):
9091
"""
9192
Return the Schubert polynomial ring over ``R`` on the X basis.
@@ -458,7 +459,7 @@ def _element_constructor_(self, x):
458459
R = x.polynomial().parent()
459460
# massage the term order to be what symmetrica expects
460461
S = PolynomialRing(R.base_ring(),
461-
names=list(map(repr,reversed(R.gens()))))
462+
names=list(map(repr, reversed(R.gens()))))
462463
return symmetrica.t_POLYNOM_SCHUBERT(S(x.polynomial()))
463464
elif isinstance(x, KeyPolynomial):
464465
return self(x.expand())

0 commit comments

Comments
 (0)