Ticket #9541: trac_9541-part4.patch

File trac_9541-part4.patch, 75.4 KB (added by was, 7 years ago)
  • sage/rings/number_field/class_group.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1279674100 -7200
    # Node ID d5abbca52e1414a1c13b23e086ca6e0b12149e8a
    # Parent  d582c0c29177f956734dc132ce6f746e7825a8e1
    trac 9541- part 4 -- improve coverage
    
    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/class_group.py
    a b  
    7676
    7777        EXAMPLES::
    7878
    79        
     79            sage: K.<b> = NumberField(x^2 + 389); C = K.class_group()
     80            sage: C(2)      # indirect doctest
     81            Trivial principal fractional ideal class
     82            sage: C(b)
     83            Trivial principal fractional ideal class
     84            sage: C.0 * 3
     85            Fractional ideal class (3, b - 1)
    8086        """
    8187        return self(x)
    8288
     
    212218    """
    213219    def __init__(self, ideal, class_group):
    214220        """
    215         Returns the ideal class of this fractional ideal.
     221        The ideal class of a fractional ideal.
     222
     223        EXAMPLES::
     224
     225            sage: G = NumberField(x^2 + 23,'a').class_group()
     226            sage: G(G.number_field().ideal(7))
     227            Trivial principal fractional ideal class
     228            sage: G(G.number_field().factor(3)[0][0])
     229            Fractional ideal class (3, -1/2*a + 1/2)
    216230        """
    217231        self.__ideal = ideal
    218232        MultiplicativeGroupElement.__init__(self, class_group)
     
    220234    def _repr_(self):
    221235        """
    222236        Return string representation of this fractional ideal class.
     237
     238        EXAMPLES::
     239
     240            sage: NumberField(x^2 + 23,'a').class_group().gen(0).__repr__()
     241            'Fractional ideal class (2, 1/2*a - 1/2)'
    223242        """
    224243        if self.is_principal():
    225244            return 'Trivial principal fractional ideal class' #%self.__ideal.number_field()
    226245        return 'Fractional ideal class %s'%self.__ideal._repr_short() #, self.__ideal.number_field())
    227246
    228247    def __cmp__(self, other):
     248        """
     249        EXAMPLES::
     250
     251            sage: I = NumberField(x^2 + 23,'a').class_group().0; J = I*I
     252            sage: I == J
     253            False
     254            sage: I == I
     255            True
     256            sage: cmp(I,J)
     257            -1
     258            sage: cmp(J,I)
     259            1
     260        """
    229261        q = self.__ideal / other.__ideal
    230262        if q.is_principal():
    231263            return 0
    232264        return cmp(self.__ideal, other.__ideal)
    233265
    234266    def _mul_(self, other):
     267        """
     268        EXAMPLES::
     269
     270            sage: I = G = NumberField(x^2 + 23,'a').class_group().0; J = I*I
     271            sage: I*J            # indirect doctest
     272            Trivial principal fractional ideal class
     273        """
    235274        return self.parent()((self.__ideal * other.__ideal).reduce_equiv())
    236275
    237276    def is_principal(self):
  • sage/rings/number_field/implementation.pyx

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/implementation.pyx
    a b  
    2525
    2626cdef class ArithmeticImplementation:
    2727    def __init__(self, name):
     28        """
     29        EXAMPLES::
     30
     31            sage: sage.rings.number_field.implementation.ArithmeticImplementation('test')
     32            Arithmetic implementation 'test'
     33        """
    2834        self._name = name
    2935
     36    def __reduce__(self):
     37        """
     38        EXAMPLES::
     39
     40            sage: A = sage.rings.number_field.implementation.ArithmeticImplementation('test')
     41            sage: loads(dumps(A))
     42            Arithmetic implementation 'test'
     43            sage: loads(dumps(A)) == A
     44            True
     45        """
     46        return self.__class__, (self._name, )
     47
    3048    def name(self):
     49        """
     50        EXAMPLES::
     51
     52            sage: sage.rings.number_field.implementation.ArithmeticImplementation('test').name()
     53            'test'
     54        """
    3155        return self._name
    3256
    3357    def __repr__(self):
     58        """
     59        EXAMPLES::
     60
     61            sage: sage.rings.number_field.implementation.ArithmeticImplementation('test').__repr__()
     62            "Arithmetic implementation 'test'"
     63        """
    3464        return "Arithmetic implementation '%s'"%self._name
    3565
    3666    def __cmp__(self, right):
     67        """
     68        EXAMPLES::
     69
     70            sage: G = sage.rings.number_field.implementation.ArithmeticImplementation('test')
     71            sage: H = sage.rings.number_field.implementation.ArithmeticImplementation('test2')
     72            sage: G == H
     73            False
     74            sage: G == G
     75            True
     76            sage: G < H
     77            True
     78            sage: H > G
     79            True
     80        """
    3781        return cmp(self.name(), right.name())
    3882
    3983cdef class ArithmeticImplementation_generic(ArithmeticImplementation):
    4084    def __init__(self, modulus):
     85        """
     86        EXAMPLES::
     87
     88            sage: sage.rings.number_field.implementation.ArithmeticImplementation_generic(x^2 + 3)
     89            Arithmetic implementation 'generic'
     90        """
    4191        self.modulus = modulus
    4292        ArithmeticImplementation.__init__(self, 'generic')
    4393
     94    def __reduce__(self):
     95        """
     96        EXAMPLES::
     97
     98            sage: A = sage.rings.number_field.implementation.ArithmeticImplementation_generic(x^2 + 3)
     99            sage: loads(dumps(A)) == A
     100            True
     101        """
     102        return self.__class__, (self.modulus, )
     103
    44104cdef class ArithmeticImplementation_ntl(ArithmeticImplementation):
    45105    def __init__(self):
     106        """
     107        EXAMPLES::
     108       
     109            sage: sage.rings.number_field.implementation.ArithmeticImplementation_ntl()
     110            Arithmetic implementation 'ntl'
     111        """
    46112        ArithmeticImplementation.__init__(self, 'ntl')
    47113
    48114cdef class ArithmeticImplementation_flint(ArithmeticImplementation):
    49115    def __init__(self):
     116        """
     117        EXAMPLES::
     118
     119            sage: sage.rings.number_field.implementation.ArithmeticImplementation_flint()
     120            Arithmetic implementation 'flint'
     121        """
    50122        ArithmeticImplementation.__init__(self, 'flint')
    51123
    52124cdef class ArithmeticImplementation_singular(ArithmeticImplementation):
    53125    def __init__(self):
     126        """
     127        EXAMPLES::
     128
     129            sage: sage.rings.number_field.implementation.ArithmeticImplementation_singular()
     130            Arithmetic implementation 'singular'
     131        """
    54132        ArithmeticImplementation.__init__(self, 'singular')
    55133
    56134cdef class ArithmeticImplementation_quadratic(ArithmeticImplementation):
    57135    def __init__(self):
     136        """
     137        EXAMPLES::
     138
     139            sage: sage.rings.number_field.implementation.ArithmeticImplementation_quadratic()
     140            Arithmetic implementation 'quadratic'
     141        """
    58142        ArithmeticImplementation.__init__(self, 'quadratic')
  • sage/rings/number_field/maps.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/maps.py
    a b  
    22Isomorphisms of number fields.  Provides isomorphisms between relative and
    33absolute presentations, to and form vector spaces, name changing maps, etc.
    44
    5 EXAMPLES:
     5EXAMPLES::
     6
    67    sage: L.<cuberoot2, zeta3> = CyclotomicField(3).extension(x^3 - 2)
    78    sage: K = L.absolute_field('a')
    89    sage: from_K, to_K = K.structure()
     
    1617      To:   Number Field in a with defining polynomial x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1
    1718"""
    1819
    19 #*****************************************************************************
    20 #       Copyright (C) 2008 William Stein <wstein@gmail.com>
     20##############################################################################
     21#       Copyright (C) 2008, 2010 William Stein <wstein@gmail.com>
    2122#
    2223#  Distributed under the terms of the GNU General Public License (GPL)
    2324#
     
    2930#  The full text of the GPL is available at:
    3031#
    3132#                  http://www.gnu.org/licenses/
    32 #*****************************************************************************
     33##############################################################################
    3334
    3435from sage.structure.sage_object import SageObject
    3536from sage.categories.map import Map
     
    4950    vector spaces.
    5051    """
    5152    def _repr_type(self):
     53        """
     54        EXAMPLES::
     55       
     56            sage: K.<alpha> = NumberField(x^4 - x + 7)
     57            sage: I = sage.rings.number_field.maps.NumberFieldIsomorphism(K.Hom(K))
     58            sage: I._repr_type()
     59            'Isomorphism'
     60        """
    5261        return "Isomorphism"
    5362
    5463    def is_injective(self):
     64        """
     65        EXAMPLES::
     66       
     67            sage: K.<alpha> = NumberField(x^4 - x + 7)
     68            sage: I = sage.rings.number_field.maps.NumberFieldIsomorphism(K.Hom(K))
     69            sage: I.is_injective()
     70            True
     71        """       
    5572        return True
    5673
    5774    def is_surjective(self):
     75        """
     76        EXAMPLES::
     77       
     78            sage: K.<alpha> = NumberField(x^4 - x + 7)
     79            sage: I = sage.rings.number_field.maps.NumberFieldIsomorphism(K.Hom(K))
     80            sage: I.is_surjective()
     81            True
     82        """       
    5883        return True
    5984
    6085class MapVectorSpaceToNumberField(NumberFieldIsomorphism):
    6186    r"""
    62     EXAMPLES:
     87    EXAMPLES::
     88   
    6389        sage: K.<a> = NumberField(x^4 + 3*x + 1)
    6490        sage: V, fr, to = K.vector_space()
    6591        sage: V
     
    113139    """
    114140
    115141    def __init__(self, V, K):
     142        """
     143        EXAMPLES::
     144
     145            sage: K.<a> = NumberField(x^4 + 3*x + 1); phi = K.vector_space()[1]; phi
     146            Isomorphism map:
     147              From: Vector space of dimension 4 over Rational Field
     148              To:   Number Field in a with defining polynomial x^4 + 3*x + 1
     149            sage: type(phi)
     150            <class 'sage.rings.number_field.maps.MapVectorSpaceToNumberField'>
     151        """
    116152        self.__V = V
    117153        self.__K = K
    118154        self.__R = K.polynomial_ring()
    119155        NumberFieldIsomorphism.__init__(self, Hom(V, K))
    120156
    121157    def _call_(self, v):
     158        """
     159        EXAMPLES::
     160
     161            sage: K.<a> = NumberField(x^4 + 3*x + 1); phi = K.vector_space()[1]
     162            sage: V = phi.domain(); V
     163            Vector space of dimension 4 over Rational Field
     164            sage: phi(V.1)
     165            a
     166            sage: phi(7/3*V.0+V.2)
     167            a^2 + 7/3
     168        """
    122169        f = self.__R(self.__V(v).list())
    123170        return self.__K._element_class(self.__K, f)
    124171
    125172class MapNumberFieldToVectorSpace(Map):
    126173    def __init__(self, K, V):
     174        """
     175        EXAMPLES::
     176
     177            sage: K.<a> = NumberField(x^4 + 3*x + 1); phi = K.vector_space()[2]
     178            sage: phi
     179            Isomorphism map:
     180              From: Number Field in a with defining polynomial x^4 + 3*x + 1
     181              To:   Vector space of dimension 4 over Rational Field
     182            sage: type(phi)
     183            <class 'sage.rings.number_field.maps.MapNumberFieldToVectorSpace'>
     184        """
    127185        self.__V = V
    128186        self.__K = K
    129187        self.__zero = QQ(0)
     
    131189        NumberFieldIsomorphism.__init__(self, Hom(K, V))
    132190
    133191    def _repr_type(self):
     192        """
     193        EXAMPLES::
     194
     195            sage: K.<a> = NumberField(x^4 + 3*x + 1); phi = K.vector_space()[2]; phi._repr_type()
     196            'Isomorphism'
     197        """
    134198        return "Isomorphism"
    135199   
    136200    def _call_(self, x):
     201        """
     202        EXAMPLES::
     203
     204            sage: K.<a> = NumberField(x^4 + 3*x + 1); phi = K.vector_space()[2]; phi(a^3 + 2/3*a + 1)
     205            (1, 2/3, 0, 1)
     206        """
    137207        y = self.__K(x)
    138208        v = y._coefficients()
    139209        w = v + [self.__zero]*(self.__n - len(v))
     
    141211
    142212class MapRelativeVectorSpaceToRelativeNumberField(NumberFieldIsomorphism):
    143213    r"""
    144     EXAMPLES:
     214    EXAMPLES::
     215   
    145216        sage: L.<b> = NumberField(x^4 + 3*x^2 + 1)
    146217        sage: K = L.relativize(L.subfields(2)[0][1], 'a'); K
    147218        Number Field in a0 with defining polynomial x^2 - b0*x + 1 over its base field
     
    172243        True
    173244    """
    174245    def __init__(self, V, K):
     246        """
     247        EXAMPLES::
     248
     249            sage: K.<a,b> = NumberField([x^3+2,x^2-2]); phi = K.relative_vector_space()[1]; phi
     250            Isomorphism map:
     251              From: Vector space of dimension 3 over Number Field in b with defining polynomial x^2 - 2
     252              To:   Number Field in a with defining polynomial x^3 + 2 over its base field
     253            sage: type(phi)
     254            <class 'sage.rings.number_field.maps.MapRelativeVectorSpaceToRelativeNumberField'>
     255        """
    175256        self.__V = V
    176257        self.__K = K
    177258        self.__R = K.polynomial_ring()
     
    180261        NumberFieldIsomorphism.__init__(self, Hom(V, K))
    181262
    182263    def _call_(self, v):
     264        """
     265        INPUT::
     266
     267           - `v` -- element
     268           
     269        EXAMPLES::
     270
     271            sage: K.<a,b> = NumberField([x^3+2,x^2-2]); phi = K.relative_vector_space()[1]
     272            sage: V = phi.domain(); phi(V.0 + 3*V.1)
     273            3*a + 1
     274        """
    183275        # Given a relative vector space element, we have to
    184276        # compute the corresponding number field element, in terms
    185277        # of an absolute generator.
     
    202294
    203295class MapRelativeNumberFieldToRelativeVectorSpace(NumberFieldIsomorphism):
    204296    def __init__(self, K, V):
     297        """
     298        EXAMPLES::
     299
     300            sage: K.<a,b> = NumberField([x^3+2,x^2-2]); phi = K.relative_vector_space()[2]; phi
     301            Isomorphism map:
     302              From: Number Field in a with defining polynomial x^3 + 2 over its base field
     303              To:   Vector space of dimension 3 over Number Field in b with defining polynomial x^2 - 2
     304            sage: type(phi)
     305            <class 'sage.rings.number_field.maps.MapRelativeNumberFieldToRelativeVectorSpace'>
     306        """
    205307        self.__V = V
    206308        self.__K = K
    207309        self.__rnf = K.pari_rnf()
     
    306408
    307409class IdentityMap(NumberFieldIsomorphism):
    308410    def __init__(self, K):
     411        """
     412        EXAMPLES::
     413
     414            sage: phi = sage.rings.number_field.maps.IdentityMap(NumberField(x^2+1,'a')); phi
     415            Identity map map:
     416              From: Number Field in a with defining polynomial x^2 + 1
     417              To:   Number Field in a with defining polynomial x^2 + 1
     418            sage: type(phi)
     419            <class 'sage.rings.number_field.maps.IdentityMap'>
     420        """
    309421        self.__K = K
    310422        NumberFieldIsomorphism.__init__(self, Hom(K, K))
    311423
    312424    def _repr_type(self):
     425        """
     426        EXAMPLES::
     427
     428            sage: phi = sage.rings.number_field.maps.IdentityMap(NumberField(x^2+1,'a')); phi._repr_type()
     429            'Identity map'
     430        """
    313431        return "Identity map"
    314432
    315433    def _call_(self, x):
     434        """
     435        EXAMPLES::
     436
     437            sage: K.<a> = NumberField(x^2 + 1)
     438            sage: phi = sage.rings.number_field.maps.IdentityMap(K)
     439            sage: phi(a)
     440            a
     441            sage: phi(a) is a
     442            True
     443        """
    316444        return self.__K(x)
    317445
    318446class NameChangeMap(NumberFieldIsomorphism):
     447    """
     448    A name change map is a canonical isomorphism from one field to
     449    another, which does nothing but change the print name of the
     450    generator.
     451    """
    319452    def __init__(self, K, L):
     453        """
     454            sage: K.<a> = NumberField(x^5 + 5)
     455            sage: L.<c> = K.absolute_field()
     456            sage: phi = L.structure()[0]; phi
     457            Isomorphism given by variable name change map:
     458              From: Number Field in c with defining polynomial x^5 + 5
     459              To:   Number Field in a with defining polynomial x^5 + 5
     460            sage: type(phi)
     461            <class 'sage.rings.number_field.maps.NameChangeMap'>
     462        """
    320463        self.__K = K
    321464        self.__L = L
    322465        NumberFieldIsomorphism.__init__(self, Hom(K, L))
    323466
    324467    def _repr_type(self):
     468        """
     469        EXAMPLES::
     470
     471            sage: K.<a> = NumberField(x^5 + 5); L.<c> = K.absolute_field(); phi = L.structure()[0]
     472            sage: phi._repr_type()
     473            'Isomorphism given by variable name change'
     474        """
    325475        return "Isomorphism given by variable name change"
    326476
    327477    def _call_(self, x):
     478        """
     479        EXAMPLES::
     480
     481            sage: K.<a> = NumberField(x^5 + 5); L.<c> = K.absolute_field(); phi = L.structure()[0]
     482            sage: phi(c)
     483            a
     484        """
    328485        y = self.__K(x)
    329486        z = y.__copy__()
    330487        z._set_parent(self.__L)
     
    332489
    333490class MapRelativeToAbsoluteNumberField(NumberFieldIsomorphism):
    334491    r"""
    335     EXAMPLES:
     492    EXAMPLES::
     493   
    336494        sage: K.<a> = NumberField(x^6 + 4*x^2 + 200)
    337495        sage: L = K.relativize(K.subfields(3)[0][1], 'b'); L
    338496        Number Field in b0 with defining polynomial x^2 + a0 over its base field
     
    373531        sage: (to * fr)(M.gen()) == M.gen(), (fr * to)(L.gen()) == L.gen()
    374532        (True, True)
    375533    """
    376 
    377534    def __init__(self, R, A):
     535        """
     536        EXAMPLES::
     537       
     538            sage: K.<a,b> = NumberField([x^2+1,x^2+3]); L.<c> = K.absolute_field(); phi = L.structure()[1]; phi
     539            Isomorphism map:
     540              From: Number Field in a with defining polynomial x^2 + 1 over its base field
     541              To:   Number Field in c with defining polynomial x^4 + 8*x^2 + 4
     542            sage: type(phi)
     543            <class 'sage.rings.number_field.maps.MapRelativeToAbsoluteNumberField'>
     544        """
    378545        self.__R = R          # relative field
    379546        self.__A = A          # absolute field
    380547        self.__poly_ring = self.__A.polynomial_ring()
     
    383550        NumberFieldIsomorphism.__init__(self, Hom(R, A))
    384551
    385552    def _call_(self, x):
     553        """
     554        EXAMPLES::
     555       
     556            sage: K.<a,b> = NumberField([x^2+1,x^2+3]); L.<c> = K.absolute_field(); phi = L.structure()[1]
     557            sage: phi(a+b)
     558            -1/2*c^3 - 4*c
     559            sage: L.structure()[0](phi(a+b))
     560            a + b
     561            sage: phi(2/3)
     562            2/3
     563            sage: phi(2/3).parent()
     564            Number Field in c with defining polynomial x^4 + 8*x^2 + 4
     565        """
    386566        f = self.__R(x).polynomial()
    387567        return self.__A._element_class(self.__A, f)
    388568   
    389569class MapAbsoluteToRelativeNumberField(NumberFieldIsomorphism):
    390570    def __init__(self, A, R):
     571        """
     572        EXAMPLES::
     573
     574            sage: K.<a,b> = NumberField([x^2+1,x^2+3]); L.<c> = K.absolute_field(); phi = L.structure()[0]
     575            sage: phi
     576            Isomorphism map:
     577              From: Number Field in c with defining polynomial x^4 + 8*x^2 + 4
     578              To:   Number Field in a with defining polynomial x^2 + 1 over its base field
     579            sage: type(phi)
     580            <class 'sage.rings.number_field.maps.MapAbsoluteToRelativeNumberField'>
     581        """
    391582        self.__A = A          # absolute field
    392583        self.__R = R          # relative field
    393584        self.__poly_ring = self.__A.polynomial_ring()       
     
    396587        NumberFieldIsomorphism.__init__(self, Hom(A, R))
    397588   
    398589    def _call_(self, x):
     590        """
     591        EXAMPLES::
     592
     593            sage: K.<a,b> = NumberField([x^2+1,x^2+3]); L.<c> = K.absolute_field(); phi = L.structure()[0]
     594            sage: phi(c)
     595            a - b
     596            sage: L.structure()[1](a-b)
     597            c
     598        """
    399599        f = self.__A(x).polynomial()
    400600        return self.__R._element_class(self.__R, f)
    401601
    402602class MapVectorSpaceToRelativeNumberField(NumberFieldIsomorphism):
    403603    def __init__(self, V, L, from_V, from_K):
     604        """
     605        EXAMPLES::
     606
     607            sage: K.<a,b> = NumberField([x^2+1,x^2+3]);  V,f,t = K.absolute_vector_space(); f
     608            Isomorphism map:
     609              From: Vector space of dimension 4 over Rational Field
     610              To:   Number Field in a with defining polynomial x^2 + 1 over its base field
     611            sage: type(f)
     612            <class 'sage.rings.number_field.maps.MapVectorSpaceToRelativeNumberField'>
     613        """
    404614        self.__V = V
    405615        self.__L = L
    406616        self.__from_V = from_V
     
    408618        NumberFieldIsomorphism.__init__(self, Hom(V, L))
    409619
    410620    def _call_(self, x):
     621        """
     622        EXAMPLES::
     623
     624            sage: K.<a,b> = NumberField([x^2+1,x^2+3]);  V,f,t = K.absolute_vector_space()
     625            sage: f(V.0 + 2*V.1)
     626            2*a - 2*b + 1
     627            sage: t(f(V.0 + 2*V.1))
     628            (1, 2, 0, 0)
     629        """
    411630        return self.__from_K(self.__from_V(x))
    412631
    413632class MapRelativeNumberFieldToVectorSpace(NumberFieldIsomorphism):
    414633    r"""
    415     EXAMPLES:
     634    EXAMPLES::
     635   
    416636        sage: K.<a> = NumberField(x^8 + 100*x^6 + x^2 + 5)
    417637        sage: L = K.relativize(K.subfields(4)[0][1], 'b'); L
    418638        Number Field in b0 with defining polynomial x^2 + a0 over its base field
     
    440660        ((0, 1, 0, 0, 0, 0, 0, 0), True)
    441661    """
    442662    def __init__(self, L, V, to_K, to_V):
     663        """
     664        EXAMPLES::
     665
     666            sage: K.<a,b> = NumberField([x^2+1,x^2+3]);  V,f,t = K.absolute_vector_space(); t
     667            Isomorphism map:
     668              From: Number Field in a with defining polynomial x^2 + 1 over its base field
     669              To:   Vector space of dimension 4 over Rational Field
     670            sage: type(t)
     671            <class 'sage.rings.number_field.maps.MapRelativeNumberFieldToVectorSpace'>
     672        """
    443673        self.__L = L
    444674        self.__V = V
    445675        self.__to_K = to_K
     
    447677        NumberFieldIsomorphism.__init__(self, Hom(L, V))
    448678
    449679    def _call_(self, x):
     680        """
     681        EXAMPLES::
     682
     683            sage: K.<a,b> = NumberField([x^2+1,x^2+3]);  V,f,t = K.absolute_vector_space()
     684            sage: t(a-b)
     685            (0, 1, 0, 0)
     686            sage: f(t(a-b))
     687            a - b
     688        """
    450689        return self.__to_V(self.__to_K(x))
    451690
  • sage/rings/number_field/morphism.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/morphism.py
    a b  
    1010    """
    1111    def __call__(self, im_gens, check=True):
    1212        """
    13         EXAMPLES:
     13        EXAMPLES::
     14       
    1415            sage: H = Hom(ZZ, QQ)
    1516            sage: phi = H([])
    1617            Traceback (most recent call last):
    1718            ...
    1819            TypeError: images do not define a valid homomorphism
    1920
    20         TESTS:
     21        TESTS::
     22       
    2123            sage: H = Hom(ZZ, QQ)
    2224            sage: H == loads(dumps(H))
    2325            True
     
    3335                raise TypeError, "images do not define a valid homomorphism"
    3436       
    3537    def _coerce_impl(self, x):
     38        """
     39        EXAMPLES::
     40       
     41            sage: L.<b> = NumberField(x^2 + 2); H = Hom(L,L)
     42            sage: a = H[1]
     43            sage: H._coerce_impl(a)
     44            Ring endomorphism of Number Field in b with defining polynomial x^2 + 2
     45              Defn: b |--> -b
     46        """
    3647        if not isinstance(x, NumberFieldHomomorphism_im_gens):
    3748            raise TypeError
    3849        if x.parent() is self:
     
    4253        raise TypeError
    4354
    4455    def _repr_(self):
     56        """
     57        EXAMPLES::
     58
     59            sage: K.<a> = NumberField(x^6 + 4*x^2 + 200); L.<b> = NumberField(x^2 + 2)
     60            sage: Hom(K,K)._repr_()
     61            'Automorphism group of Number Field in a with defining polynomial x^6 + 4*x^2 + 200'
     62            sage: Hom(L,K)._repr_()
     63            'Set of field embeddings from Number Field in b with defining polynomial x^2 + 2 to Number Field in a with defining polynomial x^6 + 4*x^2 + 200'
     64        """
    4565        D = self.domain()
    4666        C = self.codomain()
    4767        if C == D:
     
    5070            return "Set of field embeddings from %s to %s"%(D, C)
    5171
    5272    def is_aut(self):
     73        """
     74        EXAMPLES::
     75
     76            sage: K.<a> = NumberField(x^6 + 4*x^2 + 200); L.<b> = NumberField(x^2+2)
     77            sage: Hom(K,K).is_aut()
     78            True
     79            sage: Hom(L,K).is_aut()
     80            False
     81        """
    5382        return self.domain() == self.codomain()
    5483
    5584    def order(self):
    5685        """
    5786        Return the order of this set of field homomorphism.
    5887       
    59         EXAMPLES:
     88        EXAMPLES::
     89       
    6090            sage: k.<a> = NumberField(x^2 + 1)
    6191            sage: End(k)
    6292            Automorphism group of Number Field in a with defining polynomial x^2 + 1
     
    82112        """
    83113        Return a list of all the elements of self.
    84114
    85         EXAMPLES:
     115        EXAMPLES::
     116       
    86117            sage: K.<a> = NumberField( [x^2 + x + 1, x^3 + 2] )
    87118            sage: L = K.absolute_field('b')
    88119            sage: G = End(L); G
     
    123154        return v
    124155
    125156    def __getitem__(self, n):
     157        """
     158        EXAMPLES::
     159
     160            sage: L.<b> = NumberField(x^2+2)
     161            sage: Hom(L,L)[0]
     162            Ring endomorphism of Number Field in b with defining polynomial x^2 + 2
     163              Defn: b |--> b
     164            sage: Hom(L,L)[1]
     165            Ring endomorphism of Number Field in b with defining polynomial x^2 + 2
     166              Defn: b |--> -b
     167        """
    126168        return self.list()[n]
    127169       
    128170
     
    194236
    195237    EXAMPLES:
    196238    We construct a homomorphism from a relative field by giving
    197     the image of a generator:
     239    the image of a generator::
    198240
    199241        sage: L.<cuberoot2, zeta3> = CyclotomicField(3).extension(x^3 - 2)
    200242        sage: phi = L.hom([cuberoot2 * zeta3]); phi
     
    205247        zeta3*cuberoot2 + zeta3
    206248
    207249    In fact, this phi is a generator for the Kummer Galois group of this
    208     cyclic extension:
     250    cyclic extension::
     251   
    209252        sage: phi(phi(cuberoot2 + zeta3))
    210253        (-zeta3 - 1)*cuberoot2 + zeta3
    211254        sage: phi(phi(phi(cuberoot2 + zeta3)))
    212255        cuberoot2 + zeta3
    213256    """
    214257    def __call__(self, im_gen, base_hom=None, check=True):
     258        """
     259            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); H = Hom(K,K); H
     260            Automorphism group of Number Field in a with defining polynomial x^2 + 1 over its base field
     261            sage: type(H)
     262            <class 'sage.rings.number_field.morphism.RelativeNumberFieldHomset_with_category'>
     263            sage: H([-a])
     264            Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field
     265              Defn: a |--> -a
     266                    b |--> b
     267
     268        """
    215269        if isinstance(im_gen, NumberFieldHomomorphism_im_gens):
    216270            # Then it must be a homomorphism from the corresponding
    217271            # absolute number field
     
    236290        return self._from_im(im_gen, base_hom)
    237291
    238292    def _coerce_impl(self, x):
     293        """
     294        EXAMPLES::
     295
     296            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); H = Hom(K,K); H
     297            Automorphism group of Number Field in a with defining polynomial x^2 + 1 over its base field
     298            sage: H._coerce_impl(H([-a]))
     299            Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field
     300              Defn: a |--> -a
     301                    b |--> b
     302        """
    239303        if not isinstance(x, RelativeNumberFieldHomomorphism_from_abs):
    240304            raise TypeError
    241305        if x.parent() is self:
     
    248312        """
    249313        Return the homomorphism that acts on the base as given and
    250314        sends the generator of the domain to im_gen.
     315
     316        EXAMPLES::
     317
     318            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); H = Hom(K,K)
     319            sage: H._from_im(-a, K.base_field().hom([-b]))
     320            Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field
     321              Defn: a |--> -a
     322                    b |--> -b
     323       
    251324        """
    252325        K = self.domain().absolute_field('a')
    253326        from_K, to_K = K.structure()
     
    262335        return RelativeNumberFieldHomomorphism_from_abs(self, abs_hom)
    263336
    264337    def default_base_hom(self):
     338        """
     339        EXAMPLES::
     340
     341            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); H = Hom(K,K)
     342            sage: H.default_base_hom()
     343            Ring morphism:
     344              From: Number Field in b with defining polynomial x^2 + 3
     345              To:   Number Field in a with defining polynomial x^2 + 1 over its base field
     346              Defn: b |--> b
     347        """
    265348        try:
    266349            return self.__default_base_hom
    267350        except AttributeError:
     
    276359        """
    277360        Return a list of all the elements of self.
    278361
    279         EXAMPLES:
     362        EXAMPLES::
     363       
    280364            sage: K.<a, b> = NumberField( [x^2 + x + 1, x^3 + 2] )
    281365            sage: G = End(K); G
    282366            Automorphism group of Number Field in a with defining polynomial x^2 + x + 1 over its base field
     
    307391
    308392class RelativeNumberFieldHomomorphism_from_abs(RingHomomorphism):
    309393    def __init__(self, parent, abs_hom):
     394        """
     395        EXAMPLES::
     396
     397            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field()
     398            sage: abs_hom = L.Hom(L)[2]; abs_hom
     399            Ring endomorphism of Number Field in c with defining polynomial x^4 + 8*x^2 + 4
     400              Defn: c |--> 1/2*c^3 + 4*c
     401            sage: type(abs_hom)
     402            <class 'sage.rings.number_field.morphism.NumberFieldHomomorphism_im_gens'>
     403            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     404            sage: psi
     405            Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field
     406              Defn: a |--> 1/4*c^3 + 3/2*c
     407                    b |--> -1/4*c^3 - 5/2*c
     408            sage: psi(a)^2
     409            -1
     410            sage: psi(b)^2
     411            -3
     412        """
    310413        RingHomomorphism.__init__(self, parent)
    311414        self.__abs_hom = abs_hom
    312415        K = abs_hom.domain()
     
    316419        self.__to_K = to_K
    317420
    318421    def abs_hom(self):
     422        """
     423        EXAMPLES::
     424
     425            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field(); abs_hom = L.Hom(L)[2]
     426            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     427            sage: psi.abs_hom()
     428            Ring endomorphism of Number Field in c with defining polynomial x^4 + 8*x^2 + 4
     429              Defn: c |--> 1/2*c^3 + 4*c
     430        """
    319431        return self.__abs_hom
    320432
    321433    def _repr_type(self):
     434        """
     435        EXAMPLES::
     436
     437            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field(); abs_hom = L.Hom(L)[2]
     438            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     439            sage: psi._repr_type()
     440            'Relative number field'
     441        """
    322442        return "Relative number field"
    323443
    324444    def im_gens(self):
     445        """
     446        EXAMPLES::
     447
     448            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field(); abs_hom = L.Hom(L)[2]
     449            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     450            sage: psi.im_gens()
     451            [1/4*c^3 + 3/2*c, -1/4*c^3 - 5/2*c]
     452        """
    325453        try:
    326454            return self.__im_gens
    327455        except AttributeError:
     
    332460        return v
    333461
    334462    def _repr_defn(self):
     463        """
     464        EXAMPLES::
     465
     466            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field(); abs_hom = L.Hom(L)[2]
     467            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     468            sage: print psi._repr_defn()
     469            a |--> 1/4*c^3 + 3/2*c
     470            b |--> -1/4*c^3 - 5/2*c
     471        """
    335472        D = self.domain()
    336473        ig = self.im_gens()
    337474        return '\n'.join(['%s |--> %s'%(D.gen(i), ig[i]) for\
    338475                       i in range(D.ngens())])
    339476
    340477    def _call_(self, x):
     478        """
     479        EXAMPLES::
     480
     481            sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3]); L.<c> = K.absolute_field(); abs_hom = L.Hom(L)[2]
     482            sage: psi = sage.rings.number_field.morphism.RelativeNumberFieldHomomorphism_from_abs(Hom(K,K), abs_hom)
     483            sage: psi(a-b)
     484            1/2*c^3 + 4*c
     485            sage: psi(a-b).charpoly()
     486            x^4 + 8*x^2 + 4
     487            sage: (a-b).absolute_charpoly()
     488            x^4 + 8*x^2 + 4
     489        """
    341490        return self.__abs_hom(self.__to_K(x))
    342491
    343492
     
    347496    """
    348497    def __call__(self, im_gens, check=True):
    349498        """
    350         EXAMPLES:
    351             sage: End(CyclotomicField(16))
     499        EXAMPLES::
     500       
     501            sage: H = End(CyclotomicField(16)); H
    352502            Automorphism group of Cyclotomic Field of order 16 and degree 8
     503            sage: type(H)
     504            <class 'sage.rings.number_field.morphism.CyclotomicFieldHomset_with_category'>
    353505        """
    354506        if isinstance(im_gens, CyclotomicFieldHomomorphism_im_gens):
    355507            return self._coerce_impl(im_gens)
     
    362514                raise TypeError, "images do not define a valid homomorphism"
    363515       
    364516    def _coerce_impl(self, x):
     517        """
     518        EXAMPLES::
     519
     520            sage: H = End(CyclotomicField(16))
     521            sage: H._coerce_impl(H[1])
     522            Ring endomorphism of Cyclotomic Field of order 16 and degree 8
     523              Defn: zeta16 |--> zeta16^3
     524        """
    365525        if not isinstance(x, CyclotomicFieldHomomorphism_im_gens):
    366526            raise TypeError
    367527        if x.parent() is self:
     
    374534        """
    375535        Return a list of all the elements of self.
    376536
    377         EXAMPLES:
     537        EXAMPLES::
     538       
    378539            sage: K.<z> = CyclotomicField(12)
    379540            sage: G = End(K); G
    380541            Automorphism group of Cyclotomic Field of order 12 and degree 4
  • sage/rings/number_field/number_field.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field.py
    a b  
    10731073        number field into this number field.
    10741074
    10751075        INPUT:
    1076             x -- string
    1077 
    1078         EXAMPLES:
     1076            - `x` -- string
     1077
     1078        EXAMPLES::
     1079       
    10791080            sage: k.<theta25> = NumberField(x^3+(2/3)*x+1)
    10801081            sage: k._coerce_from_str('theta25^3 + (1/3)*theta25')
    10811082            -1/3*theta25 - 1
    10821083
    10831084        This function is called by the coerce method when it gets a string
    1084         as input:
     1085        as input::
     1086       
    10851087            sage: k('theta25^3 + (1/3)*theta25')
    10861088            -1/3*theta25 - 1       
    10871089        """
     
    11271129        """
    11281130        Internal function to set the structure fields of this number
    11291131        field.
     1132
     1133        EXAMPLES::
     1134
     1135            sage: K.<a> = NumberField(x^2 + 17)
     1136            sage: K.structure()
     1137            (Ring Coercion endomorphism of Number Field in a with defining polynomial x^2 + 17, Ring Coercion endomorphism of Number Field in a with defining polynomial x^2 + 17)
     1138            sage: K._set_structure(0,1)
     1139            Traceback (most recent call last):
     1140            ...
     1141            ValueError: number field structure is immutable.
     1142            sage: K._set_structure(0,1, unsafe_force_change=True)
     1143            sage: K.structure()
     1144            (0, 1)
    11301145        """
    11311146        # Note -- never call this on a cached number field, since
    11321147        # that could eventually lead to problems.
     
    35753590       
    35763591    @cached_method
    35773592    def _galois_group_cached(self, type, algorithm, names):
    3578 
    35793593        r"""
    35803594        Return the Galois group of this number field, caching the result
    35813595        properly. (This method exists because the introspection machinery
    3582         doesn't interact terribly well with the @cached_method decorator.)
     3596        doesn't interact terribly well with the @cached_method decorator.)
     3597
     3598        EXAMPLES::
     3599
     3600            sage: K.<alpha> = NumberField(x^2 - 7)
     3601            sage: G = K._galois_group_cached('pari', 'algorithm', 'g'); G
     3602            Galois group PARI group [2, -1, 1, "S2"] of degree 2 of the Number Field in alpha with defining polynomial x^2 - 7
     3603            sage: G is K._galois_group_cached('pari', 'algorithm', 'g')
     3604            True
    35833605        """
    35843606        from galois_group import GaloisGroup_v1, GaloisGroup_v2
    35853607
     
    39343956        return self.__reduced_gram_matrix
    39353957
    39363958   
    3937     #******************************************************
     3959    #######################################################
    39383960    # Supplementary algorithm to enumerate lattice points
    3939     #******************************************************
    3940 
     3961    #######################################################
    39413962    def _positive_integral_elements_with_trace(self, C):
    3942        
    39433963        r"""
    39443964        Find all totally positive integral elements in self whose
    39453965        trace is between C[0] and C[1], inclusive.
     
    41064126        return infinity.infinity
    41074127
    41084128    def absolute_polynomial_ntl(self):
     4129        """
     4130        See the docstring for polynomial_ntl.
     4131       
     4132        EXAMPLES::
     4133       
     4134            sage: NumberField(x^2 + x - 9/17,'a').absolute_polynomial_ntl()
     4135            ([-9 17 17], 17)
     4136        """
    41094137        return self.polynomial_ntl()
    41104138
    41114139    def polynomial_ntl(self):
     
    47594787                 implementation='default'):
    47604788        """
    47614789        Function to initialize an absolute number field.
     4790
     4791        EXAMPLES::
     4792
     4793            sage: K.<alpha> = NumberField(x^17 - 2)
     4794            sage: type(K)
     4795            <class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'>
    47624796        """
    47634797        NumberField_generic.__init__(self, polynomial, name, latex_name, check, embedding)
    47644798        if implementation == 'default':
     
    48044838        INPUT:
    48054839            x -- an element of some number field
    48064840
    4807         EXAMPLES:
     4841        EXAMPLES::
     4842       
    48084843            sage: K.<a> = NumberField(x^3 + 2)
    48094844            sage: L.<b> = NumberField(x^2 + 1)
    48104845            sage: K._coerce_from_other_number_field(L(2/3))
     
    48244859            x -- a non number field element x, e.g., a list, integer,
    48254860            rational, or polynomial.
    48264861
    4827         EXAMPLES:
     4862        EXAMPLES::
     4863       
    48284864            sage: K.<a> = NumberField(x^3 + 2/3)
    48294865            sage: K._coerce_non_number_field_element_in(-7/8)
    48304866            -7/8
     
    48854921        INPUT:
    48864922            x -- string
    48874923
    4888         EXAMPLES:
     4924        EXAMPLES::
     4925       
    48894926            sage: k.<theta25> = NumberField(x^3+(2/3)*x+1)
    48904927            sage: k._coerce_from_str('theta25^3 + (1/3)*theta25')
    48914928            -1/3*theta25 - 1
    48924929
    48934930        This function is called by the coerce method when it gets a string
    4894         as input:
     4931        as input::
     4932       
    48954933            sage: k('theta25^3 + (1/3)*theta25')
    48964934            -1/3*theta25 - 1       
    48974935        """
     
    66526690        else:
    66536691            return self._coerce_non_number_field_element_in(x)
    66546692
    6655     # TODO:
    6656     # The following is very nice and much more flexible / powerful.
    6657     # However, it is simply not *consistent*, since it totally
    6658     # breaks the doctests in eisenstein_submodule.py.
    6659     # FIX THIS.
    6660    
    6661 ##     def _will_be_better_coerce_from_other_cyclotomic_field(self, x, only_canonical=False):
    6662 ##         """
    6663 ##         Coerce an element x of a cyclotomic field into self, if at all possible.
    6664 
    6665 ##         INPUT:
    6666 ##             x -- number field element
    6667 
    6668 ##             only_canonical -- bool (default: False); Attempt to work,
    6669 ##                    even in some cases when x is not in a subfield of
    6670 ##                    the cyclotomics (as long as x is a root of unity).
    6671 
    6672 ##         EXAMPLES:
    6673 ##             sage: k5 = CyclotomicField(5)
    6674 ##             sage: k3 = CyclotomicField(3)
    6675 ##             sage: k15 = CyclotomicField(15)
    6676 ##             sage: k15._coerce_from_other_cyclotomic_field(k3.gen())
    6677 ##             zeta15^5
    6678 ##             sage: k15._coerce_from_other_cyclotomic_field(k3.gen()^2 + 17/3)
    6679 ##             -zeta15^5 + 14/3
    6680 ##             sage: k3._coerce_from_other_cyclotomic_field(k15.gen()^5)
    6681 ##             zeta3
    6682 ##             sage: k3._coerce_from_other_cyclotomic_field(-2/3 * k15.gen()^5 + 2/3)
    6683 ##             -2/3*zeta3 + 2/3
    6684 ##         """
    6685        
    6686 ##         K = x.parent()
    6687 
    6688 ##         if K is self:   
    6689 ##             return x
    6690 ##         elif K == self:
    6691 ##             return self._element_class(self, x.polynomial())
    6692 ##         n = K.zeta_order()
    6693 ##         m = self.zeta_order()
    6694 ##         print n, m, x
    6695 
    6696 
    6697 ##         self_gen = self.gen()
    6698 
    6699 ##         if m % n == 0:   # easy case
    6700 ##             # pass this off to a method in the element class
    6701 ##             # it can be done very quickly and easily by the cython<->NTL
    6702 ##             # interface there
    6703 ##             return x._lift_cyclotomic_element(self)
    6704 
    6705 ##         # Whatever happens below, it has to be consistent with
    6706 ##         #  zeta_r |---> (zeta_s)^m
    6707 
    6708 ##         if m % 2 and not n%2:
    6709 ##             m *= 2
    6710 ##             self_gen = -self_gen
    6711            
    6712 ##         if only_canonical and m % n:
    6713 ##             raise TypeError, "no canonical coercion"
    6714 
    6715 ##         if not is_CyclotomicField(K):
    6716 ##             raise TypeError, "x must be in a cyclotomic field"
    6717        
    6718 ##         v = x.list()
    6719 
    6720 ##         # Find the smallest power r >= 1 of the generator g of K that is in self,
    6721 ##         # i.e., find the smallest r such that g^r has order dividing m.
    6722 
    6723 ##         d = sage.rings.arith.gcd(m,n)
    6724 ##         r = n // d
    6725 
    6726 ##         # Since we use the power basis for cyclomotic fields, if every
    6727 ##         # v[i] with i not divisible by r is 0, then we're good.
    6728 
    6729 ##         # If h generates self and has order m, then the element g^r
    6730 ##         # maps to the power of self of order gcd(m,n)., i.e., h^(m/gcd(m,n))
    6731 ##         #
    6732 ##         z = self_gen**(m // d)
    6733 ##         w = self(1)
    6734 
    6735 ##         a = self(0)
    6736 ##         for i in range(len(v)):
    6737 ##             if i%r:
    6738 ##                 if v[i]:
    6739 ##                     raise TypeError, "element does not belong to cyclotomic field"
    6740 ##             else:
    6741 ##                 a += w*v[i]
    6742 ##                 w *= z
    6743 ##         return a
    6744 
    67456693    def _coerce_from_other_cyclotomic_field(self, x, only_canonical=False):
    67466694        """
    67476695        Coerce an element x of a cyclotomic field into self, if at all
  • sage/rings/number_field/number_field_base.pyx

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field_base.pyx
    a b  
    22Base class for all number fields.
    33
    44
    5 TESTS:
     5TESTS::
     6
    67    sage: k = NumberField(x^2 + 1, 'i'); k == loads(dumps(k))
    78    True
    89"""
     
    1112    """
    1213    Return True if x is of number field type.
    1314
    14     EXAMPLES:
     15    EXAMPLES::
     16   
    1517        sage: from sage.rings.number_field.number_field_base import is_NumberField
    1618        sage: is_NumberField(NumberField(x^2+1,'a'))
    1719        True
     
    2022        sage: is_NumberField(CyclotomicField(97))
    2123        True
    2224
    23     Note that the rational numbers QQ are a number field.
     25    Note that the rational numbers QQ are a number field::
     26   
    2427        sage: is_NumberField(QQ)
    2528        True
    2629        sage: is_NumberField(ZZ)
     
    6366        r"""
    6467        Synomym for \code{self.maximal_order(...)}.
    6568
    66         EXAMPLES:
     69        EXAMPLES::
     70       
    6771            sage: K.<a> = NumberField(x^2 + 1)
    6872            sage: K.ring_of_integers()
    6973            Maximal Order in Number Field in a with defining polynomial x^2 + 1
     
    7478        r"""
    7579        Synomym for \code{self.maximal_order(...)}.
    7680
    77         EXAMPLES:
     81        EXAMPLES::
     82       
    7883            sage: NumberField(x^3 - 2,'a').OK()
    7984            Maximal Order in Number Field in a with defining polynomial x^3 - 2
    8085        """
     
    8590        Return the maximal order, i.e., the ring of integers of this
    8691        number field.
    8792
    88         EXAMPLES:
     93        EXAMPLES::
     94       
    8995            sage: NumberField(x^3 - 2,'b').maximal_order()
    9096            Maximal Order in Number Field in b with defining polynomial x^3 - 2
    9197        """
     
    109115        """
    110116        Return True if self is viewed as a single extension over Q.
    111117       
    112         EXAMPLES:
     118        EXAMPLES::
     119       
    113120            sage: K.<a> = NumberField(x^3+2)
    114121            sage: K.is_absolute()
    115122            True
     
    126133        """
    127134        Return (r1, r2), where r1 and r2 are the number of real embeddings
    128135        and pairs of complex embeddings of this field, respectively.
     136
     137        This must be implemented in the derived class.
     138
     139        EXAMPLES::
     140
     141            sage: sage.rings.number_field.number_field_base.NumberField(0).signature()
     142            Traceback (most recent call last):
     143            ...
     144            NotImplementedError
    129145        """
    130146        raise NotImplementedError
    131147
    132148    def degree(self):
    133149        """
    134150        Return the degree of this number field.
     151
     152        EXAMPLES::
     153
     154            sage: sage.rings.number_field.number_field_base.NumberField(0).degree()
     155            Traceback (most recent call last):
     156            ...
     157            NotImplementedError
    135158        """
    136159        raise NotImplementedError
    137160
    138161    def discriminant(self):
    139162        """
    140163        Return the discriminant of this number field.
     164
     165        EXAMPLES::
     166
     167            sage: sage.rings.number_field.number_field_base.NumberField(0).discriminant()
     168            Traceback (most recent call last):
     169            ...
     170            NotImplementedError
    141171        """
    142172        raise NotImplementedError
    143173
     
    154184            symbolic expression or Rational
    155185
    156186        EXAMPLES:
     187       
    157188        The Minkowski bound for $\QQ[i]$ tells us that the class
    158         number is 1:
     189        number is 1::
     190       
    159191            sage: K = QQ[I]
    160192            sage: B = K.minkowski_bound(); B
    161193            4/pi
    162194            sage: B.n()
    163195            1.27323954473516
    164196
    165         We compute the Minkowski bound for $\QQ[\sqrt[3]{2}]$:
     197        We compute the Minkowski bound for $\QQ[\sqrt[3]{2}]$::
     198       
    166199            sage: K = QQ[2^(1/3)]
    167200            sage: B = K.minkowski_bound(); B
    168201            16/3*sqrt(3)/pi
     
    172205            2
    173206
    174207        We compute the Minkowski bound for $\QQ[\sqrt{10}]$, which
    175         has class number $2$:
     208        has class number $2$::
     209       
    176210            sage: K = QQ[sqrt(10)]
    177211            sage: B = K.minkowski_bound(); B
    178212            sqrt(10)
     
    181215            sage: K.class_number()
    182216            2
    183217
    184         The bound of course also works for the rational numbers:
     218        The bound of course also works for the rational numbers::
     219       
    185220            sage: QQ.minkowski_bound()
    186221            1
    187222        """
     
    208243
    209244        EXAMPLES:
    210245        We compute both the Minkowski and Bach bounds for a quadratic
    211         field, where the Minkowski bound is much better:
     246        field, where the Minkowski bound is much better::
     247       
    212248            sage: K = QQ[sqrt(5)]
    213249            sage: K.minkowski_bound()
    214250            1/2*sqrt(5)
     
    220256            31.0834847277628
    221257           
    222258        We compute both the Minkowski and Bach bounds for a bigger
    223         degree field, where the Bach bound is much better:
     259        degree field, where the Bach bound is much better::
     260       
    224261            sage: K = CyclotomicField(37)
    225262            sage: K.minkowski_bound().n()
    226263            7.50857335698544e14
    227264            sage: K.bach_bound().n()
    228265            191669.304126267
    229266
    230         The bound of course also works for the rational numbers:
     267        The bound of course also works for the rational numbers::
     268       
    231269            sage: QQ.minkowski_bound()
    232270            1
    233271        """
  • sage/rings/number_field/number_field_element.pyx

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field_element.pyx
    a b  
    176176        -a - 1
    177177    """
    178178    cpdef bint is_absolute(self):
    179         raise NotImplementedError  # exception will be ignored due to return type, so this can't be doctested.
     179        """
     180        EXAMPLES::
     181
     182            sage: A = sage.rings.number_field.number_field_element.NumberFieldElement(None)
     183            sage: A.is_absolute()
     184            False
     185        """
     186        raise NotImplementedError  # exception will be ignored due to return type, so this can't be reliably doctested.
    180187
    181188    cpdef bint is_order_element(self):
    182189        """
     
    363370        """
    364371        Return PARI C-library object corresponding to self.
    365372
    366         EXAMPLES::
     373        EXAMPLES:
    367374
    368375        Some examples involving absolute extensions::
    369376       
     
    637644    ####################################################
    638645    # First some boilerplate
    639646    def _richcmp_(left, right, int op):
     647        """
     648        Used to implement rich comparison, assuming left and right
     649        have the same parent.
     650
     651        EXAMPLES::
     652
     653            sage: K.<a> = NumberField(x^6 + 4*x^2 + 200); L.<b> = NumberField(x^2 + 1)
     654            sage: a == b
     655            False
     656            sage: a._richcmp_(b, 2)
     657            False
     658            sage: a != b
     659            True       
     660        """
    640661        if op == 2: return (<NumberFieldElement>left).cmp_eq(right)
    641662        elif op == 3: return not (<NumberFieldElement>left).cmp_eq(right)
    642663        return (<Element>left)._richcmp(right, op)
     664
    643665    # Derived classes should overload both of the following for optimal efficiency.
    644666    cdef int _cmp_c_impl(left, sage.structure.element.Element right) except -2:
    645667        return cmp(left.polynomial(), right.polynomial())
     668
    646669    cdef bint cmp_eq(left, right):
    647670        return left._cmp_c_impl(right) == 0
     671
    648672    # Derived classes that implement __hash__ !!! MUST !!! copy the following two lines!!!
    649673    def __richcmp__(left, right, int op):
    650674        return (<Element>left)._richcmp(right, op)
     
    15171541        """
    15181542        Return hash of this number field element, which is just the
    15191543        hash of the underlying polynomial.
     1544
     1545        EXAMPLES::
     1546
     1547            sage: K.<alpha> = NumberField(x^4 - x + 7); hash(alpha)
     1548            15360174650385711
     1549            sage: hash(alpha.polynomial())
     1550            15360174650385711
    15201551        """
    15211552        return hash(self.polynomial())
    15221553
     
    15311562          element written in terms of a generator.
    15321563       
    15331564        EXAMPLES:
     1565
     1566            sage: K.<alpha> = NumberField(x^4 - x + 7); hash(alpha)
     1567            15360174650385711
     1568
     1569        Note that the number of coefficients need not equal the degree of the extensions::
     1570       
     1571            sage: alpha._coefficients()
     1572            [0, 1]
     1573            sage: alpha.polynomial()
     1574            x
     1575            sage: f = (1+alpha)^3; f
     1576            alpha^3 + 3*alpha^2 + 3*alpha + 1
     1577            sage: f._coefficients()
     1578            [1, 3, 3, 1]
    15341579        """
    15351580        return self.polynomial().list()
    15361581       
  • sage/rings/number_field/number_field_element_ntl.pyx

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field_element_ntl.pyx
    a b  
    654654       
    655655        EXAMPLES:
    656656
    657         I'd love to, but since we are dealing with c-types, I
    658         can't at this level. Check __invert__ for doc-tests that rely
    659         on this functionality.
     657        I'd love to give examples, but since we are dealing with
     658        c-types, I can't at this level. Check __invert__ for doc-tests
     659        that rely on this functionality.
    660660        """
    661661        cdef ZZX_c t # unneeded except to be there
    662662        cdef ZZX_c a, b
  • sage/rings/number_field/number_field_ideal.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field_ideal.py
    a b  
    33
    44AUTHORS:
    55
    6 - Steven Sivek (2005-05-16)
    7 
    8 - William Stein (2007-09-06): vastly improved the doctesting   
    9 
    10 - William Stein and John Cremona (2007-01-28): new class
    11   NumberFieldFractionalIdeal now used for all except the 0 ideal
     6    - Steven Sivek (2005-05-16)
     7    - William Stein (2007-09-06): vastly improved the doctesting   
     8    - William Stein and John Cremona (2007-01-28): new class
     9      NumberFieldFractionalIdeal now used for all except the 0 ideal
    1210
    1311We test that pickling works::
    1412
     
    6967    converting from the order basis to the number field basis.
    7068
    7169    INPUT:
    72 
    73     -  ``field`` - a number field
    74 
    75     -   ``hnf`` - a pari HNF matrix, output by the pari_hnf() function.
     70        - ``field`` - a number field
     71        - ``hnf`` - a pari HNF matrix, output by the pari_hnf() function.
    7672
    7773    EXAMPLES::
    7874
     
    8480        [3, 0; 0, 1]
    8581        sage: convert_from_zk_basis(k, hnf)
    8682        [3, 1/2*x - 1/2]
    87    
    8883    """
    8984    return field.pari_nf().getattr('zk') * hnf
    9085
     
    9590    to a Sage ideal.
    9691   
    9792    INPUT:
    98    
    99     -  ``field`` - a number field
    100    
    101     -  ``ideal`` - a pari ideal, as output by the idealprimedec function
     93        - ``field`` - a number field
     94        - ``ideal`` - a pari ideal, as output by the idealprimedec function
    10295   
    10396    EXAMPLE::
    10497   
     
    123116    from a Sage ideal.
    124117
    125118    INPUT:
    126    
    127     -  ``field`` - a number field
    128    
    129     -  ``ideal`` - a prime ideal
     119        - ``field`` - a number field
     120        - ``ideal`` - a prime ideal
    130121
    131122    NOTE:
    132123   
     
    157148    def __init__(self, field, gens, coerce=True):
    158149        """
    159150        INPUT:
    160 
    161         -  ``field`` - a number field
    162 
    163         -   ``x`` - a list of NumberFieldElements belonging to the field
     151            - ``field`` - a number field
     152            - ``x`` - a list of NumberFieldElements belonging to the field
    164153
    165154        EXAMPLES::
    166155
     
    218207        Returns the coordinate vector of `x` with respect to this ideal.
    219208
    220209        INPUT:
    221             ``x`` -- an element of the number field (or ring of integers) of this ideal.
     210            - ``x`` -- an element of the number field (or ring of integers) of this ideal.
    222211
    223212        OUTPUT:
    224213            A vector of length `n` (the degree of the field) giving
     
    807796        ``proof=True`` (this is the default setting) to prove the correctness
    808797        of the output.
    809798
    810         EXAMPLES:
     799        EXAMPLES::
    811800
    812801            sage: K = QuadraticField(-119,'a')
    813802            sage: P = K.factor(2)[1][0]
     
    19351924
    19361925        ALGORITHM: Uses Pari function ``nfeltreduce``.
    19371926   
    1938         EXAMPLES:
    1939        
    1940         ::
     1927        EXAMPLES::
    19411928
    19421929            sage: k.<a> = NumberField(x^2 + 5)
    19431930            sage: I = k.ideal(a)
    19441931            sage: I.small_residue(14)
    19451932            -1
    1946 
    1947         ::
    1948 
    19491933            sage: K.<a> = NumberField(x^5 + 7*x^4 + 18*x^2 + x - 3)
    19501934            sage: I = K.ideal(5)
    19511935            sage: I.small_residue(a^2 -13)
     
    24272411    def __init__(self, K, M_OK_change, Q, I):
    24282412        """
    24292413        Initialize this QuotientMap.
     2414
     2415        EXAMPLES::
     2416
     2417            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2418            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2419            sage: phi = quotient_char_p(I, 5)[1]; phi       # indirect doctest
     2420            Partially defined quotient map from Number Field in i with defining polynomial x^2 + 1 to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=Fractional ideal (15).
     2421            sage: isinstance(phi, sage.rings.number_field.number_field_ideal.QuotientMap)
     2422            True
    24302423        """
    24312424        self.__M_OK_change = M_OK_change
    24322425        self.__Q = Q
     
    24392432        Apply this QuotientMap to an element of the number field.
    24402433
    24412434        INPUT:
    2442             x -- an element of the field
     2435            - `x` -- an element of the field
     2436
     2437        EXAMPLES::
     2438
     2439            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2440            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2441            sage: phi = quotient_char_p(I, 5)[1]; phi       # indirect doctest
     2442            Partially defined quotient map from Number Field in i with defining polynomial x^2 + 1 to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=Fractional ideal (15).
     2443            sage: phi(i)
     2444            (0, 1)
     2445            sage: phi(2-i)
     2446            (2, 4)
    24432447        """
    24442448        v = self.__to_L(x)
    24452449        w = v * self.__M_OK_change
     
    24482452    def __repr__(self):
    24492453        """
    24502454        Return a string representation of this QuotientMap.
     2455
     2456        EXAMPLES::
     2457
     2458            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2459            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2460            sage: quotient_char_p(I, 5)[1].__repr__()
     2461            'Partially defined quotient map from Number Field in i with defining polynomial x^2 + 1 to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=Fractional ideal (15).'
    24512462        """
    24522463        return "Partially defined quotient map from %s to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=%s."%(self.__K, self.__I)
    24532464   
     
    24592470    def __init__(self, OK, M_OK_map, Q, I):
    24602471        """
    24612472        Initialize this LiftMap.
     2473
     2474        EXAMPLES::
     2475
     2476            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2477            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2478            sage: lift = quotient_char_p(I, 5)[2]; lift
     2479            Lifting map to Maximal Order in Number Field in i with defining polynomial x^2 + 1 from quotient of integers by Fractional ideal (15)
    24622480        """
    24632481        self.__I = I
    24642482        self.__OK = OK
     
    24682486    def __call__(self, x):
    24692487        """
    24702488        Apply this LiftMap to an element of the residue field.
     2489
     2490        EXAMPLES::
     2491
     2492            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2493            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2494            sage: A = quotient_char_p(I, 5)
     2495            sage: A[0].0
     2496            (1, 0)
     2497            sage: A[2](A[0].0)
     2498            1
     2499            sage: A[2](A[0].1)
     2500            i
    24712501        """
    24722502        # This lifts to OK tensor F_p
    24732503        v = self.__Q.lift(x)
     
    24802510    def __repr__(self):
    24812511        """
    24822512        Return a string representation of this QuotientMap.
     2513
     2514        EXAMPLES::
     2515
     2516            sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
     2517            sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
     2518            sage: quotient_char_p(I, 5)[2].__repr__()
     2519            'Lifting map to Maximal Order in Number Field in i with defining polynomial x^2 + 1 from quotient of integers by Fractional ideal (15)'
    24832520        """
    24842521        return "Lifting map to %s from quotient of integers by %s"%(self.__OK, self.__I)
    24852522
     
    24922529    EXAMPLES::
    24932530
    24942531        sage: from sage.rings.number_field.number_field_ideal import quotient_char_p
    2495        
    24962532        sage: K.<i> = NumberField(x^2 + 1); O = K.maximal_order(); I = K.fractional_ideal(15)
    24972533        sage: quotient_char_p(I, 5)[0]
    24982534        Vector space quotient V/W of dimension 2 over Finite Field of size 5 where
  • sage/rings/number_field/number_field_ideal_rel.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/number_field_ideal_rel.py
    a b  
    9797
    9898            sage: K.<a, b> = NumberField([x^2 + 23, x^2 - 7])
    9999            sage: I = K.ideal(2, (a + 2*b + 3)/2)
    100             sage: [z in I for z in [a, b, 2, a + b]]
     100            sage: [z in I for z in [a, b, 2, a + b]]         # indirect doctest
    101101            [False, False, True, True]
    102102        """
    103103        abs_ideal = self.absolute_ideal()
     
    107107    def pari_rhnf(self):
    108108        """
    109109        Return PARI's representation of this relative ideal in Hermite
    110         normal form.       
     110        normal form.
     111
     112        EXAMPLES::
     113
     114            sage: K.<a, b> = NumberField([x^2 + 23, x^2 + 2]); K
     115            Number Field in a with defining polynomial x^2 + 23 over its base field
     116            sage: I = K.ideal([6, 6 + -1/2*a + b - 1/2])
     117            sage: I.pari_rhnf()
     118            [[[1, 0]~, [-6, 0]~; [0, 0]~, [1, 0]~], [[6, 2; 0, 1], [1/2, 0; 0, 1/2]]]
    111119        """
    112120        try:
    113121            return self.__pari_rhnf
     
    205213        return L.ideal(map(to_L, id.gens()))
    206214
    207215    def free_module(self):
     216        """
     217        Return the underlying free module over ZZ that defines this
     218        ideal, relative to the power basis of the number field.
     219
     220        EXAMPLES::
     221       
     222            sage: K.<a> = NumberField([x^2 + 1, x^2 + 2]); K
     223            Number Field in a0 with defining polynomial x^2 + 1 over its base field
     224            sage: I = K.ideal(38); I
     225            Fractional ideal (38)
     226            sage: I.free_module()
     227            Free module of degree 4 and rank 4 over Integer Ring
     228            User basis matrix:
     229            [   38     0     0     0]
     230            [-57/2 133/2 -19/2  19/2]
     231            [ 57/2 133/2  19/2  19/2]
     232            [    0   -95     0   -19]
     233        """
    208234        return self.absolute_ideal().free_module()
    209235
    210236    def gens_reduced(self):
     237        """
     238        Return reduced generators for this ideal.
     239
     240        EXAMPLES::
     241       
     242            sage: K.<a, b> = NumberField([x^2 + 23, x^2 + 2]); K
     243            Number Field in a with defining polynomial x^2 + 23 over its base field
     244            sage: I = K.ideal([6, 6 + -1/2*a + b - 1/2])
     245            sage: I.gens_reduced()
     246            (6, -1/2*a + b - 1/2)
     247        """
    211248        try:
    212249            ## Compute the single generator, if it exists           
    213250            dummy = self.is_principal()
     
    271308            return self.__is_principal
    272309
    273310    def is_zero(self):
     311        """
     312        Return 0 if this relative number field ideal is 0.
     313
     314        EXAMPLES::
     315       
     316            sage: K.<a, b> = NumberField([x^2 + 23, x^2 + 2]); K
     317            Number Field in a with defining polynomial x^2 + 23 over its base field
     318            sage: I = K.ideal([6, 6 + -1/2*a + b - 1/2])
     319            sage: I.is_zero()
     320            False
     321            sage: I = K.ideal(0)
     322            sage: I.is_zero()
     323            True
     324        """
    274325        zero = self.number_field().pari_rnf().rnfidealhnf(0)
    275326        return self.pari_rhnf() == zero
    276327
     
    328379
    329380    def norm(self):
    330381        """
    331         The norm of a fractional ideal in a relative number field is deliberately
    332         unimplemented, so that a user cannot mistake the absolute norm
    333         for the relative norm, or vice versa.
     382        The norm of a fractional ideal in a relative number field is
     383        deliberately unimplemented, so that a user cannot mistake the
     384        absolute norm for the relative norm, or vice versa.
     385
     386        EXAMPLES::
     387
     388            sage: K.<a, b> = NumberField([x^2 + 23, x^2 + 2]); K
     389            Number Field in a with defining polynomial x^2 + 23 over its base field
     390            sage: I = K.ideal([6, 6 + -1/2*a + b - 1/2])
     391            sage: I.norm()
     392            Traceback (most recent call last):
     393            ...
     394            NotImplementedError: For a fractional ideal in a relative number field you must use relative_norm or absolute_norm as appropriate
    334395        """
    335396        raise NotImplementedError, "For a fractional ideal in a relative number field you must use relative_norm or absolute_norm as appropriate"
    336397
     
    608669        is deliberately not implemented in order to avoid ambiguity.
    609670        Either ``relative_ramification_index`` or
    610671        ``absolute_ramification_index`` should be used instead.
     672
     673        EXAMPLES::
     674
     675            sage: K.<a, b> = NumberField([x^2 + 23, x^2 + 2]); K
     676            Number Field in a with defining polynomial x^2 + 23 over its base field
     677            sage: I = K.ideal([6, 6 + -1/2*a + b - 1/2])
     678            sage: I.ramification_index()
     679            Traceback (most recent call last):
     680            ...
     681            NotImplementedError: For an ideal in a relative number field you must use relative_ramification_index or absolute_ramification_index as appropriate
    611682        """
    612683        raise NotImplementedError, "For an ideal in a relative number field you must use relative_ramification_index or absolute_ramification_index as appropriate"
    613684
  • sage/rings/number_field/todo.txt

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/todo.txt
    a b  
    2222   [x] doctest existing code -- make ntl file use implementation='ntl' everywhere.
    2323   [x] _quadratic -- make sure datatype right in doctests there.
    2424   [x] cython arithmetic implementation object.
     25   [x] test stabilization
     26 
     27   [x] increase coverage a lot
    2528
    26    [ ] test stabilization
    27  
    2829   [ ] generic: get to work in the *relative case*
    2930
    3031   [ ] rewrite order elements to use implementation, e.g., this line in order.py:
     
    3738
    3839   [ ] move data out of elements into implementation objects for ntl and quadratic types
    3940
    40    [ ] increase coverage to 100%
    41 
    42 
    4341   [ ] fix all INPUT block list formatting
    4442
    4543   [ ] generic elements
  • sage/rings/number_field/totallyreal_rel.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/totallyreal_rel.py
    a b  
    33Enumeration of Totally Real Fields: Relative Extensions
    44
    55AUTHORS:
    6     -- John Voight (2007-11-03):
    7         * Initial version.
     6    - John Voight (2007-11-03): initial version.
     7    - William Stein (2010-07): cleaned up docstrings; improved coverage
    88"""
    99
    1010#***********************************************************************************************
     
    4242    to expand the bounds that define C by some epsilon.
    4343
    4444    INPUT:
    45 
    4645        - `K` -- a totally real number field
    47 
    4846        - `C` -- a list [[lower, upper], ...] of lower and upper bounds,
    4947                 for each embedding
    5048
    51 
    52     EXAMPLES:
     49    EXAMPLES::
    5350
    5451        sage: x = polygen(QQ)
    5552        sage: K.<alpha> = NumberField(x^2-2)
     
    174171        Initialization routine (constructor).
    175172
    176173        INPUT:
    177         F -- number field, the base field
    178         m -- integer, the relative degree
    179         B -- integer, the discriminant bound
    180         a -- list (default: []), the coefficient list to begin with, where
    181              a[len(a)]*x^n + ... + a[0]x^(n-len(a))
     174            - F -- number field, the base field
     175            - m -- integer, the relative degree
     176            - B -- integer, the discriminant bound
     177            - a -- list (default: []), the coefficient list to begin with, where
     178                   a[len(a)]*x^n + ... + a[0]x^(n-len(a))
    182179
    183180        OUTPUT:
    184181        the data initialized to begin enumeration of totally real fields
    185182        with base field F, degree n, discriminant bounded by B, and starting
    186183        with coefficients a.
    187184
    188         EXAMPLES:
     185        EXAMPLES::
     186       
    189187            sage: F.<t> = NumberField(x^2-2)
    190188            sage: T = sage.rings.number_field.totallyreal_rel.tr_data_rel(F, 2, 2000)
    191189        """
     
    295293        polynomial.
    296294 
    297295        INPUT:
    298             f_out -- an integer sequence, to be written with the
    299                      coefficients of the next polynomial
    300             verbose -- boolean to print verbosely computational details
    301             haltk -- integer, the level at which to halt the inductive
    302                      coefficient bounds
     296            - f_out -- an integer sequence, to be written with the
     297              coefficients of the next polynomial
     298            - verbose -- boolean to print verbosely computational details
     299            - haltk -- integer, the level at which to halt the inductive
     300              coefficient bounds
    303301
    304302        OUTPUT:
    305         the successor polynomial as a coefficient list.
     303            the successor polynomial as a coefficient list.
    306304        """
    307305
    308306        import numpy
     
    579577    seems in practice to give many imprimitive ones.
    580578
    581579    INPUT:
    582     F -- number field, the base field
    583     m -- integer, the degree
    584     B -- integer, the discriminant bound
    585     a -- list (default: []), the coefficient list to begin with
    586     verbose -- boolean or string (default: 0)
    587     return_seqs -- boolean (default: False)
     580        - F -- number field, the base field
     581        - m -- integer, the degree
     582        - B -- integer, the discriminant bound
     583        - a -- list (default: []), the coefficient list to begin with
     584        - ``verbose`` -- boolean or string (default: 0)
     585        - ``return_seqs`` -- boolean (default: False)
    588586
    589587    OUTPUT:
     588
    590589    the list of fields with entries [d,fabs,f], where
    591590      d is the discriminant, fabs is an absolute defining polynomial,
    592591      and f is a defining polynomial relative to F,
    593592    sorted by discriminant.
    594593
    595594    EXAMPLES:
     595
    596596    In this first simple example, we compute the totally real quadratic
    597     fields of Q(sqrt(2)) of discriminant <= 2000.
     597    fields of Q(sqrt(2)) of discriminant <= 2000::
    598598
    599     sage: ZZx = ZZ['x']
    600     sage: F.<t> = NumberField(x^2-2)
    601     sage: enumerate_totallyreal_fields_rel(F, 2, 2000)
    602     [[1600, x^4 - 6*x^2 + 4, xF^2 + xF - 1]]
     599        sage: ZZx = ZZ['x']
     600        sage: F.<t> = NumberField(x^2-2)
     601        sage: enumerate_totallyreal_fields_rel(F, 2, 2000)
     602        [[1600, x^4 - 6*x^2 + 4, xF^2 + xF - 1]]
    603603
    604604    There is indeed only one such extension, given by F(sqrt(5)).
    605605
    606606    Next, we list all totally real quadratic extensions of Q(sqrt(5))
    607     with root discriminant <= 10.
     607    with root discriminant <= 10::
    608608
    609     sage: F.<t> = NumberField(x^2-5)
    610     sage: ls = enumerate_totallyreal_fields_rel(F, 2, 10^4)
    611     sage: ls # random (the second factor is platform-dependent)
    612     [[725, x^4 - x^3 - 3*x^2 + x + 1, xF^2 + (-1/2*t - 7/2)*xF + 1],
    613      [1125, x^4 - x^3 - 4*x^2 + 4*x + 1, xF^2 + (-1/2*t - 7/2)*xF + 1/2*t + 3/2],
    614      [1600, x^4 - 6*x^2 + 4, xF^2 - 2],
    615      [2000, x^4 - 5*x^2 + 5, xF^2 - 1/2*t - 5/2],
    616      [2225, x^4 - x^3 - 5*x^2 + 2*x + 4, xF^2 + (-1/2*t + 1/2)*xF - 3/2*t - 7/2],
    617      [2525, x^4 - 2*x^3 - 4*x^2 + 5*x + 5, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 5/2],
    618      [3600, x^4 - 2*x^3 - 7*x^2 + 8*x + 1, xF^2 - 3],
    619      [4225, x^4 - 9*x^2 + 4, xF^2 + (-1/2*t - 1/2)*xF - 3/2*t - 9/2],
    620      [4400, x^4 - 7*x^2 + 11, xF^2 - 1/2*t - 7/2],
    621      [4525, x^4 - x^3 - 7*x^2 + 3*x + 9, xF^2 + (-1/2*t - 1/2)*xF - 3],
    622      [5125, x^4 - 2*x^3 - 6*x^2 + 7*x + 11, xF^2 + (-1/2*t - 1/2)*xF - t - 4],
    623      [5225, x^4 - x^3 - 8*x^2 + x + 11, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 7/2],
    624      [5725, x^4 - x^3 - 8*x^2 + 6*x + 11, xF^2 + (-1/2*t + 1/2)*xF - 1/2*t - 7/2],
    625      [6125, x^4 - x^3 - 9*x^2 + 9*x + 11, xF^2 + (-1/2*t + 1/2)*xF - t - 4],
    626      [7225, x^4 - 11*x^2 + 9, xF^2 + (-1)*xF - 4],
    627      [7600, x^4 - 9*x^2 + 19, xF^2 - 1/2*t - 9/2],
    628      [7625, x^4 - x^3 - 9*x^2 + 4*x + 16, xF^2 + (-1/2*t - 1/2)*xF - 4],
    629      [8000, x^4 - 10*x^2 + 20, xF^2 - t - 5],
    630      [8525, x^4 - 2*x^3 - 8*x^2 + 9*x + 19, xF^2 + (-1)*xF - 1/2*t - 9/2],
    631      [8725, x^4 - x^3 - 10*x^2 + 2*x + 19, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 9/2],
    632      [9225, x^4 - x^3 - 10*x^2 + 7*x + 19, xF^2 + (-1/2*t + 1/2)*xF - 1/2*t - 9/2]]
    633     sage: [ f[0] for f in ls ]
    634     [725, 1125, 1600, 2000, 2225, 2525, 3600, 4225, 4400, 4525, 5125, 5225, 5725, 6125, 7225, 7600, 7625, 8000, 8525, 8725, 9225]
    635      
    636     sage: [NumberField(ZZx(x[1]), 't').is_galois() for x in ls]
    637     [False, True, True, True, False, False, True, True, False, False, False, False, False, True, True, False, False, True, False, False, False]   
     609        sage: F.<t> = NumberField(x^2-5)
     610        sage: ls = enumerate_totallyreal_fields_rel(F, 2, 10^4)
     611        sage: ls # random (the second factor is platform-dependent)
     612        [[725, x^4 - x^3 - 3*x^2 + x + 1, xF^2 + (-1/2*t - 7/2)*xF + 1],
     613         [1125, x^4 - x^3 - 4*x^2 + 4*x + 1, xF^2 + (-1/2*t - 7/2)*xF + 1/2*t + 3/2],
     614         [1600, x^4 - 6*x^2 + 4, xF^2 - 2],
     615         [2000, x^4 - 5*x^2 + 5, xF^2 - 1/2*t - 5/2],
     616         [2225, x^4 - x^3 - 5*x^2 + 2*x + 4, xF^2 + (-1/2*t + 1/2)*xF - 3/2*t - 7/2],
     617         [2525, x^4 - 2*x^3 - 4*x^2 + 5*x + 5, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 5/2],
     618         [3600, x^4 - 2*x^3 - 7*x^2 + 8*x + 1, xF^2 - 3],
     619         [4225, x^4 - 9*x^2 + 4, xF^2 + (-1/2*t - 1/2)*xF - 3/2*t - 9/2],
     620         [4400, x^4 - 7*x^2 + 11, xF^2 - 1/2*t - 7/2],
     621         [4525, x^4 - x^3 - 7*x^2 + 3*x + 9, xF^2 + (-1/2*t - 1/2)*xF - 3],
     622         [5125, x^4 - 2*x^3 - 6*x^2 + 7*x + 11, xF^2 + (-1/2*t - 1/2)*xF - t - 4],
     623         [5225, x^4 - x^3 - 8*x^2 + x + 11, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 7/2],
     624         [5725, x^4 - x^3 - 8*x^2 + 6*x + 11, xF^2 + (-1/2*t + 1/2)*xF - 1/2*t - 7/2],
     625         [6125, x^4 - x^3 - 9*x^2 + 9*x + 11, xF^2 + (-1/2*t + 1/2)*xF - t - 4],
     626         [7225, x^4 - 11*x^2 + 9, xF^2 + (-1)*xF - 4],
     627         [7600, x^4 - 9*x^2 + 19, xF^2 - 1/2*t - 9/2],
     628         [7625, x^4 - x^3 - 9*x^2 + 4*x + 16, xF^2 + (-1/2*t - 1/2)*xF - 4],
     629         [8000, x^4 - 10*x^2 + 20, xF^2 - t - 5],
     630         [8525, x^4 - 2*x^3 - 8*x^2 + 9*x + 19, xF^2 + (-1)*xF - 1/2*t - 9/2],
     631         [8725, x^4 - x^3 - 10*x^2 + 2*x + 19, xF^2 + (-1/2*t - 1/2)*xF - 1/2*t - 9/2],
     632         [9225, x^4 - x^3 - 10*x^2 + 7*x + 19, xF^2 + (-1/2*t + 1/2)*xF - 1/2*t - 9/2]]
     633        sage: [ f[0] for f in ls ]
     634        [725, 1125, 1600, 2000, 2225, 2525, 3600, 4225, 4400, 4525, 5125, 5225, 5725, 6125, 7225, 7600, 7625, 8000, 8525, 8725, 9225]
     635
     636        sage: [NumberField(ZZx(x[1]), 't').is_galois() for x in ls]
     637        [False, True, True, True, False, False, True, True, False, False, False, False, False, True, True, False, False, True, False, False, False]   
    638638
    639639    Eight out of 21 such fields are Galois (with Galois group Z/4Z
    640640    or Z/2Z + Z/2Z); the others have have Galois closure of degree 8
    641641    (with Galois group D_8).
    642642
    643643    Finally, we compute the cubic extensions of Q(zeta_7)^+ with
    644     discriminant <= 17*10^9.
     644    discriminant <= 17*10^9::
    645645
    646     sage: F.<t> = NumberField(ZZx([1,-4,3,1]))
    647     sage: F.disc()
    648     49
    649     sage: enumerate_totallyreal_fields_rel(F, 3, 17*10^9) # not tested
    650     [[16240385609L, x^9 - x^8 - 9*x^7 + 4*x^6 + 26*x^5 - 2*x^4 - 25*x^3 - x^2 + 7*x + 1, xF^3 + (-t^2 - 4*t + 1)*xF^2 + (t^2 + 3*t - 5)*xF + 3*t^2 + 11*t - 5]]    # 32 bit
    651     [[16240385609, x^9 - x^8 - 9*x^7 + 4*x^6 + 26*x^5 - 2*x^4 - 25*x^3 - x^2 + 7*x + 1, xF^3 + (-t^2 - 4*t + 1)*xF^2 + (t^2 + 3*t - 5)*xF + 3*t^2 + 11*t - 5]]    # 64 bit
     646        sage: F.<t> = NumberField(ZZx([1,-4,3,1]))
     647        sage: F.disc()
     648        49
     649        sage: enumerate_totallyreal_fields_rel(F, 3, 17*10^9) # not tested
     650        [[16240385609L, x^9 - x^8 - 9*x^7 + 4*x^6 + 26*x^5 - 2*x^4 - 25*x^3 - x^2 + 7*x + 1, xF^3 + (-t^2 - 4*t + 1)*xF^2 + (t^2 + 3*t - 5)*xF + 3*t^2 + 11*t - 5]]    # 32 bit
     651        [[16240385609, x^9 - x^8 - 9*x^7 + 4*x^6 + 26*x^5 - 2*x^4 - 25*x^3 - x^2 + 7*x + 1, xF^3 + (-t^2 - 4*t + 1)*xF^2 + (t^2 + 3*t - 5)*xF + 3*t^2 + 11*t - 5]]    # 64 bit
    652652
    653653    NOTES:
    654654    We enumerate polynomials
  • sage/rings/number_field/unit_group.py

    diff -r d582c0c29177 -r d5abbca52e14 sage/rings/number_field/unit_group.py
    a b  
    218218
    219219        EXAMPLES::
    220220
    221             sage: x = polygen(QQ)
    222221            sage: K.<a> = NumberField(x^2-38)
    223222            sage: UK = UnitGroup(K)
    224223            sage: UK(1)
     
    258257        Canonical coercion of ``x`` into this unit group.
    259258
    260259        EXAMPLES:
    261        
     260
     261            sage: K.<a> = NumberField(x^2-38)
     262            sage: UK = UnitGroup(K)
     263            sage: UK(6*a-37)              # indirect test
     264            u1
    262265        """
    263266        return self(x)
    264267