Skip to content

Commit 5b8a696

Browse files
committed
Merge branch 'u/mantepse/parent_of_plethysm' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/parent_plethysm-27652
2 parents d95f9ba + 9280ad9 commit 5b8a696

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

src/sage/combinat/sf/sfa.py

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,21 +3043,21 @@ def plethysm(self, x, include=None, exclude=None):
30433043
sage: Sym = SymmetricFunctions(QQ)
30443044
sage: s = Sym.s()
30453045
sage: h = Sym.h()
3046-
sage: s ( h([3])( h([2]) ) )
3046+
sage: s(h[3](h[2]))
30473047
s[2, 2, 2] + s[4, 2] + s[6]
30483048
sage: p = Sym.p()
3049-
sage: p([3])( s([2,1]) )
3049+
sage: p(p[3](s[2,1]))
30503050
1/3*p[3, 3, 3] - 1/3*p[9]
30513051
sage: e = Sym.e()
3052-
sage: e([3])( e([2]) )
3052+
sage: e[3](e[2])
30533053
e[3, 3] + e[4, 1, 1] - 2*e[4, 2] - e[5, 1] + e[6]
30543054
30553055
::
30563056
30573057
sage: R.<t> = QQ[]
30583058
sage: s = SymmetricFunctions(R).s()
30593059
sage: a = s([3])
3060-
sage: f = t*s([2])
3060+
sage: f = t * s([2])
30613061
sage: a(f)
30623062
t^3*s[2, 2, 2] + t^3*s[4, 2] + t^3*s[6]
30633063
sage: f(a)
@@ -3142,39 +3142,40 @@ def plethysm(self, x, include=None, exclude=None):
31423142
Check that we can compute the plethysm with a constant::
31433143
31443144
sage: p[2,2,1](2)
3145-
8*p[]
3145+
8
31463146
31473147
sage: p[2,2,1](int(2))
3148-
8*p[]
3148+
8
31493149
31503150
sage: p[2,2,1](a1)
3151-
a1^5*p[]
3151+
a1^5
31523152
31533153
sage: X = algebras.Shuffle(QQ, 'ab')
31543154
sage: Y = algebras.Shuffle(QQ, 'bc')
3155-
sage: T = tensor([X,Y])
3155+
sage: T = tensor([X, Y])
31563156
sage: s = SymmetricFunctions(T).s()
3157-
sage: s(2*T.one())
3158-
(2*B[]#B[])*s[]
3157+
sage: s[2](5)
3158+
15*B[] # B[]
31593159
31603160
.. TODO::
31613161
31623162
The implementation of plethysm in
31633163
:class:`sage.data_structures.stream.Stream_plethysm` seems
31643164
to be faster. This should be investigated.
31653165
"""
3166-
parent = self.parent()
3166+
from sage.structure.element import parent as get_parent
3167+
Px = get_parent(x)
31673168
if not self:
3168-
return self
3169+
return Px(0)
31693170

3171+
parent = self.parent()
31703172
R = parent.base_ring()
31713173
tHA = HopfAlgebrasWithBasis(R).TensorProducts()
3172-
from sage.structure.element import parent as get_parent
3173-
Px = get_parent(x)
31743174
tensorflag = Px in tHA
31753175
if not is_SymmetricFunction(x):
3176-
if Px is R: # Handle stuff that is directly in the base ring
3177-
x = parent(x)
3176+
if R.has_coerce_map_from(Px) or x in R:
3177+
x = R(x)
3178+
Px = R
31783179
elif (not tensorflag or any(not isinstance(factor, SymmetricFunctionAlgebra_generic)
31793180
for factor in Px._sets)):
31803181
from sage.rings.lazy_series import LazySymmetricFunction
@@ -3198,13 +3199,15 @@ def plethysm(self, x, include=None, exclude=None):
31983199

31993200
if tensorflag:
32003201
tparents = Px._sets
3201-
s = sum(d * prod(sum(_raise_variables(c, r, degree_one)
3202-
* tensor([p[r].plethysm(base(la))
3203-
for base, la in zip(tparents, trm)])
3204-
for trm, c in x)
3205-
for r in mu)
3206-
for mu, d in p(self))
3207-
return tensor([parent]*len(tparents))(s)
3202+
lincomb = Px.linear_combination
3203+
elt = lincomb((prod(lincomb((tensor([p[r].plethysm(base(la))
3204+
for base, la in zip(tparents, trm)]),
3205+
_raise_variables(c, r, degree_one))
3206+
for trm, c in x)
3207+
for r in mu),
3208+
d)
3209+
for mu, d in p(self))
3210+
return Px(elt)
32083211

32093212
# Takes a symmetric function f, and an n and returns the
32103213
# symmetric function with all of its basis partitions scaled
@@ -3218,7 +3221,11 @@ def pn_pleth(f, n):
32183221
def f(part):
32193222
return p.prod(pn_pleth(p_x.map_coefficients(lambda c: _raise_variables(c, i, degree_one)), i)
32203223
for i in part)
3221-
return parent(p._apply_module_morphism(p(self), f, codomain=p))
3224+
ret = p._apply_module_morphism(p(self), f, codomain=p)
3225+
if Px is R:
3226+
# special case for things in the base ring
3227+
return next(iter(ret._monomial_coefficients.values()))
3228+
return Px(ret)
32223229

32233230
__call__ = plethysm
32243231

@@ -6202,21 +6209,20 @@ def _nonnegative_coefficients(x):
62026209
return x >= 0
62036210

62046211
def _variables_recursive(R, include=None, exclude=None):
6205-
"""
6212+
r"""
62066213
Return all variables appearing in the ring ``R``.
62076214
62086215
INPUT:
62096216
62106217
- ``R`` -- a :class:`Ring`
6211-
- ``include``, ``exclude`` (optional, default ``None``) --
6212-
iterables of variables in ``R``
6218+
- ``include``, ``exclude`` -- (optional) iterables of variables in ``R``
62136219
62146220
OUTPUT:
62156221
6216-
- If ``include`` is specified, only these variables are returned
6217-
as elements of ``R``. Otherwise, all variables in ``R``
6218-
(recursively) with the exception of those in ``exclude`` are
6219-
returned.
6222+
If ``include`` is specified, only these variables are returned
6223+
as elements of ``R``. Otherwise, all variables in ``R``
6224+
(recursively) with the exception of those in ``exclude`` are
6225+
returned.
62206226
62216227
EXAMPLES::
62226228
@@ -6251,15 +6257,15 @@ def _variables_recursive(R, include=None, exclude=None):
62516257
except AttributeError:
62526258
try:
62536259
degree_one = R.gens()
6254-
except NotImplementedError:
6260+
except (NotImplementedError, AttributeError):
62556261
degree_one = []
62566262
if exclude is not None:
62576263
degree_one = [g for g in degree_one if g not in exclude]
62586264

62596265
return [g for g in degree_one if g != R.one()]
62606266

62616267
def _raise_variables(c, n, variables):
6262-
"""
6268+
r"""
62636269
Replace the given variables in the ring element ``c`` with their
62646270
``n``-th power.
62656271
@@ -6276,6 +6282,9 @@ def _raise_variables(c, n, variables):
62766282
sage: S.<t> = R[]
62776283
sage: _raise_variables(2*a + 3*b*t, 2, [a, t])
62786284
3*b*t^2 + 2*a^2
6279-
62806285
"""
6281-
return c.subs(**{str(g): g ** n for g in variables})
6286+
try:
6287+
return c.subs(**{str(g): g ** n for g in variables})
6288+
except AttributeError:
6289+
return c
6290+

0 commit comments

Comments
 (0)