Skip to content

Commit bbe8389

Browse files
author
Release Manager
committed
sagemathgh-41038: some care about algebra_generators add type annotations to some of them also change some of them to return Family objects or tuple related to sagemath#41028 for Jordan algebras ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. - [x I have updated the documentation and checked the documentation preview. URL: sagemath#41038 Reported by: Frédéric Chapoton Reviewer(s):
2 parents 22cf736 + dc3ce8c commit bbe8389

File tree

10 files changed

+92
-106
lines changed

10 files changed

+92
-106
lines changed

src/sage/algebras/jordan_algebra.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
Jordan algebra
1010
"""
1111

12-
#*****************************************************************************
12+
# ***************************************************************************
1313
# Copyright (C) 2014, 2023 Travis Scrimshaw <tscrim at ucdavis.edu>
1414
#
1515
# Distributed under the terms of the GNU General Public License (GPL)
1616
# https://www.gnu.org/licenses/
17-
#*****************************************************************************
17+
# ***************************************************************************
1818

1919
from sage.structure.parent import Parent
2020
from sage.structure.unique_representation import UniqueRepresentation
@@ -209,7 +209,7 @@ def __classcall_private__(self, arg0, arg1=None, names=None):
209209
if not arg1.is_symmetric():
210210
raise ValueError("the bilinear form is not symmetric")
211211

212-
arg1 = arg1.change_ring(arg0) # This makes a copy
212+
arg1 = arg1.change_ring(arg0) # This makes a copy
213213
arg1.set_immutable()
214214
return JordanAlgebraSymmetricBilinear(arg0, arg1, names=names)
215215

@@ -311,7 +311,7 @@ def _an_element_(self):
311311
return self.element_class(self, self._A.an_element())
312312

313313
@cached_method
314-
def basis(self):
314+
def basis(self) -> Family:
315315
"""
316316
Return the basis of ``self``.
317317
@@ -323,12 +323,13 @@ def basis(self):
323323
Lazy family (Term map(i))_{i in Free monoid on 3 generators (x, y, z)}
324324
"""
325325
B = self._A.basis()
326-
return Family(B.keys(), lambda x: self.element_class(self, B[x]), name="Term map")
326+
return Family(B.keys(),
327+
lambda x: self.element_class(self, B[x]), name="Term map")
327328

328329
algebra_generators = basis
329330

330331
# TODO: Keep this until we can better handle R.<...> shorthand
331-
def gens(self) -> tuple:
332+
def gens(self) -> Family:
332333
"""
333334
Return the generators of ``self``.
334335
@@ -338,16 +339,14 @@ def gens(self) -> tuple:
338339
sage: C = CombinatorialFreeModule(QQ, ['x','y','z'], category=cat)
339340
sage: J = JordanAlgebra(C)
340341
sage: J.gens()
341-
(B['x'], B['y'], B['z'])
342+
Finite family {'x': B['x'], 'y': B['y'], 'z': B['z']}
342343
343344
sage: F.<x,y,z> = FreeAlgebra(QQ)
344345
sage: J = JordanAlgebra(F)
345346
sage: J.gens()
346-
Traceback (most recent call last):
347-
...
348-
NotImplementedError: infinite set
347+
Lazy family (Term map(i))_{i in Free monoid on 3 generators (x, y, z)}
349348
"""
350-
return tuple(self.algebra_generators())
349+
return self.algebra_generators()
351350

352351
@cached_method
353352
def zero(self):
@@ -741,7 +740,7 @@ def _coerce_map_from_base_ring(self):
741740
return self._generic_coerce_map(self.base_ring())
742741

743742
@cached_method
744-
def basis(self):
743+
def basis(self) -> Family:
745744
"""
746745
Return a basis of ``self``.
747746
@@ -763,7 +762,7 @@ def basis(self):
763762

764763
algebra_generators = basis
765764

