def sqrt5_ideal(X):
    """
    Return ideal in ring of integers of Q(sqrt(5)) defined by X.

    INPUT:

    - `X` -- ideal or list or element of F

    OUTPUT:

    - ideal

    EXAMPLES::

        sage: from sage.modular.hilbert.sqrt5_tables import F, sqrt5_ideal
        sage: sqrt5_ideal(7)
        Fractional ideal (7)
        sage: sqrt5_ideal(F.0)
        Fractional ideal (a)
        sage: sqrt5_ideal([F.0, 2])
        Fractional ideal (1)    
    """
    if not is_Ideal(X) or X.ring() != F:
        return O_F.ideal(X)
    return X
Beispiel #2
0
def fast_ideal(P):
    return Prime(P) if is_Ideal(P) else P
Beispiel #3
0
def check_prime(K, P):
    r"""
    Function to check that `P` determines a prime of `K`, and return that ideal.

    INPUT:

    - ``K`` -- a number field (including `\QQ`).

    - ``P`` -- an element of ``K`` or a (fractional) ideal of ``K``.

    OUTPUT:

    - If ``K`` is `\QQ`: the prime integer equal to or which generates `P`.

    - If ``K`` is not `\QQ`: the prime ideal equal to or generated by `P`.

    .. note::

       If `P` is not a prime and does not generate a prime, a TypeError is raised.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_local_data import check_prime
        sage: check_prime(QQ,3)
        3
        sage: check_prime(QQ,ZZ.ideal(31))
        31
        sage: K.<a>=NumberField(x^2-5)
        sage: check_prime(K,a)
        Fractional ideal (a)
        sage: check_prime(K,a+1)
        Fractional ideal (a + 1)
        sage: [check_prime(K,P) for P in K.primes_above(31)]
        [Fractional ideal (5/2*a + 1/2), Fractional ideal (5/2*a - 1/2)]
    """
    if K is QQ:
        if isinstance(P, (int, long, Integer)):
            P = Integer(P)
            if P.is_prime():
                return P
            else:
                raise TypeError, "%s is not prime" % P
        else:
            if is_Ideal(P) and P.base_ring() is ZZ and P.is_prime():
                return P.gen()
        raise TypeError, "%s is not a prime ideal of %s" % (P, ZZ)

    if not is_NumberField(K):
        raise TypeError, "%s is not a number field" % K

    if is_NumberFieldFractionalIdeal(P):
        if P.is_prime():
            return P
        else:
            raise TypeError, "%s is not a prime ideal of %s" % (P, K)

    if is_NumberFieldElement(P):
        if P in K:
            P = K.ideal(P)
        else:
            raise TypeError, "%s is not an element of %s" % (P, K)
        if P.is_prime():
            return P
        else:
            raise TypeError, "%s is not a prime ideal of %s" % (P, K)

    raise TypeError, "%s is not a valid prime of %s" % (P, K)
Beispiel #4
0
def check_prime(K, P):
    r"""
    Function to check that `P` determines a prime of `K`, and return that ideal.

    INPUT:

    - ``K`` -- a number field (including `\QQ`).

    - ``P`` -- an element of ``K`` or a (fractional) ideal of ``K``.

    OUTPUT:

    - If ``K`` is `\QQ`: the prime integer equal to or which generates `P`.

    - If ``K`` is not `\QQ`: the prime ideal equal to or generated by `P`.

    .. note::

       If `P` is not a prime and does not generate a prime, a TypeError is raised.

    EXAMPLES::

        sage: from sage.schemes.elliptic_curves.ell_local_data import check_prime
        sage: check_prime(QQ,3)
        3
        sage: check_prime(QQ,ZZ.ideal(31))
        31
        sage: K.<a>=NumberField(x^2-5)
        sage: check_prime(K,a)
        Fractional ideal (a)
        sage: check_prime(K,a+1)
        Fractional ideal (a + 1)
        sage: [check_prime(K,P) for P in K.primes_above(31)]
        [Fractional ideal (5/2*a + 1/2), Fractional ideal (5/2*a - 1/2)]
    """
    if K is QQ:
        if isinstance(P, (int, long, Integer)):
            P = Integer(P)
            if P.is_prime():
                return P
            else:
                raise TypeError, "%s is not prime" % P
        else:
            if is_Ideal(P) and P.base_ring() is ZZ and P.is_prime():
                return P.gen()
        raise TypeError, "%s is not a prime ideal of %s" % (P, ZZ)

    if not is_NumberField(K):
        raise TypeError, "%s is not a number field" % K

    if is_NumberFieldFractionalIdeal(P):
        if P.is_prime():
            return P
        else:
            raise TypeError, "%s is not a prime ideal of %s" % (P, K)

    if is_NumberFieldElement(P):
        if P in K:
            P = K.ideal(P)
        else:
            raise TypeError, "%s is not an element of %s" % (P, K)
        if P.is_prime():
            return P
        else:
            raise TypeError, "%s is not a prime ideal of %s" % (P, K)

    raise TypeError, "%s is not a valid prime of %s" % (P, K)
Beispiel #5
0
def ideal(X):
    if not is_Ideal(X):
        return O_F.ideal(X)
    return X