1
1
import numpy as np
2
- import torch
2
+ from numpy import random
3
3
import math
4
4
import itertools as it
5
5
6
6
from utils import *
7
7
8
+
9
+ """
10
+ Abstract class representing a finite group.
11
+ """
8
12
class abstr_group ():
9
13
def __init__ (self , order , cayley_table , irrep_dims ):
10
14
self .order = order
11
15
self .cayley_table = cayley_table
12
16
self .irrep_dims = irrep_dims
13
17
14
18
def act (self , x ):
15
- g = torch .randint (low = 0 , high = self .order , size = ( 1 ,)). item ( )
19
+ g = random .randint (low = 0 , high = self .order )
16
20
return x [self .cayley_table [g ]]
17
21
18
22
def check_dims (self ):
19
- irrep_dims = torch . tensor (self .irrep_dims )
20
- assert (irrep_dims ** 2 ).sum (). item () == self .order
23
+ irrep_dims = np . array (self .irrep_dims )
24
+ assert (irrep_dims ** 2 ).sum () == self .order
21
25
22
26
23
-
27
+ """
28
+ Cyclic groups
29
+ """
24
30
class cyclic (abstr_group ):
25
31
def __init__ (self , N ):
26
32
self .order = N
27
33
self .irrep_dims = [1 ]* N
28
34
29
- self .cayley_table = torch .zeros (N , N )
35
+ self .cayley_table = np .zeros (( N , N ) )
30
36
for i in range (N ):
31
- self .cayley_table [i ] = torch .roll (torch .arange (0 , N ), - i )
32
- self .cayley_table = self .cayley_table .long ( )
37
+ self .cayley_table [i ] = np .roll (np .arange (0 , N ), - i )
38
+ self .cayley_table = self .cayley_table .astype ( int )
33
39
34
40
35
41
36
-
42
+ """
43
+ Dihedral groups
44
+ """
37
45
class dihedral (abstr_group ):
38
46
def __init__ (self , N ):
39
47
self .order = 2 * N
@@ -44,19 +52,19 @@ def __init__(self, N):
44
52
self .irrep_dims = [1 ]* 2 + [2 ]* int ((N - 1 ) / 2 )
45
53
46
54
47
- reflection = torch . Tensor ([0 ] + [N - i for i in range (1 , N )]).long ( )
48
- self .group_elems = torch .zeros (2 * N , N )
55
+ reflection = np . array ([0 ] + [N - i for i in range (1 , N )]).astype ( int )
56
+ self .group_elems = np .zeros (( 2 * N , N ) )
49
57
for i in range (N ):
50
- cycle = torch .roll (torch .arange (0 , N ), i )
58
+ cycle = np .roll (np .arange (0 , N ), i )
51
59
self .group_elems [i ] = cycle
52
60
self .group_elems [N + i ] = cycle [reflection ]
53
- self .group_elems = self .group_elems .long ( )
61
+ self .group_elems = self .group_elems .astype ( int )
54
62
55
- self .cayley_table = torch .zeros (2 * N , 2 * N )
63
+ self .cayley_table = np .zeros (( 2 * N , 2 * N ) )
56
64
for i in range (2 * N ):
57
65
for j in range (2 * N ):
58
66
comp = self .group_elems [i ][self .group_elems [j ]]
59
- self .cayley_table [i , j ] = torch .argmin ( ((comp . unsqueeze ( 0 ) - self .group_elems )** 2 ).sum (- 1 ) )
67
+ self .cayley_table [i , j ] = np .argmin ( ((np . expand_dims ( comp , 0 ) - self .group_elems )** 2 ).sum (- 1 ) )
60
68
61
69
if N == 2 :
62
70
C = [
@@ -65,48 +73,54 @@ def __init__(self, N):
65
73
[2 , 3 , 0 , 1 ],
66
74
[3 , 2 , 1 , 0 ]
67
75
]
68
- self .cayley_table = torch .Tensor (C )
69
-
70
- self .cayley_table = self .cayley_table .long ()
76
+ self .cayley_table = np .array (C )
71
77
78
+ self .cayley_table = self .cayley_table .astype (int )
72
79
73
80
81
+ """
82
+ Symmetric groups
83
+ """
74
84
class symmetric (abstr_group ):
75
85
def __init__ (self , N ):
76
86
self .order = math .factorial (N )
77
87
78
88
self .irrep_dims = [hook_length (P , N ) for P in list (gen_partitions (N ))]
79
89
80
- self .group_elems = torch .zeros (self .order , N )
90
+ self .group_elems = np .zeros (( self .order , N ) )
81
91
for i , perm in enumerate (it .permutations (range (N ))):
82
- self .group_elems [i ] = torch . Tensor (list (perm ))
83
- self .group_elems = self .group_elems .long ( )
92
+ self .group_elems [i ] = np . array (list (perm ))
93
+ self .group_elems = self .group_elems .astype ( int )
84
94
85
- self .cayley_table = torch .zeros (self .order , self .order )
95
+ self .cayley_table = np .zeros (( self .order , self .order ) )
86
96
for i in range (self .order ):
87
97
for j in range (self .order ):
88
98
comp = self .group_elems [i ][self .group_elems [j ]]
89
- self .cayley_table [i , j ] = torch .argmin ( ((comp .unsqueeze (0 ) - self .group_elems )** 2 ).sum (- 1 ) )
99
+ self .cayley_table [i , j ] = np .argmin ( ((np .expand_dims (comp , 0 ) - self .group_elems )** 2 ).sum (- 1 ) )
100
+
101
+ self .cayley_table = self .cayley_table .astype (int )
90
102
91
- self .cayley_table = self .cayley_table .long ()
92
103
93
104
105
+ """
106
+ Direct product of groups
107
+ """
94
108
def direct_product (group_1 , group_2 ):
95
109
order_1 = group_1 .order
96
110
order_2 = group_2 .order
97
111
order_res = order_1 * order_2
98
112
99
113
cayley_1 = group_1 .cayley_table
100
114
cayley_2 = group_2 .cayley_table
101
- cayley_res = torch .zeros (order_res , order_res )
115
+ cayley_res = np .zeros (( order_res , order_res ) )
102
116
for i_1 in range (order_1 ):
103
117
for i_2 in range (order_2 ):
104
118
for j_1 in range (order_1 ):
105
119
for j_2 in range (order_2 ):
106
120
g_1 = cayley_1 [i_1 , j_1 ]
107
121
g_2 = cayley_2 [i_2 , j_2 ]
108
122
cayley_res [i_1 * order_2 + i_2 , j_1 * order_2 + j_2 ] = g_1 * order_2 + g_2
109
- cayley_res = cayley_res .long ( )
123
+ cayley_res = cayley_res .astype ( int )
110
124
111
125
irrep_dims_1 = group_1 .irrep_dims
112
126
irrep_dim_2 = group_2 .irrep_dims
@@ -115,4 +129,7 @@ def direct_product(group_1, group_2):
115
129
for d_2 in irrep_dim_2 :
116
130
irrep_dims_res .append (d_1 * d_2 )
117
131
118
- return abstr_group (order_res , cayley_res , irrep_dims_res )
132
+ return abstr_group (order_res , cayley_res , irrep_dims_res )
133
+
134
+
135
+
0 commit comments