-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultigradedRing.py
More file actions
28 lines (24 loc) · 927 Bytes
/
multigradedRing.py
File metadata and controls
28 lines (24 loc) · 927 Bytes
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
"""
Class representing a multigraded polynomial ring in Macaulay2
"""
from numpy import *
class multigradedRing(object):
def __init__ (self, variables, grading_matrix):
# Todo: Check that the dimensions match
if not grading_matrix.ndim == 2:
print "Grading should be given by a matrix"
exit(1)
self.variables = variables
self.matrix = grading_matrix
def M2Ring (self, ringname):
""" Outputs the M2 string representing the ring """
# Print M2 Matrix:
matstr = "matrix{"
dims = self.matrix.shape
rows = [self.matrix[i] for i in range (dims[0])]
matstr += ",".join([('{'+",".join([str(i) for i in row])+"}") for row in rows])
matstr += '}'
ringstr = ringname + " = QQ["
ringstr += ",".join(self.variables)
ringstr += ", Degrees => (entries " + matstr + " )]"
return ringstr