Skip to content

Commit 879963c

Browse files
fchapotondimpase
authored andcommitted
switch class functions to libgap by default
1 parent ef3a6e9 commit 879963c

File tree

5 files changed

+76
-66
lines changed

5 files changed

+76
-66
lines changed

src/sage/combinat/matrices/latin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ def check_bitrade_generators(a, b, c):
24962496
sage: a, b, c, G = p3_group_bitrade_generators(3)
24972497
sage: check_bitrade_generators(a, b, c)
24982498
True
2499-
sage: check_bitrade_generators(a, b, gap('()'))
2499+
sage: check_bitrade_generators(a, b, libgap(gap('()')))
25002500
False
25012501
"""
25022502
A = PermutationGroup([a])

src/sage/combinat/permutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def _gap_(self, gap):
707707
sage: gap(Permutation((1,2,3))) # needs sage.libs.gap
708708
(1,2,3)
709709
sage: type(_) # needs sage.libs.gap
710-
<class 'sage.interfaces.gap.GapElement'>
710+
<class 'sage.libs.gap.element.GapElement_Permutation'>
711711
"""
712712
return self.to_permutation_group_element()._gap_(gap)
713713

src/sage/groups/class_function.py

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
- Volker Braun (October 2010): Bugfixes, exterior and symmetric power.
1818
"""
1919

20-
#*****************************************************************************
20+
# ****************************************************************************
2121
# Copyright (C) 2008 Franco Saliola <[email protected]>
2222
#
2323
# Distributed under the terms of the GNU General Public License (GPL)
2424
# https://www.gnu.org/licenses/
25-
#*****************************************************************************
25+
# ****************************************************************************
2626

2727
from sage.structure.sage_object import SageObject
2828
from sage.structure.richcmp import richcmp, richcmp_method
@@ -66,24 +66,26 @@ class function on the conjugacy classes, in that order.
6666
sage: chi = ClassFunction(G, values); chi
6767
Character of Cyclic group of order 4 as a permutation group
6868
"""
69+
from sage.misc.superseded import deprecation
6970
try:
7071
return group.class_function(values)
7172
except AttributeError:
7273
pass
7374

74-
if isinstance(values, LibGapElement):
75+
if isinstance(values, (LibGapElement, tuple, list)):
7576
return ClassFunction_libgap(group, values)
7677

78+
# deprecation(36889, "please use libgap class functions instead")
7779
return ClassFunction_gap(group, values)
7880

7981

8082
#####################################################################
81-
###
82-
### GAP Interface-based Class Function
83-
###
84-
### This is old code that should be deleted once we have transitioned
85-
### everything to using the library interface to GAP.
86-
###
83+
#
84+
# GAP Interface-based Class Function
85+
#
86+
# This is old code that should be deleted once we have transitioned
87+
# everything to using the library interface to GAP.
88+
#
8789
#####################################################################
8890

8991
@richcmp_method
@@ -123,20 +125,20 @@ def __init__(self, G, values):
123125
if isinstance(values, GapElement) and gap.IsClassFunction(values):
124126
self._gap_classfunction = values
125127
else:
126-
self._gap_classfunction = gap.ClassFunction(G, list(values))
128+
self._gap_classfunction = gap.ClassFunction(G, gap(values))
127129

128130
e = self._gap_classfunction.Conductor()
129131
self._base_ring = CyclotomicField(e)
130132

