-
Notifications
You must be signed in to change notification settings - Fork 0
/
involution_gui_methods.py
79 lines (70 loc) · 2.54 KB
/
involution_gui_methods.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
r"""
This file contains the methods used in the Bijective Matrix Algebra package.
It generates the methods needed in order to generate one's own involutions
for any matrix which reduces to I and is equivalent to a singleton along
each entry in its diagonal.
AUTHORS:
- Steven Tartakovsky (2012): initial version
"""
#*****************************************************************************
# Copyright (C) 2012 Steven Tartakovsky <[email protected]>,
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# This code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# The full text of the GPL is available at:
#
# http://www.gnu.org/licenses/
#*****************************************************************************
from sage.bijectivematrixalgebra.matrix_methods import *
from sage.bijectivematrixalgebra.reduction_methods import *
from sage.sets.finite_set_maps import FiniteSetMaps
from sage.bijectivematrixalgebra.reduction_maps_dicts import ReductionMapsDict
from sage.bijectivematrixalgebra.reduction_maps import ReductionMaps
def tab_list(y, headers = None):
'''
Converts a list into an html table with borders.
'''
s = '<table border = 1>'
if headers:
for q in headers:
s = s + '<th>' + str(q) + '</th>'
for x in y:
s = s + '<tr>'
for q in x:
s = s + '<td>' + str(q) + '</td>'
s = s + '</tr>'
s = s + '</table>'
return s
def total_maps(mat):
nrows = mat.nrows()
ncols = mat.ncols()
total = 0
for i in range(nrows):
for j in range(ncols):
total += mat[i,j].get_size()
return total
def reduction_identity(mat,involution_dict, st = None):
r"""
When a matrix reduces to the identity, this returns
a ReductionMapDict of from a matrix to I.
"""
dim = mat.nrows()
fs = involution_dict
f0s = dict()
I = identity_matrix(dim)
for i in range(dim):
for j in range(dim):
if i==j:
f0s[i,j] = FiniteSetMaps(mat[i,j],I[i,j]).from_dict({mat[i,j].get_set().pop():CombinatorialObject(1,1)})
else:
f0s[i,j] = FiniteSetMaps(set(),set()).from_dict({})
d = dict()
for i in range(dim):
for j in range(dim):
d[i,j] = ReductionMaps(mat[i,j],I[i,j],fs[i,j],f0s[i,j])
return ReductionMapsDict(d,st)