Ticket #6670: trac6670group_algebra5.patch
File trac6670group_algebra5.patch, 27.9 KB (added by , 12 years ago) 


doc/en/reference/algebras.rst
# HG changeset patch # User David Loeffler <d.loeffler.01@cantab.net> # Date 1278150262 3600 # Node ID 276b87ad937f76847c9302eeeb2bf8bcd9e64aee # Parent e076fccdbc27eab0b4cf3d8a73249b47e8d24ba5 imported patch trac6670group_algebra4.patch diff r e076fccdbc27 r 276b87ad937f doc/en/reference/algebras.rst
a b 12 12 sage/algebras/free_algebra_quotient 13 13 sage/algebras/free_algebra_quotient_element 14 14 15 sage/algebras/group_algebra 16 15 17 sage/algebras/steenrod_algebra 16 18 sage/algebras/steenrod_algebra_element 17 sage/algebras/steenrod_algebra_bases 18 No newline at end of file 19 sage/algebras/steenrod_algebra_bases 
sage/algebras/group_algebra.py
diff r e076fccdbc27 r 276b87ad937f sage/algebras/group_algebra.py
a b 1 1 r""" 2 Class for group algebras of arbitrary groups (over a general commutative base 3 ring). 2 Group algebra of a group 4 3 5 NOTE: 6  It seems to be impossible to make this fit nicely with Sage's coercion 7 model. The problem is that (for example) if G is the additive group (ZZ,+), 8 and R = ZZ[G] is its group ring, then the integer 2 can be coerced into R 9 in two ways  via G, or via the base ring  and *the answers are 10 different*. In practice we get around this by preventing elements of G 11 coercing automatically into ZZ[G], which is a shame, but makes more sense 12 than preventing elements of the base ring doing so. 4 This module provides functionality for constructing and working with group 5 algebras of arbitrary groups (over a general commutative base ring). 6 7 .. note:: 8 9 It seems to be difficult to make this fit nicely with Sage's coercion 10 model. The problem is that (for example) if G is the additive group 11 `(\ZZ,+)`, and `R = \ZZ[G]` is its group ring, then the integer 2 can be 12 coerced into R in two ways  via G, or via the base ring  and *the 13 answers are different*. In practice we get around this by preventing 14 elements of G coercing automatically into `\ZZ[G]`, which is a shame, but 15 makes more sense than preventing elements of the base ring doing so. 13 16 14 17 AUTHOR: 15  David Loeffler (20080824): initial version 18 19  David Loeffler (20080824): initial version 20  Martin Raum (200908): update to use new coercion model 16 21 """ 17 22 18 23 #***************************************************************************** … … 31 36 from sage.rings.all import IntegerRing 32 37 from sage.groups.group import Group 33 38 from sage.structure.formal_sum import FormalSums_generic, FormalSums, FormalSum 39 from sage.structure.element import Element 34 40 from sage.sets.set import Set 41 from sage.misc.latex import latex 35 42 43 from sage.categories.morphism import Morphism 44 from sage.categories.pushout import ConstructionFunctor 45 from sage.categories.rings import Rings 36 46 37 class GroupAlgebra(Algebra):38 47 39 def __init__(self, group, base_ring = IntegerRing()): 40 r""" Create the given group algebra. 41 INPUT: 42  (Group) group: a generic group. 43  (Ring) base_ring: a commutative ring. 44 OUTPUT: 45  a GroupAlgebra instance. 48 _cache = dict() 49 50 51 class GroupAlgebraFunctor ( ConstructionFunctor ) : 52 r""" 53 A functor assigning a group algebra to its base ring. 54 """ 55 def __init__(self, group) : 56 r""" 57 INPUT : 58 59  group  a group that will be the module basis for the group algebras 60 in the range. 46 61 47 62 EXAMPLES:: 48 63 49 sage: GroupAlgebra(GL(3, GF(7))) 50 Group algebra of group "General Linear Group of degree 3 over Finite 51 Field of size 7" over base ring Integer Ring 52 sage: GroupAlgebra(1) 53 Traceback (most recent call last): 54 ... 55 TypeError: "1" is not a group 56 64 sage: from sage.algebras.group_algebra import GroupAlgebraFunctor 65 sage: F = GroupAlgebraFunctor(KleinFourGroup()) 66 sage: loads(dumps(F)) == F 67 True 57 68 sage: GroupAlgebra(SU(2, GF(4, 'a')), IntegerModRing(12)).category() 58 69 Category of group algebras over Ring of integers modulo 12 70 """ 71 self.__group = group 59 72 73 ConstructionFunctor.__init__(self, Rings(), Rings()) 74 75 def group(self) : 76 r""" 77 Return the group which is associtated to this functor. 78 79 EXAMPLES:: 80 81 sage: from sage.algebras.group_algebra import GroupAlgebraFunctor 82 sage: GroupAlgebraFunctor(CyclicPermutationGroup(17)).group() == CyclicPermutationGroup(17) 83 True 60 84 """ 61 if not base_ring.is_commutative(): 62 raise NotImplementedError, "Base ring must be commutative" 85 return self.__group 86 87 def __call__(self, base_ring) : 88 r""" Create the group algeba with given base ring over self.group(). 89 90 INPUT : 91 92  ``base_ring``  the base ring of the group algebra. 93 94 OUTPUT: 95 96 A group algebra. 97 98 EXAMPLES:: 99 100 sage: from sage.algebras.group_algebra import GroupAlgebraFunctor 101 sage: F = GroupAlgebraFunctor(CyclicPermutationGroup(17)) 102 sage: F(QQ) 103 Group algebra of group "Cyclic group of order 17 as a permutation group" over base ring Rational Field 104 """ 105 return GroupAlgebra(self.__group, base_ring) 106 107 def GroupAlgebra(group, base_ring = IntegerRing()) : 108 r""" 109 Create the given group algebra. 110 111 INPUT:: 112 113  (Group) group: a generic group. 114  (Ring) base_ring: a commutative ring. 115 116 OUTPUT: 117 118  a GroupAlgebra instance. 119 120 EXAMPLES:: 121 122 sage: GroupAlgebra(GL(3, GF(7))) 123 Group algebra of group "General Linear Group of degree 3 over Finite 124 Field of size 7" over base ring Integer Ring 125 sage: GroupAlgebra(1) 126 Traceback (most recent call last): 127 ... 128 TypeError: "1" is not a group 129 sage: GroupAlgebra(KleinFourGroup()) is GroupAlgebra(KleinFourGroup()) 130 True 131 """ 132 global _cache 133 134 if not base_ring.is_commutative(): 135 raise NotImplementedError, "Base ring must be commutative" 136 if not isinstance(group, Group): 137 raise TypeError, '"%s" is not a group' % group 138 139 140 key = (group, base_ring) 141 142 try : 143 return _cache[key] 144 except KeyError : 145 A = GroupAlgebra_class(group, base_ring) 146 _cache[key] = A 147 148 return A 149 150 class GroupAlgebra_class ( Algebra ) : 151 152 def __init__(self, group, base_ring): 153 r""" 154 EXAMPLES:: 155 156 sage: A = GroupAlgebra(GL(3, GF(7))) 157 sage: A.has_coerce_map_from(GL(3, GF(7))) 158 True 159 """ 63 160 64 if not isinstance(group, Group):65 raise TypeError, '"%s" is not a group' % group66 161 67 162 ParentWithGens.__init__(self, base_ring, category = GroupAlgebras(base_ring)) 68 163 69 164 self._formal_sum_module = FormalSums(base_ring) 70 165 self._group = group 71 166 167 if not base_ring.has_coerce_map_from(group) : 168 ## some matrix groups assume that coercion is only valid to 169 ## other matrix groups. This is a workaround 170 ## call _element_constructor_ to coerce group elements 171 #try : 172 self._populate_coercion_lists_( coerce_list = [base_ring, group] ) 173 #except TypeError : 174 # self._populate_coercion_lists_( coerce_list = [base_ring] ) 175 else : 176 self._populate_coercion_lists_( coerce_list = [base_ring] ) 177 178 def ngens(self) : 179 r""" 180 Return the number of generators. 181 182 EXAMPLES:: 183 184 sage: A = GroupAlgebra(SL2Z) 185 sage: A.ngens() 186 2 187 """ 188 return self._group.ngens() 189 190 def gen(self, i = 0) : 191 r""" 192 EXAMPLES:: 193 194 sage: A = GroupAlgebra(GL(3, GF(7))) 195 sage: A.gen(0) 196 [3 0 0] 197 [0 1 0] 198 [0 0 1] 199 """ 200 return self._element_constructor(self._group.gen(i), as_group_element = True) 201 202 72 203 def group(self): 73 r""" Return the group of this group algebra. 74 EXAMPLES: 204 r""" 205 Return the group of this group algebra. 206 207 EXAMPLES:: 208 75 209 sage: GroupAlgebra(GL(3, GF(11))).group() 76 210 General Linear Group of degree 3 over Finite Field of size 11 77 211 sage: GroupAlgebra(SymmetricGroup(10)).group() … … 79 213 """ 80 214 return self._group 81 215 216 ########################################################################### 217 ## GroupAlgebra_class :: mathmatical properties 218 ########################################################################### 219 82 220 def is_commutative(self): 83 r""" Return True if self is a commutative ring. True if and only if 84 self.group() is abelian. 221 r""" 222 Return True if self is a commutative ring. True if and only if 223 ``self.group()`` is abelian. 85 224 86 EXAMPLES: 225 EXAMPLES:: 226 87 227 sage: GroupAlgebra(SymmetricGroup(2)).is_commutative() 88 228 True 89 229 sage: GroupAlgebra(SymmetricGroup(3)).is_commutative() … … 92 232 return self.group().is_abelian() 93 233 94 234 def is_field(self, proof = True): 95 r""" Return True if self is a field. This is always false unless 96 self.group() is trivial and self.base_ring() is a field. 97 EXAMPLES: 235 r""" 236 Return True if self is a field. This is always false unless 237 ``self.group()`` is trivial and ``self.base_ring()`` is a field. 238 239 EXAMPLES:: 240 98 241 sage: GroupAlgebra(SymmetricGroup(2)).is_field() 99 242 False 100 243 sage: GroupAlgebra(SymmetricGroup(1)).is_field() … … 107 250 return (self.group().order() == 1) 108 251 109 252 def is_finite(self): 110 r""" Return True if self is finite, which is true if and only if 111 self.group() and self.base_ring() are both finite. 253 r""" 254 Return True if self is finite, which is true if and only if 255 ``self.group()`` and ``self.base_ring()`` are both finite. 112 256 113 EXAMPLES: 257 EXAMPLES:: 258 114 259 sage: GroupAlgebra(SymmetricGroup(2), IntegerModRing(10)).is_finite() 115 260 True 116 261 sage: GroupAlgebra(SymmetricGroup(2)).is_finite() … … 121 266 return (self.base_ring().is_finite() and self.group().is_finite()) 122 267 123 268 def is_exact(self): 124 r""" Return True if elements of self have exact representations, 125 which is true of self if and only if it is true of self.group() 126 and self.base_ring(). 269 r""" 270 Return True if elements of self have exact representations, which is 271 true of self if and only if it is true of ``self.group()`` and 272 ``self.base_ring()``. 127 273 128 EXAMPLES: 274 EXAMPLES:: 275 129 276 sage: GroupAlgebra(GL(3, GF(7))).is_exact() 130 277 True 131 278 sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() … … 136 283 return self.group().is_exact() and self.base_ring().is_exact() 137 284 138 285 def is_integral_domain(self, proof = True): 139 r""" Return True if self is an integral domain. 286 r""" 287 Return True if self is an integral domain. 140 288 141 This is false unless 142 self.base_ring() is an integral domain, and even then it is false unless 143 self.group() has no nontrivial elements of finite order. I don't know if 144 this condition suffices, but it obviously does if the group is abelian and 145 finitely generated. 289 This is false unless ``self.base_ring()`` is an integral domain, and 290 even then it is false unless ``self.group()`` has no nontrivial 291 elements of finite order. I don't know if this condition suffices, but 292 it obviously does if the group is abelian and finitely generated. 146 293 147 EXAMPLES: 294 EXAMPLES:: 295 148 296 sage: GroupAlgebra(SymmetricGroup(2)).is_integral_domain() 149 297 False 150 298 sage: GroupAlgebra(SymmetricGroup(1)).is_integral_domain() … … 191 339 # I don't know if that means "is canonically isomorphic to a prime field" 192 340 # or "is identical to a prime field". 193 341 194 def _coerce_impl(self, x): 195 return self(self.base_ring().coerce(x)) 342 ########################################################################### 343 ## GroupAlgebra_class :: elements 344 ########################################################################### 196 345 197 def _an_element_impl(self): 346 def _an_element_(self): 347 r""" 348 Return an element of self. 349 350 EXAMPLES:: 351 352 sage: A = GroupAlgebra(GL(3, GF(7))) 353 sage: A.an_element() 354 [3 0 0] 355 [0 1 0] 356 [0 0 1] 198 357 """ 199 Return an element of self. 200 201 EXAMPLE: 358 return self(self._formal_sum_module([ 359 (self.base_ring().an_element(), self.group().an_element()) 360 ])) 361 362 def random_element(self) : 363 r""" 364 Return a random element of self. 365 366 EXAMPLE:: 367 202 368 sage: GroupAlgebra(SU(2, 13), QQ).an_element() # random; hideous formatting! 203 369 1/95*[ 9 2*a + 12] 204 370 [ 0 3]  4*[ 9 9*a + 2] 205 371 [3*a + 5 1] 206 372 """ 207 try: 208 return self(self._formal_sum_module([ 209 (self.base_ring().random_element(), self.group().random_element()), 210 (self.base_ring().random_element(), self.group().random_element()), 211 ])) 212 except: # base ring or group might not implement .random_element() 213 return self(self._formal_sum_module([ (self.base_ring().an_element(), self.group().an_element()) ])) 373 return self(self._formal_sum_module([ 374 (self.base_ring().random_element(), self.group().random_element()), 375 (self.base_ring().random_element(), self.group().random_element()), 376 ])) 214 377 215 def __call__(self, x, check=True): 378 def construction(self) : 379 r""" 380 EXAMPLES:: 381 382 sage: A = GroupAlgebra(KleinFourGroup(), QQ) 383 sage: A.construction() 384 (GroupAlgebraFunctor, Rational Field) 385 """ 386 return GroupAlgebraFunctor(self._group), self.base_ring() 387 388 def _element_constructor_(self, x, as_group_element = False) : 216 389 r""" 217 390 Create an element of this group algebra. 218 391 219 392 INPUT: 220  x: either a FormalSum element consisting of elements of221 self.group(), an element of self.base_ring(), or an element222 of self.group().223  check (boolean): whether or not to check that the given elements224 really do lie in self.group(). Chiefly provided to speed up225 arithmetic operations with elements that have already been checked226 to lie in the group.227 393 394  ``x``: either a FormalSum element consisting of elements of 395 ``self.group()``, an element of ``self.base_ring()``, or an element 396 of ``self.group()``. 397  ``as_group_element``: if true and ``x`` may be considered as a basis 398 element and a group element, consider it a group element 399 228 400 OUTPUT: 229  a GroupAlgebraElement instance whose parent is self.230 401 231 EXAMPLES: 232 sage: G = AbelianGroup(1) 233 sage: f = G.gen() 402  a GroupAlgebraElement instance whose parent is self. 403 404 EXAMPLES:: 405 406 sage: G = KleinFourGroup() 407 sage: f = G.gen(0) 234 408 sage: ZG = GroupAlgebra(G) 235 409 sage: ZG(f) 236 f410 (3,4) 237 411 sage: ZG(1) == ZG(G(1)) 238 412 True 413 sage: G = AbelianGroup(1) 414 sage: ZG = GroupAlgebra(G) 415 sage: f = ZG.group().gen() 239 416 sage: ZG(FormalSum([(1,f), (2, f**2)])) 240 2*f^2 + f417 f + 2*f^2 241 418 sage: G = GL(2,7) 242 419 sage: OG = GroupAlgebra(G, ZZ[sqrt(5)]) 243 420 sage: OG(2) … … 249 426 sage: OG(FormalSum([ (1, G(2)), (2, RR(0.77)) ]) ) 250 427 Traceback (most recent call last): 251 428 ... 252 TypeError: 0.770000000000000 is not an element of group General Linear Group of degree 2over Finite Field of size 7429 TypeError: Cannot coerce 0.770000000000000 to a 2by2 matrix over Finite Field of size 7 253 430 254 431 Ordering of elements in output unpredictable as sort order of such wildly 255 432 dissimilar elements is subject to change between platforms and versions 256 433 (see trac ticket \#4373). 257 sage: OG(FormalSum([ (1, G(2)), (2, RR(0.77)) ]), check=False) # random258 [2 0]259 [0 2] + 2*0.770000000000000 434 435 :: 436 260 437 sage: OG(OG.base_ring().gens()[1]) 261 438 sqrt5*[1 0] 262 439 [0 1] 263 """ 264 return GroupAlgebraElement(self, x, check) 440 """ 441 if isinstance(x, Element) : 442 P = x.parent() 443 if P is self.base_ring() and not as_group_element: 444 return GroupAlgebraElement_class(self, 445 self._formal_sum_module( [(x, self.group()(1))] ) ) 446 elif P is self.group() : 447 return GroupAlgebraElement_class(self, 448 self._formal_sum_module( [(self.base_ring().one_element(), x)] ) ) 449 elif P is self._formal_sum_module : 450 return GroupAlgebraElement_class(self, x) 451 elif isinstance(x, FormalSum) and self._formal_sum_module.has_coerce_map_from(P) : 452 return GroupAlgebraElement_class(self, 453 self._formal_sum_module( 454 [(self.base_ring()(c), self.group()(g)) for c,g in x] ) ) 265 455 266 def __eq__(self, other): 267 r""" Test for equality. 268 EXAMPLES: 456 raise TypeError, "Don't know how to create an element of %s from %s" % \ 457 (self, x) 458 459 def __cmp__(self, other) : 460 r""" 461 Compare two algebras self and other. They are considered equal if and only 462 if their base rings and their groups coincide. 463 464 EXAMPLES:: 465 269 466 sage: GroupAlgebra(AbelianGroup(1)) == GroupAlgebra(AbelianGroup(1)) 270 467 True 271 468 sage: GroupAlgebra(AbelianGroup(1), QQ) == GroupAlgebra(AbelianGroup(1), ZZ) 272 469 False 273 470 sage: GroupAlgebra(AbelianGroup(2)) == GroupAlgebra(AbelianGroup(1)) 274 471 False 275 """ 276 if not isinstance(other, GroupAlgebra): 277 return False 278 else: 279 return self.base_ring() == other.base_ring() and self.group() == other.group() 472 sage: from sage.algebras.group_algebra import GroupAlgebra_class 473 sage: A = GroupAlgebra_class(KleinFourGroup(), ZZ) 474 sage: B = GroupAlgebra_class(KleinFourGroup(), QQ) 475 sage: A == B 476 False 477 sage: A == A 478 True 479 """ 480 c = cmp(type(self), type(other)) 481 482 if c == 0 : 483 c = cmp(self._group, other._group) 484 if c == 0 : 485 c = cmp(self.base_ring(), other.base_ring()) 486 487 return c 280 488 281 489 def _repr_(self): 282 r""" String representation of self. See GroupAlgebra.__init__ for a 283 doctest.""" 284 return "Group algebra of group \"%s\" over base ring %s" % (self.group(), self.base_ring()) 490 r""" 491 String representation of self. See GroupAlgebra.__init__ for a doctest. 492 493 EXAMPLES:: 494 495 sage: A = GroupAlgebra(KleinFourGroup(), ZZ) 496 sage: A 497 Group algebra of group "The Klein 4 group of order 4, as a permutation group" over base ring Integer Ring 498 """ 499 return "Group algebra of group \"%s\" over base ring %s" % \ 500 (self.group(), self.base_ring()) 501 502 def _latex_(self): 503 r"""Latex string of self. 504 505 EXAMPLES:: 506 507 sage: A = GroupAlgebra(KleinFourGroup(), ZZ) 508 sage: latex(A) 509 Group algebra of group \langle (3,4), (1,2) \rangle over base ring \Bold{Z} 510 """ 511 return "Group algebra of group %s over base ring %s" % \ 512 (latex(self.group()), latex(self.base_ring())) 285 513 286 514 def element_class(self): 287 515 r""" 288 516 The class of elements of self, which is GroupAlgebraElement. 289 517 290 EXAMPLES: 518 EXAMPLES:: 519 291 520 sage: GroupAlgebra(SU(2, GF(4,'a'))).element_class() 292 <class 'sage.algebras.group_algebra.GroupAlgebraElement '>521 <class 'sage.algebras.group_algebra.GroupAlgebraElement_class'> 293 522 """ 294 return GroupAlgebraElement 523 return GroupAlgebraElement_class 295 524 525 def GroupAlgebraElement(parent, x, check = True) : 526 r""" 527 Create an element of the group algebra parent. 296 528 297 class GroupAlgebraElement(AlgebraElement): 529  ``x``  an element of the base ring, the group or a formal sum with 530 summand ``(a, g)``, where a is in the base ring and g is in the group 531  ``check``  determines whether the summand of a formal sum will be 532 checked for correctness 298 533 299 def __init__(self, parent, x, check): 300 r""" Create an element of the parent group algebra. Not intended to be 301 called by the user; see GroupAlgebra.__call__ for examples and 302 doctests.""" 534 EXAMPLES:: 535 536 sage: G = KleinFourGroup() 537 sage: A = GroupAlgebra(G) 538 sage: GroupAlgebraElement(A, A.group().gen(1)) 539 (1,2) 540 sage: GroupAlgebraElement(A, 1) 541 () 542 sage: GroupAlgebraElement(A, 10) 543 10*() 544 """ 545 ## Provide this for backward compatibility to the old class layout 546 547 assert isinstance(parent, GroupAlgebra_class), "%s must be group algebra" 548 if not isinstance(x, Element) : 549 x = IntegerRing()(x) 550 551 if isinstance(x, FormalSum) and check : 552 for c,g in x : 553 if not c in parent.base_ring() or not g in parent.group() : 554 raise ValueError, "summands of %s must be elements of base " + \ 555 "ring and group respectively" 556 557 return parent._element_constructor(x) 558 559 ########################################################################### 560 ## GroupAlgebraElement_class 561 ########################################################################### 562 563 class GroupAlgebraElement_class ( AlgebraElement ) : 564 565 def __init__(self, parent, x): 566 r""" 567 Create an element of the parent group algebra. Not intended to be 568 called by the user; see GroupAlgebra._element_constructor_ for examples 569 and doctests. 570 571 EXAMPLES:: 572 573 sage: A = GroupAlgebra(KleinFourGroup(), ZZ) 574 sage: GroupAlgebraElement(A, A._formal_sum_module([(1, KleinFourGroup().gen(0))])) 575 (3,4) 576 """ 303 577 AlgebraElement.__init__(self, parent) 578 self._fs = x 304 579 305 if not hasattr(x, 'parent'): 306 x = IntegerRing()(x) # occasionally coercion framework tries to pass a Python int 580 ########################################################################### 581 ## GroupAlgebraElement_class :: Arithmetic 582 ########################################################################### 307 583 308 if isinstance(x, FormalSum): 309 if check: 310 for c,d in x._data: 311 if d.parent() != self.parent().group(): 312 raise TypeError, "%s is not an element of group %s" % (d, self.parent().group()) 313 self._fs = x 314 else: 315 self._fs = x 584 def _add_(left, right): 585 r""" 586 Add left to right. 316 587 317 elif self.base_ring().has_coerce_map_from(x.parent()): 318 self._fs = self.parent()._formal_sum_module([ (x, self.parent().group()(1)) ]) 319 elif self.parent().group().has_coerce_map_from(x.parent()): 320 self._fs = self.parent()._formal_sum_module([ (1, self.parent().group()(x)) ]) 321 else: 322 raise TypeError, "Don't know how to create an element of %s from %s" % (self.parent(), x) 588 EXAMPLE:: 323 589 324 def _repr_(self):325 return self._fs._repr_()326 327 def _add_(self, other):328 r"""329 Add self to other.330 331 EXAMPLE:332 590 sage: G = GL(3, GF(7)) 333 591 sage: ZG = GroupAlgebra(G) 334 sage: g1 = G([0,0,2,2,5,0,6,6,2])592 sage: g1 = ZG.group()([0,0,2,2,5,0,6,6,2]) 335 593 sage: s = ZG(g1) 336 594 sage: s + s 337 595 2*[0 0 2] 338 596 [2 5 0] 339 597 [6 6 2] 340 """ 341 fs_sum = self._fs + other._fs 342 return self.parent()(fs_sum, check=False) 598 """ 599 return left.parent()(left._fs + right._fs) 343 600 344 def _mul_(self, right): 345 r""" Calculate self*right, where both self and right are GroupAlgebraElements. 601 def _mul_(left, right): 602 r""" Calculate left*right, where both left and right are 603 GroupAlgebraElements_class. 346 604 347 EXAMPLE: 605 EXAMPLE:: 606 348 607 sage: G = GL(3, GF(7)) 349 608 sage: ZG = GroupAlgebra(G) 350 609 sage: a, b = G.random_element(), G.random_element() … … 360 619 sage: za*za == za^2 361 620 True 362 621 """ 363 d1 = self._fs._data 364 d2 = right._fs._data 365 new = [] 366 for (a1, g1) in d1: 367 for a2,g2 in d2: 368 if self.parent().group().is_multiplicative(): 369 new.append( (a1*a2, g1*g2) ) 370 else: 371 new.append( (a1*a2, g1 + g2) ) 372 return self.parent()( self.parent()._formal_sum_module(new), check=False) 622 if left.parent().group().is_multiplicative() : 623 product = [ (a1 * a2, g1 * g2) 624 for (a1,g1) in left._fs for (a2,g2) in right._fs ] 625 else : 626 product = [ (a1 * a2, g1 + g2) 627 for (a1,g1) in left._fs for (a2,g2) in right._fs ] 373 628 374 def __eq__(self, other): 375 r""" Test if self is equal to other. 629 return left.parent()( left.parent()._formal_sum_module(product) ) 376 630 377 EXAMPLES: 631 ########################################################################### 632 ## GroupAlgebraElement_class :: Comparision 633 ########################################################################### 634 635 def __cmp__(self, other) : 636 r""" Compare self and other. 637 638 EXAMPLES:: 639 378 640 sage: G = AbelianGroup(1,[4]) 379 sage: a = GroupAlgebra(G)(1) 380 sage: b = GroupAlgebra(G)(2) 641 sage: ZG = GroupAlgebra(G) 642 sage: a = ZG(1) 643 sage: b = ZG(2) 381 644 sage: a + a == b 382 645 True 383 646 sage: a == b … … 385 648 sage: a == GroupAlgebra(AbelianGroup(1, [5]))(1) 386 649 False 387 650 """ 388 if isinstance(other, GroupAlgebraElement) and self.parent() == other.parent(): 389 return self._fs == other._fs 390 else: 391 return False 651 c = cmp(type(self), type(other)) 652 653 if c == 0 : 654 c = cmp(self._fs, other._fs) 655 656 return c 657 658 ########################################################################### 659 ## GroupAlgebraElement_class :: Representations 660 ########################################################################### 661 662 def _repr_(self) : 663 r""" 664 EXAMPLES:: 665 666 sage: G = KleinFourGroup() 667 sage: A = GroupAlgebra(G, ZZ) 668 sage: latex(A(1) + A(A.group().gen(0))) 669 () + (3,4) 670 """ 671 return self._fs._repr_() 672 673 def _latex_(self) : 674 r""" 675 EXAMPLES:: 676 677 sage: G = KleinFourGroup() 678 sage: A = GroupAlgebra(G, ZZ) 679 sage: latex(A(1) + A(A.group().gen(0))) 680 () + (3,4) 681 """ 682 return latex(self._fs) 683