131133
def _gap_init_(self):
132134
r"""
133-
Returns a string showing how to declare / initialize self in Gap.
135+
Return a string showing how to declare / initialize self in Gap.
134136
Stored in the \code{self._gap_string} attribute.
135137
136138
EXAMPLES::
137139
138140
sage: G = CyclicPermutationGroup(4)
139-
sage: values = [1, -1, 1, -1]
141+
sage: values = gap([1, -1, 1, -1])
140142
sage: ClassFunction(G, values)._gap_init_()
141143
'ClassFunction( CharacterTable( Group( [ (1,2,3,4) ] ) ), [ 1, -1, 1, -1 ] )'
142144
"""
@@ -149,7 +151,7 @@ def _gap_(self, *args):
149151
EXAMPLES::
150152
151153
sage: G = CyclicPermutationGroup(4)
152-
sage: values = [1, -1, 1, -1]
154+
sage: values = gap([1, -1, 1, -1])
153155
sage: chi = ClassFunction(G, values); chi
154156
Character of Cyclic group of order 4 as a permutation group
155157
sage: type(_)
@@ -173,7 +175,7 @@ def __repr__(self):
173175
174176
sage: G = SymmetricGroup(4)
175177
sage: values = [1, -1, 1, 1, -1]
176-
sage: ClassFunction(G, values)
178+
sage: ClassFunction(G, gap(values))
177179
Character of Symmetric group of order 4! as a permutation group
178180
"""
179181
return "Character of %s" % repr(self._group)
@@ -185,7 +187,7 @@ def __iter__(self):
185187
186188
EXAMPLES::
187189
188-
sage: xi = ClassFunction(SymmetricGroup(4), [1, -1, 1, 1, -1])
190+
sage: xi = ClassFunction(SymmetricGroup(4), gap([1, -1, 1, 1, -1]))
189191
sage: list(xi)
190192
[1, -1, 1, 1, -1]
191193
"""
@@ -239,7 +241,7 @@ def __reduce__(self):
239241
EXAMPLES::
240242
241243
sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
242-
sage: chi = ClassFunction(G, [1, 1, 1, 1, 1, 1, 1])
244+
sage: chi = ClassFunction(G, gap([1, 1, 1, 1, 1, 1, 1]))
243245
sage: type(chi)
244246
<class 'sage.groups.class_function.ClassFunction_gap'>
245247
sage: loads(dumps(chi)) == chi
@@ -249,7 +251,7 @@ def __reduce__(self):
249251

250252
def domain(self):
251253
r"""
252-
Returns the domain of the self.
254+
Return the domain of the ``self``.
253255
254256
OUTPUT:
255257
@@ -294,7 +296,7 @@ def __call__(self, g):
294296

295297
def __add__(self, other):
296298
r"""
297-
Returns the sum of the characters self and other.
299+
Return the sum of the characters self and other.
298300
299301
INPUT:
300302
@@ -307,7 +309,7 @@ def __add__(self, other):
307309
308310
EXAMPLES::
309311
310-
sage: chi = ClassFunction(SymmetricGroup(4), [3, 1, -1, 0, -1])
312+
sage: chi = ClassFunction(SymmetricGroup(4), gap([3, 1, -1, 0, -1]))
311313
sage: s = chi+chi
312314
sage: s
313315
Character of Symmetric group of order 4! as a permutation group
@@ -321,7 +323,7 @@ def __add__(self, other):
321323

