update hensel.py

This commit is contained in:
Ata Deniz Aydin 2017-05-15 11:14:40 +03:00
parent 058b45976f
commit a3e31fb0db
2 changed files with 13 additions and 6 deletions

View file

@ -19,11 +19,16 @@ class PAdicPoly(PAdic):
# take care of trailing zeros
digit = self.root
self.val = str(digit)
self.exp = self.p
while digit == 0:
digit = self._nextdigit()
self.order += 1
self.prec += 1
digit = self._nextdigit()
# self.prec += 1
def _nextdigit(self):
self.root = ModP(self.p ** (self.order + 2), self.root)
self.root = self.root - self.poly(self.root) / self.deriv(self.root) # coercions automatically taken care of
self.root = ModP(self.exp * self.p, self.root)
self.root = self.root - self.poly(self.root) / self.deriv(self.root) # coercions automatically taken care of
digit = self.root // self.exp
self.exp *= self.p
return digit

View file

@ -26,6 +26,8 @@ class Poly:
return str(self)
# arithmetic
def __neg__(self):
return Poly({(i, -self.coeffs[i]) for i in self.coeffs})
def __add__(self, other):
if not isinstance(other, Poly):
other = Poly(other)
@ -41,11 +43,11 @@ class Poly:
def __sub__(self, other):
if not isinstance(other, Poly):
other = Poly(other)
return self.__add__(other._neg())
return self.__add__(other.__neg__())
def __rsub__(self, other):
if not isinstance(other, Poly):
other = Poly(other)
return other.__add__(self._neg())
return other.__add__(self.__neg__())
def __mul__(self, other):
if not isinstance(other, Poly):