"Fix" invertibles
This commit is contained in:
parent
1a958042e1
commit
ee39f1f88d
64
main.py
64
main.py
@ -1,5 +1,4 @@
|
||||
import itertools
|
||||
import math
|
||||
|
||||
|
||||
class Poly:
|
||||
@ -144,6 +143,19 @@ class Poly:
|
||||
|
||||
return Poly(poly.int_mod, list(reversed(list(els.values()))))
|
||||
|
||||
def __eq__(self, other):
|
||||
elements_equal = True
|
||||
for e in self.elements:
|
||||
if e not in other.elements:
|
||||
elements_equal = False
|
||||
break
|
||||
else:
|
||||
if self.elements[e] != other.elements[e]:
|
||||
elements_equal = False
|
||||
break
|
||||
|
||||
return elements_equal and self.int_mod == other.int_mod
|
||||
|
||||
def __mod__(self, other):
|
||||
|
||||
assert self.int_mod == other.int_mod
|
||||
@ -157,11 +169,11 @@ class Poly:
|
||||
|
||||
while fdeg >= sdeg:
|
||||
coefficient = other.elements[f"x{sdeg}"]
|
||||
|
||||
if poly.is_empty():
|
||||
break
|
||||
|
||||
for i in range(1, poly.int_mod):
|
||||
# print("I")
|
||||
# print(poly.elements)
|
||||
if coefficient * i % poly.int_mod == poly.elements[f"x{fdeg}"]:
|
||||
coefficient = i
|
||||
break
|
||||
@ -183,14 +195,7 @@ class Poly:
|
||||
|
||||
return poly
|
||||
|
||||
# def __eq__(self, other):
|
||||
# equal = True
|
||||
# for e in self.elements:
|
||||
# if e not in other.elements:
|
||||
# equal = False
|
||||
# break
|
||||
#
|
||||
# return equal
|
||||
# TODO
|
||||
@staticmethod
|
||||
def gcd(self, other):
|
||||
|
||||
@ -255,14 +260,18 @@ class PolyIntField:
|
||||
p = [x % int_mod for x in p]
|
||||
self.elements.append(Poly(int_mod, p))
|
||||
|
||||
|
||||
# FIXME
|
||||
def invertibles(self):
|
||||
invertibles = []
|
||||
|
||||
for e in self.elements:
|
||||
if not e.is_empty():
|
||||
if Poly.gcd(e, self.poly_modulo) == 1:
|
||||
invertibles.append(e)
|
||||
for f in self.elements:
|
||||
if not f.is_empty():
|
||||
if (e * f % self.poly_modulo).elements == {"x0": 1}:
|
||||
invertibles.append(
|
||||
list(reversed(list(e.elements.values()))))
|
||||
break
|
||||
|
||||
return invertibles
|
||||
|
||||
@ -304,7 +313,7 @@ class PolyIntField:
|
||||
|
||||
def __str__(self):
|
||||
str_form = "[\n\t"
|
||||
str_form += str([]) + ",\n\t"
|
||||
str_form += str(self.invertibles()) + ",\n\t"
|
||||
str_form += str(self.zero_divisors()) + ",\n\t"
|
||||
str_form += str(self.nilpotents()) + ",\n\t"
|
||||
str_form += str(self.idempotents()) + "\n"
|
||||
@ -313,9 +322,30 @@ class PolyIntField:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# print(phi(36))
|
||||
|
||||
pf = PolyIntField(2, [1, 1, 1])
|
||||
print(pf)
|
||||
# a = Poly(5, [1])
|
||||
# b = Poly(5, [3, 5])
|
||||
# # print(a == )
|
||||
# p = Poly(2, [1, 1, 1])
|
||||
# c = Poly(2, [1, 1])
|
||||
# d = Poly(2, [1])
|
||||
# print(c * Poly(2, [0, 1]) % p)
|
||||
# print(d)
|
||||
# print((c * Poly(2, [0, 1]) % p) == d)
|
||||
# pf = PolyIntField(2, [1, 1, 1])
|
||||
# print(pf.invertibles())
|
||||
# a = pf.invertibles()
|
||||
# for i in a:
|
||||
# print(i)
|
||||
|
||||
# a = Poly(5, [1, 1])
|
||||
# print(a.elements == {"x1": 1, "x0": 1})
|
||||
# [[1], [2], [0, 1], [0, 2], [0, 0, 1], [1, 0, 1], [2, 1, 1], [2, 2, 1], [0, 0, 2], [2, 0, 2], [1, 1, 2], [1, 2, 2]], # odwracalne
|
||||
# [ ],
|
||||
|
||||
# [[0, 0, 1], [0, 0, 2], [0, 1], [0, 1, 1], [0, 1, 2], [0, 2], [0, 2, 1], [0, 2, 2], [1], [1, 0, 1], [1, 0, 2], [1, 1], [1, 1, 1], [1, 1, 2], [1, 2], [1, 2, 1], [1, 2, 2], [2], [2, 0, 1], [2, 0, 2], [2, 1], [2, 1, 1], [2, 1, 2], [2, 2], [2, 2, 1], [2, 2, 2]
|
||||
d = [[1], [2], [0, 1], [0, 2], [0, 0, 1], [1, 0, 1], [2, 1, 1], [2, 2, 1], [0, 0, 2], [2, 0, 2], [1, 1, 2], [1, 2, 2]]
|
||||
print(len(d))
|
||||
poly_field = PolyIntField(3, [1, 1, 2, 2])
|
||||
print(poly_field)
|
||||
|
Loading…
Reference in New Issue
Block a user