root_system.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. from .cartan_type import CartanType
  2. from sympy.core.basic import Atom
  3. class RootSystem(Atom):
  4. """Represent the root system of a simple Lie algebra
  5. Every simple Lie algebra has a unique root system. To find the root
  6. system, we first consider the Cartan subalgebra of g, which is the maximal
  7. abelian subalgebra, and consider the adjoint action of g on this
  8. subalgebra. There is a root system associated with this action. Now, a
  9. root system over a vector space V is a set of finite vectors Phi (called
  10. roots), which satisfy:
  11. 1. The roots span V
  12. 2. The only scalar multiples of x in Phi are x and -x
  13. 3. For every x in Phi, the set Phi is closed under reflection
  14. through the hyperplane perpendicular to x.
  15. 4. If x and y are roots in Phi, then the projection of y onto
  16. the line through x is a half-integral multiple of x.
  17. Now, there is a subset of Phi, which we will call Delta, such that:
  18. 1. Delta is a basis of V
  19. 2. Each root x in Phi can be written x = sum k_y y for y in Delta
  20. The elements of Delta are called the simple roots.
  21. Therefore, we see that the simple roots span the root space of a given
  22. simple Lie algebra.
  23. References
  24. ==========
  25. .. [1] https://en.wikipedia.org/wiki/Root_system
  26. .. [2] Lie Algebras and Representation Theory - Humphreys
  27. """
  28. def __new__(cls, cartantype):
  29. """Create a new RootSystem object
  30. This method assigns an attribute called cartan_type to each instance of
  31. a RootSystem object. When an instance of RootSystem is called, it
  32. needs an argument, which should be an instance of a simple Lie algebra.
  33. We then take the CartanType of this argument and set it as the
  34. cartan_type attribute of the RootSystem instance.
  35. """
  36. obj = Atom.__new__(cls)
  37. obj.cartan_type = CartanType(cartantype)
  38. return obj
  39. def simple_roots(self):
  40. """Generate the simple roots of the Lie algebra
  41. The rank of the Lie algebra determines the number of simple roots that
  42. it has. This method obtains the rank of the Lie algebra, and then uses
  43. the simple_root method from the Lie algebra classes to generate all the
  44. simple roots.
  45. Examples
  46. ========
  47. >>> from sympy.liealgebras.root_system import RootSystem
  48. >>> c = RootSystem("A3")
  49. >>> roots = c.simple_roots()
  50. >>> roots
  51. {1: [1, -1, 0, 0], 2: [0, 1, -1, 0], 3: [0, 0, 1, -1]}
  52. """
  53. n = self.cartan_type.rank()
  54. roots = {}
  55. for i in range(1, n+1):
  56. root = self.cartan_type.simple_root(i)
  57. roots[i] = root
  58. return roots
  59. def all_roots(self):
  60. """Generate all the roots of a given root system
  61. The result is a dictionary where the keys are integer numbers. It
  62. generates the roots by getting the dictionary of all positive roots
  63. from the bases classes, and then taking each root, and multiplying it
  64. by -1 and adding it to the dictionary. In this way all the negative
  65. roots are generated.
  66. """
  67. alpha = self.cartan_type.positive_roots()
  68. keys = list(alpha.keys())
  69. k = max(keys)
  70. for val in keys:
  71. k += 1
  72. root = alpha[val]
  73. newroot = [-x for x in root]
  74. alpha[k] = newroot
  75. return alpha
  76. def root_space(self):
  77. """Return the span of the simple roots
  78. The root space is the vector space spanned by the simple roots, i.e. it
  79. is a vector space with a distinguished basis, the simple roots. This
  80. method returns a string that represents the root space as the span of
  81. the simple roots, alpha[1],...., alpha[n].
  82. Examples
  83. ========
  84. >>> from sympy.liealgebras.root_system import RootSystem
  85. >>> c = RootSystem("A3")
  86. >>> c.root_space()
  87. 'alpha[1] + alpha[2] + alpha[3]'
  88. """
  89. n = self.cartan_type.rank()
  90. rs = " + ".join("alpha["+str(i) +"]" for i in range(1, n+1))
  91. return rs
  92. def add_simple_roots(self, root1, root2):
  93. """Add two simple roots together
  94. The function takes as input two integers, root1 and root2. It then
  95. uses these integers as keys in the dictionary of simple roots, and gets
  96. the corresponding simple roots, and then adds them together.
  97. Examples
  98. ========
  99. >>> from sympy.liealgebras.root_system import RootSystem
  100. >>> c = RootSystem("A3")
  101. >>> newroot = c.add_simple_roots(1, 2)
  102. >>> newroot
  103. [1, 0, -1, 0]
  104. """
  105. alpha = self.simple_roots()
  106. if root1 > len(alpha) or root2 > len(alpha):
  107. raise ValueError("You've used a root that doesn't exist!")
  108. a1 = alpha[root1]
  109. a2 = alpha[root2]
  110. newroot = []
  111. length = len(a1)
  112. for i in range(length):
  113. newroot.append(a1[i] + a2[i])
  114. return newroot
  115. def add_as_roots(self, root1, root2):
  116. """Add two roots together if and only if their sum is also a root
  117. It takes as input two vectors which should be roots. It then computes
  118. their sum and checks if it is in the list of all possible roots. If it
  119. is, it returns the sum. Otherwise it returns a string saying that the
  120. sum is not a root.
  121. Examples
  122. ========
  123. >>> from sympy.liealgebras.root_system import RootSystem
  124. >>> c = RootSystem("A3")
  125. >>> c.add_as_roots([1, 0, -1, 0], [0, 0, 1, -1])
  126. [1, 0, 0, -1]
  127. >>> c.add_as_roots([1, -1, 0, 0], [0, 0, -1, 1])
  128. 'The sum of these two roots is not a root'
  129. """
  130. alpha = self.all_roots()
  131. newroot = []
  132. for entry in range(len(root1)):
  133. newroot.append(root1[entry] + root2[entry])
  134. if newroot in alpha.values():
  135. return newroot
  136. else:
  137. return "The sum of these two roots is not a root"
  138. def cartan_matrix(self):
  139. """Cartan matrix of Lie algebra associated with this root system
  140. Examples
  141. ========
  142. >>> from sympy.liealgebras.root_system import RootSystem
  143. >>> c = RootSystem("A3")
  144. >>> c.cartan_matrix()
  145. Matrix([
  146. [ 2, -1, 0],
  147. [-1, 2, -1],
  148. [ 0, -1, 2]])
  149. """
  150. return self.cartan_type.cartan_matrix()
  151. def dynkin_diagram(self):
  152. """Dynkin diagram of the Lie algebra associated with this root system
  153. Examples
  154. ========
  155. >>> from sympy.liealgebras.root_system import RootSystem
  156. >>> c = RootSystem("A3")
  157. >>> print(c.dynkin_diagram())
  158. 0---0---0
  159. 1 2 3
  160. """
  161. return self.cartan_type.dynkin_diagram()