Exemple #1
0
    def _element_constructor_(self, u):
        """
        Returns the abstract group element corresponding to the unit u.

        INPUT:

        - ``u`` -- Any object from which an element of the unit group's number
          field `K` may be constructed; an error is raised if an element of `K`
          cannot be constructed from u, or if the element constructed is not a
          unit.

        EXAMPLES::

            sage: x = polygen(QQ)
            sage: K.<a> = NumberField(x^2-38)
            sage: UK = UnitGroup(K)
            sage: UK(1)
            1
            sage: UK(-1)
            u0
            sage: UK.gens()
            (u0, u1)
            sage: UK.gens_values()
            [-1, 6*a - 37]
            sage: UK.ngens()
            2
            sage: [UK(u) for u in UK.gens()]
            [u0, u1]
            sage: [UK(u).exponents() for u in UK.gens()]
            [(1, 0), (0, 1)]
            sage: UK(a)
            Traceback (most recent call last):
            ...
            ValueError: a is not a unit
        """
        K = self.__number_field
        pK = self.__pari_number_field
        try:
            u = K(u)
        except TypeError:
            raise ValueError, "%s is not an element of %s" % (u, K)
        if self.__S:
            m = pK.bnfissunit(self.__S_unit_data, pari(u)).mattranspose()
            if m.ncols() == 0:
                raise ValueError, "%s is not an S-unit" % u
        else:
            if not u.is_integral() or u.norm().abs() != 1:
                raise ValueError, "%s is not a unit" % u
            m = pK.bnfisunit(pari(u)).mattranspose()

        # convert column matrix to a list:
        m = [ZZ(m[0, i].python()) for i in range(m.ncols())]

        # NB pari puts the torsion after the fundamental units, before
        # the extra S-units but we have the torsion first:
        m = [m[self.__nfu]] + m[:self.__nfu] + m[self.__nfu + 1:]

        return self.element_class(self, m)
Exemple #2
0
    def _element_constructor_(self, u):
        """
        Returns the abstract group element corresponding to the unit u.

        INPUT:

        - ``u`` -- Any object from which an element of the unit group's number
          field `K` may be constructed; an error is raised if an element of `K`
          cannot be constructed from u, or if the element constructed is not a
          unit.

        EXAMPLES::

            sage: x = polygen(QQ)
            sage: K.<a> = NumberField(x^2-38)
            sage: UK = UnitGroup(K)
            sage: UK(1)
            1
            sage: UK(-1)
            u0
            sage: UK.gens()
            (u0, u1)
            sage: UK.gens_values()
            [-1, 6*a - 37]
            sage: UK.ngens()
            2
            sage: [UK(u) for u in UK.gens()]
            [u0, u1]
            sage: [UK(u).exponents() for u in UK.gens()]
            [(1, 0), (0, 1)]
            sage: UK(a)
            Traceback (most recent call last):
            ...
            ValueError: a is not a unit
        """
        K = self.__number_field
        pK = self.__pari_number_field
        try:
            u = K(u)
        except TypeError:
            raise ValueError, "%s is not an element of %s"%(u,K)
        if self.__S:
            m = pK.bnfissunit(self.__S_unit_data, pari(u)).mattranspose()
            if m.ncols()==0:
                raise ValueError, "%s is not an S-unit"%u
        else:
            if not u.is_integral() or u.norm().abs() != 1:
                raise ValueError, "%s is not a unit"%u
            m = pK.bnfisunit(pari(u)).mattranspose()

        # convert column matrix to a list:
        m = [ZZ(m[0,i].python()) for i in range(m.ncols())]

        # NB pari puts the torsion after the fundamental units, before
        # the extra S-units but we have the torsion first:
        m = [m[self.__nfu]] + m[:self.__nfu] + m[self.__nfu+1:]

        return self.element_class(self, m)
Exemple #3
0
def primes_of_bounded_norm(B):
    """
    Return the prime ideals of the integers of the field Q(sqrt(5)) of
    norm at most B, ordered first by norm, then by the image of the
    golden ratio mod the prime in GF(p)={0,1,...,p-1}.

    INPUT:

        - B -- integer

    OUTPUT:

        - list of prime ideals

    EXAMPLES::

        sage: import psage
        sage: psage.modform.hilbert.sqrt5.primes_of_bounded_norm(4)
        [Fractional ideal (2)]
        sage: len(psage.modform.hilbert.sqrt5.primes_of_bounded_norm(10^4))
        1233
        sage: v = psage.modform.hilbert.sqrt5.primes_of_bounded_norm(11); v
        [Fractional ideal (2), Fractional ideal (2*a - 1), Fractional ideal (3), Fractional ideal (3*a - 1), Fractional ideal (3*a - 2)]

    Check that the sort order is as claimed::
    
        sage: P0 = v[-2]; P1 = v[-1]
        sage: K = P0.number_field(); K
        Number Field in a with defining polynomial x^2 - x - 1
        sage: P0.residue_field()(K.gen())
        4
        sage: P1.residue_field()(K.gen())   # yep, 4 < 8
        8
    """
    v = []
    g = F.gen()
    for p in primes(B + 1):
        if p == 5:
            v.append((5, F.ideal(2 * g - 1)))
        elif p % 5 in [2, 3]:
            Norm = p * p
            if Norm <= B:
                v.append((Norm, F.ideal(p)))
        else:
            s = pari(5).Mod(p).sqrt()
            a = int(((1 + s) / 2).lift())
            b = int(((1 - s) / 2).lift())
            v.append((p, a, F.ideal([p, g - a])))
            v.append((p, b, F.ideal([p, g - b])))
    v.sort()
    return [z[-1] for z in v]