766-
def gens(self) -> tuple:
765+
def gens(self) -> Family:
767766
"""
768767
Return the generators of ``self``.
769768
@@ -772,9 +771,9 @@ def gens(self) -> tuple:
772771
sage: m = matrix([[0,1],[1,1]])
773772
sage: J = JordanAlgebra(m)
774773
sage: J.gens()
775-
(1 + (0, 0), 0 + (1, 0), 0 + (0, 1))
774+
Family (1 + (0, 0), 0 + (1, 0), 0 + (0, 1))
776775
"""
777-
return tuple(self.algebra_generators())
776+
return self.algebra_generators()
778777

779778
@cached_method
780779
def zero(self):
@@ -974,7 +973,7 @@ def _mul_(self, other):
974973
P = self.parent()
975974
return self.__class__(P,
976975
self._s * other._s
977-
+ (self._v * P._form * other._v.column())[0],
976+
+ (self._v * P._form * other._v.column())[0],
978977
other._s * self._v + self._s * other._v)
979978

980979
def _lmul_(self, other):
@@ -1023,8 +1022,8 @@ def monomial_coefficients(self, copy=True):
10231022
{0: 1, 1: 2, 2: -1}
10241023
"""
10251024
d = {0: self._s}
1026-
for i,c in enumerate(self._v):
1027-
d[i+1] = c
1025+
for i, c in enumerate(self._v):
1026+
d[i + 1] = c
10281027
return d
10291028

10301029
def trace(self):
@@ -1258,8 +1257,8 @@ def _test_multiplication_self_adjoint(self, **options):
12581257
[SD[3].conjugate(), SD[1], SD[5]],
12591258
[SD[4].conjugate(), SD[5].conjugate(), SD[2]]]
12601259
Y = [[OD[0], OD[3], OD[4]],
1261-
[OD[3].conjugate(), OD[1], OD[5]],
1262-
[OD[4].conjugate(), OD[5].conjugate(), OD[2]]]
1260+
[OD[3].conjugate(), OD[1], OD[5]],
1261+
[OD[4].conjugate(), OD[5].conjugate(), OD[2]]]
12631262
for r, c in data_pairs:
12641263
if r != c:
12651264
val = sum(X[r][i] * Y[i][c] + Y[r][i] * X[i][c] for i in range(3)) * self._half
@@ -1270,7 +1269,7 @@ def _test_multiplication_self_adjoint(self, **options):
12701269
tester.assertEqual(val.imag_part(), zerO)
12711270

12721271
@cached_method
1273-
def basis(self):
1272+
def basis(self) -> Family:
12741273
r"""
12751274
Return a basis of ``self``.
12761275
@@ -1315,7 +1314,7 @@ def basis(self):
13151314

13161315
algebra_generators = basis
13171316

1318-
def gens(self) -> tuple:
1317+
def gens(self) -> Family:
13191318
"""
13201319
Return the generators of ``self``.
13211320
@@ -1337,7 +1336,7 @@ def gens(self) -> tuple:
13371336
[ 0 0 k]
13381337
[ 0 -k 0]
13391338
"""
1340-
return tuple(self.algebra_generators())
1339+
return self.basis()
13411340

