@@ -3043,21 +3043,21 @@ def plethysm(self, x, include=None, exclude=None):
3043
3043
sage: Sym = SymmetricFunctions(QQ)
3044
3044
sage: s = Sym.s()
3045
3045
sage: h = Sym.h()
3046
- sage: s ( h( [3])( h( [2]) ) )
3046
+ sage: s(h [3](h [2]))
3047
3047
s[2, 2, 2] + s[4, 2] + s[6]
3048
3048
sage: p = Sym.p()
3049
- sage: p([3])( s( [2,1]) )
3049
+ sage: p(p [3](s [2,1]))
3050
3050
1/3*p[3, 3, 3] - 1/3*p[9]
3051
3051
sage: e = Sym.e()
3052
- sage: e( [3])( e( [2]) )
3052
+ sage: e[3](e [2])
3053
3053
e[3, 3] + e[4, 1, 1] - 2*e[4, 2] - e[5, 1] + e[6]
3054
3054
3055
3055
::
3056
3056
3057
3057
sage: R.<t> = QQ[]
3058
3058
sage: s = SymmetricFunctions(R).s()
3059
3059
sage: a = s([3])
3060
- sage: f = t* s([2])
3060
+ sage: f = t * s([2])
3061
3061
sage: a(f)
3062
3062
t^3*s[2, 2, 2] + t^3*s[4, 2] + t^3*s[6]
3063
3063
sage: f(a)
@@ -3142,39 +3142,40 @@ def plethysm(self, x, include=None, exclude=None):
3142
3142
Check that we can compute the plethysm with a constant::
3143
3143
3144
3144
sage: p[2,2,1](2)
3145
- 8*p[]
3145
+ 8
3146
3146
3147
3147
sage: p[2,2,1](int(2))
3148
- 8*p[]
3148
+ 8
3149
3149
3150
3150
sage: p[2,2,1](a1)
3151
- a1^5*p[]
3151
+ a1^5
3152
3152
3153
3153
sage: X = algebras.Shuffle(QQ, 'ab')
3154
3154
sage: Y = algebras.Shuffle(QQ, 'bc')
3155
- sage: T = tensor([X,Y])
3155
+ sage: T = tensor([X, Y])
3156
3156
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 []
3159
3159
3160
3160
.. TODO::
3161
3161
3162
3162
The implementation of plethysm in
3163
3163
:class:`sage.data_structures.stream.Stream_plethysm` seems
3164
3164
to be faster. This should be investigated.
3165
3165
"""
3166
- parent = self .parent ()
3166
+ from sage .structure .element import parent as get_parent
3167
+ Px = get_parent (x )
3167
3168
if not self :
3168
- return self
3169
+ return Px ( 0 )
3169
3170
3171
+ parent = self .parent ()
3170
3172
R = parent .base_ring ()
3171
3173
tHA = HopfAlgebrasWithBasis (R ).TensorProducts ()
3172
- from sage .structure .element import parent as get_parent
3173
- Px = get_parent (x )
3174
3174
tensorflag = Px in tHA
3175
3175
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
3178
3179
elif (not tensorflag or any (not isinstance (factor , SymmetricFunctionAlgebra_generic )
3179
3180
for factor in Px ._sets )):
3180
3181
from sage .rings .lazy_series import LazySymmetricFunction
@@ -3198,13 +3199,15 @@ def plethysm(self, x, include=None, exclude=None):
3198
3199
3199
3200
if tensorflag :
3200
3201
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 )
3208
3211
3209
3212
# Takes a symmetric function f, and an n and returns the
3210
3213
# symmetric function with all of its basis partitions scaled
@@ -3218,7 +3221,11 @@ def pn_pleth(f, n):
3218
3221
def f (part ):
3219
3222
return p .prod (pn_pleth (p_x .map_coefficients (lambda c : _raise_variables (c , i , degree_one )), i )
3220
3223
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 )
3222
3229
3223
3230
__call__ = plethysm
3224
3231
@@ -6202,21 +6209,20 @@ def _nonnegative_coefficients(x):
6202
6209
return x >= 0
6203
6210
6204
6211
def _variables_recursive (R , include = None , exclude = None ):
6205
- """
6212
+ r """
6206
6213
Return all variables appearing in the ring ``R``.
6207
6214
6208
6215
INPUT:
6209
6216
6210
6217
- ``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``
6213
6219
6214
6220
OUTPUT:
6215
6221
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.
6220
6226
6221
6227
EXAMPLES::
6222
6228
@@ -6251,15 +6257,15 @@ def _variables_recursive(R, include=None, exclude=None):
6251
6257
except AttributeError :
6252
6258
try :
6253
6259
degree_one = R .gens ()
6254
- except NotImplementedError :
6260
+ except ( NotImplementedError , AttributeError ) :
6255
6261
degree_one = []
6256
6262
if exclude is not None :
6257
6263
degree_one = [g for g in degree_one if g not in exclude ]
6258
6264
6259
6265
return [g for g in degree_one if g != R .one ()]
6260
6266
6261
6267
def _raise_variables (c , n , variables ):
6262
- """
6268
+ r """
6263
6269
Replace the given variables in the ring element ``c`` with their
6264
6270
``n``-th power.
6265
6271
@@ -6276,6 +6282,9 @@ def _raise_variables(c, n, variables):
6276
6282
sage: S.<t> = R[]
6277
6283
sage: _raise_variables(2*a + 3*b*t, 2, [a, t])
6278
6284
3*b*t^2 + 2*a^2
6279
-
6280
6285
"""
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