Exemple #4
0
def primes_of_bounded_norm(B):
    """
    Return the prime ideals of the integers of the field Q(sqrt(5)) of
    norm at most B, ordered first by norm, then by the image of the
    golden ratio mod the prime in GF(p)={0,1,...,p-1}.

    INPUT:

        - B -- integer

    OUTPUT:

        - list of prime ideals

    EXAMPLES::

        sage: import psage
        sage: psage.modform.hilbert.sqrt5.primes_of_bounded_norm(4)
        [Fractional ideal (2)]
        sage: len(psage.modform.hilbert.sqrt5.primes_of_bounded_norm(10^4))
        1233
        sage: v = psage.modform.hilbert.sqrt5.primes_of_bounded_norm(11); v
        [Fractional ideal (2), Fractional ideal (2*a - 1), Fractional ideal (3), Fractional ideal (3*a - 1), Fractional ideal (3*a - 2)]

    Check that the sort order is as claimed::
    
        sage: P0 = v[-2]; P1 = v[-1]
        sage: K = P0.number_field(); K
        Number Field in a with defining polynomial x^2 - x - 1
        sage: P0.residue_field()(K.gen())
        4
        sage: P1.residue_field()(K.gen())   # yep, 4 < 8
        8
    """
    v = []
    g = F.gen()
    for p in primes(B+1):
        if p == 5:
            v.append((5, F.ideal(2*g-1)))
        elif p%5 in [2,3]:
            Norm = p*p
            if Norm <= B:
                v.append((Norm, F.ideal(p)))
        else:
            s = pari(5).Mod(p).sqrt()
            a = int(((1 + s)/2).lift()); b = int(((1 - s)/2).lift())
            v.append((p, a, F.ideal([p, g - a])))
            v.append((p, b, F.ideal([p, g - b])))
    v.sort()    
    return [z[-1] for z in v]
Exemple #5
0
def elliptic_j(z):
    r"""
   Returns the elliptic modular `j`-function evaluated at `z`.

   INPUT:

   - ``z`` (complex) -- a complex number with positive imaginary part.

   OUTPUT:

   (complex) The value of `j(z)`.

   ALGORITHM:

   Calls the ``pari`` function ``ellj()``.

   AUTHOR:

   John Cremona

   EXAMPLES::

       sage: elliptic_j(CC(i))
       1728.00000000000
       sage: elliptic_j(sqrt(-2.0))
       8000.00000000000
       sage: z = ComplexField(100)(1,sqrt(11))/2
       sage: elliptic_j(z)
       -32768.000...
       sage: elliptic_j(z).real().round()
       -32768

    ::

       sage: tau = (1 + sqrt(-163))/2
       sage: (-elliptic_j(tau.n(100)).real().round())^(1/3)
       640320

   """
    CC = z.parent()
    from sage.rings.complex_field import is_ComplexField
    if not is_ComplexField(CC):
        CC = ComplexField()
        try:
            z = CC(z)
        except ValueError:
            raise ValueError("elliptic_j only defined for complex arguments.")
    from sage.libs.all import pari
    return CC(pari(z).ellj())
Exemple #6
0
def elliptic_j(z):
   r"""
   Returns the elliptic modular `j`-function evaluated at `z`.

   INPUT:

   - ``z`` (complex) -- a complex number with positive imaginary part.

   OUTPUT:

   (complex) The value of `j(z)`.

   ALGORITHM:

   Calls the ``pari`` function ``ellj()``.

   AUTHOR:

   John Cremona

   EXAMPLES::

       sage: elliptic_j(CC(i))
       1728.00000000000
       sage: elliptic_j(sqrt(-2.0))
       8000.00000000000
       sage: z = ComplexField(100)(1,sqrt(11))/2
       sage: elliptic_j(z)
       -32768.000...
       sage: elliptic_j(z).real().round()
       -32768

    ::

       sage: tau = (1 + sqrt(-163))/2
       sage: (-elliptic_j(tau.n(100)).real().round())^(1/3)
       640320

   """
   CC = z.parent()
   from sage.rings.complex_field import is_ComplexField
   if not is_ComplexField(CC):
      CC = ComplexField()
      try:
         z = CC(z)
      except ValueError:
         raise ValueError("elliptic_j only defined for complex arguments.")
   from sage.libs.all import pari
   return CC(pari(z).ellj())
