applied-ai-018 commited on
Commit
c633c49
·
verified ·
1 Parent(s): da400c4

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/__init__.py +3 -0
  2. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/cartan_matrix.py +25 -0
  3. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/cartan_type.py +73 -0
  4. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/dynkin_diagram.py +24 -0
  5. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/root_system.py +199 -0
  6. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__init__.py +0 -0
  7. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_cartan_type.cpython-310.pyc +0 -0
  8. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_B.cpython-310.pyc +0 -0
  9. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_D.cpython-310.pyc +0 -0
  10. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_E.cpython-310.pyc +0 -0
  11. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_F.cpython-310.pyc +0 -0
  12. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_G.cpython-310.pyc +0 -0
  13. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_weyl_group.cpython-310.pyc +0 -0
  14. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_cartan_matrix.py +10 -0
  15. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_cartan_type.py +12 -0
  16. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_dynkin_diagram.py +9 -0
  17. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_root_system.py +18 -0
  18. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_A.py +17 -0
  19. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_B.py +17 -0
  20. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_C.py +22 -0
  21. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_D.py +19 -0
  22. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_E.py +19 -0
  23. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_F.py +24 -0
  24. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_G.py +16 -0
  25. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_weyl_group.py +35 -0
  26. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_a.py +166 -0
  27. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_b.py +172 -0
  28. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_c.py +171 -0
  29. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_d.py +175 -0
  30. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_e.py +287 -0
  31. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_f.py +162 -0
  32. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_g.py +111 -0
  33. llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/weyl_group.py +403 -0
  34. llmeval-env/lib/python3.10/site-packages/sympy/vector/__init__.py +47 -0
  35. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/__init__.cpython-310.pyc +0 -0
  36. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/basisdependent.cpython-310.pyc +0 -0
  37. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/coordsysrect.cpython-310.pyc +0 -0
  38. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/deloperator.cpython-310.pyc +0 -0
  39. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/dyadic.cpython-310.pyc +0 -0
  40. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/functions.cpython-310.pyc +0 -0
  41. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/implicitregion.cpython-310.pyc +0 -0
  42. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/integrals.cpython-310.pyc +0 -0
  43. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/operators.cpython-310.pyc +0 -0
  44. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/orienters.cpython-310.pyc +0 -0
  45. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/parametricregion.cpython-310.pyc +0 -0
  46. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/point.cpython-310.pyc +0 -0
  47. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/scalar.cpython-310.pyc +0 -0
  48. llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/vector.cpython-310.pyc +0 -0
  49. llmeval-env/lib/python3.10/site-packages/sympy/vector/basisdependent.py +365 -0
  50. llmeval-env/lib/python3.10/site-packages/sympy/vector/functions.py +517 -0
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+
3
+ __all__ = ['CartanType']
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/cartan_matrix.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import CartanType
2
+
3
+ def CartanMatrix(ct):
4
+ """Access the Cartan matrix of a specific Lie algebra
5
+
6
+ Examples
7
+ ========
8
+
9
+ >>> from sympy.liealgebras.cartan_matrix import CartanMatrix
10
+ >>> CartanMatrix("A2")
11
+ Matrix([
12
+ [ 2, -1],
13
+ [-1, 2]])
14
+
15
+ >>> CartanMatrix(['C', 3])
16
+ Matrix([
17
+ [ 2, -1, 0],
18
+ [-1, 2, -1],
19
+ [ 0, -2, 2]])
20
+
21
+ This method works by returning the Cartan matrix
22
+ which corresponds to Cartan type t.
23
+ """
24
+
25
+ return CartanType(ct).cartan_matrix()
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/cartan_type.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core import Atom, Basic
2
+
3
+
4
+ class CartanType_generator():
5
+ """
6
+ Constructor for actually creating things
7
+ """
8
+ def __call__(self, *args):
9
+ c = args[0]
10
+ if isinstance(c, list):
11
+ letter, n = c[0], int(c[1])
12
+ elif isinstance(c, str):
13
+ letter, n = c[0], int(c[1:])
14
+ else:
15
+ raise TypeError("Argument must be a string (e.g. 'A3') or a list (e.g. ['A', 3])")
16
+
17
+ if n < 0:
18
+ raise ValueError("Lie algebra rank cannot be negative")
19
+ if letter == "A":
20
+ from . import type_a
21
+ return type_a.TypeA(n)
22
+ if letter == "B":
23
+ from . import type_b
24
+ return type_b.TypeB(n)
25
+
26
+ if letter == "C":
27
+ from . import type_c
28
+ return type_c.TypeC(n)
29
+
30
+ if letter == "D":
31
+ from . import type_d
32
+ return type_d.TypeD(n)
33
+
34
+ if letter == "E":
35
+ if n >= 6 and n <= 8:
36
+ from . import type_e
37
+ return type_e.TypeE(n)
38
+
39
+ if letter == "F":
40
+ if n == 4:
41
+ from . import type_f
42
+ return type_f.TypeF(n)
43
+
44
+ if letter == "G":
45
+ if n == 2:
46
+ from . import type_g
47
+ return type_g.TypeG(n)
48
+
49
+ CartanType = CartanType_generator()
50
+
51
+
52
+ class Standard_Cartan(Atom):
53
+ """
54
+ Concrete base class for Cartan types such as A4, etc
55
+ """
56
+
57
+ def __new__(cls, series, n):
58
+ obj = Basic.__new__(cls)
59
+ obj.n = n
60
+ obj.series = series
61
+ return obj
62
+
63
+ def rank(self):
64
+ """
65
+ Returns the rank of the Lie algebra
66
+ """
67
+ return self.n
68
+
69
+ def series(self):
70
+ """
71
+ Returns the type of the Lie algebra
72
+ """
73
+ return self.series
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/dynkin_diagram.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import CartanType
2
+
3
+
4
+ def DynkinDiagram(t):
5
+ """Display the Dynkin diagram of a given Lie algebra
6
+
7
+ Works by generating the CartanType for the input, t, and then returning the
8
+ Dynkin diagram method from the individual classes.
9
+
10
+ Examples
11
+ ========
12
+
13
+ >>> from sympy.liealgebras.dynkin_diagram import DynkinDiagram
14
+ >>> print(DynkinDiagram("A3"))
15
+ 0---0---0
16
+ 1 2 3
17
+
18
+ >>> print(DynkinDiagram("B4"))
19
+ 0---0---0=>=0
20
+ 1 2 3 4
21
+
22
+ """
23
+
24
+ return CartanType(t).dynkin_diagram()
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/root_system.py ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import CartanType
2
+ from sympy.core.basic import Atom
3
+
4
+ class RootSystem(Atom):
5
+ """Represent the root system of a simple Lie algebra
6
+
7
+ Every simple Lie algebra has a unique root system. To find the root
8
+ system, we first consider the Cartan subalgebra of g, which is the maximal
9
+ abelian subalgebra, and consider the adjoint action of g on this
10
+ subalgebra. There is a root system associated with this action. Now, a
11
+ root system over a vector space V is a set of finite vectors Phi (called
12
+ roots), which satisfy:
13
+
14
+ 1. The roots span V
15
+ 2. The only scalar multiples of x in Phi are x and -x
16
+ 3. For every x in Phi, the set Phi is closed under reflection
17
+ through the hyperplane perpendicular to x.
18
+ 4. If x and y are roots in Phi, then the projection of y onto
19
+ the line through x is a half-integral multiple of x.
20
+
21
+ Now, there is a subset of Phi, which we will call Delta, such that:
22
+ 1. Delta is a basis of V
23
+ 2. Each root x in Phi can be written x = sum k_y y for y in Delta
24
+
25
+ The elements of Delta are called the simple roots.
26
+ Therefore, we see that the simple roots span the root space of a given
27
+ simple Lie algebra.
28
+
29
+ References
30
+ ==========
31
+
32
+ .. [1] https://en.wikipedia.org/wiki/Root_system
33
+ .. [2] Lie Algebras and Representation Theory - Humphreys
34
+
35
+ """
36
+
37
+ def __new__(cls, cartantype):
38
+ """Create a new RootSystem object
39
+
40
+ This method assigns an attribute called cartan_type to each instance of
41
+ a RootSystem object. When an instance of RootSystem is called, it
42
+ needs an argument, which should be an instance of a simple Lie algebra.
43
+ We then take the CartanType of this argument and set it as the
44
+ cartan_type attribute of the RootSystem instance.
45
+
46
+ """
47
+ obj = Atom.__new__(cls)
48
+ obj.cartan_type = CartanType(cartantype)
49
+ return obj
50
+
51
+ def simple_roots(self):
52
+ """Generate the simple roots of the Lie algebra
53
+
54
+ The rank of the Lie algebra determines the number of simple roots that
55
+ it has. This method obtains the rank of the Lie algebra, and then uses
56
+ the simple_root method from the Lie algebra classes to generate all the
57
+ simple roots.
58
+
59
+ Examples
60
+ ========
61
+
62
+ >>> from sympy.liealgebras.root_system import RootSystem
63
+ >>> c = RootSystem("A3")
64
+ >>> roots = c.simple_roots()
65
+ >>> roots
66
+ {1: [1, -1, 0, 0], 2: [0, 1, -1, 0], 3: [0, 0, 1, -1]}
67
+
68
+ """
69
+ n = self.cartan_type.rank()
70
+ roots = {}
71
+ for i in range(1, n+1):
72
+ root = self.cartan_type.simple_root(i)
73
+ roots[i] = root
74
+ return roots
75
+
76
+
77
+ def all_roots(self):
78
+ """Generate all the roots of a given root system
79
+
80
+ The result is a dictionary where the keys are integer numbers. It
81
+ generates the roots by getting the dictionary of all positive roots
82
+ from the bases classes, and then taking each root, and multiplying it
83
+ by -1 and adding it to the dictionary. In this way all the negative
84
+ roots are generated.
85
+
86
+ """
87
+ alpha = self.cartan_type.positive_roots()
88
+ keys = list(alpha.keys())
89
+ k = max(keys)
90
+ for val in keys:
91
+ k += 1
92
+ root = alpha[val]
93
+ newroot = [-x for x in root]
94
+ alpha[k] = newroot
95
+ return alpha
96
+
97
+ def root_space(self):
98
+ """Return the span of the simple roots
99
+
100
+ The root space is the vector space spanned by the simple roots, i.e. it
101
+ is a vector space with a distinguished basis, the simple roots. This
102
+ method returns a string that represents the root space as the span of
103
+ the simple roots, alpha[1],...., alpha[n].
104
+
105
+ Examples
106
+ ========
107
+
108
+ >>> from sympy.liealgebras.root_system import RootSystem
109
+ >>> c = RootSystem("A3")
110
+ >>> c.root_space()
111
+ 'alpha[1] + alpha[2] + alpha[3]'
112
+
113
+ """
114
+ n = self.cartan_type.rank()
115
+ rs = " + ".join("alpha["+str(i) +"]" for i in range(1, n+1))
116
+ return rs
117
+
118
+ def add_simple_roots(self, root1, root2):
119
+ """Add two simple roots together
120
+
121
+ The function takes as input two integers, root1 and root2. It then
122
+ uses these integers as keys in the dictionary of simple roots, and gets
123
+ the corresponding simple roots, and then adds them together.
124
+
125
+ Examples
126
+ ========
127
+
128
+ >>> from sympy.liealgebras.root_system import RootSystem
129
+ >>> c = RootSystem("A3")
130
+ >>> newroot = c.add_simple_roots(1, 2)
131
+ >>> newroot
132
+ [1, 0, -1, 0]
133
+
134
+ """
135
+
136
+ alpha = self.simple_roots()
137
+ if root1 > len(alpha) or root2 > len(alpha):
138
+ raise ValueError("You've used a root that doesn't exist!")
139
+ a1 = alpha[root1]
140
+ a2 = alpha[root2]
141
+ newroot = [_a1 + _a2 for _a1, _a2 in zip(a1, a2)]
142
+ return newroot
143
+
144
+ def add_as_roots(self, root1, root2):
145
+ """Add two roots together if and only if their sum is also a root
146
+
147
+ It takes as input two vectors which should be roots. It then computes
148
+ their sum and checks if it is in the list of all possible roots. If it
149
+ is, it returns the sum. Otherwise it returns a string saying that the
150
+ sum is not a root.
151
+
152
+ Examples
153
+ ========
154
+
155
+ >>> from sympy.liealgebras.root_system import RootSystem
156
+ >>> c = RootSystem("A3")
157
+ >>> c.add_as_roots([1, 0, -1, 0], [0, 0, 1, -1])
158
+ [1, 0, 0, -1]
159
+ >>> c.add_as_roots([1, -1, 0, 0], [0, 0, -1, 1])
160
+ 'The sum of these two roots is not a root'
161
+
162
+ """
163
+ alpha = self.all_roots()
164
+ newroot = [r1 + r2 for r1, r2 in zip(root1, root2)]
165
+ if newroot in alpha.values():
166
+ return newroot
167
+ else:
168
+ return "The sum of these two roots is not a root"
169
+
170
+
171
+ def cartan_matrix(self):
172
+ """Cartan matrix of Lie algebra associated with this root system
173
+
174
+ Examples
175
+ ========
176
+
177
+ >>> from sympy.liealgebras.root_system import RootSystem
178
+ >>> c = RootSystem("A3")
179
+ >>> c.cartan_matrix()
180
+ Matrix([
181
+ [ 2, -1, 0],
182
+ [-1, 2, -1],
183
+ [ 0, -1, 2]])
184
+ """
185
+ return self.cartan_type.cartan_matrix()
186
+
187
+ def dynkin_diagram(self):
188
+ """Dynkin diagram of the Lie algebra associated with this root system
189
+
190
+ Examples
191
+ ========
192
+
193
+ >>> from sympy.liealgebras.root_system import RootSystem
194
+ >>> c = RootSystem("A3")
195
+ >>> print(c.dynkin_diagram())
196
+ 0---0---0
197
+ 1 2 3
198
+ """
199
+ return self.cartan_type.dynkin_diagram()
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__init__.py ADDED
File without changes
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_cartan_type.cpython-310.pyc ADDED
Binary file (598 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_B.cpython-310.pyc ADDED
Binary file (1.06 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_D.cpython-310.pyc ADDED
Binary file (1.25 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_E.cpython-310.pyc ADDED
Binary file (1.4 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_F.cpython-310.pyc ADDED
Binary file (2 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_type_G.cpython-310.pyc ADDED
Binary file (921 Bytes). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/__pycache__/test_weyl_group.cpython-310.pyc ADDED
Binary file (1.72 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_cartan_matrix.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_matrix import CartanMatrix
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_CartanMatrix():
5
+ c = CartanMatrix("A3")
6
+ m = Matrix(3, 3, [2, -1, 0, -1, 2, -1, 0, -1, 2])
7
+ assert c == m
8
+ a = CartanMatrix(["G",2])
9
+ mt = Matrix(2, 2, [2, -1, -3, 2])
10
+ assert a == mt
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_cartan_type.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType, Standard_Cartan
2
+
3
+ def test_Standard_Cartan():
4
+ c = CartanType("A4")
5
+ assert c.rank() == 4
6
+ assert c.series == "A"
7
+ m = Standard_Cartan("A", 2)
8
+ assert m.rank() == 2
9
+ assert m.series == "A"
10
+ b = CartanType("B12")
11
+ assert b.rank() == 12
12
+ assert b.series == "B"
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_dynkin_diagram.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.dynkin_diagram import DynkinDiagram
2
+
3
+ def test_DynkinDiagram():
4
+ c = DynkinDiagram("A3")
5
+ diag = "0---0---0\n1 2 3"
6
+ assert c == diag
7
+ ct = DynkinDiagram(["B", 3])
8
+ diag2 = "0---0=>=0\n1 2 3"
9
+ assert ct == diag2
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_root_system.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.root_system import RootSystem
2
+ from sympy.liealgebras.type_a import TypeA
3
+ from sympy.matrices import Matrix
4
+
5
+ def test_root_system():
6
+ c = RootSystem("A3")
7
+ assert c.cartan_type == TypeA(3)
8
+ assert c.simple_roots() == {1: [1, -1, 0, 0], 2: [0, 1, -1, 0], 3: [0, 0, 1, -1]}
9
+ assert c.root_space() == "alpha[1] + alpha[2] + alpha[3]"
10
+ assert c.cartan_matrix() == Matrix([[ 2, -1, 0], [-1, 2, -1], [ 0, -1, 2]])
11
+ assert c.dynkin_diagram() == "0---0---0\n1 2 3"
12
+ assert c.add_simple_roots(1, 2) == [1, 0, -1, 0]
13
+ assert c.all_roots() == {1: [1, -1, 0, 0], 2: [1, 0, -1, 0],
14
+ 3: [1, 0, 0, -1], 4: [0, 1, -1, 0], 5: [0, 1, 0, -1],
15
+ 6: [0, 0, 1, -1], 7: [-1, 1, 0, 0], 8: [-1, 0, 1, 0],
16
+ 9: [-1, 0, 0, 1], 10: [0, -1, 1, 0],
17
+ 11: [0, -1, 0, 1], 12: [0, 0, -1, 1]}
18
+ assert c.add_as_roots([1, 0, -1, 0], [0, 0, 1, -1]) == [1, 0, 0, -1]
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_A.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_type_A():
5
+ c = CartanType("A3")
6
+ m = Matrix(3, 3, [2, -1, 0, -1, 2, -1, 0, -1, 2])
7
+ assert m == c.cartan_matrix()
8
+ assert c.basis() == 8
9
+ assert c.roots() == 12
10
+ assert c.dimension() == 4
11
+ assert c.simple_root(1) == [1, -1, 0, 0]
12
+ assert c.highest_root() == [1, 0, 0, -1]
13
+ assert c.lie_algebra() == "su(4)"
14
+ diag = "0---0---0\n1 2 3"
15
+ assert c.dynkin_diagram() == diag
16
+ assert c.positive_roots() == {1: [1, -1, 0, 0], 2: [1, 0, -1, 0],
17
+ 3: [1, 0, 0, -1], 4: [0, 1, -1, 0], 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_B.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_type_B():
5
+ c = CartanType("B3")
6
+ m = Matrix(3, 3, [2, -1, 0, -1, 2, -2, 0, -1, 2])
7
+ assert m == c.cartan_matrix()
8
+ assert c.dimension() == 3
9
+ assert c.roots() == 18
10
+ assert c.simple_root(3) == [0, 0, 1]
11
+ assert c.basis() == 3
12
+ assert c.lie_algebra() == "so(6)"
13
+ diag = "0---0=>=0\n1 2 3"
14
+ assert c.dynkin_diagram() == diag
15
+ assert c.positive_roots() == {1: [1, -1, 0], 2: [1, 1, 0], 3: [1, 0, -1],
16
+ 4: [1, 0, 1], 5: [0, 1, -1], 6: [0, 1, 1], 7: [1, 0, 0],
17
+ 8: [0, 1, 0], 9: [0, 0, 1]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_C.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_type_C():
5
+ c = CartanType("C4")
6
+ m = Matrix(4, 4, [2, -1, 0, 0, -1, 2, -1, 0, 0, -1, 2, -1, 0, 0, -2, 2])
7
+ assert c.cartan_matrix() == m
8
+ assert c.dimension() == 4
9
+ assert c.simple_root(4) == [0, 0, 0, 2]
10
+ assert c.roots() == 32
11
+ assert c.basis() == 36
12
+ assert c.lie_algebra() == "sp(8)"
13
+ t = CartanType(['C', 3])
14
+ assert t.dimension() == 3
15
+ diag = "0---0---0=<=0\n1 2 3 4"
16
+ assert c.dynkin_diagram() == diag
17
+ assert c.positive_roots() == {1: [1, -1, 0, 0], 2: [1, 1, 0, 0],
18
+ 3: [1, 0, -1, 0], 4: [1, 0, 1, 0], 5: [1, 0, 0, -1],
19
+ 6: [1, 0, 0, 1], 7: [0, 1, -1, 0], 8: [0, 1, 1, 0],
20
+ 9: [0, 1, 0, -1], 10: [0, 1, 0, 1], 11: [0, 0, 1, -1],
21
+ 12: [0, 0, 1, 1], 13: [2, 0, 0, 0], 14: [0, 2, 0, 0], 15: [0, 0, 2, 0],
22
+ 16: [0, 0, 0, 2]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_D.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+
4
+
5
+
6
+ def test_type_D():
7
+ c = CartanType("D4")
8
+ m = Matrix(4, 4, [2, -1, 0, 0, -1, 2, -1, -1, 0, -1, 2, 0, 0, -1, 0, 2])
9
+ assert c.cartan_matrix() == m
10
+ assert c.basis() == 6
11
+ assert c.lie_algebra() == "so(8)"
12
+ assert c.roots() == 24
13
+ assert c.simple_root(3) == [0, 0, 1, -1]
14
+ diag = " 3\n 0\n |\n |\n0---0---0\n1 2 4"
15
+ assert diag == c.dynkin_diagram()
16
+ assert c.positive_roots() == {1: [1, -1, 0, 0], 2: [1, 1, 0, 0],
17
+ 3: [1, 0, -1, 0], 4: [1, 0, 1, 0], 5: [1, 0, 0, -1], 6: [1, 0, 0, 1],
18
+ 7: [0, 1, -1, 0], 8: [0, 1, 1, 0], 9: [0, 1, 0, -1], 10: [0, 1, 0, 1],
19
+ 11: [0, 0, 1, -1], 12: [0, 0, 1, 1]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_E.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_type_E():
5
+ c = CartanType("E6")
6
+ m = Matrix(6, 6, [2, 0, -1, 0, 0, 0, 0, 2, 0, -1, 0, 0,
7
+ -1, 0, 2, -1, 0, 0, 0, -1, -1, 2, -1, 0, 0, 0, 0,
8
+ -1, 2, -1, 0, 0, 0, 0, -1, 2])
9
+ assert c.cartan_matrix() == m
10
+ assert c.dimension() == 8
11
+ assert c.simple_root(6) == [0, 0, 0, -1, 1, 0, 0, 0]
12
+ assert c.roots() == 72
13
+ assert c.basis() == 78
14
+ diag = " "*8 + "2\n" + " "*8 + "0\n" + " "*8 + "|\n" + " "*8 + "|\n"
15
+ diag += "---".join("0" for i in range(1, 6))+"\n"
16
+ diag += "1 " + " ".join(str(i) for i in range(3, 7))
17
+ assert c.dynkin_diagram() == diag
18
+ posroots = c.positive_roots()
19
+ assert posroots[8] == [1, 0, 0, 0, 1, 0, 0, 0]
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_F.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import CartanType
2
+ from sympy.matrices import Matrix
3
+ from sympy.core.backend import S
4
+
5
+ def test_type_F():
6
+ c = CartanType("F4")
7
+ m = Matrix(4, 4, [2, -1, 0, 0, -1, 2, -2, 0, 0, -1, 2, -1, 0, 0, -1, 2])
8
+ assert c.cartan_matrix() == m
9
+ assert c.dimension() == 4
10
+ assert c.simple_root(1) == [1, -1, 0, 0]
11
+ assert c.simple_root(2) == [0, 1, -1, 0]
12
+ assert c.simple_root(3) == [0, 0, 0, 1]
13
+ assert c.simple_root(4) == [-S.Half, -S.Half, -S.Half, -S.Half]
14
+ assert c.roots() == 48
15
+ assert c.basis() == 52
16
+ diag = "0---0=>=0---0\n" + " ".join(str(i) for i in range(1, 5))
17
+ assert c.dynkin_diagram() == diag
18
+ assert c.positive_roots() == {1: [1, -1, 0, 0], 2: [1, 1, 0, 0], 3: [1, 0, -1, 0],
19
+ 4: [1, 0, 1, 0], 5: [1, 0, 0, -1], 6: [1, 0, 0, 1], 7: [0, 1, -1, 0],
20
+ 8: [0, 1, 1, 0], 9: [0, 1, 0, -1], 10: [0, 1, 0, 1], 11: [0, 0, 1, -1],
21
+ 12: [0, 0, 1, 1], 13: [1, 0, 0, 0], 14: [0, 1, 0, 0], 15: [0, 0, 1, 0],
22
+ 16: [0, 0, 0, 1], 17: [S.Half, S.Half, S.Half, S.Half], 18: [S.Half, -S.Half, S.Half, S.Half],
23
+ 19: [S.Half, S.Half, -S.Half, S.Half], 20: [S.Half, S.Half, S.Half, -S.Half], 21: [S.Half, S.Half, -S.Half, -S.Half],
24
+ 22: [S.Half, -S.Half, S.Half, -S.Half], 23: [S.Half, -S.Half, -S.Half, S.Half], 24: [S.Half, -S.Half, -S.Half, -S.Half]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_type_G.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ from sympy.liealgebras.cartan_type import CartanType
3
+ from sympy.matrices import Matrix
4
+
5
+ def test_type_G():
6
+ c = CartanType("G2")
7
+ m = Matrix(2, 2, [2, -1, -3, 2])
8
+ assert c.cartan_matrix() == m
9
+ assert c.simple_root(2) == [1, -2, 1]
10
+ assert c.basis() == 14
11
+ assert c.roots() == 12
12
+ assert c.dimension() == 3
13
+ diag = "0≡<≡0\n1 2"
14
+ assert diag == c.dynkin_diagram()
15
+ assert c.positive_roots() == {1: [0, 1, -1], 2: [1, -2, 1], 3: [1, -1, 0],
16
+ 4: [1, 0, 1], 5: [1, 1, -2], 6: [2, -1, -1]}
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/tests/test_weyl_group.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.weyl_group import WeylGroup
2
+ from sympy.matrices import Matrix
3
+
4
+ def test_weyl_group():
5
+ c = WeylGroup("A3")
6
+ assert c.matrix_form('r1*r2') == Matrix([[0, 0, 1, 0], [1, 0, 0, 0],
7
+ [0, 1, 0, 0], [0, 0, 0, 1]])
8
+ assert c.generators() == ['r1', 'r2', 'r3']
9
+ assert c.group_order() == 24.0
10
+ assert c.group_name() == "S4: the symmetric group acting on 4 elements."
11
+ assert c.coxeter_diagram() == "0---0---0\n1 2 3"
12
+ assert c.element_order('r1*r2*r3') == 4
13
+ assert c.element_order('r1*r3*r2*r3') == 3
14
+ d = WeylGroup("B5")
15
+ assert d.group_order() == 3840
16
+ assert d.element_order('r1*r2*r4*r5') == 12
17
+ assert d.matrix_form('r2*r3') == Matrix([[0, 0, 1, 0, 0], [1, 0, 0, 0, 0],
18
+ [0, 1, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]])
19
+ assert d.element_order('r1*r2*r1*r3*r5') == 6
20
+ e = WeylGroup("D5")
21
+ assert e.element_order('r2*r3*r5') == 4
22
+ assert e.matrix_form('r2*r3*r5') == Matrix([[1, 0, 0, 0, 0], [0, 0, 0, 0, -1],
23
+ [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, -1, 0]])
24
+ f = WeylGroup("G2")
25
+ assert f.element_order('r1*r2*r1*r2') == 3
26
+ assert f.element_order('r2*r1*r1*r2') == 1
27
+
28
+ assert f.matrix_form('r1*r2*r1*r2') == Matrix([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
29
+ g = WeylGroup("F4")
30
+ assert g.matrix_form('r2*r3') == Matrix([[1, 0, 0, 0], [0, 1, 0, 0],
31
+ [0, 0, 0, -1], [0, 0, 1, 0]])
32
+
33
+ assert g.element_order('r2*r3') == 4
34
+ h = WeylGroup("E6")
35
+ assert h.group_order() == 51840
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_a.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.liealgebras.cartan_type import Standard_Cartan
2
+ from sympy.core.backend import eye
3
+
4
+
5
+ class TypeA(Standard_Cartan):
6
+ """
7
+ This class contains the information about
8
+ the A series of simple Lie algebras.
9
+ ====
10
+ """
11
+
12
+ def __new__(cls, n):
13
+ if n < 1:
14
+ raise ValueError("n cannot be less than 1")
15
+ return Standard_Cartan.__new__(cls, "A", n)
16
+
17
+
18
+ def dimension(self):
19
+ """Dimension of the vector space V underlying the Lie algebra
20
+
21
+ Examples
22
+ ========
23
+
24
+ >>> from sympy.liealgebras.cartan_type import CartanType
25
+ >>> c = CartanType("A4")
26
+ >>> c.dimension()
27
+ 5
28
+ """
29
+ return self.n+1
30
+
31
+
32
+ def basic_root(self, i, j):
33
+ """
34
+ This is a method just to generate roots
35
+ with a 1 iin the ith position and a -1
36
+ in the jth position.
37
+
38
+ """
39
+
40
+ n = self.n
41
+ root = [0]*(n+1)
42
+ root[i] = 1
43
+ root[j] = -1
44
+ return root
45
+
46
+ def simple_root(self, i):
47
+ """
48
+ Every lie algebra has a unique root system.
49
+ Given a root system Q, there is a subset of the
50
+ roots such that an element of Q is called a
51
+ simple root if it cannot be written as the sum
52
+ of two elements in Q. If we let D denote the
53
+ set of simple roots, then it is clear that every
54
+ element of Q can be written as a linear combination
55
+ of elements of D with all coefficients non-negative.
56
+
57
+ In A_n the ith simple root is the root which has a 1
58
+ in the ith position, a -1 in the (i+1)th position,
59
+ and zeroes elsewhere.
60
+
61
+ This method returns the ith simple root for the A series.
62
+
63
+ Examples
64
+ ========
65
+
66
+ >>> from sympy.liealgebras.cartan_type import CartanType
67
+ >>> c = CartanType("A4")
68
+ >>> c.simple_root(1)
69
+ [1, -1, 0, 0, 0]
70
+
71
+ """
72
+
73
+ return self.basic_root(i-1, i)
74
+
75
+ def positive_roots(self):
76
+ """
77
+ This method generates all the positive roots of
78
+ A_n. This is half of all of the roots of A_n;
79
+ by multiplying all the positive roots by -1 we
80
+ get the negative roots.
81
+
82
+ Examples
83
+ ========
84
+
85
+ >>> from sympy.liealgebras.cartan_type import CartanType
86
+ >>> c = CartanType("A3")
87
+ >>> c.positive_roots()
88
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
89
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
90
+ """
91
+
92
+ n = self.n
93
+ posroots = {}
94
+ k = 0
95
+ for i in range(0, n):
96
+ for j in range(i+1, n+1):
97
+ k += 1
98
+ posroots[k] = self.basic_root(i, j)
99
+ return posroots
100
+
101
+ def highest_root(self):
102
+ """
103
+ Returns the highest weight root for A_n
104
+ """
105
+
106
+ return self.basic_root(0, self.n)
107
+
108
+ def roots(self):
109
+ """
110
+ Returns the total number of roots for A_n
111
+ """
112
+ n = self.n
113
+ return n*(n+1)
114
+
115
+ def cartan_matrix(self):
116
+ """
117
+ Returns the Cartan matrix for A_n.
118
+ The Cartan matrix matrix for a Lie algebra is
119
+ generated by assigning an ordering to the simple
120
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
121
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
122
+
123
+ Examples
124
+ ========
125
+
126
+ >>> from sympy.liealgebras.cartan_type import CartanType
127
+ >>> c = CartanType('A4')
128
+ >>> c.cartan_matrix()
129
+ Matrix([
130
+ [ 2, -1, 0, 0],
131
+ [-1, 2, -1, 0],
132
+ [ 0, -1, 2, -1],
133
+ [ 0, 0, -1, 2]])
134
+
135
+ """
136
+
137
+ n = self.n
138
+ m = 2 * eye(n)
139
+ i = 1
140
+ while i < n-1:
141
+ m[i, i+1] = -1
142
+ m[i, i-1] = -1
143
+ i += 1
144
+ m[0,1] = -1
145
+ m[n-1, n-2] = -1
146
+ return m
147
+
148
+ def basis(self):
149
+ """
150
+ Returns the number of independent generators of A_n
151
+ """
152
+ n = self.n
153
+ return n**2 - 1
154
+
155
+ def lie_algebra(self):
156
+ """
157
+ Returns the Lie algebra associated with A_n
158
+ """
159
+ n = self.n
160
+ return "su(" + str(n + 1) + ")"
161
+
162
+ def dynkin_diagram(self):
163
+ n = self.n
164
+ diag = "---".join("0" for i in range(1, n+1)) + "\n"
165
+ diag += " ".join(str(i) for i in range(1, n+1))
166
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_b.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import Standard_Cartan
2
+ from sympy.core.backend import eye
3
+
4
+ class TypeB(Standard_Cartan):
5
+
6
+ def __new__(cls, n):
7
+ if n < 2:
8
+ raise ValueError("n cannot be less than 2")
9
+ return Standard_Cartan.__new__(cls, "B", n)
10
+
11
+ def dimension(self):
12
+ """Dimension of the vector space V underlying the Lie algebra
13
+
14
+ Examples
15
+ ========
16
+
17
+ >>> from sympy.liealgebras.cartan_type import CartanType
18
+ >>> c = CartanType("B3")
19
+ >>> c.dimension()
20
+ 3
21
+ """
22
+
23
+ return self.n
24
+
25
+ def basic_root(self, i, j):
26
+ """
27
+ This is a method just to generate roots
28
+ with a 1 iin the ith position and a -1
29
+ in the jth position.
30
+
31
+ """
32
+ root = [0]*self.n
33
+ root[i] = 1
34
+ root[j] = -1
35
+ return root
36
+
37
+ def simple_root(self, i):
38
+ """
39
+ Every lie algebra has a unique root system.
40
+ Given a root system Q, there is a subset of the
41
+ roots such that an element of Q is called a
42
+ simple root if it cannot be written as the sum
43
+ of two elements in Q. If we let D denote the
44
+ set of simple roots, then it is clear that every
45
+ element of Q can be written as a linear combination
46
+ of elements of D with all coefficients non-negative.
47
+
48
+ In B_n the first n-1 simple roots are the same as the
49
+ roots in A_(n-1) (a 1 in the ith position, a -1 in
50
+ the (i+1)th position, and zeroes elsewhere). The n-th
51
+ simple root is the root with a 1 in the nth position
52
+ and zeroes elsewhere.
53
+
54
+ This method returns the ith simple root for the B series.
55
+
56
+ Examples
57
+ ========
58
+
59
+ >>> from sympy.liealgebras.cartan_type import CartanType
60
+ >>> c = CartanType("B3")
61
+ >>> c.simple_root(2)
62
+ [0, 1, -1]
63
+
64
+ """
65
+ n = self.n
66
+ if i < n:
67
+ return self.basic_root(i-1, i)
68
+ else:
69
+ root = [0]*self.n
70
+ root[n-1] = 1
71
+ return root
72
+
73
+ def positive_roots(self):
74
+ """
75
+ This method generates all the positive roots of
76
+ A_n. This is half of all of the roots of B_n;
77
+ by multiplying all the positive roots by -1 we
78
+ get the negative roots.
79
+
80
+ Examples
81
+ ========
82
+
83
+ >>> from sympy.liealgebras.cartan_type import CartanType
84
+ >>> c = CartanType("A3")
85
+ >>> c.positive_roots()
86
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
87
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
88
+ """
89
+
90
+ n = self.n
91
+ posroots = {}
92
+ k = 0
93
+ for i in range(0, n-1):
94
+ for j in range(i+1, n):
95
+ k += 1
96
+ posroots[k] = self.basic_root(i, j)
97
+ k += 1
98
+ root = self.basic_root(i, j)
99
+ root[j] = 1
100
+ posroots[k] = root
101
+
102
+ for i in range(0, n):
103
+ k += 1
104
+ root = [0]*n
105
+ root[i] = 1
106
+ posroots[k] = root
107
+
108
+ return posroots
109
+
110
+ def roots(self):
111
+ """
112
+ Returns the total number of roots for B_n"
113
+ """
114
+
115
+ n = self.n
116
+ return 2*(n**2)
117
+
118
+ def cartan_matrix(self):
119
+ """
120
+ Returns the Cartan matrix for B_n.
121
+ The Cartan matrix matrix for a Lie algebra is
122
+ generated by assigning an ordering to the simple
123
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
124
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
125
+
126
+ Examples
127
+ ========
128
+
129
+ >>> from sympy.liealgebras.cartan_type import CartanType
130
+ >>> c = CartanType('B4')
131
+ >>> c.cartan_matrix()
132
+ Matrix([
133
+ [ 2, -1, 0, 0],
134
+ [-1, 2, -1, 0],
135
+ [ 0, -1, 2, -2],
136
+ [ 0, 0, -1, 2]])
137
+
138
+ """
139
+
140
+ n = self.n
141
+ m = 2* eye(n)
142
+ i = 1
143
+ while i < n-1:
144
+ m[i, i+1] = -1
145
+ m[i, i-1] = -1
146
+ i += 1
147
+ m[0, 1] = -1
148
+ m[n-2, n-1] = -2
149
+ m[n-1, n-2] = -1
150
+ return m
151
+
152
+ def basis(self):
153
+ """
154
+ Returns the number of independent generators of B_n
155
+ """
156
+
157
+ n = self.n
158
+ return (n**2 - n)/2
159
+
160
+ def lie_algebra(self):
161
+ """
162
+ Returns the Lie algebra associated with B_n
163
+ """
164
+
165
+ n = self.n
166
+ return "so(" + str(2*n) + ")"
167
+
168
+ def dynkin_diagram(self):
169
+ n = self.n
170
+ diag = "---".join("0" for i in range(1, n)) + "=>=0\n"
171
+ diag += " ".join(str(i) for i in range(1, n+1))
172
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_c.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import Standard_Cartan
2
+ from sympy.core.backend import eye
3
+
4
+ class TypeC(Standard_Cartan):
5
+
6
+ def __new__(cls, n):
7
+ if n < 3:
8
+ raise ValueError("n cannot be less than 3")
9
+ return Standard_Cartan.__new__(cls, "C", n)
10
+
11
+
12
+ def dimension(self):
13
+ """Dimension of the vector space V underlying the Lie algebra
14
+
15
+ Examples
16
+ ========
17
+
18
+ >>> from sympy.liealgebras.cartan_type import CartanType
19
+ >>> c = CartanType("C3")
20
+ >>> c.dimension()
21
+ 3
22
+ """
23
+ n = self.n
24
+ return n
25
+
26
+ def basic_root(self, i, j):
27
+ """Generate roots with 1 in ith position and a -1 in jth position
28
+ """
29
+ n = self.n
30
+ root = [0]*n
31
+ root[i] = 1
32
+ root[j] = -1
33
+ return root
34
+
35
+ def simple_root(self, i):
36
+ """The ith simple root for the C series
37
+
38
+ Every lie algebra has a unique root system.
39
+ Given a root system Q, there is a subset of the
40
+ roots such that an element of Q is called a
41
+ simple root if it cannot be written as the sum
42
+ of two elements in Q. If we let D denote the
43
+ set of simple roots, then it is clear that every
44
+ element of Q can be written as a linear combination
45
+ of elements of D with all coefficients non-negative.
46
+
47
+ In C_n, the first n-1 simple roots are the same as
48
+ the roots in A_(n-1) (a 1 in the ith position, a -1
49
+ in the (i+1)th position, and zeroes elsewhere). The
50
+ nth simple root is the root in which there is a 2 in
51
+ the nth position and zeroes elsewhere.
52
+
53
+ Examples
54
+ ========
55
+
56
+ >>> from sympy.liealgebras.cartan_type import CartanType
57
+ >>> c = CartanType("C3")
58
+ >>> c.simple_root(2)
59
+ [0, 1, -1]
60
+
61
+ """
62
+
63
+ n = self.n
64
+ if i < n:
65
+ return self.basic_root(i-1,i)
66
+ else:
67
+ root = [0]*self.n
68
+ root[n-1] = 2
69
+ return root
70
+
71
+
72
+ def positive_roots(self):
73
+ """Generates all the positive roots of A_n
74
+
75
+ This is half of all of the roots of C_n; by multiplying all the
76
+ positive roots by -1 we get the negative roots.
77
+
78
+ Examples
79
+ ========
80
+
81
+ >>> from sympy.liealgebras.cartan_type import CartanType
82
+ >>> c = CartanType("A3")
83
+ >>> c.positive_roots()
84
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
85
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
86
+
87
+ """
88
+
89
+ n = self.n
90
+ posroots = {}
91
+ k = 0
92
+ for i in range(0, n-1):
93
+ for j in range(i+1, n):
94
+ k += 1
95
+ posroots[k] = self.basic_root(i, j)
96
+ k += 1
97
+ root = self.basic_root(i, j)
98
+ root[j] = 1
99
+ posroots[k] = root
100
+
101
+ for i in range(0, n):
102
+ k += 1
103
+ root = [0]*n
104
+ root[i] = 2
105
+ posroots[k] = root
106
+
107
+ return posroots
108
+
109
+ def roots(self):
110
+ """
111
+ Returns the total number of roots for C_n"
112
+ """
113
+
114
+ n = self.n
115
+ return 2*(n**2)
116
+
117
+ def cartan_matrix(self):
118
+ """The Cartan matrix for C_n
119
+
120
+ The Cartan matrix matrix for a Lie algebra is
121
+ generated by assigning an ordering to the simple
122
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
123
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
124
+
125
+ Examples
126
+ ========
127
+
128
+ >>> from sympy.liealgebras.cartan_type import CartanType
129
+ >>> c = CartanType('C4')
130
+ >>> c.cartan_matrix()
131
+ Matrix([
132
+ [ 2, -1, 0, 0],
133
+ [-1, 2, -1, 0],
134
+ [ 0, -1, 2, -1],
135
+ [ 0, 0, -2, 2]])
136
+
137
+ """
138
+
139
+ n = self.n
140
+ m = 2 * eye(n)
141
+ i = 1
142
+ while i < n-1:
143
+ m[i, i+1] = -1
144
+ m[i, i-1] = -1
145
+ i += 1
146
+ m[0,1] = -1
147
+ m[n-1, n-2] = -2
148
+ return m
149
+
150
+
151
+ def basis(self):
152
+ """
153
+ Returns the number of independent generators of C_n
154
+ """
155
+
156
+ n = self.n
157
+ return n*(2*n + 1)
158
+
159
+ def lie_algebra(self):
160
+ """
161
+ Returns the Lie algebra associated with C_n"
162
+ """
163
+
164
+ n = self.n
165
+ return "sp(" + str(2*n) + ")"
166
+
167
+ def dynkin_diagram(self):
168
+ n = self.n
169
+ diag = "---".join("0" for i in range(1, n)) + "=<=0\n"
170
+ diag += " ".join(str(i) for i in range(1, n+1))
171
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_d.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import Standard_Cartan
2
+ from sympy.core.backend import eye
3
+
4
+ class TypeD(Standard_Cartan):
5
+
6
+ def __new__(cls, n):
7
+ if n < 3:
8
+ raise ValueError("n cannot be less than 3")
9
+ return Standard_Cartan.__new__(cls, "D", n)
10
+
11
+
12
+ def dimension(self):
13
+ """Dmension of the vector space V underlying the Lie algebra
14
+
15
+ Examples
16
+ ========
17
+
18
+ >>> from sympy.liealgebras.cartan_type import CartanType
19
+ >>> c = CartanType("D4")
20
+ >>> c.dimension()
21
+ 4
22
+ """
23
+
24
+ return self.n
25
+
26
+ def basic_root(self, i, j):
27
+ """
28
+ This is a method just to generate roots
29
+ with a 1 iin the ith position and a -1
30
+ in the jth position.
31
+
32
+ """
33
+
34
+ n = self.n
35
+ root = [0]*n
36
+ root[i] = 1
37
+ root[j] = -1
38
+ return root
39
+
40
+ def simple_root(self, i):
41
+ """
42
+ Every lie algebra has a unique root system.
43
+ Given a root system Q, there is a subset of the
44
+ roots such that an element of Q is called a
45
+ simple root if it cannot be written as the sum
46
+ of two elements in Q. If we let D denote the
47
+ set of simple roots, then it is clear that every
48
+ element of Q can be written as a linear combination
49
+ of elements of D with all coefficients non-negative.
50
+
51
+ In D_n, the first n-1 simple roots are the same as
52
+ the roots in A_(n-1) (a 1 in the ith position, a -1
53
+ in the (i+1)th position, and zeroes elsewhere).
54
+ The nth simple root is the root in which there 1s in
55
+ the nth and (n-1)th positions, and zeroes elsewhere.
56
+
57
+ This method returns the ith simple root for the D series.
58
+
59
+ Examples
60
+ ========
61
+
62
+ >>> from sympy.liealgebras.cartan_type import CartanType
63
+ >>> c = CartanType("D4")
64
+ >>> c.simple_root(2)
65
+ [0, 1, -1, 0]
66
+
67
+ """
68
+
69
+ n = self.n
70
+ if i < n:
71
+ return self.basic_root(i-1, i)
72
+ else:
73
+ root = [0]*n
74
+ root[n-2] = 1
75
+ root[n-1] = 1
76
+ return root
77
+
78
+
79
+ def positive_roots(self):
80
+ """
81
+ This method generates all the positive roots of
82
+ A_n. This is half of all of the roots of D_n
83
+ by multiplying all the positive roots by -1 we
84
+ get the negative roots.
85
+
86
+ Examples
87
+ ========
88
+
89
+ >>> from sympy.liealgebras.cartan_type import CartanType
90
+ >>> c = CartanType("A3")
91
+ >>> c.positive_roots()
92
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
93
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
94
+ """
95
+
96
+ n = self.n
97
+ posroots = {}
98
+ k = 0
99
+ for i in range(0, n-1):
100
+ for j in range(i+1, n):
101
+ k += 1
102
+ posroots[k] = self.basic_root(i, j)
103
+ k += 1
104
+ root = self.basic_root(i, j)
105
+ root[j] = 1
106
+ posroots[k] = root
107
+ return posroots
108
+
109
+ def roots(self):
110
+ """
111
+ Returns the total number of roots for D_n"
112
+ """
113
+
114
+ n = self.n
115
+ return 2*n*(n-1)
116
+
117
+ def cartan_matrix(self):
118
+ """
119
+ Returns the Cartan matrix for D_n.
120
+ The Cartan matrix matrix for a Lie algebra is
121
+ generated by assigning an ordering to the simple
122
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
123
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
124
+
125
+ Examples
126
+ ========
127
+
128
+ >>> from sympy.liealgebras.cartan_type import CartanType
129
+ >>> c = CartanType('D4')
130
+ >>> c.cartan_matrix()
131
+ Matrix([
132
+ [ 2, -1, 0, 0],
133
+ [-1, 2, -1, -1],
134
+ [ 0, -1, 2, 0],
135
+ [ 0, -1, 0, 2]])
136
+
137
+ """
138
+
139
+ n = self.n
140
+ m = 2*eye(n)
141
+ i = 1
142
+ while i < n-2:
143
+ m[i,i+1] = -1
144
+ m[i,i-1] = -1
145
+ i += 1
146
+ m[n-2, n-3] = -1
147
+ m[n-3, n-1] = -1
148
+ m[n-1, n-3] = -1
149
+ m[0, 1] = -1
150
+ return m
151
+
152
+ def basis(self):
153
+ """
154
+ Returns the number of independent generators of D_n
155
+ """
156
+ n = self.n
157
+ return n*(n-1)/2
158
+
159
+ def lie_algebra(self):
160
+ """
161
+ Returns the Lie algebra associated with D_n"
162
+ """
163
+
164
+ n = self.n
165
+ return "so(" + str(2*n) + ")"
166
+
167
+ def dynkin_diagram(self):
168
+ n = self.n
169
+ diag = " "*4*(n-3) + str(n-1) + "\n"
170
+ diag += " "*4*(n-3) + "0\n"
171
+ diag += " "*4*(n-3) +"|\n"
172
+ diag += " "*4*(n-3) + "|\n"
173
+ diag += "---".join("0" for i in range(1,n)) + "\n"
174
+ diag += " ".join(str(i) for i in range(1, n-1)) + " "+str(n)
175
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_e.py ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import Standard_Cartan
2
+ from sympy.core.backend import eye, Rational
3
+
4
+
5
+ class TypeE(Standard_Cartan):
6
+
7
+ def __new__(cls, n):
8
+ if n < 6 or n > 8:
9
+ raise ValueError("Invalid value of n")
10
+ return Standard_Cartan.__new__(cls, "E", n)
11
+
12
+ def dimension(self):
13
+ """Dimension of the vector space V underlying the Lie algebra
14
+
15
+ Examples
16
+ ========
17
+
18
+ >>> from sympy.liealgebras.cartan_type import CartanType
19
+ >>> c = CartanType("E6")
20
+ >>> c.dimension()
21
+ 8
22
+ """
23
+
24
+ return 8
25
+
26
+ def basic_root(self, i, j):
27
+ """
28
+ This is a method just to generate roots
29
+ with a -1 in the ith position and a 1
30
+ in the jth position.
31
+
32
+ """
33
+
34
+ root = [0]*8
35
+ root[i] = -1
36
+ root[j] = 1
37
+ return root
38
+
39
+ def simple_root(self, i):
40
+ """
41
+ Every lie algebra has a unique root system.
42
+ Given a root system Q, there is a subset of the
43
+ roots such that an element of Q is called a
44
+ simple root if it cannot be written as the sum
45
+ of two elements in Q. If we let D denote the
46
+ set of simple roots, then it is clear that every
47
+ element of Q can be written as a linear combination
48
+ of elements of D with all coefficients non-negative.
49
+
50
+ This method returns the ith simple root for E_n.
51
+
52
+ Examples
53
+ ========
54
+
55
+ >>> from sympy.liealgebras.cartan_type import CartanType
56
+ >>> c = CartanType("E6")
57
+ >>> c.simple_root(2)
58
+ [1, 1, 0, 0, 0, 0, 0, 0]
59
+ """
60
+ n = self.n
61
+ if i == 1:
62
+ root = [-0.5]*8
63
+ root[0] = 0.5
64
+ root[7] = 0.5
65
+ return root
66
+ elif i == 2:
67
+ root = [0]*8
68
+ root[1] = 1
69
+ root[0] = 1
70
+ return root
71
+ else:
72
+ if i in (7, 8) and n == 6:
73
+ raise ValueError("E6 only has six simple roots!")
74
+ if i == 8 and n == 7:
75
+ raise ValueError("E7 has only 7 simple roots!")
76
+
77
+ return self.basic_root(i - 3, i - 2)
78
+
79
+ def positive_roots(self):
80
+ """
81
+ This method generates all the positive roots of
82
+ A_n. This is half of all of the roots of E_n;
83
+ by multiplying all the positive roots by -1 we
84
+ get the negative roots.
85
+
86
+ Examples
87
+ ========
88
+
89
+ >>> from sympy.liealgebras.cartan_type import CartanType
90
+ >>> c = CartanType("A3")
91
+ >>> c.positive_roots()
92
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
93
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
94
+ """
95
+ n = self.n
96
+ if n == 6:
97
+ posroots = {}
98
+ k = 0
99
+ for i in range(n-1):
100
+ for j in range(i+1, n-1):
101
+ k += 1
102
+ root = self.basic_root(i, j)
103
+ posroots[k] = root
104
+ k += 1
105
+ root = self.basic_root(i, j)
106
+ root[i] = 1
107
+ posroots[k] = root
108
+
109
+ root = [Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2),
110
+ Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]
111
+ for a in range(0, 2):
112
+ for b in range(0, 2):
113
+ for c in range(0, 2):
114
+ for d in range(0, 2):
115
+ for e in range(0, 2):
116
+ if (a + b + c + d + e)%2 == 0:
117
+ k += 1
118
+ if a == 1:
119
+ root[0] = Rational(-1, 2)
120
+ if b == 1:
121
+ root[1] = Rational(-1, 2)
122
+ if c == 1:
123
+ root[2] = Rational(-1, 2)
124
+ if d == 1:
125
+ root[3] = Rational(-1, 2)
126
+ if e == 1:
127
+ root[4] = Rational(-1, 2)
128
+ posroots[k] = root
129
+
130
+ return posroots
131
+ if n == 7:
132
+ posroots = {}
133
+ k = 0
134
+ for i in range(n-1):
135
+ for j in range(i+1, n-1):
136
+ k += 1
137
+ root = self.basic_root(i, j)
138
+ posroots[k] = root
139
+ k += 1
140
+ root = self.basic_root(i, j)
141
+ root[i] = 1
142
+ posroots[k] = root
143
+
144
+ k += 1
145
+ posroots[k] = [0, 0, 0, 0, 0, 1, 1, 0]
146
+ root = [Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2),
147
+ Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]
148
+ for a in range(0, 2):
149
+ for b in range(0, 2):
150
+ for c in range(0, 2):
151
+ for d in range(0, 2):
152
+ for e in range(0, 2):
153
+ for f in range(0, 2):
154
+ if (a + b + c + d + e + f)%2 == 0:
155
+ k += 1
156
+ if a == 1:
157
+ root[0] = Rational(-1, 2)
158
+ if b == 1:
159
+ root[1] = Rational(-1, 2)
160
+ if c == 1:
161
+ root[2] = Rational(-1, 2)
162
+ if d == 1:
163
+ root[3] = Rational(-1, 2)
164
+ if e == 1:
165
+ root[4] = Rational(-1, 2)
166
+ if f == 1:
167
+ root[5] = Rational(1, 2)
168
+ posroots[k] = root
169
+
170
+ return posroots
171
+ if n == 8:
172
+ posroots = {}
173
+ k = 0
174
+ for i in range(n):
175
+ for j in range(i+1, n):
176
+ k += 1
177
+ root = self.basic_root(i, j)
178
+ posroots[k] = root
179
+ k += 1
180
+ root = self.basic_root(i, j)
181
+ root[i] = 1
182
+ posroots[k] = root
183
+
184
+ root = [Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2),
185
+ Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]
186
+ for a in range(0, 2):
187
+ for b in range(0, 2):
188
+ for c in range(0, 2):
189
+ for d in range(0, 2):
190
+ for e in range(0, 2):
191
+ for f in range(0, 2):
192
+ for g in range(0, 2):
193
+ if (a + b + c + d + e + f + g)%2 == 0:
194
+ k += 1
195
+ if a == 1:
196
+ root[0] = Rational(-1, 2)
197
+ if b == 1:
198
+ root[1] = Rational(-1, 2)
199
+ if c == 1:
200
+ root[2] = Rational(-1, 2)
201
+ if d == 1:
202
+ root[3] = Rational(-1, 2)
203
+ if e == 1:
204
+ root[4] = Rational(-1, 2)
205
+ if f == 1:
206
+ root[5] = Rational(1, 2)
207
+ if g == 1:
208
+ root[6] = Rational(1, 2)
209
+ posroots[k] = root
210
+
211
+ return posroots
212
+
213
+
214
+
215
+ def roots(self):
216
+ """
217
+ Returns the total number of roots of E_n
218
+ """
219
+
220
+ n = self.n
221
+ if n == 6:
222
+ return 72
223
+ if n == 7:
224
+ return 126
225
+ if n == 8:
226
+ return 240
227
+
228
+
229
+ def cartan_matrix(self):
230
+ """
231
+ Returns the Cartan matrix for G_2
232
+ The Cartan matrix matrix for a Lie algebra is
233
+ generated by assigning an ordering to the simple
234
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
235
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
236
+
237
+ Examples
238
+ ========
239
+
240
+ >>> from sympy.liealgebras.cartan_type import CartanType
241
+ >>> c = CartanType('A4')
242
+ >>> c.cartan_matrix()
243
+ Matrix([
244
+ [ 2, -1, 0, 0],
245
+ [-1, 2, -1, 0],
246
+ [ 0, -1, 2, -1],
247
+ [ 0, 0, -1, 2]])
248
+
249
+
250
+ """
251
+
252
+ n = self.n
253
+ m = 2*eye(n)
254
+ i = 3
255
+ while i < n-1:
256
+ m[i, i+1] = -1
257
+ m[i, i-1] = -1
258
+ i += 1
259
+ m[0, 2] = m[2, 0] = -1
260
+ m[1, 3] = m[3, 1] = -1
261
+ m[2, 3] = -1
262
+ m[n-1, n-2] = -1
263
+ return m
264
+
265
+
266
+ def basis(self):
267
+ """
268
+ Returns the number of independent generators of E_n
269
+ """
270
+
271
+ n = self.n
272
+ if n == 6:
273
+ return 78
274
+ if n == 7:
275
+ return 133
276
+ if n == 8:
277
+ return 248
278
+
279
+ def dynkin_diagram(self):
280
+ n = self.n
281
+ diag = " "*8 + str(2) + "\n"
282
+ diag += " "*8 + "0\n"
283
+ diag += " "*8 + "|\n"
284
+ diag += " "*8 + "|\n"
285
+ diag += "---".join("0" for i in range(1, n)) + "\n"
286
+ diag += "1 " + " ".join(str(i) for i in range(3, n+1))
287
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_f.py ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .cartan_type import Standard_Cartan
2
+ from sympy.core.backend import Matrix, Rational
3
+
4
+
5
+ class TypeF(Standard_Cartan):
6
+
7
+ def __new__(cls, n):
8
+ if n != 4:
9
+ raise ValueError("n should be 4")
10
+ return Standard_Cartan.__new__(cls, "F", 4)
11
+
12
+ def dimension(self):
13
+ """Dimension of the vector space V underlying the Lie algebra
14
+
15
+ Examples
16
+ ========
17
+
18
+ >>> from sympy.liealgebras.cartan_type import CartanType
19
+ >>> c = CartanType("F4")
20
+ >>> c.dimension()
21
+ 4
22
+ """
23
+
24
+ return 4
25
+
26
+
27
+ def basic_root(self, i, j):
28
+ """Generate roots with 1 in ith position and -1 in jth position
29
+
30
+ """
31
+
32
+ n = self.n
33
+ root = [0]*n
34
+ root[i] = 1
35
+ root[j] = -1
36
+ return root
37
+
38
+ def simple_root(self, i):
39
+ """The ith simple root of F_4
40
+
41
+ Every lie algebra has a unique root system.
42
+ Given a root system Q, there is a subset of the
43
+ roots such that an element of Q is called a
44
+ simple root if it cannot be written as the sum
45
+ of two elements in Q. If we let D denote the
46
+ set of simple roots, then it is clear that every
47
+ element of Q can be written as a linear combination
48
+ of elements of D with all coefficients non-negative.
49
+
50
+ Examples
51
+ ========
52
+
53
+ >>> from sympy.liealgebras.cartan_type import CartanType
54
+ >>> c = CartanType("F4")
55
+ >>> c.simple_root(3)
56
+ [0, 0, 0, 1]
57
+
58
+ """
59
+
60
+ if i < 3:
61
+ return self.basic_root(i-1, i)
62
+ if i == 3:
63
+ root = [0]*4
64
+ root[3] = 1
65
+ return root
66
+ if i == 4:
67
+ root = [Rational(-1, 2)]*4
68
+ return root
69
+
70
+ def positive_roots(self):
71
+ """Generate all the positive roots of A_n
72
+
73
+ This is half of all of the roots of F_4; by multiplying all the
74
+ positive roots by -1 we get the negative roots.
75
+
76
+ Examples
77
+ ========
78
+
79
+ >>> from sympy.liealgebras.cartan_type import CartanType
80
+ >>> c = CartanType("A3")
81
+ >>> c.positive_roots()
82
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
83
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
84
+
85
+ """
86
+
87
+ n = self.n
88
+ posroots = {}
89
+ k = 0
90
+ for i in range(0, n-1):
91
+ for j in range(i+1, n):
92
+ k += 1
93
+ posroots[k] = self.basic_root(i, j)
94
+ k += 1
95
+ root = self.basic_root(i, j)
96
+ root[j] = 1
97
+ posroots[k] = root
98
+
99
+ for i in range(0, n):
100
+ k += 1
101
+ root = [0]*n
102
+ root[i] = 1
103
+ posroots[k] = root
104
+
105
+ k += 1
106
+ root = [Rational(1, 2)]*n
107
+ posroots[k] = root
108
+ for i in range(1, 4):
109
+ k += 1
110
+ root = [Rational(1, 2)]*n
111
+ root[i] = Rational(-1, 2)
112
+ posroots[k] = root
113
+
114
+ posroots[k+1] = [Rational(1, 2), Rational(1, 2), Rational(-1, 2), Rational(-1, 2)]
115
+ posroots[k+2] = [Rational(1, 2), Rational(-1, 2), Rational(1, 2), Rational(-1, 2)]
116
+ posroots[k+3] = [Rational(1, 2), Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]
117
+ posroots[k+4] = [Rational(1, 2), Rational(-1, 2), Rational(-1, 2), Rational(-1, 2)]
118
+
119
+ return posroots
120
+
121
+
122
+ def roots(self):
123
+ """
124
+ Returns the total number of roots for F_4
125
+ """
126
+ return 48
127
+
128
+ def cartan_matrix(self):
129
+ """The Cartan matrix for F_4
130
+
131
+ The Cartan matrix matrix for a Lie algebra is
132
+ generated by assigning an ordering to the simple
133
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
134
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
135
+
136
+ Examples
137
+ ========
138
+
139
+ >>> from sympy.liealgebras.cartan_type import CartanType
140
+ >>> c = CartanType('A4')
141
+ >>> c.cartan_matrix()
142
+ Matrix([
143
+ [ 2, -1, 0, 0],
144
+ [-1, 2, -1, 0],
145
+ [ 0, -1, 2, -1],
146
+ [ 0, 0, -1, 2]])
147
+ """
148
+
149
+ m = Matrix( 4, 4, [2, -1, 0, 0, -1, 2, -2, 0, 0,
150
+ -1, 2, -1, 0, 0, -1, 2])
151
+ return m
152
+
153
+ def basis(self):
154
+ """
155
+ Returns the number of independent generators of F_4
156
+ """
157
+ return 52
158
+
159
+ def dynkin_diagram(self):
160
+ diag = "0---0=>=0---0\n"
161
+ diag += " ".join(str(i) for i in range(1, 5))
162
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/type_g.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .cartan_type import Standard_Cartan
4
+ from sympy.core.backend import Matrix
5
+
6
+ class TypeG(Standard_Cartan):
7
+
8
+ def __new__(cls, n):
9
+ if n != 2:
10
+ raise ValueError("n should be 2")
11
+ return Standard_Cartan.__new__(cls, "G", 2)
12
+
13
+
14
+ def dimension(self):
15
+ """Dimension of the vector space V underlying the Lie algebra
16
+
17
+ Examples
18
+ ========
19
+
20
+ >>> from sympy.liealgebras.cartan_type import CartanType
21
+ >>> c = CartanType("G2")
22
+ >>> c.dimension()
23
+ 3
24
+ """
25
+ return 3
26
+
27
+ def simple_root(self, i):
28
+ """The ith simple root of G_2
29
+
30
+ Every lie algebra has a unique root system.
31
+ Given a root system Q, there is a subset of the
32
+ roots such that an element of Q is called a
33
+ simple root if it cannot be written as the sum
34
+ of two elements in Q. If we let D denote the
35
+ set of simple roots, then it is clear that every
36
+ element of Q can be written as a linear combination
37
+ of elements of D with all coefficients non-negative.
38
+
39
+ Examples
40
+ ========
41
+
42
+ >>> from sympy.liealgebras.cartan_type import CartanType
43
+ >>> c = CartanType("G2")
44
+ >>> c.simple_root(1)
45
+ [0, 1, -1]
46
+
47
+ """
48
+ if i == 1:
49
+ return [0, 1, -1]
50
+ else:
51
+ return [1, -2, 1]
52
+
53
+ def positive_roots(self):
54
+ """Generate all the positive roots of A_n
55
+
56
+ This is half of all of the roots of A_n; by multiplying all the
57
+ positive roots by -1 we get the negative roots.
58
+
59
+ Examples
60
+ ========
61
+
62
+ >>> from sympy.liealgebras.cartan_type import CartanType
63
+ >>> c = CartanType("A3")
64
+ >>> c.positive_roots()
65
+ {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
66
+ 5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
67
+
68
+ """
69
+
70
+ roots = {1: [0, 1, -1], 2: [1, -2, 1], 3: [1, -1, 0], 4: [1, 0, 1],
71
+ 5: [1, 1, -2], 6: [2, -1, -1]}
72
+ return roots
73
+
74
+ def roots(self):
75
+ """
76
+ Returns the total number of roots of G_2"
77
+ """
78
+ return 12
79
+
80
+ def cartan_matrix(self):
81
+ """The Cartan matrix for G_2
82
+
83
+ The Cartan matrix matrix for a Lie algebra is
84
+ generated by assigning an ordering to the simple
85
+ roots, (alpha[1], ...., alpha[l]). Then the ijth
86
+ entry of the Cartan matrix is (<alpha[i],alpha[j]>).
87
+
88
+ Examples
89
+ ========
90
+
91
+ >>> from sympy.liealgebras.cartan_type import CartanType
92
+ >>> c = CartanType("G2")
93
+ >>> c.cartan_matrix()
94
+ Matrix([
95
+ [ 2, -1],
96
+ [-3, 2]])
97
+
98
+ """
99
+
100
+ m = Matrix( 2, 2, [2, -1, -3, 2])
101
+ return m
102
+
103
+ def basis(self):
104
+ """
105
+ Returns the number of independent generators of G_2
106
+ """
107
+ return 14
108
+
109
+ def dynkin_diagram(self):
110
+ diag = "0≡<≡0\n1 2"
111
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/liealgebras/weyl_group.py ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from .cartan_type import CartanType
4
+ from mpmath import fac
5
+ from sympy.core.backend import Matrix, eye, Rational, igcd
6
+ from sympy.core.basic import Atom
7
+
8
+ class WeylGroup(Atom):
9
+
10
+ """
11
+ For each semisimple Lie group, we have a Weyl group. It is a subgroup of
12
+ the isometry group of the root system. Specifically, it's the subgroup
13
+ that is generated by reflections through the hyperplanes orthogonal to
14
+ the roots. Therefore, Weyl groups are reflection groups, and so a Weyl
15
+ group is a finite Coxeter group.
16
+
17
+ """
18
+
19
+ def __new__(cls, cartantype):
20
+ obj = Atom.__new__(cls)
21
+ obj.cartan_type = CartanType(cartantype)
22
+ return obj
23
+
24
+ def generators(self):
25
+ """
26
+ This method creates the generating reflections of the Weyl group for
27
+ a given Lie algebra. For a Lie algebra of rank n, there are n
28
+ different generating reflections. This function returns them as
29
+ a list.
30
+
31
+ Examples
32
+ ========
33
+
34
+ >>> from sympy.liealgebras.weyl_group import WeylGroup
35
+ >>> c = WeylGroup("F4")
36
+ >>> c.generators()
37
+ ['r1', 'r2', 'r3', 'r4']
38
+ """
39
+ n = self.cartan_type.rank()
40
+ generators = []
41
+ for i in range(1, n+1):
42
+ reflection = "r"+str(i)
43
+ generators.append(reflection)
44
+ return generators
45
+
46
+ def group_order(self):
47
+ """
48
+ This method returns the order of the Weyl group.
49
+ For types A, B, C, D, and E the order depends on
50
+ the rank of the Lie algebra. For types F and G,
51
+ the order is fixed.
52
+
53
+ Examples
54
+ ========
55
+
56
+ >>> from sympy.liealgebras.weyl_group import WeylGroup
57
+ >>> c = WeylGroup("D4")
58
+ >>> c.group_order()
59
+ 192.0
60
+ """
61
+ n = self.cartan_type.rank()
62
+ if self.cartan_type.series == "A":
63
+ return fac(n+1)
64
+
65
+ if self.cartan_type.series in ("B", "C"):
66
+ return fac(n)*(2**n)
67
+
68
+ if self.cartan_type.series == "D":
69
+ return fac(n)*(2**(n-1))
70
+
71
+ if self.cartan_type.series == "E":
72
+ if n == 6:
73
+ return 51840
74
+ if n == 7:
75
+ return 2903040
76
+ if n == 8:
77
+ return 696729600
78
+ if self.cartan_type.series == "F":
79
+ return 1152
80
+
81
+ if self.cartan_type.series == "G":
82
+ return 12
83
+
84
+ def group_name(self):
85
+ """
86
+ This method returns some general information about the Weyl group for
87
+ a given Lie algebra. It returns the name of the group and the elements
88
+ it acts on, if relevant.
89
+ """
90
+ n = self.cartan_type.rank()
91
+ if self.cartan_type.series == "A":
92
+ return "S"+str(n+1) + ": the symmetric group acting on " + str(n+1) + " elements."
93
+
94
+ if self.cartan_type.series in ("B", "C"):
95
+ return "The hyperoctahedral group acting on " + str(2*n) + " elements."
96
+
97
+ if self.cartan_type.series == "D":
98
+ return "The symmetry group of the " + str(n) + "-dimensional demihypercube."
99
+
100
+ if self.cartan_type.series == "E":
101
+ if n == 6:
102
+ return "The symmetry group of the 6-polytope."
103
+
104
+ if n == 7:
105
+ return "The symmetry group of the 7-polytope."
106
+
107
+ if n == 8:
108
+ return "The symmetry group of the 8-polytope."
109
+
110
+ if self.cartan_type.series == "F":
111
+ return "The symmetry group of the 24-cell, or icositetrachoron."
112
+
113
+ if self.cartan_type.series == "G":
114
+ return "D6, the dihedral group of order 12, and symmetry group of the hexagon."
115
+
116
+ def element_order(self, weylelt):
117
+ """
118
+ This method returns the order of a given Weyl group element, which should
119
+ be specified by the user in the form of products of the generating
120
+ reflections, i.e. of the form r1*r2 etc.
121
+
122
+ For types A-F, this method current works by taking the matrix form of
123
+ the specified element, and then finding what power of the matrix is the
124
+ identity. It then returns this power.
125
+
126
+ Examples
127
+ ========
128
+
129
+ >>> from sympy.liealgebras.weyl_group import WeylGroup
130
+ >>> b = WeylGroup("B4")
131
+ >>> b.element_order('r1*r4*r2')
132
+ 4
133
+ """
134
+ n = self.cartan_type.rank()
135
+ if self.cartan_type.series == "A":
136
+ a = self.matrix_form(weylelt)
137
+ order = 1
138
+ while a != eye(n+1):
139
+ a *= self.matrix_form(weylelt)
140
+ order += 1
141
+ return order
142
+
143
+ if self.cartan_type.series == "D":
144
+ a = self.matrix_form(weylelt)
145
+ order = 1
146
+ while a != eye(n):
147
+ a *= self.matrix_form(weylelt)
148
+ order += 1
149
+ return order
150
+
151
+ if self.cartan_type.series == "E":
152
+ a = self.matrix_form(weylelt)
153
+ order = 1
154
+ while a != eye(8):
155
+ a *= self.matrix_form(weylelt)
156
+ order += 1
157
+ return order
158
+
159
+ if self.cartan_type.series == "G":
160
+ elts = list(weylelt)
161
+ reflections = elts[1::3]
162
+ m = self.delete_doubles(reflections)
163
+ while self.delete_doubles(m) != m:
164
+ m = self.delete_doubles(m)
165
+ reflections = m
166
+ if len(reflections) % 2 == 1:
167
+ return 2
168
+
169
+ elif len(reflections) == 0:
170
+ return 1
171
+
172
+ else:
173
+ if len(reflections) == 1:
174
+ return 2
175
+ else:
176
+ m = len(reflections) // 2
177
+ lcm = (6 * m)/ igcd(m, 6)
178
+ order = lcm / m
179
+ return order
180
+
181
+
182
+ if self.cartan_type.series == 'F':
183
+ a = self.matrix_form(weylelt)
184
+ order = 1
185
+ while a != eye(4):
186
+ a *= self.matrix_form(weylelt)
187
+ order += 1
188
+ return order
189
+
190
+
191
+ if self.cartan_type.series in ("B", "C"):
192
+ a = self.matrix_form(weylelt)
193
+ order = 1
194
+ while a != eye(n):
195
+ a *= self.matrix_form(weylelt)
196
+ order += 1
197
+ return order
198
+
199
+ def delete_doubles(self, reflections):
200
+ """
201
+ This is a helper method for determining the order of an element in the
202
+ Weyl group of G2. It takes a Weyl element and if repeated simple reflections
203
+ in it, it deletes them.
204
+ """
205
+ counter = 0
206
+ copy = list(reflections)
207
+ for elt in copy:
208
+ if counter < len(copy)-1:
209
+ if copy[counter + 1] == elt:
210
+ del copy[counter]
211
+ del copy[counter]
212
+ counter += 1
213
+
214
+
215
+ return copy
216
+
217
+
218
+ def matrix_form(self, weylelt):
219
+ """
220
+ This method takes input from the user in the form of products of the
221
+ generating reflections, and returns the matrix corresponding to the
222
+ element of the Weyl group. Since each element of the Weyl group is
223
+ a reflection of some type, there is a corresponding matrix representation.
224
+ This method uses the standard representation for all the generating
225
+ reflections.
226
+
227
+ Examples
228
+ ========
229
+
230
+ >>> from sympy.liealgebras.weyl_group import WeylGroup
231
+ >>> f = WeylGroup("F4")
232
+ >>> f.matrix_form('r2*r3')
233
+ Matrix([
234
+ [1, 0, 0, 0],
235
+ [0, 1, 0, 0],
236
+ [0, 0, 0, -1],
237
+ [0, 0, 1, 0]])
238
+
239
+ """
240
+ elts = list(weylelt)
241
+ reflections = elts[1::3]
242
+ n = self.cartan_type.rank()
243
+ if self.cartan_type.series == 'A':
244
+ matrixform = eye(n+1)
245
+ for elt in reflections:
246
+ a = int(elt)
247
+ mat = eye(n+1)
248
+ mat[a-1, a-1] = 0
249
+ mat[a-1, a] = 1
250
+ mat[a, a-1] = 1
251
+ mat[a, a] = 0
252
+ matrixform *= mat
253
+ return matrixform
254
+
255
+ if self.cartan_type.series == 'D':
256
+ matrixform = eye(n)
257
+ for elt in reflections:
258
+ a = int(elt)
259
+ mat = eye(n)
260
+ if a < n:
261
+ mat[a-1, a-1] = 0
262
+ mat[a-1, a] = 1
263
+ mat[a, a-1] = 1
264
+ mat[a, a] = 0
265
+ matrixform *= mat
266
+ else:
267
+ mat[n-2, n-1] = -1
268
+ mat[n-2, n-2] = 0
269
+ mat[n-1, n-2] = -1
270
+ mat[n-1, n-1] = 0
271
+ matrixform *= mat
272
+ return matrixform
273
+
274
+ if self.cartan_type.series == 'G':
275
+ matrixform = eye(3)
276
+ for elt in reflections:
277
+ a = int(elt)
278
+ if a == 1:
279
+ gen1 = Matrix([[1, 0, 0], [0, 0, 1], [0, 1, 0]])
280
+ matrixform *= gen1
281
+ else:
282
+ gen2 = Matrix([[Rational(2, 3), Rational(2, 3), Rational(-1, 3)],
283
+ [Rational(2, 3), Rational(-1, 3), Rational(2, 3)],
284
+ [Rational(-1, 3), Rational(2, 3), Rational(2, 3)]])
285
+ matrixform *= gen2
286
+ return matrixform
287
+
288
+ if self.cartan_type.series == 'F':
289
+ matrixform = eye(4)
290
+ for elt in reflections:
291
+ a = int(elt)
292
+ if a == 1:
293
+ mat = Matrix([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
294
+ matrixform *= mat
295
+ elif a == 2:
296
+ mat = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])
297
+ matrixform *= mat
298
+ elif a == 3:
299
+ mat = Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]])
300
+ matrixform *= mat
301
+ else:
302
+
303
+ mat = Matrix([[Rational(1, 2), Rational(1, 2), Rational(1, 2), Rational(1, 2)],
304
+ [Rational(1, 2), Rational(1, 2), Rational(-1, 2), Rational(-1, 2)],
305
+ [Rational(1, 2), Rational(-1, 2), Rational(1, 2), Rational(-1, 2)],
306
+ [Rational(1, 2), Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]])
307
+ matrixform *= mat
308
+ return matrixform
309
+
310
+ if self.cartan_type.series == 'E':
311
+ matrixform = eye(8)
312
+ for elt in reflections:
313
+ a = int(elt)
314
+ if a == 1:
315
+ mat = Matrix([[Rational(3, 4), Rational(1, 4), Rational(1, 4), Rational(1, 4),
316
+ Rational(1, 4), Rational(1, 4), Rational(1, 4), Rational(-1, 4)],
317
+ [Rational(1, 4), Rational(3, 4), Rational(-1, 4), Rational(-1, 4),
318
+ Rational(-1, 4), Rational(-1, 4), Rational(1, 4), Rational(-1, 4)],
319
+ [Rational(1, 4), Rational(-1, 4), Rational(3, 4), Rational(-1, 4),
320
+ Rational(-1, 4), Rational(-1, 4), Rational(-1, 4), Rational(1, 4)],
321
+ [Rational(1, 4), Rational(-1, 4), Rational(-1, 4), Rational(3, 4),
322
+ Rational(-1, 4), Rational(-1, 4), Rational(-1, 4), Rational(1, 4)],
323
+ [Rational(1, 4), Rational(-1, 4), Rational(-1, 4), Rational(-1, 4),
324
+ Rational(3, 4), Rational(-1, 4), Rational(-1, 4), Rational(1, 4)],
325
+ [Rational(1, 4), Rational(-1, 4), Rational(-1, 4), Rational(-1, 4),
326
+ Rational(-1, 4), Rational(3, 4), Rational(-1, 4), Rational(1, 4)],
327
+ [Rational(1, 4), Rational(-1, 4), Rational(-1, 4), Rational(-1, 4),
328
+ Rational(-1, 4), Rational(-1, 4), Rational(-3, 4), Rational(1, 4)],
329
+ [Rational(1, 4), Rational(-1, 4), Rational(-1, 4), Rational(-1, 4),
330
+ Rational(-1, 4), Rational(-1, 4), Rational(-1, 4), Rational(3, 4)]])
331
+ matrixform *= mat
332
+ elif a == 2:
333
+ mat = eye(8)
334
+ mat[0, 0] = 0
335
+ mat[0, 1] = -1
336
+ mat[1, 0] = -1
337
+ mat[1, 1] = 0
338
+ matrixform *= mat
339
+ else:
340
+ mat = eye(8)
341
+ mat[a-3, a-3] = 0
342
+ mat[a-3, a-2] = 1
343
+ mat[a-2, a-3] = 1
344
+ mat[a-2, a-2] = 0
345
+ matrixform *= mat
346
+ return matrixform
347
+
348
+
349
+ if self.cartan_type.series in ("B", "C"):
350
+ matrixform = eye(n)
351
+ for elt in reflections:
352
+ a = int(elt)
353
+ mat = eye(n)
354
+ if a == 1:
355
+ mat[0, 0] = -1
356
+ matrixform *= mat
357
+ else:
358
+ mat[a - 2, a - 2] = 0
359
+ mat[a-2, a-1] = 1
360
+ mat[a - 1, a - 2] = 1
361
+ mat[a -1, a - 1] = 0
362
+ matrixform *= mat
363
+ return matrixform
364
+
365
+
366
+
367
+ def coxeter_diagram(self):
368
+ """
369
+ This method returns the Coxeter diagram corresponding to a Weyl group.
370
+ The Coxeter diagram can be obtained from a Lie algebra's Dynkin diagram
371
+ by deleting all arrows; the Coxeter diagram is the undirected graph.
372
+ The vertices of the Coxeter diagram represent the generating reflections
373
+ of the Weyl group, $s_i$. An edge is drawn between $s_i$ and $s_j$ if the order
374
+ $m(i, j)$ of $s_is_j$ is greater than two. If there is one edge, the order
375
+ $m(i, j)$ is 3. If there are two edges, the order $m(i, j)$ is 4, and if there
376
+ are three edges, the order $m(i, j)$ is 6.
377
+
378
+ Examples
379
+ ========
380
+
381
+ >>> from sympy.liealgebras.weyl_group import WeylGroup
382
+ >>> c = WeylGroup("B3")
383
+ >>> print(c.coxeter_diagram())
384
+ 0---0===0
385
+ 1 2 3
386
+ """
387
+ n = self.cartan_type.rank()
388
+ if self.cartan_type.series in ("A", "D", "E"):
389
+ return self.cartan_type.dynkin_diagram()
390
+
391
+ if self.cartan_type.series in ("B", "C"):
392
+ diag = "---".join("0" for i in range(1, n)) + "===0\n"
393
+ diag += " ".join(str(i) for i in range(1, n+1))
394
+ return diag
395
+
396
+ if self.cartan_type.series == "F":
397
+ diag = "0---0===0---0\n"
398
+ diag += " ".join(str(i) for i in range(1, 5))
399
+ return diag
400
+
401
+ if self.cartan_type.series == "G":
402
+ diag = "0≡≡≡0\n1 2"
403
+ return diag
llmeval-env/lib/python3.10/site-packages/sympy/vector/__init__.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.vector.coordsysrect import CoordSys3D
2
+ from sympy.vector.vector import (Vector, VectorAdd, VectorMul,
3
+ BaseVector, VectorZero, Cross, Dot, cross, dot)
4
+ from sympy.vector.dyadic import (Dyadic, DyadicAdd, DyadicMul,
5
+ BaseDyadic, DyadicZero)
6
+ from sympy.vector.scalar import BaseScalar
7
+ from sympy.vector.deloperator import Del
8
+ from sympy.vector.functions import (express, matrix_to_vector,
9
+ laplacian, is_conservative,
10
+ is_solenoidal, scalar_potential,
11
+ directional_derivative,
12
+ scalar_potential_difference)
13
+ from sympy.vector.point import Point
14
+ from sympy.vector.orienters import (AxisOrienter, BodyOrienter,
15
+ SpaceOrienter, QuaternionOrienter)
16
+ from sympy.vector.operators import Gradient, Divergence, Curl, Laplacian, gradient, curl, divergence
17
+ from sympy.vector.implicitregion import ImplicitRegion
18
+ from sympy.vector.parametricregion import (ParametricRegion, parametric_region_list)
19
+ from sympy.vector.integrals import (ParametricIntegral, vector_integrate)
20
+
21
+ __all__ = [
22
+ 'Vector', 'VectorAdd', 'VectorMul', 'BaseVector', 'VectorZero', 'Cross',
23
+ 'Dot', 'cross', 'dot',
24
+
25
+ 'Dyadic', 'DyadicAdd', 'DyadicMul', 'BaseDyadic', 'DyadicZero',
26
+
27
+ 'BaseScalar',
28
+
29
+ 'Del',
30
+
31
+ 'CoordSys3D',
32
+
33
+ 'express', 'matrix_to_vector', 'laplacian', 'is_conservative',
34
+ 'is_solenoidal', 'scalar_potential', 'directional_derivative',
35
+ 'scalar_potential_difference',
36
+
37
+ 'Point',
38
+
39
+ 'AxisOrienter', 'BodyOrienter', 'SpaceOrienter', 'QuaternionOrienter',
40
+
41
+ 'Gradient', 'Divergence', 'Curl', 'Laplacian', 'gradient', 'curl',
42
+ 'divergence',
43
+
44
+ 'ParametricRegion', 'parametric_region_list', 'ImplicitRegion',
45
+
46
+ 'ParametricIntegral', 'vector_integrate',
47
+ ]
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.77 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/basisdependent.cpython-310.pyc ADDED
Binary file (12.2 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/coordsysrect.cpython-310.pyc ADDED
Binary file (31.4 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/deloperator.cpython-310.pyc ADDED
Binary file (3.7 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/dyadic.cpython-310.pyc ADDED
Binary file (8.99 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/functions.cpython-310.pyc ADDED
Binary file (13.2 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/implicitregion.cpython-310.pyc ADDED
Binary file (13 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/integrals.cpython-310.pyc ADDED
Binary file (6.07 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/operators.cpython-310.pyc ADDED
Binary file (9.76 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/orienters.cpython-310.pyc ADDED
Binary file (12.3 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/parametricregion.cpython-310.pyc ADDED
Binary file (6.4 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/point.cpython-310.pyc ADDED
Binary file (4.13 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/scalar.cpython-310.pyc ADDED
Binary file (2.36 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/__pycache__/vector.cpython-310.pyc ADDED
Binary file (18.1 kB). View file
 
llmeval-env/lib/python3.10/site-packages/sympy/vector/basisdependent.py ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING
3
+
4
+ from sympy.simplify import simplify as simp, trigsimp as tsimp # type: ignore
5
+ from sympy.core.decorators import call_highest_priority, _sympifyit
6
+ from sympy.core.assumptions import StdFactKB
7
+ from sympy.core.function import diff as df
8
+ from sympy.integrals.integrals import Integral
9
+ from sympy.polys.polytools import factor as fctr
10
+ from sympy.core import S, Add, Mul
11
+ from sympy.core.expr import Expr
12
+
13
+ if TYPE_CHECKING:
14
+ from sympy.vector.vector import BaseVector
15
+
16
+
17
+ class BasisDependent(Expr):
18
+ """
19
+ Super class containing functionality common to vectors and
20
+ dyadics.
21
+ Named so because the representation of these quantities in
22
+ sympy.vector is dependent on the basis they are expressed in.
23
+ """
24
+
25
+ zero: BasisDependentZero
26
+
27
+ @call_highest_priority('__radd__')
28
+ def __add__(self, other):
29
+ return self._add_func(self, other)
30
+
31
+ @call_highest_priority('__add__')
32
+ def __radd__(self, other):
33
+ return self._add_func(other, self)
34
+
35
+ @call_highest_priority('__rsub__')
36
+ def __sub__(self, other):
37
+ return self._add_func(self, -other)
38
+
39
+ @call_highest_priority('__sub__')
40
+ def __rsub__(self, other):
41
+ return self._add_func(other, -self)
42
+
43
+ @_sympifyit('other', NotImplemented)
44
+ @call_highest_priority('__rmul__')
45
+ def __mul__(self, other):
46
+ return self._mul_func(self, other)
47
+
48
+ @_sympifyit('other', NotImplemented)
49
+ @call_highest_priority('__mul__')
50
+ def __rmul__(self, other):
51
+ return self._mul_func(other, self)
52
+
53
+ def __neg__(self):
54
+ return self._mul_func(S.NegativeOne, self)
55
+
56
+ @_sympifyit('other', NotImplemented)
57
+ @call_highest_priority('__rtruediv__')
58
+ def __truediv__(self, other):
59
+ return self._div_helper(other)
60
+
61
+ @call_highest_priority('__truediv__')
62
+ def __rtruediv__(self, other):
63
+ return TypeError("Invalid divisor for division")
64
+
65
+ def evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False):
66
+ """
67
+ Implements the SymPy evalf routine for this quantity.
68
+
69
+ evalf's documentation
70
+ =====================
71
+
72
+ """
73
+ options = {'subs':subs, 'maxn':maxn, 'chop':chop, 'strict':strict,
74
+ 'quad':quad, 'verbose':verbose}
75
+ vec = self.zero
76
+ for k, v in self.components.items():
77
+ vec += v.evalf(n, **options) * k
78
+ return vec
79
+
80
+ evalf.__doc__ += Expr.evalf.__doc__ # type: ignore
81
+
82
+ n = evalf
83
+
84
+ def simplify(self, **kwargs):
85
+ """
86
+ Implements the SymPy simplify routine for this quantity.
87
+
88
+ simplify's documentation
89
+ ========================
90
+
91
+ """
92
+ simp_components = [simp(v, **kwargs) * k for
93
+ k, v in self.components.items()]
94
+ return self._add_func(*simp_components)
95
+
96
+ simplify.__doc__ += simp.__doc__ # type: ignore
97
+
98
+ def trigsimp(self, **opts):
99
+ """
100
+ Implements the SymPy trigsimp routine, for this quantity.
101
+
102
+ trigsimp's documentation
103
+ ========================
104
+
105
+ """
106
+ trig_components = [tsimp(v, **opts) * k for
107
+ k, v in self.components.items()]
108
+ return self._add_func(*trig_components)
109
+
110
+ trigsimp.__doc__ += tsimp.__doc__ # type: ignore
111
+
112
+ def _eval_simplify(self, **kwargs):
113
+ return self.simplify(**kwargs)
114
+
115
+ def _eval_trigsimp(self, **opts):
116
+ return self.trigsimp(**opts)
117
+
118
+ def _eval_derivative(self, wrt):
119
+ return self.diff(wrt)
120
+
121
+ def _eval_Integral(self, *symbols, **assumptions):
122
+ integral_components = [Integral(v, *symbols, **assumptions) * k
123
+ for k, v in self.components.items()]
124
+ return self._add_func(*integral_components)
125
+
126
+ def as_numer_denom(self):
127
+ """
128
+ Returns the expression as a tuple wrt the following
129
+ transformation -
130
+
131
+ expression -> a/b -> a, b
132
+
133
+ """
134
+ return self, S.One
135
+
136
+ def factor(self, *args, **kwargs):
137
+ """
138
+ Implements the SymPy factor routine, on the scalar parts
139
+ of a basis-dependent expression.
140
+
141
+ factor's documentation
142
+ ========================
143
+
144
+ """
145
+ fctr_components = [fctr(v, *args, **kwargs) * k for
146
+ k, v in self.components.items()]
147
+ return self._add_func(*fctr_components)
148
+
149
+ factor.__doc__ += fctr.__doc__ # type: ignore
150
+
151
+ def as_coeff_Mul(self, rational=False):
152
+ """Efficiently extract the coefficient of a product."""
153
+ return (S.One, self)
154
+
155
+ def as_coeff_add(self, *deps):
156
+ """Efficiently extract the coefficient of a summation."""
157
+ l = [x * self.components[x] for x in self.components]
158
+ return 0, tuple(l)
159
+
160
+ def diff(self, *args, **kwargs):
161
+ """
162
+ Implements the SymPy diff routine, for vectors.
163
+
164
+ diff's documentation
165
+ ========================
166
+
167
+ """
168
+ for x in args:
169
+ if isinstance(x, BasisDependent):
170
+ raise TypeError("Invalid arg for differentiation")
171
+ diff_components = [df(v, *args, **kwargs) * k for
172
+ k, v in self.components.items()]
173
+ return self._add_func(*diff_components)
174
+
175
+ diff.__doc__ += df.__doc__ # type: ignore
176
+
177
+ def doit(self, **hints):
178
+ """Calls .doit() on each term in the Dyadic"""
179
+ doit_components = [self.components[x].doit(**hints) * x
180
+ for x in self.components]
181
+ return self._add_func(*doit_components)
182
+
183
+
184
+ class BasisDependentAdd(BasisDependent, Add):
185
+ """
186
+ Denotes sum of basis dependent quantities such that they cannot
187
+ be expressed as base or Mul instances.
188
+ """
189
+
190
+ def __new__(cls, *args, **options):
191
+ components = {}
192
+
193
+ # Check each arg and simultaneously learn the components
194
+ for i, arg in enumerate(args):
195
+ if not isinstance(arg, cls._expr_type):
196
+ if isinstance(arg, Mul):
197
+ arg = cls._mul_func(*(arg.args))
198
+ elif isinstance(arg, Add):
199
+ arg = cls._add_func(*(arg.args))
200
+ else:
201
+ raise TypeError(str(arg) +
202
+ " cannot be interpreted correctly")
203
+ # If argument is zero, ignore
204
+ if arg == cls.zero:
205
+ continue
206
+ # Else, update components accordingly
207
+ if hasattr(arg, "components"):
208
+ for x in arg.components:
209
+ components[x] = components.get(x, 0) + arg.components[x]
210
+
211
+ temp = list(components.keys())
212
+ for x in temp:
213
+ if components[x] == 0:
214
+ del components[x]
215
+
216
+ # Handle case of zero vector
217
+ if len(components) == 0:
218
+ return cls.zero
219
+
220
+ # Build object
221
+ newargs = [x * components[x] for x in components]
222
+ obj = super().__new__(cls, *newargs, **options)
223
+ if isinstance(obj, Mul):
224
+ return cls._mul_func(*obj.args)
225
+ assumptions = {'commutative': True}
226
+ obj._assumptions = StdFactKB(assumptions)
227
+ obj._components = components
228
+ obj._sys = (list(components.keys()))[0]._sys
229
+
230
+ return obj
231
+
232
+
233
+ class BasisDependentMul(BasisDependent, Mul):
234
+ """
235
+ Denotes product of base- basis dependent quantity with a scalar.
236
+ """
237
+
238
+ def __new__(cls, *args, **options):
239
+ from sympy.vector import Cross, Dot, Curl, Gradient
240
+ count = 0
241
+ measure_number = S.One
242
+ zeroflag = False
243
+ extra_args = []
244
+
245
+ # Determine the component and check arguments
246
+ # Also keep a count to ensure two vectors aren't
247
+ # being multiplied
248
+ for arg in args:
249
+ if isinstance(arg, cls._zero_func):
250
+ count += 1
251
+ zeroflag = True
252
+ elif arg == S.Zero:
253
+ zeroflag = True
254
+ elif isinstance(arg, (cls._base_func, cls._mul_func)):
255
+ count += 1
256
+ expr = arg._base_instance
257
+ measure_number *= arg._measure_number
258
+ elif isinstance(arg, cls._add_func):
259
+ count += 1
260
+ expr = arg
261
+ elif isinstance(arg, (Cross, Dot, Curl, Gradient)):
262
+ extra_args.append(arg)
263
+ else:
264
+ measure_number *= arg
265
+ # Make sure incompatible types weren't multiplied
266
+ if count > 1:
267
+ raise ValueError("Invalid multiplication")
268
+ elif count == 0:
269
+ return Mul(*args, **options)
270
+ # Handle zero vector case
271
+ if zeroflag:
272
+ return cls.zero
273
+
274
+ # If one of the args was a VectorAdd, return an
275
+ # appropriate VectorAdd instance
276
+ if isinstance(expr, cls._add_func):
277
+ newargs = [cls._mul_func(measure_number, x) for
278
+ x in expr.args]
279
+ return cls._add_func(*newargs)
280
+
281
+ obj = super().__new__(cls, measure_number,
282
+ expr._base_instance,
283
+ *extra_args,
284
+ **options)
285
+ if isinstance(obj, Add):
286
+ return cls._add_func(*obj.args)
287
+ obj._base_instance = expr._base_instance
288
+ obj._measure_number = measure_number
289
+ assumptions = {'commutative': True}
290
+ obj._assumptions = StdFactKB(assumptions)
291
+ obj._components = {expr._base_instance: measure_number}
292
+ obj._sys = expr._base_instance._sys
293
+
294
+ return obj
295
+
296
+ def _sympystr(self, printer):
297
+ measure_str = printer._print(self._measure_number)
298
+ if ('(' in measure_str or '-' in measure_str or
299
+ '+' in measure_str):
300
+ measure_str = '(' + measure_str + ')'
301
+ return measure_str + '*' + printer._print(self._base_instance)
302
+
303
+
304
+ class BasisDependentZero(BasisDependent):
305
+ """
306
+ Class to denote a zero basis dependent instance.
307
+ """
308
+ components: dict['BaseVector', Expr] = {}
309
+ _latex_form: str
310
+
311
+ def __new__(cls):
312
+ obj = super().__new__(cls)
313
+ # Pre-compute a specific hash value for the zero vector
314
+ # Use the same one always
315
+ obj._hash = (S.Zero, cls).__hash__()
316
+ return obj
317
+
318
+ def __hash__(self):
319
+ return self._hash
320
+
321
+ @call_highest_priority('__req__')
322
+ def __eq__(self, other):
323
+ return isinstance(other, self._zero_func)
324
+
325
+ __req__ = __eq__
326
+
327
+ @call_highest_priority('__radd__')
328
+ def __add__(self, other):
329
+ if isinstance(other, self._expr_type):
330
+ return other
331
+ else:
332
+ raise TypeError("Invalid argument types for addition")
333
+
334
+ @call_highest_priority('__add__')
335
+ def __radd__(self, other):
336
+ if isinstance(other, self._expr_type):
337
+ return other
338
+ else:
339
+ raise TypeError("Invalid argument types for addition")
340
+
341
+ @call_highest_priority('__rsub__')
342
+ def __sub__(self, other):
343
+ if isinstance(other, self._expr_type):
344
+ return -other
345
+ else:
346
+ raise TypeError("Invalid argument types for subtraction")
347
+
348
+ @call_highest_priority('__sub__')
349
+ def __rsub__(self, other):
350
+ if isinstance(other, self._expr_type):
351
+ return other
352
+ else:
353
+ raise TypeError("Invalid argument types for subtraction")
354
+
355
+ def __neg__(self):
356
+ return self
357
+
358
+ def normalize(self):
359
+ """
360
+ Returns the normalized version of this vector.
361
+ """
362
+ return self
363
+
364
+ def _sympystr(self, printer):
365
+ return '0'
llmeval-env/lib/python3.10/site-packages/sympy/vector/functions.py ADDED
@@ -0,0 +1,517 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.vector.coordsysrect import CoordSys3D
2
+ from sympy.vector.deloperator import Del
3
+ from sympy.vector.scalar import BaseScalar
4
+ from sympy.vector.vector import Vector, BaseVector
5
+ from sympy.vector.operators import gradient, curl, divergence
6
+ from sympy.core.function import diff
7
+ from sympy.core.singleton import S
8
+ from sympy.integrals.integrals import integrate
9
+ from sympy.simplify.simplify import simplify
10
+ from sympy.core import sympify
11
+ from sympy.vector.dyadic import Dyadic
12
+
13
+
14
+ def express(expr, system, system2=None, variables=False):
15
+ """
16
+ Global function for 'express' functionality.
17
+
18
+ Re-expresses a Vector, Dyadic or scalar(sympyfiable) in the given
19
+ coordinate system.
20
+
21
+ If 'variables' is True, then the coordinate variables (base scalars)
22
+ of other coordinate systems present in the vector/scalar field or
23
+ dyadic are also substituted in terms of the base scalars of the
24
+ given system.
25
+
26
+ Parameters
27
+ ==========
28
+
29
+ expr : Vector/Dyadic/scalar(sympyfiable)
30
+ The expression to re-express in CoordSys3D 'system'
31
+
32
+ system: CoordSys3D
33
+ The coordinate system the expr is to be expressed in
34
+
35
+ system2: CoordSys3D
36
+ The other coordinate system required for re-expression
37
+ (only for a Dyadic Expr)
38
+
39
+ variables : boolean
40
+ Specifies whether to substitute the coordinate variables present
41
+ in expr, in terms of those of parameter system
42
+
43
+ Examples
44
+ ========
45
+
46
+ >>> from sympy.vector import CoordSys3D
47
+ >>> from sympy import Symbol, cos, sin
48
+ >>> N = CoordSys3D('N')
49
+ >>> q = Symbol('q')
50
+ >>> B = N.orient_new_axis('B', q, N.k)
51
+ >>> from sympy.vector import express
52
+ >>> express(B.i, N)
53
+ (cos(q))*N.i + (sin(q))*N.j
54
+ >>> express(N.x, B, variables=True)
55
+ B.x*cos(q) - B.y*sin(q)
56
+ >>> d = N.i.outer(N.i)
57
+ >>> express(d, B, N) == (cos(q))*(B.i|N.i) + (-sin(q))*(B.j|N.i)
58
+ True
59
+
60
+ """
61
+
62
+ if expr in (0, Vector.zero):
63
+ return expr
64
+
65
+ if not isinstance(system, CoordSys3D):
66
+ raise TypeError("system should be a CoordSys3D \
67
+ instance")
68
+
69
+ if isinstance(expr, Vector):
70
+ if system2 is not None:
71
+ raise ValueError("system2 should not be provided for \
72
+ Vectors")
73
+ # Given expr is a Vector
74
+ if variables:
75
+ # If variables attribute is True, substitute
76
+ # the coordinate variables in the Vector
77
+ system_list = {x.system for x in expr.atoms(BaseScalar, BaseVector)} - {system}
78
+ subs_dict = {}
79
+ for f in system_list:
80
+ subs_dict.update(f.scalar_map(system))
81
+ expr = expr.subs(subs_dict)
82
+ # Re-express in this coordinate system
83
+ outvec = Vector.zero
84
+ parts = expr.separate()
85
+ for x in parts:
86
+ if x != system:
87
+ temp = system.rotation_matrix(x) * parts[x].to_matrix(x)
88
+ outvec += matrix_to_vector(temp, system)
89
+ else:
90
+ outvec += parts[x]
91
+ return outvec
92
+
93
+ elif isinstance(expr, Dyadic):
94
+ if system2 is None:
95
+ system2 = system
96
+ if not isinstance(system2, CoordSys3D):
97
+ raise TypeError("system2 should be a CoordSys3D \
98
+ instance")
99
+ outdyad = Dyadic.zero
100
+ var = variables
101
+ for k, v in expr.components.items():
102
+ outdyad += (express(v, system, variables=var) *
103
+ (express(k.args[0], system, variables=var) |
104
+ express(k.args[1], system2, variables=var)))
105
+
106
+ return outdyad
107
+
108
+ else:
109
+ if system2 is not None:
110
+ raise ValueError("system2 should not be provided for \
111
+ Vectors")
112
+ if variables:
113
+ # Given expr is a scalar field
114
+ system_set = set()
115
+ expr = sympify(expr)
116
+ # Substitute all the coordinate variables
117
+ for x in expr.atoms(BaseScalar):
118
+ if x.system != system:
119
+ system_set.add(x.system)
120
+ subs_dict = {}
121
+ for f in system_set:
122
+ subs_dict.update(f.scalar_map(system))
123
+ return expr.subs(subs_dict)
124
+ return expr
125
+
126
+
127
+ def directional_derivative(field, direction_vector):
128
+ """
129
+ Returns the directional derivative of a scalar or vector field computed
130
+ along a given vector in coordinate system which parameters are expressed.
131
+
132
+ Parameters
133
+ ==========
134
+
135
+ field : Vector or Scalar
136
+ The scalar or vector field to compute the directional derivative of
137
+
138
+ direction_vector : Vector
139
+ The vector to calculated directional derivative along them.
140
+
141
+
142
+ Examples
143
+ ========
144
+
145
+ >>> from sympy.vector import CoordSys3D, directional_derivative
146
+ >>> R = CoordSys3D('R')
147
+ >>> f1 = R.x*R.y*R.z
148
+ >>> v1 = 3*R.i + 4*R.j + R.k
149
+ >>> directional_derivative(f1, v1)
150
+ R.x*R.y + 4*R.x*R.z + 3*R.y*R.z
151
+ >>> f2 = 5*R.x**2*R.z
152
+ >>> directional_derivative(f2, v1)
153
+ 5*R.x**2 + 30*R.x*R.z
154
+
155
+ """
156
+ from sympy.vector.operators import _get_coord_systems
157
+ coord_sys = _get_coord_systems(field)
158
+ if len(coord_sys) > 0:
159
+ # TODO: This gets a random coordinate system in case of multiple ones:
160
+ coord_sys = next(iter(coord_sys))
161
+ field = express(field, coord_sys, variables=True)
162
+ i, j, k = coord_sys.base_vectors()
163
+ x, y, z = coord_sys.base_scalars()
164
+ out = Vector.dot(direction_vector, i) * diff(field, x)
165
+ out += Vector.dot(direction_vector, j) * diff(field, y)
166
+ out += Vector.dot(direction_vector, k) * diff(field, z)
167
+ if out == 0 and isinstance(field, Vector):
168
+ out = Vector.zero
169
+ return out
170
+ elif isinstance(field, Vector):
171
+ return Vector.zero
172
+ else:
173
+ return S.Zero
174
+
175
+
176
+ def laplacian(expr):
177
+ """
178
+ Return the laplacian of the given field computed in terms of
179
+ the base scalars of the given coordinate system.
180
+
181
+ Parameters
182
+ ==========
183
+
184
+ expr : SymPy Expr or Vector
185
+ expr denotes a scalar or vector field.
186
+
187
+ Examples
188
+ ========
189
+
190
+ >>> from sympy.vector import CoordSys3D, laplacian
191
+ >>> R = CoordSys3D('R')
192
+ >>> f = R.x**2*R.y**5*R.z
193
+ >>> laplacian(f)
194
+ 20*R.x**2*R.y**3*R.z + 2*R.y**5*R.z
195
+ >>> f = R.x**2*R.i + R.y**3*R.j + R.z**4*R.k
196
+ >>> laplacian(f)
197
+ 2*R.i + 6*R.y*R.j + 12*R.z**2*R.k
198
+
199
+ """
200
+
201
+ delop = Del()
202
+ if expr.is_Vector:
203
+ return (gradient(divergence(expr)) - curl(curl(expr))).doit()
204
+ return delop.dot(delop(expr)).doit()
205
+
206
+
207
+ def is_conservative(field):
208
+ """
209
+ Checks if a field is conservative.
210
+
211
+ Parameters
212
+ ==========
213
+
214
+ field : Vector
215
+ The field to check for conservative property
216
+
217
+ Examples
218
+ ========
219
+
220
+ >>> from sympy.vector import CoordSys3D
221
+ >>> from sympy.vector import is_conservative
222
+ >>> R = CoordSys3D('R')
223
+ >>> is_conservative(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)
224
+ True
225
+ >>> is_conservative(R.z*R.j)
226
+ False
227
+
228
+ """
229
+
230
+ # Field is conservative irrespective of system
231
+ # Take the first coordinate system in the result of the
232
+ # separate method of Vector
233
+ if not isinstance(field, Vector):
234
+ raise TypeError("field should be a Vector")
235
+ if field == Vector.zero:
236
+ return True
237
+ return curl(field).simplify() == Vector.zero
238
+
239
+
240
+ def is_solenoidal(field):
241
+ """
242
+ Checks if a field is solenoidal.
243
+
244
+ Parameters
245
+ ==========
246
+
247
+ field : Vector
248
+ The field to check for solenoidal property
249
+
250
+ Examples
251
+ ========
252
+
253
+ >>> from sympy.vector import CoordSys3D
254
+ >>> from sympy.vector import is_solenoidal
255
+ >>> R = CoordSys3D('R')
256
+ >>> is_solenoidal(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)
257
+ True
258
+ >>> is_solenoidal(R.y * R.j)
259
+ False
260
+
261
+ """
262
+
263
+ # Field is solenoidal irrespective of system
264
+ # Take the first coordinate system in the result of the
265
+ # separate method in Vector
266
+ if not isinstance(field, Vector):
267
+ raise TypeError("field should be a Vector")
268
+ if field == Vector.zero:
269
+ return True
270
+ return divergence(field).simplify() is S.Zero
271
+
272
+
273
+ def scalar_potential(field, coord_sys):
274
+ """
275
+ Returns the scalar potential function of a field in a given
276
+ coordinate system (without the added integration constant).
277
+
278
+ Parameters
279
+ ==========
280
+
281
+ field : Vector
282
+ The vector field whose scalar potential function is to be
283
+ calculated
284
+
285
+ coord_sys : CoordSys3D
286
+ The coordinate system to do the calculation in
287
+
288
+ Examples
289
+ ========
290
+
291
+ >>> from sympy.vector import CoordSys3D
292
+ >>> from sympy.vector import scalar_potential, gradient
293
+ >>> R = CoordSys3D('R')
294
+ >>> scalar_potential(R.k, R) == R.z
295
+ True
296
+ >>> scalar_field = 2*R.x**2*R.y*R.z
297
+ >>> grad_field = gradient(scalar_field)
298
+ >>> scalar_potential(grad_field, R)
299
+ 2*R.x**2*R.y*R.z
300
+
301
+ """
302
+
303
+ # Check whether field is conservative
304
+ if not is_conservative(field):
305
+ raise ValueError("Field is not conservative")
306
+ if field == Vector.zero:
307
+ return S.Zero
308
+ # Express the field exntirely in coord_sys
309
+ # Substitute coordinate variables also
310
+ if not isinstance(coord_sys, CoordSys3D):
311
+ raise TypeError("coord_sys must be a CoordSys3D")
312
+ field = express(field, coord_sys, variables=True)
313
+ dimensions = coord_sys.base_vectors()
314
+ scalars = coord_sys.base_scalars()
315
+ # Calculate scalar potential function
316
+ temp_function = integrate(field.dot(dimensions[0]), scalars[0])
317
+ for i, dim in enumerate(dimensions[1:]):
318
+ partial_diff = diff(temp_function, scalars[i + 1])
319
+ partial_diff = field.dot(dim) - partial_diff
320
+ temp_function += integrate(partial_diff, scalars[i + 1])
321
+ return temp_function
322
+
323
+
324
+ def scalar_potential_difference(field, coord_sys, point1, point2):
325
+ """
326
+ Returns the scalar potential difference between two points in a
327
+ certain coordinate system, wrt a given field.
328
+
329
+ If a scalar field is provided, its values at the two points are
330
+ considered. If a conservative vector field is provided, the values
331
+ of its scalar potential function at the two points are used.
332
+
333
+ Returns (potential at point2) - (potential at point1)
334
+
335
+ The position vectors of the two Points are calculated wrt the
336
+ origin of the coordinate system provided.
337
+
338
+ Parameters
339
+ ==========
340
+
341
+ field : Vector/Expr
342
+ The field to calculate wrt
343
+
344
+ coord_sys : CoordSys3D
345
+ The coordinate system to do the calculations in
346
+
347
+ point1 : Point
348
+ The initial Point in given coordinate system
349
+
350
+ position2 : Point
351
+ The second Point in the given coordinate system
352
+
353
+ Examples
354
+ ========
355
+
356
+ >>> from sympy.vector import CoordSys3D
357
+ >>> from sympy.vector import scalar_potential_difference
358
+ >>> R = CoordSys3D('R')
359
+ >>> P = R.origin.locate_new('P', R.x*R.i + R.y*R.j + R.z*R.k)
360
+ >>> vectfield = 4*R.x*R.y*R.i + 2*R.x**2*R.j
361
+ >>> scalar_potential_difference(vectfield, R, R.origin, P)
362
+ 2*R.x**2*R.y
363
+ >>> Q = R.origin.locate_new('O', 3*R.i + R.j + 2*R.k)
364
+ >>> scalar_potential_difference(vectfield, R, P, Q)
365
+ -2*R.x**2*R.y + 18
366
+
367
+ """
368
+
369
+ if not isinstance(coord_sys, CoordSys3D):
370
+ raise TypeError("coord_sys must be a CoordSys3D")
371
+ if isinstance(field, Vector):
372
+ # Get the scalar potential function
373
+ scalar_fn = scalar_potential(field, coord_sys)
374
+ else:
375
+ # Field is a scalar
376
+ scalar_fn = field
377
+ # Express positions in required coordinate system
378
+ origin = coord_sys.origin
379
+ position1 = express(point1.position_wrt(origin), coord_sys,
380
+ variables=True)
381
+ position2 = express(point2.position_wrt(origin), coord_sys,
382
+ variables=True)
383
+ # Get the two positions as substitution dicts for coordinate variables
384
+ subs_dict1 = {}
385
+ subs_dict2 = {}
386
+ scalars = coord_sys.base_scalars()
387
+ for i, x in enumerate(coord_sys.base_vectors()):
388
+ subs_dict1[scalars[i]] = x.dot(position1)
389
+ subs_dict2[scalars[i]] = x.dot(position2)
390
+ return scalar_fn.subs(subs_dict2) - scalar_fn.subs(subs_dict1)
391
+
392
+
393
+ def matrix_to_vector(matrix, system):
394
+ """
395
+ Converts a vector in matrix form to a Vector instance.
396
+
397
+ It is assumed that the elements of the Matrix represent the
398
+ measure numbers of the components of the vector along basis
399
+ vectors of 'system'.
400
+
401
+ Parameters
402
+ ==========
403
+
404
+ matrix : SymPy Matrix, Dimensions: (3, 1)
405
+ The matrix to be converted to a vector
406
+
407
+ system : CoordSys3D
408
+ The coordinate system the vector is to be defined in
409
+
410
+ Examples
411
+ ========
412
+
413
+ >>> from sympy import ImmutableMatrix as Matrix
414
+ >>> m = Matrix([1, 2, 3])
415
+ >>> from sympy.vector import CoordSys3D, matrix_to_vector
416
+ >>> C = CoordSys3D('C')
417
+ >>> v = matrix_to_vector(m, C)
418
+ >>> v
419
+ C.i + 2*C.j + 3*C.k
420
+ >>> v.to_matrix(C) == m
421
+ True
422
+
423
+ """
424
+
425
+ outvec = Vector.zero
426
+ vects = system.base_vectors()
427
+ for i, x in enumerate(matrix):
428
+ outvec += x * vects[i]
429
+ return outvec
430
+
431
+
432
+ def _path(from_object, to_object):
433
+ """
434
+ Calculates the 'path' of objects starting from 'from_object'
435
+ to 'to_object', along with the index of the first common
436
+ ancestor in the tree.
437
+
438
+ Returns (index, list) tuple.
439
+ """
440
+
441
+ if from_object._root != to_object._root:
442
+ raise ValueError("No connecting path found between " +
443
+ str(from_object) + " and " + str(to_object))
444
+
445
+ other_path = []
446
+ obj = to_object
447
+ while obj._parent is not None:
448
+ other_path.append(obj)
449
+ obj = obj._parent
450
+ other_path.append(obj)
451
+ object_set = set(other_path)
452
+ from_path = []
453
+ obj = from_object
454
+ while obj not in object_set:
455
+ from_path.append(obj)
456
+ obj = obj._parent
457
+ index = len(from_path)
458
+ i = other_path.index(obj)
459
+ while i >= 0:
460
+ from_path.append(other_path[i])
461
+ i -= 1
462
+ return index, from_path
463
+
464
+
465
+ def orthogonalize(*vlist, orthonormal=False):
466
+ """
467
+ Takes a sequence of independent vectors and orthogonalizes them
468
+ using the Gram - Schmidt process. Returns a list of
469
+ orthogonal or orthonormal vectors.
470
+
471
+ Parameters
472
+ ==========
473
+
474
+ vlist : sequence of independent vectors to be made orthogonal.
475
+
476
+ orthonormal : Optional parameter
477
+ Set to True if the vectors returned should be
478
+ orthonormal.
479
+ Default: False
480
+
481
+ Examples
482
+ ========
483
+
484
+ >>> from sympy.vector.coordsysrect import CoordSys3D
485
+ >>> from sympy.vector.functions import orthogonalize
486
+ >>> C = CoordSys3D('C')
487
+ >>> i, j, k = C.base_vectors()
488
+ >>> v1 = i + 2*j
489
+ >>> v2 = 2*i + 3*j
490
+ >>> orthogonalize(v1, v2)
491
+ [C.i + 2*C.j, 2/5*C.i + (-1/5)*C.j]
492
+
493
+ References
494
+ ==========
495
+
496
+ .. [1] https://en.wikipedia.org/wiki/Gram-Schmidt_process
497
+
498
+ """
499
+
500
+ if not all(isinstance(vec, Vector) for vec in vlist):
501
+ raise TypeError('Each element must be of Type Vector')
502
+
503
+ ortho_vlist = []
504
+ for i, term in enumerate(vlist):
505
+ for j in range(i):
506
+ term -= ortho_vlist[j].projection(vlist[i])
507
+ # TODO : The following line introduces a performance issue
508
+ # and needs to be changed once a good solution for issue #10279 is
509
+ # found.
510
+ if simplify(term).equals(Vector.zero):
511
+ raise ValueError("Vector set not linearly independent")
512
+ ortho_vlist.append(term)
513
+
514
+ if orthonormal:
515
+ ortho_vlist = [vec.normalize() for vec in ortho_vlist]
516
+
517
+ return ortho_vlist