From a3e31fb0db0d28be490eae3cc0cb8dc54d88b155 Mon Sep 17 00:00:00 2001 From: Ata Deniz Aydin Date: Mon, 15 May 2017 11:14:40 +0300 Subject: [PATCH] update hensel.py --- hensel.py | 13 +++++++++---- poly.py | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hensel.py b/hensel.py index 8227a5e..2faf9fe 100644 --- a/hensel.py +++ b/hensel.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/poly.py b/poly.py index cceb65d..4356981 100644 --- a/poly.py +++ b/poly.py @@ -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):