Exemplo n.º 1
0
    def __call__(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()
            [-1, 6*a - 37]
            sage: UK.ngens()
            2
            sage: [UK(u) for u in UK.gens()]
            [u0, u1]
            sage: [UK(u).list() 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 AbelianGroupElement(self, m)
Exemplo n.º 2
0
 def _element_constructor_(self, *args, **kwargs):
     try:
         return AbelianGroupElement(args[0], self)
     except:
         I = self.__number_field.ideal(*args, **kwargs)
         return AbelianGroupElement(self, self.log(I))