Example #1
0
    def save_roots(self, f, p2):
        """Save roots between last prime upto p2."""
        p = next_prime(self.last_prime(f))

        if p > p2:
            print "Already calculated upto", p
            return None

        roots = polynomial.solve_roots_range(f, p, p2, extra=True)
        fconn = self.connect(f)
        for r in roots:
            fconn.execute("INSERT INTO roots VALUES(?,?,?,?,?)", r)
        fconn.commit()

        count = len(roots) + self.count(f)
        last_prime = r[1]

        self.conn.execute("UPDATE polynomials \
                          SET roots=?, last_prime=? \
                          WHERE coefficients=?",
                          (count, last_prime,
                           polynomial.name_polynomial(f)))
        self.conn.commit()

        return None
Example #2
0
    def check_missing_roots(self, f):
        """Check all primes upto last_prime for missing roots.
        THIS DOESN'T WORK IN REASONABLE TIME!
        """
        last_prime = self.last_prime(f, True)
        p = 1
        missing = list()
        for r in self.roots(f):
            if r[1] > next_prime(p):
                gap_roots = polynomial.solve_roots_range(f,
                        next_prime(p), r[1])
                missing += (gap_roots)
                if gap_roots:
                    print "Missing:", gap_roots
            p = r[1]

        return missing