Ejemplo n.º 1
0
    def local_data(self, E, n, prec=64):
        import re
        R = PolynomialRing(RationalField(), 'x')

        if prec > 64:
            raise ValueError("prec (=%s) must be at most 64" % prec)
        if prec < 1:
            raise ValueError("prec (=%s) must be at least 1" % prec)

        if n % 2 != 1:
            v = self('-sp %sp%s -local  %s' % (n, prec, self._curve_str(E)))
        else:
            v = self('-sp %sp%sd0 -local  %s' % (n, prec, self._curve_str(E)))

        vv = v.split('\n')

        bad_primes_l = [i for i in vv if re.match(r'sp %d: Euler' % n, i)]

        bad_primes = [(Integer(i.split()[5]),
                       R(i.split()[7]).coefficients(sparse=False))
                      for i in bad_primes_l]

        cond_rootn_string = [i for i in vv if re.search('conductor', i)].pop()
        cond_rootn_string = cond_rootn_string.replace(',', ' ')

        conductor, root = Integer(cond_rootn_string.split()[5]), Integer(
            cond_rootn_string.split()[-1])

        return bad_primes, conductor, root
Ejemplo n.º 2
0
def p2sage(s):
    """Convert s to something sensible in Sage.  Can handle objects
    (including strings) representing integers, reals, complexes (in
    terms of 'i' or 'I'), polynomials in 'a' with integer
    coefficients, or lists of the above.
    """
    z = s
    if type(z) in [list, tuple]:
        return [p2sage(t) for t in z]
    else:
        Qa = PolynomialRing(RationalField(),"a")
        for f in [ZZ, RR, CC, Qa]:
            try:
                return f(z)
            # SyntaxError is raised by CC('??')
            # NameError is raised by CC('a')
            except (ValueError, TypeError, NameError, SyntaxError):
                try:
                    return f(str(z))
                except (ValueError, TypeError, NameError, SyntaxError):
                    pass
        if z!='??':
            logger.error('Error converting "{}" in p2sage'.format(z))
        return z
Ejemplo n.º 3
0
from .plot import Plot
from .polyviewer import PolyViewer, color_string
from numpy import (array, matrix, dot, prod, diag, transpose, zeros, ones, eye,
                   log, exp, pi, sqrt, ceil, dtype, take, arange, sum, argmin, fft)
from numpy.linalg import svd, norm, eig, solve, lstsq, matrix_rank

class Infinity(object):
    def __repr__(self):
        return '1/0'

try:
    from sage.all import PolynomialRing, IntegerRing, RationalField, RealField, ComplexField
    from sage.rings.complex_number import is_ComplexNumber
    from .mpfft import ComplexFFT
    ZZ = IntegerRing()
    QQ = RationalField()
    sage_poly_ring = PolynomialRing(IntegerRing(), ('M', 'L'))
    def fraction(numerator, denominator):
        if denominator:
            return QQ(numerator)/QQ(denominator)
        elif numerator:
            return Infinity()
        else:
            raise RuntimeError('0/0 is undefined.')

except ImportError:
    def no_sage(*args):
        print('Sage could not be imported')
    sage_poly_ring = no_sage
    def fraction(numerator, denominator):
        return '%d/%d'%(numerator, denominator)