diff --git a/hensel.py b/hensel.py index 2faf9fe..a9b1bd4 100644 --- a/hensel.py +++ b/hensel.py @@ -3,6 +3,14 @@ from padic import * from poly import * +def roots(p, poly): + 'Yield all roots of polynomial in the given p-adic integers.' + for root in xrange(p): + try: + yield PAdicPoly(p, poly, root) + except ValueError: + pass + class PAdicPoly(PAdic): 'Result of lifting a root of a polynomial in the integers mod p to the p-adic integers.' def __init__(self, p, poly, root): diff --git a/poly.py b/poly.py index 4356981..3652bcd 100644 --- a/poly.py +++ b/poly.py @@ -19,7 +19,8 @@ class Poly: def term(coeff, expt): if coeff == 1 and expt == 0: return '1' - return ' * '.join(([] if coeff == 1 else [str(coeff)]) + ([] if expt == 0 else ['X'] if expt == 1 else ['X ** ' + expt])) + return ' * '.join(([] if coeff == 1 else [str(coeff)]) + \ + ([] if expt == 0 else ['X'] if expt == 1 else ['X ** %d' % expt])) return ' + '.join(term(self.coeffs[i], i) for i in self.coeffs if self.coeffs[i] != 0) def __repr__(self):