Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

r""" 

Examples of algebras with basis 

""" 

#***************************************************************************** 

# Copyright (C) 2008-2009 Nicolas M. Thiery <nthiery at users.sf.net> 

# 

# Distributed under the terms of the GNU General Public License (GPL) 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

 

from sage.misc.cachefunc import cached_method 

from sage.sets.family import Family 

from sage.categories.all import AlgebrasWithBasis 

from sage.combinat.free_module import CombinatorialFreeModule 

from sage.combinat.words.words import Words 

 

class FreeAlgebra(CombinatorialFreeModule): 

r""" 

An example of an algebra with basis: the free algebra 

 

This class illustrates a minimal implementation of an algebra with basis. 

""" 

 

def __init__(self, R, alphabet = ("a", "b", "c")): 

""" 

EXAMPLES:: 

 

sage: A = AlgebrasWithBasis(QQ).example(); A 

An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field 

sage: TestSuite(A).run() 

 

""" 

self._alphabet = alphabet 

CombinatorialFreeModule.__init__(self, R, Words(alphabet, infinite=False), category = AlgebrasWithBasis(R)) 

 

def _repr_(self): 

""" 

EXAMPLES:: 

 

sage: AlgebrasWithBasis(QQ).example() # indirect doctest 

An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field 

""" 

return "An example of an algebra with basis: the free algebra on the generators %s over %s"%(self._alphabet, self.base_ring()) 

 

@cached_method 

def one_basis(self): 

""" 

Returns the empty word, which index the one of this algebra, 

as per :meth:`AlgebrasWithBasis.ParentMethods.one_basis`. 

 

EXAMPLES::r 

 

sage: A = AlgebrasWithBasis(QQ).example() 

sage: A.one_basis() 

word: 

sage: A.one() 

B[word: ] 

""" 

return self.basis().keys()([]) 

 

def product_on_basis(self, w1, w2): 

r""" 

Product of basis elements, as per 

:meth:`AlgebrasWithBasis.ParentMethods.product_on_basis`. 

 

EXAMPLES:: 

 

sage: A = AlgebrasWithBasis(QQ).example() 

sage: Words = A.basis().keys() 

sage: A.product_on_basis(Words("acb"), Words("cba")) 

B[word: acbcba] 

sage: (a,b,c) = A.algebra_generators() 

sage: a * (1-b)^2 * c 

B[word: abbc] - 2*B[word: abc] + B[word: ac] 

""" 

return self.basis()[w1 + w2] 

 

@cached_method 

def algebra_generators(self): 

r""" 

Return the generators of this algebra, as per :meth:`~.magmatic_algebras.MagmaticAlgebras.ParentMethods.algebra_generators`. 

 

EXAMPLES:: 

 

sage: A = AlgebrasWithBasis(QQ).example(); A 

An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field 

sage: A.algebra_generators() 

Family (B[word: a], B[word: b], B[word: c]) 

""" 

Words = self.basis().keys() 

return Family( [self.monomial(Words(a)) for a in self._alphabet] ) 

# FIXME: use this once the keys argument of FiniteFamily will be honoured 

# for the specifying the order of the elements in the family 

#return Family(self._alphabet, lambda a: self.term(self.basis().keys()(a))) 

 

Example = FreeAlgebra