Exemple #7
0
    def _element_constructor_(self, u):
        """
        Returns the abstract group element corresponding to the unit u.

        INPUT:

        - ``u`` -- Any object from which an element of the unit group's number
          field `K` may be constructed; an error is raised if an element of `K`
          cannot be constructed from u, or if the element constructed is not a
          unit.

        EXAMPLES::

            sage: x = polygen(QQ)
            sage: K.<a> = NumberField(x^2-38)
            sage: UK = UnitGroup(K)
            sage: UK(1)
            1
            sage: UK(-1)
            u0
            sage: UK.gens()
            (u0, u1)
            sage: UK.gens_values()
            [-1, 6*a - 37]
            sage: UK.ngens()
            2
            sage: [UK(u) for u in UK.gens()]
            [u0, u1]
            sage: [UK(u).exponents() for u in UK.gens()]
            [(1, 0), (0, 1)]
            sage: UK(a)
            Traceback (most recent call last):
            ...
            ValueError: a is not a unit
        """
        K = self.__number_field
        try:
            u = K(u)
        except TypeError:
            raise ValueError, "%s is not an element of %s" % (u, K)
        if not u.is_integral() or u.norm().abs() != 1:
            raise ValueError, "%s is not a unit" % u
        m = K.pari_bnf().bnfisunit(pari(u)).mattranspose()
        # convert column matrix to a list:
        m = [ZZ(m[0, i].python()) for i in range(m.ncols())]
        # NB pari puts the torsion at the end!
        m.insert(0, m.pop())
        return self.element_class(m, self)
Exemple #8
0
    def _element_constructor_(self, u):
        """
        Returns the abstract group element corresponding to the unit u.

        INPUT:

        - ``u`` -- Any object from which an element of the unit group's number
          field `K` may be constructed; an error is raised if an element of `K`
          cannot be constructed from u, or if the element constructed is not a
          unit.

        EXAMPLES::

            sage: x = polygen(QQ)
            sage: K.<a> = NumberField(x^2-38)
            sage: UK = UnitGroup(K)
            sage: UK(1)
            1
            sage: UK(-1)
            u0
            sage: UK.gens()
            (u0, u1)
            sage: UK.gens_values()
            [-1, 6*a - 37]
            sage: UK.ngens()
            2
            sage: [UK(u) for u in UK.gens()]
            [u0, u1]
            sage: [UK(u).exponents() for u in UK.gens()]
            [(1, 0), (0, 1)]
            sage: UK(a)
            Traceback (most recent call last):
            ...
            ValueError: a is not a unit
        """
        K = self.__number_field
        try:
            u = K(u)
        except TypeError:
            raise ValueError, "%s is not an element of %s"%(u,K)
        if not u.is_integral() or u.norm().abs() != 1:
            raise ValueError, "%s is not a unit"%u
        m = K.pari_bnf().bnfisunit(pari(u)).mattranspose()
        # convert column matrix to a list:
        m = [ZZ(m[0,i].python()) for i in range(m.ncols())]
        # NB pari puts the torsion at the end!
        m.insert(0,m.pop())
        return self.element_class(m, self)
Exemple #9
0
 def _pari_(self, variable=None):
     if variable is None:
         variable = self.parent().variable_name()
     return pari(self.list()).Polrev(variable)
 def _pari_(self, variable = None):
     if variable is None:
         variable = self.parent().variable_name()
     return pari(self.list()).Polrev(variable)
Exemple #11
0
def elliptic_j(z, prec=53):
    r"""
    Returns the elliptic modular `j`-function evaluated at `z`.

    INPUT:

    - ``z`` (complex) -- a complex number with positive imaginary part.

    - ``prec`` (default: 53) -- precision in bits for the complex field.

    OUTPUT:

    (complex) The value of `j(z)`.

    ALGORITHM:

    Calls the ``pari`` function ``ellj()``.

    AUTHOR:

    John Cremona

    EXAMPLES::

        sage: elliptic_j(CC(i))
        1728.00000000000
        sage: elliptic_j(sqrt(-2.0))
        8000.00000000000
        sage: z = ComplexField(100)(1,sqrt(11))/2
        sage: elliptic_j(z)
        -32768.000...
        sage: elliptic_j(z).real().round()
        -32768

    ::

        sage: tau = (1 + sqrt(-163))/2
        sage: (-elliptic_j(tau.n(100)).real().round())^(1/3)
        640320

    This example shows the need for higher precision than the default one of
    the `ComplexField`, see :trac:`28355`::

        sage: -elliptic_j(tau) # rel tol 1e-2
        2.62537412640767e17 - 732.558854258998*I
        sage: -elliptic_j(tau,75) # rel tol 1e-2
        2.625374126407680000000e17 - 0.0001309913593909879441262*I
        sage: -elliptic_j(tau,100) # rel tol 1e-2
        2.6253741264076799999999999999e17 - 1.3012822400356887122945119790e-12*I
        sage: (-elliptic_j(tau, 100).real().round())^(1/3)
        640320
    """
    CC = z.parent()
    if not isinstance(CC, sage.rings.abc.ComplexField):
        from sage.rings.complex_mpfr import ComplexField
        CC = ComplexField(prec)
        try:
            z = CC(z)
        except ValueError:
            raise ValueError("elliptic_j only defined for complex arguments.")
    from sage.libs.all import pari
    return CC(pari(z).ellj())