DALGLI0/main.py

59 lines
1.4 KiB
Python
Raw Normal View History

2018-06-26 02:05:11 +02:00
import itertools
2018-06-27 19:14:55 +02:00
class Poly:
def __init__(self, elements):
self.elements = {}
i = len(elements) - 1
for e in reversed(elements):
self.elements[f"x{i}"] = e
i -= 1
def __str__(self):
return str(self.elements)
def __mul__(self, other):
elements = {}
for e in self.elements:
for f in other.elements:
coefficient = self.elements[e] * other.elements[f]
degree = f"x{int(e[1:])+int(f[1:])}"
if elements.get(f"{degree}") is None:
elements[degree] = coefficient
else:
elements[degree] += coefficient
return Poly(list(reversed(list(elements.values()))))
def __mod__(self, other):
elements = {}
2018-06-26 02:05:11 +02:00
class PolyIntField:
def __init__(self, int_modulo, poly_modulo):
self.int_modulo = int_modulo
2018-06-27 19:14:55 +02:00
self.poly_modulo = Poly(poly_modulo)
2018-06-26 02:05:11 +02:00
self.elements = list(itertools.product([x for x in range(0, int_modulo)]
, repeat=len(poly_modulo) - 1))
2018-06-27 19:14:55 +02:00
def get_nilpotents(self):
nilpotents = []
# for element in self.elements:
2018-06-26 02:05:11 +02:00
if __name__ == "__main__":
2018-06-27 19:14:55 +02:00
# a = PolyIntField(3, [1, 1, 2, 2])
# print(a.elements)
# print(len(a.elements))
b = Poly([4, 8, 1, 3])
c = Poly([1, 4])
print(b.elements)
print(b * c * c)
# c = Poly()