Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorkarn committed Aug 29, 2022
1 parent 9b683f1 commit e0bbdbd
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions src/sage/combinat/key_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
EXAMPLES::
<Lots and lots of examples>
When the composition is a partition, the key polynomial
agrees with the Schur polynomial::
sage: from sage.combinat.key_polynomial import KeyPolynomialRing
sage: K = KeyPolynomialRing(QQ)
sage: s = SymmetricFunctions(QQ).schur()
sage: K(Composition([3,2,1])).expand()
x0^3*x1^2*x2 + x0^2*x1^3*x2 + x0^3*x1*x2^2 + 2*x0^2*x1^2*x2^2 + x0*x1^3*x2^2 + x0^2*x1*x2^3 + x0*x1^2*x2^3
sage: s[3,2,1].expand(3)
x0^3*x1^2*x2 + x0^2*x1^3*x2 + x0^3*x1*x2^2 + 2*x0^2*x1^2*x2^2 + x0*x1^3*x2^2 + x0^2*x1*x2^3 + x0*x1^2*x2^3
.. SEEALSO::
Expand Down Expand Up @@ -40,19 +51,8 @@ def expand(self):
r"""
Return ``self`` written in the monomial basis.
EXAMPLES::
TESTS:
The when the composition is a partition, the key polynomial
agrees with the Schur polynomial::
sage: from sage.combinat.key_polynomial import KeyPolynomialRing
sage: K = KeyPolynomialRing(QQ)
sage: s = SymmetricFunctions(QQ).schur()
sage: K(Composition([3,2,1])).expand()
x0^3*x1^2*x2 + x0^2*x1^3*x2 + x0^3*x1*x2^2 + 2*x0^2*x1^2*x2^2 + x0*x1^3*x2^2 + x0^2*x1*x2^3 + x0*x1^2*x2^3
sage: s[3,2,1].expand(3)
x0^3*x1^2*x2 + x0^2*x1^3*x2 + x0^3*x1*x2^2 + 2*x0^2*x1^2*x2^2 + x0*x1^3*x2^2 + x0^2*x1*x2^3 + x0*x1^2*x2^3
"""
R = self.parent().polynomial_ring()
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, R):
"""
self._name = "Ring of key polynomials"
self._repr_option_bracket = False
CombinatorialFreeModule.__init__(self, R, Compositions(),
CombinatorialFreeModule.__init__(self, R, Compositions(), # should this be indexed by
category=GradedAlgebrasWithBasis(R),
prefix='k')

Expand All @@ -105,16 +105,40 @@ def polynomial_ring(self):
def from_polynomial(self, f):
r"""
Expand a polynomial in terms of the key basis.
EXAMPLES::
sage: from sage.combinat.key_polynomial import KeyPolynomialRing
sage: K = KeyPolynomialRing(QQ)
sage: R = K.polynomial_ring(); z, = R.gens()
sage: p = z[0]^4*z[1]^2*z[2]*z[3] + z[0]^4*z[1]*z[2]^2*z[3]
sage: K.from_polynomial(p)
k[4, 1, 2, 1]
sage: all(K({c:1}) == K.from_polynomial(K({c:1}).expand())
....: for c in Compositions(5))
True
sage: T = crystals.Tableaux(['A', 4], shape=[4,2,1,1])
sage: K.from_polynomial(T.demazure_character([2]))
k[4, 1, 2, 1]
"""
from sage.symbolic.ring import SymbolicRing
if f.parent() is SymbolicRing: # to accept Demazure characters from crystals
f.substitute(list(d == var(f'z_{i}') for i,d in enumerate(f.variables())))

if not f in self.polynomial_ring(): #todo: change this to accept coerce
raise ValueError(f"f must be an element of {self.polynomial_ring()}")


out = self.zero()

while f.monomials():
m = f.monomials()[0] #i'm assuming these are sorted in lex order but that is an educated guess.

m = f.monomials()[0] #i'm assuming these are sorted in lex order but that is an educated guess.
c = f.monomial_coefficient(m)
new_term = c * self(Composition(m))
new_term = self({Composition(m.exponents()[0]).reversed().trim():c})
f -= new_term.expand()
out += new_term

Expand Down Expand Up @@ -244,6 +268,15 @@ def _divided_difference_on_monomial(self, i, m):
factors_dict[x[i + 1] - x[i]] = factors_dict[x[i + 1] - x[i]] - 1
return R.prod(k**v for k,v in factors_dict.items()) * factors.unit()

def product_on_basis(self, a, b):
r"""
"""

p = self(a).expand() * self(b).expand()

return self.from_polynomial(p)

def _sorting_permutation(alpha):
r"""
Get the sorting permutation for a composition ``alpha``.
Expand Down

0 comments on commit e0bbdbd

Please sign in to comment.