322324
def __sub__(self, other):
323325
r"""
324-
Returns the difference of the characters ``self`` and ``other``.
326+
Return the difference of the characters ``self`` and ``other``.
325327
326328
INPUT:
327329
@@ -366,7 +368,7 @@ def __mul__(self, other):
366368
EXAMPLES::
367369
368370
sage: G = SymmetricGroup(4)
369-
sage: chi1 = ClassFunction(G, [3, 1, -1, 0, -1])
371+
sage: chi1 = ClassFunction(G, gap([3, 1, -1, 0, -1]))
370372
sage: 3*chi1
371373
Character of Symmetric group of order 4! as a permutation group
372374
sage: 3*chi1 == chi1+chi1+chi1
@@ -384,7 +386,7 @@ def __mul__(self, other):
384386
sage: (zeta3 * chi1).values()
385387
[3*zeta3, zeta3, -zeta3, 0, -zeta3]
386388
387-
sage: chi2 = ClassFunction(G, [1, -1, 1, 1, -1])
389+
sage: chi2 = ClassFunction(G, gap([1, -1, 1, 1, -1]))
388390
sage: p = chi1*chi2
389391
sage: p
390392
Character of Symmetric group of order 4! as a permutation group
@@ -456,7 +458,7 @@ def __neg__(self):
456458

457459
def __pow__(self, other):
458460
r"""
459-
Returns the product of self with itself other times.
461+
Return the product of self with itself other times.
460462
461463
EXAMPLES::
462464
@@ -467,13 +469,13 @@ def __pow__(self, other):
467469
sage: p.values()
468470
[27, 1, -1, 0, -1]
469471
"""
470-
if not isinstance(other, (int,Integer)):
472+
if not isinstance(other, (int, Integer)):
471473
raise NotImplementedError
472474
return ClassFunction(self._group, self._gap_classfunction ** other)
473475

474476
def symmetric_power(self, n):
475477
r"""
476-
Returns the symmetrized product of self with itself ``n`` times.
478+
Return the symmetrized product of self with itself ``n`` times.
477479
478480
INPUT:
479481
@@ -486,7 +488,7 @@ def symmetric_power(self, n):
486488
487489
EXAMPLES::
488490
489-
sage: chi = ClassFunction(SymmetricGroup(4), [3, 1, -1, 0, -1])
491+
sage: chi = ClassFunction(SymmetricGroup(4), gap([3, 1, -1, 0, -1]))
490492
sage: p = chi.symmetric_power(3)
491493
sage: p
492494
Character of Symmetric group of order 4! as a permutation group
@@ -495,11 +497,11 @@ def symmetric_power(self, n):
495497
"""
496498
n = Integer(n)
497499
tbl = gap.UnderlyingCharacterTable(self)
498-
return ClassFunction(self._group, gap.SymmetricParts(tbl,[self],n)[1])
500+
return ClassFunction(self._group, gap.SymmetricParts(tbl, [self], n)[1])
499501

500502
def exterior_power(self, n):
501503
r"""
502-
Returns the anti-symmetrized product of self with itself ``n`` times.
504+
Return the anti-symmetrized product of self with itself ``n`` times.
503505
504506
INPUT:
505507
@@ -512,7 +514,7 @@ def exterior_power(self, n):
512514
513515
EXAMPLES::
514516
515-
sage: chi = ClassFunction(SymmetricGroup(4), [3, 1, -1, 0, -1])
517+
sage: chi = ClassFunction(SymmetricGroup(4), gap([3, 1, -1, 0, -1]))
516518
sage: p = chi.exterior_power(3) # the highest anti-symmetric power for a 3-d character
517519
sage: p
518520
Character of Symmetric group of order 4! as a permutation group
@@ -523,11 +525,11 @@ def exterior_power(self, n):
523525
"""
524526
n = Integer(n)
525527
tbl = gap.UnderlyingCharacterTable(self)
526-
return ClassFunction(self._group, gap.AntiSymmetricParts(tbl,[self],n)[1])
528+
return ClassFunction(self._group, gap.AntiSymmetricParts(tbl, [self], n)[1])
527529

528530
def scalar_product(self, other):
529531
r"""
530-
Returns the scalar product of self with other.
532+
Return the scalar product of self with other.
531533
532534
EXAMPLES::
533535
@@ -544,7 +546,7 @@ def scalar_product(self, other):
544546

545547
def is_irreducible(self):
546548
r"""
547-
Returns True if self cannot be written as the sum of two nonzero
549+
Return True if self cannot be written as the sum of two nonzero
548550
characters of self.
549551
550552
EXAMPLES::
@@ -558,7 +560,7 @@ def is_irreducible(self):
558560

559561
def degree(self):
560562
r"""
561-
Returns the degree of the character self.
563+
Return the degree of the character self.
562564
563565
EXAMPLES::
564566
@@ -571,7 +573,7 @@ def degree(self):
571573

572574
def irreducible_constituents(self):
573575
r"""
574-
Returns a list of the characters that appear in the decomposition
576+
Return a list of the characters that appear in the decomposition
575577
of chi.
576578
577579
EXAMPLES::
@@ -694,7 +696,7 @@ def tensor_product(self, other):
694696
sage: chi1.tensor_product(chi3).values()
695697
[1, -1, 1]
696698
"""
697-
return ClassFunction(self._group, gap.Tensored([self],[other])[1])
699+
return ClassFunction(self._group, gap.Tensored([self], [other])[1])
698700

