Skip to content

Commit da45bef

Browse files
committed
Merge branch 'u/tkarn/schubert-key-34518' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/schubert_key-34518
2 parents 124900f + 3a2999b commit da45bef

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

src/sage/combinat/key_polynomial.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def _coerce_map_from_(self, R):
479479
EXAMPLES::
480480
481481
sage: k = KeyPolynomials(QQ)
482-
sage: m1 = k([3,2,4,0]); m1
482+
sage: m1 = k([3, 2, 4, 0]); m1
483483
k[3, 2, 4]
484484
sage: m2 = k(Composition([3, 2, 4])); m2
485485
k[3, 2, 4]
@@ -490,10 +490,19 @@ def _coerce_map_from_(self, R):
490490
sage: z = R.gen()
491491
sage: z[0] * k([4, 3, 3, 2])
492492
k[5, 3, 3, 2]
493+
494+
sage: X = SchubertPolynomialRing(QQ)
495+
sage: k(X([4, 3, 2, 1]))
496+
k[3, 2, 1]
493497
"""
494498
P = self._polynomial_ring
495499
if R is P:
496500
return self.from_polynomial
501+
502+
from sage.combinat.schubert_polynomial import SchubertPolynomialRing_xbasis
503+
if isinstance(R, SchubertPolynomialRing_xbasis):
504+
return CallableConvertMap(R, self, self.from_schubert_polynomial)
505+
497506
phi = P.coerce_map_from(R)
498507
if phi is not None:
499508
return self.coerce_map_from(P) * phi
@@ -645,6 +654,52 @@ def from_polynomial(self, f):
645654

646655
return out
647656

657+
def from_schubert_polynomial(self, x):
658+
r"""
659+
Expand a Schubert polynomial in the key basis.
660+
661+
EXAMPLES::
662+
663+
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
664+
sage: k = KeyPolynomialBasis(ZZ)
665+
sage: X = SchubertPolynomialRing(ZZ)
666+
sage: f = X([2,1,5,4,3])
667+
sage: k.from_schubert_polynomial(f)
668+
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
669+
sage: k.from_schubert_polynomial(2)
670+
2*k[]
671+
sage: k(f) #indirect doctest
672+
k[1, 0, 2, 1] + k[2, 0, 2] + k[3, 0, 0, 1]
673+
674+
TESTS::
675+
676+
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
677+
sage: k = KeyPolynomialBasis(ZZ)
678+
sage: k.from_schubert_polynomial(k([3,2]))
679+
Traceback (most recent call last):
680+
...
681+
ValueError: Please provide a Schubert polynomial
682+
"""
683+
if x in self.base_ring():
684+
return self(x)
685+
from sage.combinat.schubert_polynomial import SchubertPolynomial_class
686+
if not isinstance(x, SchubertPolynomial_class):
687+
raise ValueError('Please provide a Schubert polynomial')
688+
689+
from sage.combinat.diagram import RotheDiagram
690+
R = KeyPolynomialBasis(self.base_ring())
691+
out = R.zero()
692+
693+
for m, c in x.monomial_coefficients().items():
694+
D = RotheDiagram(m)
695+
a = R.zero()
696+
for d in D.peelable_tableaux():
697+
a += R(d.left_key_tableau().weight())
698+
out += c * a
699+
700+
return out
701+
702+
648703
def divided_difference(f, i):
649704
r"""
650705
Apply the ``i``-th divided difference operator to the polynomial ``f``.

src/sage/combinat/schubert_polynomial.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,18 @@
7373
#
7474
# https://www.gnu.org/licenses/
7575
# ****************************************************************************
76-
from sage.combinat.free_module import CombinatorialFreeModule
7776
from sage.categories.all import GradedAlgebrasWithBasis
77+
from sage.combinat.free_module import CombinatorialFreeModule
78+
from sage.combinat.key_polynomial import KeyPolynomial
79+
from sage.combinat.permutation import Permutations, Permutation
80+
from sage.misc.cachefunc import cached_method
7881
from sage.rings.integer import Integer
7982
from sage.rings.integer_ring import ZZ
83+
from sage.rings.polynomial.infinite_polynomial_element import InfinitePolynomial_sparse
8084
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
8185
from sage.rings.polynomial.multi_polynomial import is_MPolynomial
82-
from sage.combinat.permutation import Permutations, Permutation
86+
8387
import sage.libs.symmetrica.all as symmetrica
84-
from sage.misc.cachefunc import cached_method
8588

8689

8790
def SchubertPolynomialRing(R):
@@ -414,6 +417,17 @@ def _element_constructor_(self, x):
414417
sage: X(x1^2*x2)
415418
X[3, 2, 1]
416419
420+
sage: S.<x> = InfinitePolynomialRing(QQ)
421+
sage: X(x[0]^2*x[1])
422+
X[3, 2, 1]
423+
sage: X(x[0]*x[1]^2*x[2]^2*x[3] + x[0]^2*x[1]^2*x[2]*x[3] + x[0]^2*x[1]*x[2]^2*x[3])
424+
X[2, 4, 5, 3, 1]
425+
426+
sage: from sage.combinat.key_polynomial import KeyPolynomialBasis
427+
sage: k = KeyPolynomialBasis(QQ)
428+
sage: X(k([3,2,1]))
429+
X[4, 3, 2, 1]
430+
417431
TESTS:
418432
419433
We check that :trac:`12924` is fixed::
@@ -441,6 +455,14 @@ def _element_constructor_(self, x):
441455
return self._from_dict({perm: self.base_ring().one()})
442456
elif is_MPolynomial(x):
443457
return symmetrica.t_POLYNOM_SCHUBERT(x)
458+
elif isinstance(x, InfinitePolynomial_sparse):
459+
R = x.polynomial().parent()
460+
# massage the term order to be what symmetrica expects
461+
S = PolynomialRing(R.base_ring(),
462+
names=list(map(repr, reversed(R.gens()))))
463+
return symmetrica.t_POLYNOM_SCHUBERT(S(x.polynomial()))
464+
elif isinstance(x, KeyPolynomial):
465+
return self(x.expand())
444466
else:
445467
raise TypeError
446468

0 commit comments

Comments
 (0)