Ticket #9764: 9764_ideal_repr.patch

File 9764_ideal_repr.patch, 17.5 KB (added by Jeroen Demeyer, 12 years ago)

Patch against sage-4.5.3.alpha0

  • sage/modular/cusps_nf.py

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1282168698 -7200
    # Node ID cd0835fd8db85d7335abd80b8190e5492d99cf76
    # Parent  2b8baef774a4d70701460f3126f816a83b25778f
    [mq]: 9400_ideal_repr
    
    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/modular/cusps_nf.py
    a b  
    140140        sage: N = k.ideal(713, a + 208)
    141141        sage: L = list_of_representatives(N); L
    142142        (Fractional ideal (1),
    143         Fractional ideal (37, a + 12),
    144         Fractional ideal (47, a - 9))
     143        Fractional ideal (a + 12, 37),
     144        Fractional ideal (a - 9, 47))
    145145
    146146    The output of ``list_of_representatives`` has been cached:
    147147
     
    151151        [Fractional ideal (713, a + 208)]
    152152        sage: sage.modular.cusps_nf._list_reprs_cache[N]
    153153        (Fractional ideal (1),
    154         Fractional ideal (37, a + 12),
    155         Fractional ideal (47, a - 9))
     154        Fractional ideal (a + 12, 37),
     155        Fractional ideal (a - 9, 47))
    156156    """
    157157    if _list_reprs_cache.has_key(N):
    158158        lreps = _list_reprs_cache[N]
     
    12911291    from sage.misc.mrange import xmrange
    12921292    from sage.misc.misc import prod
    12931293
    1294     return [prod([u**e for u,e in zip(ulist,ei)],k(1)) for ei in xmrange(elist)]
    1295  No newline at end of file
     1294    return [prod([u**e for u,e in zip(ulist,ei)],k(1)) for ei in xmrange(elist)]
  • sage/rings/number_field/class_group.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/number_field/class_group.py
    a b  
    162162            sage: G
    163163            Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^4 + 23
    164164            sage: list(G)
    165             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 32-bit
    166             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 - a + 3/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 64-bit
     165            [Trivial principal fractional ideal class, Fractional ideal class (a + 1, 1/4*a^3 + 1/4*a^2 + 1/4*a + 1/4, 2, 1/2*a^2 + 1/2), Fractional ideal class (1/4*a^3 + 1/4*a^2 + 5/4*a + 5/4, 2, 2*a, 1/2*a^2 + 1/2)]           
    167166            sage: G.list()
    168             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 + a - 1/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 32-bit
    169             [Trivial principal fractional ideal class, Fractional ideal class (2, 1/2*a^2 - a + 3/2), Fractional ideal class (2, 1/2*a^2 + 1/2)] # 64-bit
     167            [Trivial principal fractional ideal class, Fractional ideal class (a + 1, 1/4*a^3 + 1/4*a^2 + 1/4*a + 1/4, 2, 1/2*a^2 + 1/2), Fractional ideal class (1/4*a^3 + 1/4*a^2 + 5/4*a + 5/4, 2, 2*a, 1/2*a^2 + 1/2)]
    170168
    171169        TESTS::
    172170
  • sage/rings/number_field/number_field.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/number_field/number_field.py
    a b  
    43414341            sage: K.<a> = NumberField(x^4+3*x^2-17)
    43424342            sage: P = K.ideal(61).factor()[0][0]
    43434343            sage: K.residue_field(P)
    4344             Residue field in abar of Fractional ideal (-2*a^2 + 1)
     4344            Residue field in abar of Fractional ideal (a^2 + 30, 61)
    43454345       
    43464346        ::
    43474347       
     
    43554355            sage: L.residue_field(P)
    43564356            Traceback (most recent call last):
    43574357            ...
    4358             ValueError: Fractional ideal (-2*a^2 + 1) is not an ideal of Number Field in b with defining polynomial x^2 + 5
     4358            ValueError: Fractional ideal (a^2 + 30, 61) is not an ideal of Number Field in b with defining polynomial x^2 + 5
    43594359            sage: L.residue_field(2)
    43604360            Traceback (most recent call last):
    43614361            ...
  • sage/rings/number_field/number_field_ideal.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/number_field/number_field_ideal.py
    a b  
    3636#                  http://www.gnu.org/licenses/
    3737#*****************************************************************************
    3838
     39SMALL_DISC = 1000000
     40
    3941import operator
    4042
    4143import sage.misc.latex as latex
     
    178180        if len(gens)==0:
    179181            raise ValueError, "gens must have length at least 1 (zero ideal is not a fractional ideal)"
    180182        Ideal_generic.__init__(self, field, gens, coerce)
     183
     184    def __hash__(self):
     185        """
     186        EXAMPLES::
     187
     188            sage: NumberField(x^2 + 1, 'a').ideal(7).__hash__()
     189            7225361069995395753                  # 64-bit
     190            -1895626071                          # 32-bit
     191        """
     192        try: return self._hash
     193        # At some point in the future (e.g., for relative extensions), we'll likely
     194        # have to consider other hashes, like the following.
     195        #except AttributeError: self._hash = hash(self.gens())
     196        except AttributeError: self._hash = self.pari_hnf().__hash__()
     197        return self._hash
    181198       
    182199    def _latex_(self):
    183200        """
     
    188205            '\\left(2, \\frac{1}{2} a - \\frac{1}{2}\\right)'
    189206            sage: latex(K.ideal([2, 1/2*a - 1/2]))
    190207            \left(2, \frac{1}{2} a - \frac{1}{2}\right)
     208
     209        The gens are reduced only if the norm of the discriminant of
     210        the defining polynomial is at most
     211        sage.rings.number_field.number_field_ideal.SMALL_DISC::
     212
     213            sage: K.<a> = NumberField(x^2 + 902384092834); K
     214            Number Field in a with defining polynomial x^2 + 902384092834
     215            sage: I = K.factor(19)[0][0]; I._latex_()
     216            '\\left(19\\right)'
     217
     218        We can make the generators reduced by increasing SMALL_DISC.
     219        We had better also set proof to False, or computing reduced
     220        gens could take too long::
     221       
     222            sage: proof.number_field(False)
     223            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC = 10^20
     224            sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
     225            sage: K.ideal([17*a,17,17,17*a])._latex_()
     226            '\\left(17\\right)'
    191227        """
    192         return '\\left(%s\\right)'%(", ".join(map(latex.latex, self.gens_reduced())))
     228        return '\\left(%s\\right)'%(", ".join(map(latex.latex, self._gens_repr())))
    193229       
    194230    def __cmp__(self, other):
    195231        """
     
    363399
    364400    def _repr_short(self):
    365401        """
    366         Efficient string representation of this fraction ideal.
     402        Compact string representation of this fraction ideal.  When
     403        the norm of the discriminant of the defining polynomial of the
     404        number field is less than
     405
     406            sage.rings.number_field.number_field_ideal.SMALL_DISC
     407           
     408        then display reduced generators.  Otherwise just display generators.
    367409
    368410        EXAMPLES::
    369411
     
    372414            sage: I = K.factor(17)[0][0]; I
    373415            Fractional ideal (17, a^2 - 6)
    374416            sage: I._repr_short()
    375             '(17, a^2 - 6)'       
     417            '(17, a^2 - 6)'
     418
     419        We use reduced gens, because the discriminant is small::
     420       
     421            sage: K.<a> = NumberField(x^2 + 17); K
     422            Number Field in a with defining polynomial x^2 + 17
     423            sage: I = K.factor(17)[0][0]; I
     424            Fractional ideal (a)
     425
     426        Here the discriminant is 'large', so the gens aren't reduced::
     427
     428            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC
     429            1000000
     430            sage: K.<a> = NumberField(x^2 + 902384094); K
     431            Number Field in a with defining polynomial x^2 + 902384094
     432            sage: I = K.factor(19)[0][0]; I
     433            Fractional ideal (19, a + 14)
     434            sage: I.gens_reduced()                 # long time
     435            (19, a - 5)
    376436        """
    377         #NOTE -- we will *have* to not reduce the gens soon, since this
    378         # makes things insanely slow in general.
    379         # When I fix this, I *have* to also change the _latex_ method.
    380         return '(%s)'%(', '.join(map(str, self.gens_reduced())))
    381 #         return '(%s)'%(', '.join(map(str, self.gens())))
     437        return '(%s)'%(', '.join(map(str, self._gens_repr())))
     438
     439    def _gens_repr(self):
     440        """
     441        Returns tuple of generators to be used for printing this
     442        number field idea.  The gens are reduced only if the absolute
     443        value of the norm of the discriminant of the defining
     444        polynomial is at most
     445        sage.rings.number_field.number_field_ideal.SMALL_DISC.
     446       
     447        EXAMPLES::
     448
     449            sage: sage.rings.number_field.number_field_ideal.SMALL_DISC
     450            1000000
     451           
     452           
     453            sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
     454            sage: K.discriminant()  # too big
     455            -1612688
     456            sage: I = K.ideal([17*a,17,17,17*a]); I._gens_repr()
     457            (17, 17*a)
     458            sage: I.gens_reduced()
     459            (17,)
     460        """
     461        # Small discriminant is easy to find nice gens -- otherwise it
     462        # is potentially very hard
     463        try:
     464            if abs(self.number_field().defining_polynomial().discriminant().norm()) <= SMALL_DISC:
     465                return self.gens_reduced()
     466        except TypeError:
     467            # In some cases with relative extensions, computing the
     468            # discriminant of the defining polynomial is not
     469            # supported.
     470            pass
     471        # Return unique sorted generators.  This eliminates the common case
     472        # where self.gens() is something like (17, 17), which looks silly.
     473        return tuple(sorted(set(self.gens())))
     474       
    382475
    383476    def _pari_(self):
    384477        """
     
    12941387            sage: K.<a> = CyclotomicField(11); K
    12951388            Cyclotomic Field of order 11 and degree 10
    12961389            sage: I = K.factor(31)[0][0]; I
    1297             Fractional ideal (-3*a^7 - 4*a^5 - 3*a^4 - 3*a^2 - 3*a - 3)
     1390            Fractional ideal (a^5 + 10*a^4 - a^3 + a^2 + 9*a - 1, 31)
    12981391            sage: I.divides(I)
    12991392            True
    13001393            sage: I.divides(31)
     
    13171410            sage: I = K.ideal(19); I
    13181411            Fractional ideal (19)
    13191412            sage: F = I.factor(); F
    1320             (Fractional ideal (a^2 + 2*a + 2)) * (Fractional ideal (a^2 - 2*a + 2))
     1413            (Fractional ideal (a^2 + 2*a + 2, 19)) * (Fractional ideal (19, a^2 - 2*a + 2))           
    13211414            sage: type(F)
    13221415            <class 'sage.structure.factorization.Factorization'>
    13231416            sage: list(F)
    1324             [(Fractional ideal (a^2 + 2*a + 2), 1), (Fractional ideal (a^2 - 2*a + 2), 1)]
     1417            [(Fractional ideal (a^2 + 2*a + 2, 19), 1), (Fractional ideal (19, a^2 - 2*a + 2), 1)]
    13251418            sage: F.prod()
    1326             Fractional ideal (19)
     1419            Fractional ideal (19*a^2 + 38*a + 38, 361, 19*a^2 - 38*a + 38, -19)
    13271420        """
    13281421        try:
    13291422            return self.__factorization
  • sage/rings/number_field/order.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/number_field/order.py
    a b  
    673673            sage: P = K.ideal(61).factor()[0][0]
    674674            sage: OK = K.maximal_order()
    675675            sage: OK.residue_field(P)
    676             Residue field in abar of Fractional ideal (-2*a^2 + 1)
     676            Residue field in abar of Fractional ideal (a^2 + 30, 61)
    677677        """
    678678        if self.is_maximal():
    679679            return self.number_field().residue_field(prime, name, check)
  • sage/rings/number_field/small_primes_of_degree_one.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/number_field/small_primes_of_degree_one.py
    a b  
    4646EXAMPLES::
    4747
    4848    sage: x = ZZ['x'].gen()
    49     sage: F.<a> = NumberField(x^2 - 2, 'a')
     49    sage: F.<a> = NumberField(x^2 - 2)
    5050    sage: Ps = F.primes_of_degree_one_list(3)
    5151    sage: Ps # random
    5252    [Fractional ideal (2*a + 1), Fractional ideal (-3*a + 1), Fractional ideal (-a + 5)]
     
    5959
    6060The next two examples are for relative number fields.::
    6161
    62     sage: L.<b> = F.extension(x^3 - a, 'b')
     62    sage: L.<b> = F.extension(x^3 - a)
    6363    sage: Ps = L.primes_of_degree_one_list(3)
    6464    sage: Ps # random
    6565    [Fractional ideal (17, b - 5), Fractional ideal (23, b - 4), Fractional ideal (31, b - 2)]
     
    6969    True
    7070    sage: all(P.residue_class_degree() == 1 for P in Ps)
    7171    True
    72     sage: M.<c> = NumberField(x^2 - x*b^2 + b, 'c')
     72    sage: M.<c> = NumberField(x^2 - x*b^2 + b)
    7373    sage: Ps = M.primes_of_degree_one_list(3)
    7474    sage: Ps # random
    7575    [Fractional ideal (17, c - 2), Fractional ideal (c - 1), Fractional ideal (41, c + 15)]
  • sage/rings/polynomial/polynomial_quotient_ring.py

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/polynomial/polynomial_quotient_ring.py
    a b  
    888888             ((...1/3*a - 1)*b^2 + ...*b + ...*a + ..., +Infinity),
    889889             ((...1/3*a + 1)*b^2 ...*b ...*a ..., +Infinity)]
    890890            sage: L.S_units([K.ideal(1/2*a - 3/2)])
    891             [((...1/6*a - 1/2)*b^2 + (...1/3*a + 1)*b ... 2/3*a - 2, +Infinity),
    892              (-1/2*a + 1/2, 6),
    893              ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity),
    894              ((...1/3*a ... 1)*b^2 + (...2/3*a - 2)*b + ...*a + ..., +Infinity)]
     891            [(1/3*a*b^2 - 2/3*a*b + 4/3*a, +Infinity), (-1/2*a + 1/2, 6),
     892             ((-1/3*a - 1)*b^2 + (2/3*a - 2)*b + 13/6*a + 1/2, +Infinity),
     893             ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]
    895894            sage: L.S_units([K.ideal(2)])
    896             [((...*a ... 1/2)*b^2 + (...a ... 1)*b + ...*a ... 3/2, +Infinity),
     895            [((-1/2*a - 1/2)*b^2 + (a + 1)*b - 3/2*a - 3/2, +Infinity),
    897896             ((1/6*a + 1/2)*b^2 + (-1/3*a - 1)*b + 1/6*a + 3/2, +Infinity),
    898              ((...*a + 1/2)*b^2 + (...a - 1)*b ...*a + ..., +Infinity),
    899              (-1/2*a + 1/2, 6),
    900              ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity),
    901              ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]   
     897             ((1/6*a + 1/2)*b^2 + (-1/3*a - 1)*b + 2/3*a + 1, +Infinity),
     898              (-1/2*a + 1/2, 6), ((-1/3*a - 1)*b^2 + (2/3*a - 2)*b + 13/6*a + 1/2, +Infinity),
     899              ((-1/3*a + 1)*b^2 - 4/3*a*b - 4/3*a - 3, +Infinity)]
    902900
    903901        Note that all the returned values live where we expect them to::
    904902       
     
    948946            sage: L.<b> = K['y'].quotient(y^3 + 5); L
    949947            Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with modulus y^3 + 5
    950948            sage: L.units()
    951             [(-1/2*a + 1/2, 6),
    952              ((...1/3*a - 1)*b^2 + ...*b + ...*a + ..., +Infinity),
     949            [(-1/2*a + 1/2, 6), (2/3*a*b^2 + (2/3*a + 2)*b - 4/3*a + 3, +Infinity),
    953950             ((-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2, +Infinity)]
    954951            sage: L.<b> = K.extension(y^3 + 5)
    955952            sage: L.unit_group()
    956953            Unit group with structure C6 x Z x Z of Number Field in b with defining polynomial x^3 + 5 over its base field
    957954            sage: L.unit_group().gens()
    958             [-1/2*a + 1/2,
    959              (...1/3*a - 1)*b^2 + ...*b + ...*a + ...,
    960              (-1/3*a + 1)*b^2 + (2/3*a - 2)*b - 5/6*a + 7/2]
     955            [-1/2*a + 1/2, (1/3*a + 1)*b^2 + (-2/3*a - 2)*b + 4/3*a + 3,
     956             (1/3*a + 1)*b^2 + (-2/3*a - 2)*b + 5/6*a + 7/2]
    961957
    962958        Note that all the returned values live where we expect them to::
    963959       
     
    11391135            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1)], 3)
    11401136            [2, -a - 1]
    11411137            sage: D.selmer_group([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3)
    1142             [2, -a - 1, -a]
     1138            [2, -a - 1, a]
    11431139
    11441140        """
    11451141        units, clgp_gens = self._S_class_group_and_units(tuple(S), proof=proof)
  • sage/rings/residue_field.pyx

    diff -r 2b8baef774a4 -r cd0835fd8db8 sage/rings/residue_field.pyx
    a b  
    6868    sage: R.<X, Y> = PolynomialRing(Rf)
    6969    sage: ubar = Rf(u)
    7070    sage: I = ideal([ubar*X + Y]); I
    71     Ideal ((ubar)*X + Y) of Multivariate Polynomial Ring in X, Y over Residue field in ubar of Fractional ideal (47, 517/55860*u^5 + 235/3724*u^4 + 9829/13965*u^3 + 54106/13965*u^2 + 64517/27930*u + 755696/13965)
     71    Ideal ((ubar)*X + Y) of Multivariate Polynomial Ring in X, Y over Residue field in ubar of Fractional ideal (u^3 - 22*u^2 - 9*u + 5, 47)
    7272    sage: I.groebner_basis()
    7373    [X + (-19*ubar^2 - 5*ubar - 17)*Y]
    7474
     
    163163   
    164164        sage: K.<a> = NumberField(x^3-875)
    165165        sage: P = K.ideal(5).factor()[0][0]; k = K.residue_field(P); k
    166         Residue field in abar of Fractional ideal (5, -2/25*a^2 - 1/5*a + 2)
     166        Residue field in abar of Fractional ideal (-2/25*a^2 - 1/5*a + 2, 5)
    167167        sage: k.polynomial()
    168168        abar^2 + 3*abar + 4
    169169        sage: k.0^3 - 875
     
    172172    An example where the residue class field is large but of degree 1::
    173173   
    174174        sage: K.<a> = NumberField(x^3-875); P = K.ideal(2007).factor()[0][0]; k = K.residue_field(P); k
    175         Residue field of Fractional ideal (-2/25*a^2 - 2/5*a - 3)
     175        Residue field of Fractional ideal (a + 55, 223)
    176176        sage: k(a)
    177177        168
    178178        sage: k(a)^3 - 875