-
Notifications
You must be signed in to change notification settings - Fork 0
/
graded_module_test.py
executable file
·167 lines (138 loc) · 4.84 KB
/
graded_module_test.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
#!/usr/local/bin/sage
import unittest
from graded_module import wieghted_max_degree
from graded_module import wieghted_min_degree
from graded_module import monomials_of_order
from graded_module import GradedModule
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.sets.set import Set
class TestWeightedMaxDegree(unittest.TestCase):
def setUp(self):
self.poly_ring = PolynomialRing(QQ,"x",3);
self.x = self.poly_ring.gens()[0];
self.y = self.poly_ring.gens()[1];
self.z = self.poly_ring.gens()[2];
def test_zero(self):
self.assertEqual(wieghted_max_degree(self.poly_ring.zero(),[1,1,1]),0);
def test_homogeneous(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_max_degree(f,[1,1,1]),4);
def test_non_homogeneous(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_max_degree(f,[2,1,2]),8);
def test_negative_wieghts(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_max_degree(f,[-1,-1,1]),2);
class TestWeightedMinDegree(unittest.TestCase):
def setUp(self):
self.poly_ring = PolynomialRing(QQ,"x",3);
self.x = self.poly_ring.gens()[0];
self.y = self.poly_ring.gens()[1];
self.z = self.poly_ring.gens()[2];
def test_zero(self):
self.assertEqual(wieghted_min_degree(self.poly_ring.zero(),[1,1,1]),0);
def test_homogeneous(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_min_degree(f,[1,1,1]),2);
def test_non_homogeneous(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_min_degree(f,[2,1,2]),4);
def test_negative_wieghts(self):
x = self.x;
y = self.y;
z = self.z;
f = x**4 + 4*y*z**3 - z**2;
self.assertEqual(wieghted_min_degree(f,[-1,-1,1]),-4);
class TestMonomialsOfOrder(unittest.TestCase):
def setUp(self):
self.poly_ring = PolynomialRing(QQ,"x",3);
self.x = self.poly_ring.gens()[0];
self.y = self.poly_ring.gens()[1];
self.z = self.poly_ring.gens()[2];
def test_zero(self):
mons = [mon for mon in monomials_of_order(0,self.poly_ring,[1,1,1])]
self.assertEqual(mons,[self.poly_ring.one()])
def test_homogeneous_3(self):
x = self.x;
y = self.y;
z = self.z;
true_mons = Set([x**3,y**3,z**3,x**2*y,x**2*z,y**2*x,y**2*z,z**2*x,z**2*y,x*y*z])
mons = [mon for mon in monomials_of_order(3,self.poly_ring,[1,1,1])]
self.assertEqual(true_mons,Set(mons))
def test_non_homogeneous_4(self):
x = self.x;
y = self.y;
z = self.z;
true_mons = Set([x**4,x**2*y,x*z,y**2])
mons = [mon for mon in monomials_of_order(4,self.poly_ring,[1,2,3])]
self.assertEqual(true_mons,Set(mons))
class TestGradedModule(unittest.TestCase):
def setUp(self):
self.poly_ring = PolynomialRing(QQ,"x",3);
self.x = self.poly_ring.gens()[0];
self.y = self.poly_ring.gens()[1];
self.z = self.poly_ring.gens()[2];
def test_monomial_basis_zero(self):
one = self.poly_ring.one()
zero = self.poly_ring.zero()
gm = GradedModule([[one,one,one,one]],[0,1,2,3],[1,2,3])
self.assertEqual(gm.monomial_basis(0),[(one,zero,zero,zero)])
def test_monomial_basis(self):
x = self.x
y = self.y
one = self.poly_ring.one()
zero = self.poly_ring.zero()
gm = GradedModule([[one,one]],[0,1],[1,2,3])
true_basis = [(x**2,zero),(y,zero),(zero,x)]
self.assertEqual(Set(gm.monomial_basis(2)),Set(true_basis))
def test_homogeneous_parts_A(self):
one = self.poly_ring.one()
zero = self.poly_ring.zero()
gm = GradedModule([[one,one]],[0,1],[1,2,3])
parts = gm.get_homogeneous_parts([one,one])
parts_true = { 0:[one,zero] , 1:[zero,one] }
self.assertEqual(parts,parts_true)
def test_homogeneous_parts_B(self):
x = self.x
y = self.y
z = self.z
one = self.poly_ring.one()
zero = self.poly_ring.zero()
gm = GradedModule([[one,one]],[0,1],[1,2,3])
parts = gm.get_homogeneous_parts([x*y,x**3+z*y])
self.assertEqual(parts,{3:[x*y,zero],4:[zero,x**3],6:[zero,z*y]})
def test_homogeneous_part_basisA(self):
x = self.x
y = self.y
z = self.z
one = self.poly_ring.one()
gm = GradedModule([[z,one,x**2 + y]],[0,1,2],[1,2,3])
basis = gm.homogeneous_part_basis(6);
self.assertEqual(len(basis),10)
def test_homogeneous_part_basisB(self):
#From bug found with ncd
x = self.x
y = self.y
z = self.z
zero = self.poly_ring.zero()
gm = GradedModule([[zero, x*z, x*y], [zero, -x*z, zero], [y*z, zero, zero]],[1, 1, 1],[1, 1, 1])
basis = gm.homogeneous_part_basis(3);
self.assertEqual(len(basis),3)
if __name__=="__main__":
unittest.main()