-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.py
101 lines (80 loc) · 3.64 KB
/
misc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import itertools
from sympy.combinatorics import Permutation
from sympy import symbols, sympify #symbols, simplify, sympify
import os
import json
class _IteratorPairings:
def __init__(self, n):
self.n = n
self.it = self.iterate_pairs(list(range(n)))
def __iter__(self):
return self
def __next__(self):
x = next(self.it)
return x
def iterate_pairs(self, ns):
if ns==[]:
yield []
return
ns_shorter = ns[1:]
for i, n in enumerate(ns_shorter):
for pairs in self.iterate_pairs(ns_shorter[:i] + ns_shorter[i+1:]):
yield [(ns[0], n)] + pairs
def _generate_iterator4reconnections(size, is_group, is_complex):
if is_complex:
if is_group:
it = (([(i, j) for i,j in enumerate(c)], Permutation(c, size=size)) for c in itertools.permutations(range(size)))
else:
it = (([(i, j) for i,j in enumerate(c)], None) for c in itertools.permutations(range(size)))
else:
if is_group:
it =((c, Permutation(c, size=size)) for c in _IteratorPairings(size*2))
else:
it =((c, None) for c in _IteratorPairings(size*2))
# returning the iterator.
return it
class _WeingartenFormulas:
def functions(is_complex, size):
n = symbols('n')
if is_complex:
with open(os.path.join('wfu_json', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
else:
with open(os.path.join('wfo_json', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
return {sympify(young_diagram_str): sympify(wf_str) for young_diagram_str, wf_str in wfs.items()}
def nums(is_complex, size, dim):
n = symbols('n')
if is_complex:
with open(os.path.join('wfu_json', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
else:
with open(os.path.join('wfo_json', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
return {sympify(young_diagram_str): sympify(wf_str).subs(n, dim) for young_diagram_str, wf_str in wfs.items()}
def nums_low_dims(is_complex, size, dim):
n = symbols('n')
if is_complex:
with open(os.path.join('wfu_json_nums', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
else:
with open(os.path.join('wfo_json_nums', f'{size:02d}.json'), 'r') as file:
wfs= json.load(file)
return {sympify(young_diagram_str): sympify(wf_str) for young_diagram_str, wf_str in wfs[str(dim)].items()}
class _WeingartenNote:
def __init__(self,):
self._note_dict = {'formula':{}, 'nums':{}}
self.n = symbols('n')
def get(self, is_symbolic, is_complex, size, dim, yd):
if is_symbolic:
if (is_complex, size) not in self._note_dict['formula']:
self._note_dict['formula'][(is_complex, size)] = _WeingartenFormulas.functions(is_complex, size)
# print(self._note_dict['formula'][(is_complex, size)])
return self._note_dict['formula'][(is_complex, size)][yd].subs(self.n, dim)
else:
if (is_complex, size, dim) not in self._note_dict['nums']:
if size <= dim:
self._note_dict['nums'][(is_complex, size, dim)] = _WeingartenFormulas.nums(is_complex, size, dim)
else:
self._note_dict['nums'][(is_complex, size, dim)] = _WeingartenFormulas.nums_low_dims(is_complex, size, dim)
return self._note_dict['nums'][(is_complex, size, dim)][yd]