-
Notifications
You must be signed in to change notification settings - Fork 1
/
poly_systems.sage
297 lines (267 loc) · 12.9 KB
/
poly_systems.sage
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
class PolynomialSystem():
def __init__(self, field_size, var_name='x', mon_order="degrevlex"):
self.field = GF(field_size)
self.var_name = var_name
self.mon_order = mon_order
def super_simple(self):
ring = PolynomialRing(self.field, self.var_name, 2, order=self.mon_order)
x = ring.gens()
polys = [x[0] + x[1],
x[0]*x[1]]
return polys
def perry_intro(self):
ring = PolynomialRing(self.field, self.var_name, 2, order=self.mon_order)
x = ring.gens()
polys = [x[0]^2 - 1,
x[0] - x[1],
x[0]*x[1] - 1,]
return polys
def jfs_fglm(self): # Ferdinand's FGLM example
ring = PolynomialRing(self.field, self.var_name, 2, order=self.mon_order)
x = ring.gens()
polys = [x[0]^3 - x[0]^2 - x[1]^6 + x[1]^5,
x[0]^2*x[1] + x[1]^7 - x[1]^6,
x[0]*x[1]^4 + x[1]^6,
x[1]^8]
return polys
def sys_a(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[0] - x[2],
x[0]^2 + x[2]^2 - x[1],
x[0]^2 + x[1]^2 + x[2]^2 - 1]
return polys
def sys_b(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[0]^5 + x[1]^4 + x[2]^3 - 1,
x[0]^3 + x[1]^2 + x[2]^2 - 1]
return polys
def sys_c(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[2] + 3*x[1],
x[1] + x[2] + 2,
x[0]*x[1] + x[1]^2]
return polys
def iva_ex(self): # Has one syzygy vector with signature (x1*x3, 2)
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1] - x[1]*x[3],
x[0]^2 - x[2]*x[3],
x[2]^3 - x[3]^3]
return polys
def iva_ex_redundant(self):
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1] - x[1]*x[3],
x[0]^2 - x[2]*x[3],
x[1]*x[2]^3 - x[1]*x[3]^3,
x[2]*x[2]^3 - x[2]*x[3]^3,
x[2]*x[2]^3 - x[2]*x[3]^3]
return polys
def eder_faugere_ex4_3(self):
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1]*x[2] - x[2]^2*x[3],
x[0]^2*x[1] - x[1]^3,
x[1]^3 - x[2]*x[3]^2 - x[3]^3]
return polys
def gb_already(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [x[0]^7,
x[1]^7,
x[2]^7,
# x[3]^7,
# x[4]^7,
# x[5]^7,
]
return polys
def dreg_voo_diff(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[0]^4*x[1]*x[2] + x[0]^2,
x[1]^4*x[2]*x[0] + x[1]^2 + 1,
x[2]^4*x[0]*x[1] + x[2]^2]
return polys
def dreg_voo_diff_stacked(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [x[0]^2*x[1]*x[2] + x[0],
x[1]^2*x[2]*x[0] + x[1] + 1,
x[2]^2*x[0]*x[1] + x[2],
x[3]^2*x[4]*x[5] + x[3],
x[4]^2*x[5]*x[3] + x[4] + 1,
x[5]^2*x[3]*x[4] + x[5]]
return polys
def dreg_voo_diff_stacked_linked(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [x[0]^2*x[1]*x[2] + x[0],
x[1]^2*x[2]*x[0] + x[1] + 1,
x[2]^2*x[0]*x[1] + x[2],
x[3]^2*x[4]*x[5] + x[3],
x[4]^2*x[5]*x[3] + x[4] + 1,
x[5]^4 + x[0]^4,]
return polys
def dreg_voo_diff_2(self, degree=10, num_vars=3, linear_transform=None):
ring = PolynomialRing(self.field, self.var_name, num_vars, order=self.mon_order)
x = ring.gens()
polys = []
for i in range(num_vars):
exp = [1] * num_vars
exp[i] = degree
polys += [ring.monomial(*exp) + 1]
polys[-1] -= 1
if linear_transform:
y = linear_transform * vector(x)
polys = [p(*y) for p in polys]
return polys
def dreg_voo_diff_3(self, degree=10, num_vars=3, linear_transform=None):
ring = PolynomialRing(self.field, self.var_name, num_vars, order=self.mon_order)
x = ring.gens()
polys = [x[0]^degree*x[1] +1, x[0]*x[1]^degree]
polys += x[2:]
if linear_transform:
y = linear_transform * vector(x)
polys = [p(*y) for p in polys]
return polys
def dreg_voo_diff_extreme(self, degree=20, num_vars=3):
ring = PolynomialRing(self.field, self.var_name, num_vars, order=self.mon_order)
x = ring.gens()
polys = []
for i in range(num_vars):
j = (i + 1) % num_vars
polys += [x[i]^degree*x[j] + x[i]^(degree//2)]
return polys
def high_dreg(self, degree=7, num_vars=2, linear_transform=None):
ring = PolynomialRing(self.field, self.var_name, num_vars, order=self.mon_order)
x = ring.gens()
polys = [x[1]^degree + x[0]]
polys += x[1:]
if linear_transform:
y = linear_transform * vector(x)
polys = [p(*y) for p in polys]
return polys
def low_involv(self):
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]^10*x[1] + x[0],
x[1]^10*x[0] + x[1],
x[2]^6*x[3] + x[2]^3,
x[3]^6*x[2] + x[3]^3,
x[0]*x[2]]
return polys
def low_involv_2(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [x[0]^10*x[1] + x[0],
x[1]^10*x[0] + x[1],
x[2]^6*x[3] + x[2]^3,
x[3]^6*x[2] + x[3]^3,
x[0]*x[2],
x[4]^6*x[5] + x[4]^3,
x[5]^6*x[4] + x[5]^3,
x[2]*x[4]]
return polys
def faugere_paper(self):
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]^2*x[1]-x[2]^2*x[3],
x[0]*x[2]^2-x[1]^2*x[3],
x[0]*x[1]^3*x[3]-x[2]^4*x[3],
x[2]^6*x[3]-x[1]^5*x[3]^2,
x[1]*x[2]^3-x[0]^2*x[3]^2,
x[1]^3*x[2]*x[3]-x[0]^3*x[3]^2,
x[2]^5*x[3]-x[0]^4*x[3]^2,
x[1]^5*x[3]^2-x[0]^4*x[2]*x[3]^2,
-x[0]^5*x[3]^2+x[1]^2*x[2]^3*x[3]^2,
x[1]^6*x[3]^2-x[0]*x[1]^2*x[2]*x[3]^4]
return polys
def cyclic_3(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[0]+x[1]+x[2],
x[0]*x[1]+x[1]*x[2]+x[2]*x[0],
x[0]*x[1]*x[2]-1]
return polys
def cyclic_4(self):
ring = PolynomialRing(self.field, self.var_name, 4, order=self.mon_order)
x = ring.gens()
polys = [x[0]+x[1]+x[2]+x[3],
x[0]*x[1]+x[1]*x[2]+x[2]*x[3]+x[3]*x[0],
x[0]*x[1]*x[2]+x[1]*x[2]*x[3]+x[2]*x[3]*x[0]+x[3]*x[0]*x[1],
x[0]*x[1]*x[2]*x[3]-1]
return polys
def cyclic_5(self):
ring = PolynomialRing(self.field, self.var_name, 5, order=self.mon_order)
x = ring.gens()
polys = [x[0]+x[1]+x[2]+x[3]+x[4],
x[0]*x[1]+x[1]*x[2]+x[2]*x[3]+x[3]*x[4]+x[4]*x[0],
x[0]*x[1]*x[2]+x[1]*x[2]*x[3]+x[2]*x[3]*x[4]+x[3]*x[4]*x[0]+x[4]*x[0]*x[1],
x[0]*x[1]*x[2]*x[3]+x[1]*x[2]*x[3]*x[4]+x[2]*x[3]*x[4]*x[0]+x[3]*x[4]*x[0]*x[1]+x[4]*x[0]*x[1]*x[2],
x[0]*x[1]*x[2]*x[3]*x[4]-1]
return polys
def cyclic_6(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1]*x[2]*x[3]*x[4]*x[5]-1,
x[0]*x[1]*x[2]*x[3]*x[4]+x[0]*x[1]*x[2]*x[3]*x[5]+x[0]*x[1]*x[2]*x[4]*x[5]+x[0]*x[1]*x[3]*x[4]*x[5]+x[0]*x[2]*x[3]*x[4]*x[5]+x[1]*x[2]*x[3]*x[4]*x[5],
x[0]*x[1]*x[2]*x[3]+x[0]*x[1]*x[2]*x[5]+x[0]*x[1]*x[4]*x[5]+x[0]*x[3]*x[4]*x[5]+x[1]*x[2]*x[3]*x[4]+x[2]*x[3]*x[4]*x[5],
x[0]*x[1]*x[2]+x[0]*x[1]*x[5]+x[0]*x[4]*x[5]+x[1]*x[2]*x[3]+x[2]*x[3]*x[4]+x[3]*x[4]*x[5],
x[0]*x[1]+x[0]*x[5]+x[1]*x[2]+x[2]*x[3]+x[3]*x[4]+x[4]*x[5],
x[0]+x[1]+x[2]+x[3]+x[4]+x[5]]
return polys
def cyclic_7(self):
ring = PolynomialRing(self.field, self.var_name, 7, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1]*x[2]*x[3]*x[4]*x[5]*x[6]-1,
x[0]*x[1]*x[2]*x[3]*x[4]*x[5]+x[0]*x[1]*x[2]*x[3]*x[4]*x[6]+x[0]*x[1]*x[2]*x[3]*x[5]*x[6]+x[0]*x[1]*x[2]*x[4]*x[5]*x[6]+x[0]*x[1]*x[3]*x[4]*x[5]*x[6]+x[0]*x[2]*x[3]*x[4]*x[5]*x[6]+x[1]*x[2]*x[3]*x[4]*x[5]*x[6],
x[0]*x[1]*x[2]*x[3]*x[4]+x[0]*x[1]*x[2]*x[3]*x[6]+x[0]*x[1]*x[2]*x[5]*x[6]+x[0]*x[1]*x[4]*x[5]*x[6]+x[0]*x[3]*x[4]*x[5]*x[6]+x[1]*x[2]*x[3]*x[4]*x[5]+x[2]*x[3]*x[4]*x[5]*x[6],
x[0]*x[1]*x[2]*x[3]+x[0]*x[1]*x[2]*x[6]+x[0]*x[1]*x[5]*x[6]+x[0]*x[4]*x[5]*x[6]+x[1]*x[2]*x[3]*x[4]+x[2]*x[3]*x[4]*x[5]+x[3]*x[4]*x[5]*x[6],
x[0]*x[1]*x[2]+x[0]*x[1]*x[6]+x[0]*x[5]*x[6]+x[1]*x[2]*x[3]+x[2]*x[3]*x[4]+x[3]*x[4]*x[5]+x[4]*x[5]*x[6],
x[0]*x[1]+x[0]*x[6]+x[1]*x[2]+x[2]*x[3]+x[3]*x[4]+x[4]*x[5]+x[5]*x[6],
x[0]+x[1]+x[2]+x[3]+x[4]+x[5]+x[6]]
return polys
def cyclic_8(self):
ring = PolynomialRing(self.field, self.var_name, 8, order=self.mon_order)
x = ring.gens()
polys = [x[0]*x[1]*x[2]*x[3]*x[4]*x[5]*x[6]*x[7]-1,
x[0]*x[1]*x[2]*x[3]*x[4]*x[5]*x[6]+x[0]*x[1]*x[2]*x[3]*x[4]*x[5]*x[7]+x[0]*x[1]*x[2]*x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x[6]+x[7]]
return polys
def katsura_3(self):
ring = PolynomialRing(self.field, self.var_name, 5, order=self.mon_order)
x = ring.gens()
polys = [x[1]+2*x[2]+2*x[3]+2*x[4]-x[0],
x[2]^2+2*x[1]*x[3]+2*x[2]*x[4]-x[0]*x[3],
2*x[1]*x[2]+2*x[2]*x[3]+2*x[3]*x[4]-x[0]*x[2],
x[1]^2+2*x[2]^2+2*x[3]^2+2*x[4]^2-x[0]*x[1]]
return polys
def katsura_5(self):
ring = PolynomialRing(self.field, self.var_name, 6, order=self.mon_order)
x = ring.gens()
polys = [2*x[0]^2+2*x[1]^2+2*x[2]^2+2*x[3]^2+2*x[4]^2+x[5]^2-x[5],
x[0]*x[1]+x[1]*x[2]+2*x[2]*x[3]+2*x[3]*x[4]+2*x[4]*x[5]-x[4],
2*x[0]*x[2]+2*x[1]*x[3]+2*x[2]*x[4]+x[4]^2+2*x[3]*x[5]-x[3],
2*x[0]*x[3]+2*x[1]*x[4]+2*x[3]*x[4]+2*x[2]*x[5]-x[2],
x[3]^2+2*x[0]*x[5]+2*x[1]*x[5]+2*x[2]*x[5]-x[1],
2*x[0]+2*x[1]+2*x[2]+2*x[3]+2*x[4]+x[5]-1]
return polys
def dreg_is_off(self):
ring = PolynomialRing(self.field, self.var_name, 3, order=self.mon_order)
x = ring.gens()
polys = [x[1]^4 - x[0]*x[2]^3,
x[0]^2*x[1]^2 + x[1]^3*x[2],
x[0]^3*x[1] - x[0]^2*x[1]^2 + 1]
return polys
def random(self, num_vars=4, degree=4, terms=6):
ring = PolynomialRing(self.field, self.var_name, num_vars, order=self.mon_order)
polys = [ring.random_element(degree, terms) for _ in range(num_vars)]
return polys