699701
def restrict(self, H):
700702
r"""
@@ -791,9 +793,9 @@ def adams_operation(self, k):
791793

792794

793795
#####################################################################
794-
###
795-
### Class function using the GAP library
796-
###
796+
#
797+
# Class function using the GAP library
798+
#
797799
#####################################################################
798800

799801

@@ -834,12 +836,12 @@ def __init__(self, G, values):
834836
if isinstance(values, LibGapElement) and values.IsClassFunction():
835837
self._gap_classfunction = values
836838
else:
837-
self._gap_classfunction = libgap.ClassFunction(G._libgap_(),
838-
list(values))
839+
self._gap_classfunction = libgap.ClassFunction(G,
840+
libgap(values))
839841
e = self._gap_classfunction.Conductor().sage()
840842
self._base_ring = CyclotomicField(e)
841843

842-
def gap(self):
844+
def _libgap_(self):
843845
r"""
844846
Return the underlying LibGAP element.
845847
@@ -850,15 +852,15 @@ def gap(self):
850852
sage: chi = ClassFunction(G, values); chi
851853
Character of Cyclic group of order 4 as a permutation group
852854
sage: type(chi)
853-
<class 'sage.groups.class_function.ClassFunction_gap'>
854-
sage: gap(chi)
855-
ClassFunction( CharacterTable( Group( [ (1,2,3,4) ] ) ), [ 1, -1, 1, -1 ] )
855+
<class 'sage.groups.class_function.ClassFunction_libgap'>
856+
sage: libgap(chi)
857+
ClassFunction( CharacterTable( Group([ (1,2,3,4) ]) ), [ 1, -1, 1, -1 ] )
856858
sage: type(_)
857-
<class 'sage.interfaces.gap.GapElement'>
859+
<class 'sage.libs.gap.element.GapElement_List'>
858860
"""
859861
return self._gap_classfunction
860862

861-
_libgap_ = _gap_ = gap
863+
gap = _gap_ = _libgap_
862864

863865
def _repr_(self):
864866
r"""
@@ -877,6 +879,16 @@ def _repr_(self):
877879
"""
878880
return "Character of %s" % repr(self._group)
879881

882+
def __hash__(self):
883+
r"""
884+
TESTS::
885+
886+
sage: G = SymmetricGroup(5)
887+
sage: chi1 = ClassFunction(G,[1,1,1,1,1,1,1])
888+
sage: d = {chi1:'trivial'}
889+
"""
890+
return hash((self._group, tuple(self)))
891+
880892
def __iter__(self):
881893
r"""
882894
Iterate through the values.
@@ -1162,7 +1174,7 @@ def __pow__(self, other):
11621174
sage: p.values()
11631175
[27, 1, -1, 0, -1]
11641176
"""
1165-
if not isinstance(other, (int,Integer)):
1177+
if not isinstance(other, (int, Integer)):
11661178
raise NotImplementedError
11671179
return ClassFunction(self._group, self._gap_classfunction ** other)
11681180

@@ -1189,8 +1201,8 @@ def symmetric_power(self, n):
11891201
[10, 2, -2, 1, 0]
11901202
"""
11911203
n = Integer(n)
1192-
tbl = self._gap_classfunction.UnderlyingCharacterTable(self)
1193-
return ClassFunction(self._group, tbl.SymmetricParts([self],n)[1])
1204+
tbl = self._gap_classfunction.UnderlyingCharacterTable()
1205+
return ClassFunction(self._group, tbl.SymmetricParts([self], n)[0])
11941206

11951207
def exterior_power(self, n):
11961208
r"""
@@ -1217,8 +1229,8 @@ def exterior_power(self, n):
12171229
True
12181230
"""
12191231
n = Integer(n)
1220-
tbl = self._gap_classfunction.UnderlyingCharacterTable(self)
1221-
return ClassFunction(self._group, tbl.AntiSymmetricParts([self],n)[1])
1232+
tbl = self._gap_classfunction.UnderlyingCharacterTable()
1233+
return ClassFunction(self._group, tbl.AntiSymmetricParts([self], n)[0])
12221234

12231235
def scalar_product(self, other):
12241236
r"""

0 commit comments

Comments
 (0)