13421341
@cached_method
13431342
def zero(self):
@@ -1684,8 +1683,8 @@ def _mul_(self, other):
16841683
[SD[3].conjugate(), SD[1], SD[5]],
16851684
[SD[4].conjugate(), SD[5].conjugate(), SD[2]]]
16861685
Y = [[OD[0], OD[3], OD[4]],
1687-
[OD[3].conjugate(), OD[1], OD[5]],
1688-
[OD[4].conjugate(), OD[5].conjugate(), OD[2]]]
1686+
[OD[3].conjugate(), OD[1], OD[5]],
1687+
[OD[4].conjugate(), OD[5].conjugate(), OD[2]]]
16891688
# we do a simplified multiplication for the diagonal entries since
16901689
# we have, e.g., \alpha * \alpha' + (x (x')^* + x' x^* + y (y')^* + y' y^*) / 2
16911690
ret = [X[0][0] * Y[0][0] + (X[0][1] * Y[1][0]).real_part() + (X[0][2] * Y[2][0]).real_part(),

src/sage/combinat/free_dendriform_algebra.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def gen(self, i):
249249
return G[G.keys().unrank(i)]
250250

251251
@cached_method
252-
def algebra_generators(self):
252+
def algebra_generators(self) -> Family:
253253
r"""
254254
Return the generators of this algebra.
255255
@@ -266,6 +266,12 @@ def algebra_generators(self):
266266
sage: A = algebras.FreeDendriform(QQ, ['x1','x2'])
267267
sage: list(A.algebra_generators())
268268
[B[x1[., .]], B[x2[., .]]]
269+
270+
TESTS::
271+
272+
sage: A = algebras.FreeDendriform(ZZ, 'fgh')
273+
sage: A.gens()
274+
Finite family {'f': B[f[., .]], 'g': B[g[., .]], 'h': B[h[., .]]}
269275
"""
270276
Trees = self.basis().keys()
271277
return Family(self._alphabet, lambda a: self.monomial(Trees([], a)))
@@ -287,17 +293,7 @@ def change_ring(self, R):
287293
"""
288294
return FreeDendriformAlgebra(R, names=self.variable_names())
289295

290-
def gens(self) -> tuple:
291-
"""
292-
Return the generators of ``self`` (as an algebra).
293-
294-
EXAMPLES::
295-
296-
sage: A = algebras.FreeDendriform(ZZ, 'fgh')
297-
sage: A.gens()
298-
(B[f[., .]], B[g[., .]], B[h[., .]])
299-
"""
300-
return tuple(self.algebra_generators())
296+
gens = algebra_generators
301297

302298
def degree_on_basis(self, t):
303299
"""

src/sage/combinat/free_prelie_algebra.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def gen(self, i):
310310
return G[G.keys().unrank(i)]
311311

312312
@cached_method
313-
def algebra_generators(self):
313+
def algebra_generators(self) -> Family:
314314
r"""
315315
Return the generators of this algebra.
316316
@@ -327,6 +327,12 @@ def algebra_generators(self):
327327
sage: A = algebras.FreePreLie(QQ, ['x1','x2'])
328328
sage: list(A.algebra_generators())
329329
[B[x1[]], B[x2[]]]
330+
331+
TESTS::
332+
333+
sage: A = algebras.FreePreLie(ZZ, 'fgh')
334+
sage: A.gens()
335+
Finite family {'f': B[f[]], 'g': B[g[]], 'h': B[h[]]}
330336
"""
331337
Trees = self.basis().keys()
332338
return Family(self._alphabet, lambda a: self.monomial(Trees([], a)))
@@ -348,17 +354,7 @@ def change_ring(self, R):
348354
"""
349355
return FreePreLieAlgebra(R, names=self.variable_names())
350356

351-
def gens(self) -> tuple:
352-
"""
353-
Return the generators of ``self`` (as an algebra).
354-
355-
EXAMPLES::
356-
357-
sage: A = algebras.FreePreLie(ZZ, 'fgh')
358-
sage: A.gens()
359-
(B[f[]], B[g[]], B[h[]])
360-
"""
361-
return tuple(self.algebra_generators())
357+
gens = algebra_generators
362358

363359
def degree_on_basis(self, t):
364360
"""

src/sage/combinat/ncsf_qsym/ncsf.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
coeff_sp, coeff_ell, m_to_s_stat, number_of_fCT, number_of_SSRCT, compositions_order)
4040
from sage.combinat.partition import Partition
4141
from sage.combinat.permutation import Permutations
42+
from sage.combinat.sf.sf import SymmetricFunctions
4243
from sage.matrix.constructor import matrix
4344
from sage.matrix.matrix_space import MatrixSpace
44-
from sage.combinat.sf.sf import SymmetricFunctions
45+
from sage.sets.family import Family
4546

4647

4748
class NonCommutativeSymmetricFunctions(UniqueRepresentation, Parent):
@@ -2031,7 +2032,7 @@ def super_categories(self):
20312032
class ParentMethods:
20322033

