-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_marin_data.py
executable file
·308 lines (246 loc) · 9.4 KB
/
create_marin_data.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/python
# -*- coding: utf-8 -*-
r"""
Python script to create the source for the ``database_cubic_hecke`` package
in ``py`` format in the given path. This utility should be used to switch
to a new version of the data files if the original files have changed.
.. NOTE::
This function needs `SymPy <https://de.wikipedia.org/wiki/SymPy>`__
INPUT:
- ``path`` -- name of path where to store the generated files
(if not provided, the the subdirectory ``database_cubic_hecke``)
under the current working directory is used)
EXAMPLES::
python create_marin_data.py
python create_marin_data.py ~
"""
##############################################################################
# Copyright (C) 2021 Sebastian Oehms <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
##############################################################################
import sys
from os import environ
from os.path import join, exists
from sympy import var, eye
from sympy import __version__ as sympy_version
from database_cubic_hecke import FileNames, marin_url
from database_cubic_hecke import __version__ as this_version
cmdline_args = sys.argv[1:]
path = None
if len(cmdline_args) > 0:
path = cmdline_args[0]
if not exists(path):
raise ValueError("the path '%s' does not exist" % path)
if not path:
pwd = environ['PWD']
path = join(pwd, 'database_cubic_hecke')
if not exists(path):
path = pwd
# -----------------------------------------------------------------------------
# Templates
# -----------------------------------------------------------------------------
py_header_text = r"""# ------------------------------------------------------------
# This file was generated using create_marin_data.py
#
# on : Version %s
# under : SymPy %s
# using : Python %s
# ------------------------------------------------------------
"""
function_name = '_read_%s'
template=r"""# generated data function for cubic Hecke algebra
def %s(%s):
%s
data = %s
return data
"""
rem=r"""
This code has been generated by ``create_marin_data.py`` (from
the `database_cubic_hecke repository <https://github.com/soehms/database_cubic_hecke>`__),
please don't edit.
"""
doc=r"""{}
Return precomputed basis of Ivan Marin
%s
OUTPUT:
A list of lists where each of it represents a braid pre image
in Tietze form.
EXAMPLES::
>>> from database_cubic_hecke import %s
>>> res = %s()
>>> len(res)
648
{}
""".format('r"""', '"""')
docrep=r"""{}
Return precomputed representation matrices of Ivan Marin
%s
INPUT:
``%s`` -- values for the variables of the representation matrices
OUTPUT:
A triple ``dim_list, repr_list, repr_list_inv`` where each member
is a list indexed by the number of the representation.
``dim_list`` is a list of integers representing the dimension of
the corresponding representation
``repr_list`` is a triple of dictionaries each describing the
representation matrix of the corresponding generator of the
cubic Hecke algebra.
``repr_list_inv`` is a triple of dictionaries each describing the
inverse of the correspondig matrix of ``repr_list``.
EXAMPLES::
>>> from database_cubic_hecke import %s
>>> dim_list, repr_list, repr_list_inv = %s(%s)
>>> dim_list
%s
>>> len(repr_list)
%s
>>> g1, g2, g3 = repr_list[0]
>>> list(g1.items())[0]
%s
{}
""".format('r"""', '"""')
# -----------------------------------------------------------------------------
# Auxillary function to generate the function code
# -----------------------------------------------------------------------------
def _write_data_function(filename, data):
r"""
Generate code for functions to access the data.
"""
from textwrap import fill
def fl(s):
return fill(str(s), subsequent_indent=' ')
func_name = function_name %filename.cache()
if filename == FileNames.basis:
var = ''
elif filename == FileNames.irred_split:
var = 'a, b, c, j'
varexp = '3, 5, 7, 11'
res1 = '[1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 8, 8, 8, 9, 9]'
res2 = '24'
res3 = '((0, 0), 3)'
else:
var = 'u, v, w'
varexp = '3, 5, 7'
res1 = '[648]'
res2 = '1'
res3 = '((0, 27), -5)'
if var:
docstr = docrep %(rem, var, func_name, func_name, varexp, res1, res2, res3)
func = template %(func_name, var, docstr, fl(str(data)))
else:
docstr = doc %(rem, func_name, func_name)
func = template %(func_name, '', docstr, fl(str(data)))
header = py_header_text %(this_version.value, sympy_version, sys.version.split(' ')[0])
import_filen = join(path, filename.py())
with open(import_filen, 'w') as f:
f.write(header)
f.write(func)
# -----------------------------------------------------------------------------
# Auxillary function to load the data from Ivan Marins web page
# -----------------------------------------------------------------------------
def _load_data(filename):
r"""
Download a data file in maple syntax.
"""
# import directly from the internet page
from six.moves.urllib.request import urlopen
try:
from urllib.error import HTTPError, URLError
except ImportError:
from urllib2 import HTTPError
import ssl
context = ssl._create_unverified_context()
try:
download = join(marin_url, filename)
download_data = urlopen(download, context=context).read().decode()
preparsed_data = download_data.replace(':=', '=').replace(';', '').replace('^', '**')
return preparsed_data
except (HTTPError, URLError):
raise IOError('Data import file %s not found! Internet connection needed!' %(filename))
return None
# -----------------------------------------------------------------------------
# Functions to create the Python files
# -----------------------------------------------------------------------------
def create_marin_split_repr():
r"""
Create the data base for split irreducible representations of the
cubic Hecke algebra according to the original data from Iwan Marin's
home page.
"""
# ------------------------------------------------------
# Ivan Marin's data file uses a, b, c for the variables
# corresponding to the eigenvalues of the cubic equation.
# ------------------------------------------------------
fname = FileNames.irred_split
preparsed_data = _load_data(fname.maple())
global a, b, c, j # set in exec
a, b, c, j = var('a, b, c, j')
exec(preparsed_data, globals())
u, v, w = (-a-b-c, a*b+b*c+a*c, -a*b*c)
def invert(matr, dim):
"""
Return inverse matrix for generators
"""
matri = v/w*eye(dim)
matri += u/w*matr
matri += 1/w*matr**2
matri.simplify()
return -matri
# ----------------------------------------------------------------------
# Restoring the split irreducibles from Iwan Marin's homepage
# ----------------------------------------------------------------------
from sympy import Matrix
anz_reps = len(reps)
dim_list = []
repr_list = []
repr_list_inv = []
for i in range(anz_reps):
repi = reps[i]
if len(repi) != 3:
raise RuntimeError( 'Error at position %d: three generators expected, got: %d' %( i, len(repi)))
mt = []
mtI = []
for j in range(3):
mat = Matrix(repi[j])
d, e = mat.shape
matI = invert(mat, d)
mt.append(mat.todok())
mtI.append(matI.todok())
dim_list.append(d)
repr_list.append( mt )
repr_list_inv.append( mtI )
_write_data_function(fname, (dim_list, repr_list, repr_list_inv))
def create_static_db_marin_regular(right=False):
r"""
Create the data base for regular representations of the cubic
Hecke algebra according to the original data from Iwan Marin's home page.
"""
if right == False:
fname = FileNames.regular_left
else:
fname = FileNames.regular_right
preparsed_data = _load_data(fname.maple())
global baseH4, Matrix, u, v, w, mm1, mm2, mm3, mm1I, mm2I, mm3I, reps # set in exec
u, v, w = var('u, v, w')
dim_list = [None]
from sympy import Matrix as sMatrix
def Matrix(d, e, data):
dim_list[0]=d
return sMatrix(data)
exec(preparsed_data, globals())
repr_list = [[mm1.todok(), mm2.todok(), mm3.todok()]]
repr_list_inv = [[mm1I.todok(), mm2I.todok(), mm3I.todok()]]
if not right:
_write_data_function(FileNames.basis, baseH4)
_write_data_function(fname, (dim_list, repr_list, repr_list_inv))
# -------------------------------------------------------------------------------------
# Create all files
# -------------------------------------------------------------------------------------
create_marin_split_repr()
create_static_db_marin_regular()
create_static_db_marin_regular(right=True)