Rozwiązanie zadania "Ilorazy pierścienia wielomianów" #35
119
main.py
119
main.py
@ -146,17 +146,7 @@ class Poly:
|
|||||||
return Poly(poly.int_mod, list(reversed(list(els.values()))))
|
return Poly(poly.int_mod, list(reversed(list(els.values()))))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
elements_equal = True
|
return self.int_mod == other.int_mod and self.elements == other.elements
|
||||||
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):
|
def __mod__(self, other):
|
||||||
|
|
||||||
@ -240,12 +230,7 @@ class Poly:
|
|||||||
return div_result
|
return div_result
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
|
return self == Poly(self.int_mod, [0])
|
||||||
for e in self.elements:
|
|
||||||
if self.elements[e] != 0:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class PolyIntField:
|
class PolyIntField:
|
||||||
@ -266,23 +251,39 @@ class PolyIntField:
|
|||||||
def invertibles(self):
|
def invertibles(self):
|
||||||
invertibles = []
|
invertibles = []
|
||||||
|
|
||||||
|
one = Poly(self.int_modulo, [1])
|
||||||
|
|
||||||
for e in self.elements:
|
for e in self.elements:
|
||||||
if not e.is_empty():
|
for f in self.elements:
|
||||||
for f in self.elements:
|
if e * f % self.poly_modulo == one:
|
||||||
if not f.is_empty():
|
invertibles.append(
|
||||||
if (e * f % self.poly_modulo).elements == {"x0": 1}:
|
list(reversed(list(e.elements.values()))))
|
||||||
invertibles.append(
|
break
|
||||||
list(reversed(list(e.elements.values()))))
|
|
||||||
break
|
|
||||||
|
|
||||||
return invertibles
|
return invertibles
|
||||||
|
|
||||||
|
def zero_divisors(self):
|
||||||
|
zero_divisors = [[0]]
|
||||||
|
|
||||||
|
zero = Poly(self.int_modulo, [0])
|
||||||
|
|
||||||
|
for e in self.elements:
|
||||||
|
for f in self.elements:
|
||||||
|
if e * f % self.poly_modulo == zero and e != zero and f != zero:
|
||||||
|
zero_divisors.append(
|
||||||
|
list(reversed(list(e.elements.values()))))
|
||||||
|
break
|
||||||
|
|
||||||
|
return zero_divisors
|
||||||
|
|
||||||
def nilpotents(self):
|
def nilpotents(self):
|
||||||
nilpotents = []
|
nilpotents = []
|
||||||
|
|
||||||
|
zero = Poly(self.int_modulo, [0])
|
||||||
|
|
||||||
for e in self.elements:
|
for e in self.elements:
|
||||||
for n in range(1, self.int_modulo):
|
for n in range(1, self.int_modulo):
|
||||||
if ((e ** n) % self.poly_modulo).elements == {}:
|
if e ** n % self.poly_modulo == zero:
|
||||||
nilpotents.append(list(reversed(list(e.elements.values()))))
|
nilpotents.append(list(reversed(list(e.elements.values()))))
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -293,26 +294,12 @@ class PolyIntField:
|
|||||||
idempotents = []
|
idempotents = []
|
||||||
|
|
||||||
for e in self.elements:
|
for e in self.elements:
|
||||||
if ((e ** 2) % self.poly_modulo).elements == e.elements:
|
if e ** 2 % self.poly_modulo == e:
|
||||||
idempotents.append(list(reversed(list(e.elements.values()))))
|
idempotents.append(list(reversed(list(e.elements.values()))))
|
||||||
|
|
||||||
idempotents[idempotents.index([])] = [0]
|
idempotents[idempotents.index([])] = [0]
|
||||||
return idempotents
|
return idempotents
|
||||||
|
|
||||||
def zero_divisors(self):
|
|
||||||
zero_divisors = [[0]]
|
|
||||||
|
|
||||||
for e in self.elements:
|
|
||||||
if not e.is_empty():
|
|
||||||
for f in self.elements:
|
|
||||||
if not f.is_empty():
|
|
||||||
if (e * f % self.poly_modulo).elements == {}:
|
|
||||||
zero_divisors.append(
|
|
||||||
list(reversed(list(e.elements.values()))))
|
|
||||||
break
|
|
||||||
|
|
||||||
return zero_divisors
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
str_form = "[\n\t"
|
str_form = "[\n\t"
|
||||||
str_form += str(self.invertibles()) + ", # odwracalne\n\t"
|
str_form += str(self.invertibles()) + ", # odwracalne\n\t"
|
||||||
@ -325,13 +312,51 @@ class PolyIntField:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
if len(sys.argv) < 3:
|
# if len(sys.argv) < 3:
|
||||||
print("Niepoprawny input")
|
# print("Niepoprawny input")
|
||||||
exit(1)
|
# exit(1)
|
||||||
|
#
|
||||||
|
# if sys.argv[1].find(",") != -1:
|
||||||
|
# print(f"Proszę użyć spacji, nie przecinków: '{sys.argv[1]}'")
|
||||||
|
# exit(1)
|
||||||
|
|
||||||
if sys.argv[1].find(",") != -1:
|
|
||||||
print(f"Proszę użyć spacji, nie przecinków: '{sys.argv[1]}'")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
field = PolyIntField(int(sys.argv[1]), ast.literal_eval(sys.argv[2]))
|
# field = PolyIntField(int(sys.argv[1]), ast.literal_eval(sys.argv[2]))
|
||||||
|
# c = Poly(2, [0, 0, 0, 1])
|
||||||
|
# # print(c)
|
||||||
|
# a = Poly(2, [1, 0, 0, 1])
|
||||||
|
# print(a == c)
|
||||||
|
# print(c == a)
|
||||||
|
# print(a + Poly(2, [1]) == c)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
f = PolyIntField(2, [1, 1, 1])
|
||||||
|
print(f)
|
||||||
|
|
||||||
|
field = PolyIntField(3, [1, 1, 2, 2])
|
||||||
print(field)
|
print(field)
|
||||||
|
|
||||||
|
# g = PolyIntField(3, [1, 2, 3])
|
||||||
|
# print(g)
|
||||||
|
|
||||||
|
|
||||||
|
# a = Poly(5, [1, 0, 0])
|
||||||
|
# b = Poly(5, [1])
|
||||||
|
# print(a == b)
|
||||||
|
# print(b == a)
|
||||||
|
# a = Poly(5, [1, 3])
|
||||||
|
# b = Poly(5, [1, 2])
|
||||||
|
# print(a + b)
|
||||||
|
#
|
||||||
|
# c = Poly(4, [2, 0, 3, 2])
|
||||||
|
# d = Poly(4, [2, 0, 1, 2])
|
||||||
|
# print(c)
|
||||||
|
# print(d)
|
||||||
|
# # 0x^5 + 3x^4 + 0x^3 + 0x^2 + 0x^1 + 0
|
||||||
|
# print(c * d)
|
||||||
|
# print(Poly(5, [1, 1]) == Poly(5, [1]))
|
||||||
|
# print(Poly(5, [1]) == Poly(5, [1]))
|
||||||
|
|
||||||
|
# [[0], [1, 1], [2, 1], [1, 2], [2, 2], [2, 0, 1], [0, 1, 1], [1, 1, 1], [0, 2, 1], [1, 2, 1], [1, 0, 2], [0, 1, 2], [2, 1, 2], [0, 2, 2], [2, 2, 2]],
|
||||||
|
# [[0], [0, 1, 1], [0, 1, 2], [0, 2, 1], [0, 2, 2], [1, 0, 2], [1, 1], [1, 1, 1], [1, 2], [1, 2, 1], [2, 0, 1], [2, 1], [2, 1, 2], [2, 2], [2, 2, 2]],
|
||||||
|
Loading…
Reference in New Issue
Block a user