20332034
@cached_method
2034-
def algebra_generators(self):
2035+
def algebra_generators(self) -> Family:
20352036
"""
20362037
Return the algebra generators of a given multiplicative basis of
20372038
non-commutative symmetric functions.
@@ -2047,9 +2048,9 @@ def algebra_generators(self):
20472048
sage: f[1], f[2], f[3]
20482049
(Psi[1], Psi[2], Psi[3])
20492050
"""
2050-
from sage.sets.family import Family
20512051
from sage.sets.positive_integers import PositiveIntegers
2052-
return Family(PositiveIntegers(), lambda i: self.monomial(self._indices([i])))
2052+
return Family(PositiveIntegers(),
2053+
lambda i: self.monomial(self._indices([i])))
20532054

20542055
def product_on_basis(self, composition1, composition2):
20552056
"""

src/sage/combinat/symmetric_group_algebra.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
Permutations,
2323
from_permutation_group_element,
2424
)
25-
from sage.combinat.permutation_cython import left_action_same_n, right_action_same_n
25+
from sage.combinat.permutation_cython import (left_action_same_n,
26+
right_action_same_n)
2627
from sage.combinat.skew_tableau import SkewTableau
2728
from sage.combinat.tableau import (
2829
StandardTableaux,
@@ -38,6 +39,7 @@
3839
from sage.modules.free_module_element import vector
3940
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
4041
from sage.rings.rational_field import QQ
42+
from sage.sets.family import Family
4143

4244
lazy_import('sage.groups.perm_gps.permgroup_element',
4345
'PermutationGroupElement')
@@ -244,7 +246,7 @@ def SymmetricGroupAlgebra(R, W, category=None):
244246

245247
class SymmetricGroupAlgebra_n(GroupAlgebra_class):
246248

247-
def __init__(self, R, W, category):
249+
def __init__(self, R, W, category) -> None:
248250
"""
249251
TESTS::
250252
@@ -1355,10 +1357,9 @@ def ladder_idempotent(self, la):
13551357
return Elad * eprod
13561358

13571359
@cached_method
1358-
def algebra_generators(self):
1360+
def algebra_generators(self) -> Family:
13591361
r"""
1360-
Return generators of this group algebra (as algebra) as a
1361-
list of permutations.
1362+
Return generators of this group algebra (as algebra).
13621363
13631364
The generators used for the group algebra of `S_n` are the
13641365
transposition `(2, 1)` and the `n`-cycle `(1, 2, \ldots, n)`,
@@ -1386,7 +1387,6 @@ def algebra_generators(self):
13861387
sage: M = C.module_morphism(lambda x: S3.zero(), codomain=S3)
13871388
sage: M.register_as_coercion()
13881389
"""
1389-
from sage.sets.family import Family
13901390
if self.n <= 1:
13911391
return Family([])
13921392
a = list(range(1, self.n + 1))
@@ -3574,7 +3574,7 @@ def _element_constructor_(self, x):
35743574

35753575
class HeckeAlgebraSymmetricGroup_t(HeckeAlgebraSymmetricGroup_generic):
35763576

3577-
def __init__(self, R, n, q=None):
3577+
def __init__(self, R, n, q=None) -> None:
35783578
"""
35793579
TESTS::
35803580
@@ -3686,16 +3686,16 @@ def t(self, i):
36863686
list(range(i + 2, self.n + 1))))
36873687
# The permutation here is simply the transposition (i, i+1).
36883688

3689-
def algebra_generators(self):
3689+
def algebra_generators(self) -> tuple:
36903690
"""
36913691
Return the generators of the algebra.
36923692
36933693
EXAMPLES::
36943694
36953695
sage: HeckeAlgebraSymmetricGroupT(QQ,3).algebra_generators()
3696-
[T[2, 1, 3], T[1, 3, 2]]
3696+
(T[2, 1, 3], T[1, 3, 2])
36973697
"""
3698-
return [self.t(i) for i in range(1, self.n)]
3698+
return tuple(self.t(i) for i in range(1, self.n))
36993699

37003700
def jucys_murphy(self, k):
37013701
r"""

0 commit comments

Comments
 (0)