Changeset 7508:0e1318c724ad


Ignore:
Timestamp:
12/02/07 12:17:20 (5 years ago)
Author:
mabshoff@…
Branch:
default
Parents:
7505:2a3f3513a11b (diff), 7507:de39c2037850 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge

Location:
sage/rings
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/number_field/number_field.py

    r7478 r7508  
    13561356            return False 
    13571357 
    1358     def pari_polynomial(self): 
     1358    def pari_polynomial(self, name='x'): 
    13591359        """ 
    13601360        PARI polynomial corresponding to polynomial that defines 
    1361         this field.   This is always a polynomial in the variable "x". 
     1361        this field. By default, this is a polynomial in the 
     1362        variable "x". 
    13621363 
    13631364        EXAMPLES: 
     
    13651366            sage: k.<a> = NumberField(y^2 - 3/2*y + 5/3) 
    13661367            sage: k.pari_polynomial() 
    1367             x^2 - 3/2*x + 5/3         
     1368            x^2 - 3/2*x + 5/3 
     1369            sage: k.pari_polynomial('a') 
     1370            a^2 - 3/2*a + 5/3 
    13681371        """ 
    13691372        try: 
    1370             return self.__pari_polynomial 
     1373            if (self.__pari_polynomial_var == name): 
     1374                return self.__pari_polynomial 
     1375            else: 
     1376                self.__pari_polynomial = self.__pari_polynomial(name) 
     1377                self.__pari_polynomial_var = name 
     1378                return self.__pari_polynomial 
    13711379        except AttributeError: 
    13721380            poly = self.polynomial() 
    1373             with localvars(poly.parent(), 'x'): 
     1381            with localvars(poly.parent(), name): 
    13741382                self.__pari_polynomial = poly._pari_() 
     1383                self.__pari_polynomial_var = name 
    13751384            return self.__pari_polynomial 
    13761385 
  • sage/rings/number_field/number_field.py

    r7506 r7508  
    21182118        """ 
    21192119        return infinity.infinity 
    2120          
     2120 
    21212121    def polynomial_ntl(self): 
    21222122        """ 
     
    22272227        return self.__regulator 
    22282228 
    2229     def residue_field(self, prime, name = None, check = False): 
     2229    def residue_field(self, prime, names = None, check = False): 
    22302230        """ 
    22312231        Return the residue field of this number field at a given prime, ie $O_K / p O_K$. 
     
    22332233        INPUT: 
    22342234            prime -- a prime ideal of the maximal order in this number field. 
    2235             name -- the name of the variable in the residue field 
     2235            names -- the name of the variable in the residue field 
    22362236            check -- whether or not to check the primality of prime. 
    22372237        OUTPUT: 
     
    22432243        sage: P = K.ideal(61).factor()[0][0] 
    22442244        sage: K.residue_field(P) 
    2245         Residue field of Fractional ideal (-2*a^2 + 1) 
     2245        Residue field in abar of Fractional ideal (-2*a^2 + 1) 
    22462246        """ 
    22472247        import sage.rings.residue_field 
    2248         return sage.rings.residue_field.ResidueField(prime) 
     2248        return sage.rings.residue_field.ResidueField(prime, names = names) 
    22492249 
    22502250    def signature(self): 
     
    36883688        return K 
    36893689 
     3690    def absolute_polynomial_ntl(self): 
     3691        """ 
     3692        Return defining polynomial of this number field 
     3693        as a pair, an ntl polynomial and a denominator. 
     3694 
     3695        This is used mainly to implement some internal arithmetic. 
     3696 
     3697        EXAMPLES: 
     3698            sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial_ntl() 
     3699            ([-27 34 51], 51) 
     3700        """ 
     3701        try: 
     3702            return (self.__abs_polynomial_ntl, self.__abs_denominator_ntl) 
     3703        except AttributeError: 
     3704            self.__abs_denominator_ntl = ntl.ZZ() 
     3705            den = self.absolute_polynomial().denominator() 
     3706            self.__abs_denominator_ntl.set_from_sage_int(ZZ(den)) 
     3707            self.__abs_polynomial_ntl = ntl.ZZX((self.absolute_polynomial()*den).list()) 
     3708        return (self.__abs_polynomial_ntl, self.__abs_denominator_ntl) 
     3709 
    36903710    def absolute_polynomial(self): 
    36913711        r""" 
     
    37623782              To:   Complex Field with 58 bits of precision 
    37633783              Defn: a |--> -0.62996052494743676 - 1.0911236359717214*I 
    3764                     b |--> -0.00000000000000019428902930940239 + 1.0000000000000000*I,  
    3765               ...         
     3784                    b |--> -1.9428902930940239e-16 + 1.0000000000000000*I, Relative number field morphism: 
     3785              ... 
     3786              From: Number Field in a with defining polynomial x^3 - 2 over its base field 
    37663787              To:   Complex Field with 58 bits of precision 
    37673788              Defn: a |--> 1.2599210498948731 
    37683789                    b |--> -0.99999999999999999*I] 
    37693790            sage: f[0](a)^3 
    3770             2.0000000000000002 - 0.00000000000000086389229103644993*I 
     3791            2.0000000000000002 - 8.6389229103644993e-16*I 
    37713792            sage: f[0](b)^2 
    3772             -1.0000000000000001 - 0.00000000000000038857805861880480*I 
     3793            -1.0000000000000001 - 3.8857805861880480e-16*I 
    37733794            sage: f[0](a+b) 
    37743795            -0.62996052494743693 - 0.091123635971721295*I 
     
    44164437            sage: C.complex_embeddings() 
    44174438            [Ring morphism: 
    4418               From: Cyclotomic Field of order 4 and degree 2 
    4419               To:   Complex Field with 53 bits of precision 
    4420               Defn: zeta4 |--> 6.12323399573677e-17 + 1.00000000000000*I, Ring morphism: 
    4421               From: Cyclotomic Field of order 4 and degree 2 
    4422               To:   Complex Field with 53 bits of precision 
    4423               Defn: zeta4 |--> -0.000000000000000183697019872103 - 1.00000000000000*I] 
     4439             From: Cyclotomic Field of order 4 and degree 2 
     4440             To:   Complex Field with 53 bits of precision 
     4441             Defn: zeta4 |--> 6.12323399573677e-17 + 1.00000000000000*I, Ring morphism: 
     4442             From: Cyclotomic Field of order 4 and degree 2 
     4443             To:   Complex Field with 53 bits of precision 
     4444             Defn: zeta4 |--> -1.83697019872103e-16 - 1.00000000000000*I] 
    44244445        """ 
    44254446        CC = sage.rings.complex_field.ComplexField(prec) 
     
    46164637        parts = -b/(2*a), (Dpoly/D).sqrt()/(2*a) 
    46174638        self._NumberField_generic__gen = self._element_class(self, parts) 
     4639 
     4640 
     4641    def coerce_map_from_impl(self, S): 
     4642        """ 
     4643        EXAMPLES: 
     4644            sage: K.<a> = QuadraticField(-3) 
     4645            sage: f = K.coerce_map_from(QQ); f 
     4646            Natural morphism: 
     4647              From: Rational Field 
     4648              To:   Number Field in a with defining polynomial x^2 + 3 
     4649            sage: f(3/5) 
     4650            3/5 
     4651            sage: parent(f(3/5)) is K 
     4652            True 
     4653        """ 
     4654        if S is QQ: 
     4655            return number_field_element_quadratic.Q_to_quadratic_field_element(self) 
     4656        else: 
     4657            return NumberField_absolute.coerce_map_from_impl(self, S) 
     4658 
     4659 
    46184660         
    46194661    def discriminant(self, v=None): 
  • sage/rings/polynomial/polynomial_element.pyx

    r7504 r7508  
    15231523            sage: expand(F) 
    15241524            T^6 + 10/7*T^5 + (-867/49)*T^4 + (-76/245)*T^3 + 3148/35*T^2 + (-25944/245)*T + 48771/1225 
     1525 
     1526            sage: f = x^2 - 1/3 ; K.<a> = NumberField(f) ; A.<T> = K[] ; g = A(x^2-1) 
     1527            sage: g.factor() 
     1528            (T - 1) * (T + 1) 
     1529 
     1530            sage: h = A(3*x^2-1) ; h.factor() 
     1531            (3) * (T - a) * (T + a) 
     1532 
     1533            sage: h = A(x^2-1/3) ; h.factor() 
     1534            (T - a) * (T + a) 
    15251535         
    15261536        Over the real double field: 
     
    15931603        G = None 
    15941604         
    1595         from sage.rings.number_field.all import is_NumberField, is_RelativeNumberField 
     1605        from sage.rings.number_field.all import is_NumberField, \ 
     1606             is_RelativeNumberField, NumberField 
    15961607        from sage.rings.finite_field import is_FiniteField 
    15971608 
     
    16161627            return Factorization(v, from_M(F.unit())) 
    16171628 
    1618  
    1619         elif is_NumberField(R) or is_FiniteField(R): 
     1629        elif is_FiniteField(R): 
    16201630            v = [x._pari_("a") for x in self.list()] 
    16211631            f = pari(v).Polrev() 
    16221632            G = list(f.factor()) 
     1633 
     1634             
     1635        elif is_NumberField(R): 
     1636            if (R.defining_polynomial().denominator() == 1) and \ 
     1637                   (self.denominator() == 1): 
     1638                v = [ x._pari_("a") for x in self.list() ] 
     1639                f = pari(v).Polrev() 
     1640                Rpari = R.pari_nf() 
     1641                if (Rpari.variable() != "a"): 
     1642                    Rpari = Rpari.copy() 
     1643                    Rpari[0] = Rpari[0]("a") 
     1644                    Rpari[6] = [ x("a") for x in Rpari[6] ] 
     1645                G = list(Rpari.nffactor(f)) 
     1646 
     1647            else: 
     1648 
     1649                Rdenom = R.defining_polynomial().denominator() 
     1650 
     1651                new_Rpoly = (R.defining_polynomial() * Rdenom).change_variable_name("a") 
     1652 
     1653                Rpari, Rdiff = new_Rpoly._pari_().nfinit(3) 
     1654 
     1655                AZ = polynomial_ring.PolynomialRing(QQ,'z') 
     1656                Raux = NumberField(AZ(Rpari[0]),'alpha') 
     1657 
     1658                S, gSRaux, fRauxS = Raux.change_generator(Raux(Rdiff)) 
     1659 
     1660                phi_RS = R.Hom(S)([S.gen(0)]) 
     1661                phi_SR = S.Hom(R)([R.gen(0)]) 
     1662 
     1663                unit = self.leading_coefficient() 
     1664                temp_f = self * 1/unit 
     1665 
     1666                v = [ gSRaux(phi_RS(x))._pari_("a") for x in temp_f.list() ] 
     1667                f = pari(v).Polrev() 
     1668 
     1669                pari_factors = Rpari.nffactor(f) 
     1670 
     1671                factors = [ ( self.parent([ phi_SR(fRauxS(Raux(pari_factors[0][i][j]))) 
     1672                                            for j in range(len(pari_factors[0][i])) ]) , 
     1673                             int(pari_factors[1][i]) ) 
     1674                            for i in range(pari_factors.nrows()) ] 
     1675 
     1676                return Factorization(factors, unit) 
     1677         
    16231678 
    16241679        elif is_RealField(R): 
     
    30313086            sage: R(4).is_irreducible() 
    30323087            True 
     3088 
     3089        TESTS: 
     3090            sage: F.<t> = NumberField(x^2-5) 
     3091            sage: Fx.<xF> = PolynomialRing(F) 
     3092            sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) 
     3093            sage: f.is_irreducible() 
     3094            False 
     3095            sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) 
     3096            sage: f.is_irreducible() 
     3097            True             
    30333098        """ 
    30343099        if self.is_zero(): 
  • sage/rings/polynomial/polynomial_element.pyx

    r7507 r7508  
    3636import sage.rings.complex_field 
    3737import sage.rings.fraction_field_element 
    38 from sage.rings.infinity import infinity 
     38import sage.rings.infinity as infinity 
    3939#import sage.misc.misc as misc 
    4040from sage.misc.sage_eval import sage_eval 
     
    7474 
    7575cdef object is_AlgebraicRealField 
     76cdef object is_AlgebraicField 
     77cdef object is_AlgebraicField_common 
     78cdef object NumberField_quadratic 
     79cdef object is_ComplexIntervalField 
    7680 
    7781cdef void late_import(): 
    7882    # A hack to avoid circular imports. 
    7983    global is_AlgebraicRealField 
     84    global is_AlgebraicField 
     85    global is_AlgebraicField_common 
     86    global NumberField_quadratic 
     87    global is_ComplexIntervalField 
    8088 
    8189    if is_AlgebraicRealField is not None: 
    8290        return 
    8391 
    84     import sage.rings.algebraic_real 
    85     is_AlgebraicRealField = sage.rings.algebraic_real.is_AlgebraicRealField 
     92    import sage.rings.qqbar 
     93    is_AlgebraicRealField = sage.rings.qqbar.is_AlgebraicRealField 
     94    is_AlgebraicField = sage.rings.qqbar.is_AlgebraicField 
     95    is_AlgebraicField_common = sage.rings.qqbar.is_AlgebraicField_common 
     96    import sage.rings.number_field.number_field 
     97    NumberField_quadratic = sage.rings.number_field.number_field.NumberField_quadratic 
     98    import sage.rings.complex_interval_field 
     99    is_ComplexIntervalField = sage.rings.complex_interval_field.is_ComplexIntervalField 
    86100 
    87101cdef class Polynomial(CommutativeAlgebraElement): 
     
    525539 
    526540    def _integer_(self): 
     541        r""" 
     542        EXAMPLES: 
     543            sage: k = GF(47) 
     544            sage: R.<x> = PolynomialRing(k) 
     545            sage: ZZ(R(45)) 
     546            45 
     547            sage: ZZ(3*x + 45) 
     548            Traceback (most recent call last): 
     549            ... 
     550            TypeError: cannot coerce nonconstant polynomial 
     551        """ 
    527552        if self.degree() > 0: 
    528553            raise TypeError, "cannot coerce nonconstant polynomial" 
    529554        return sage.rings.integer.Integer(self[0]) 
     555 
     556    def _rational_(self): 
     557        r""" 
     558        EXAMPLES: 
     559            sage: R.<x> = PolynomialRing(QQ) 
     560            sage: QQ(R(45/4)) 
     561            45/4 
     562            sage: QQ(3*x + 45) 
     563            Traceback (most recent call last): 
     564            ... 
     565            TypeError: cannot coerce nonconstant polynomial 
     566        """ 
     567        if self.degree() > 0: 
     568            raise TypeError, "cannot coerce nonconstant polynomial" 
     569        return sage.rings.rational.Rational(self[0]) 
    530570 
    531571    def __invert__(self): 
     
    10421082            sage: f = y^10 - 1.393493*y + 0.3 
    10431083            sage: f._mul_karatsuba(f) 
    1044             1.00000000000000*y^20 - 2.78698600000000*y^11 + 0.600000000000000*y^10 + 0.000000000000000111022302462516*y^8 - 0.000000000000000111022302462516*y^6 - 0.000000000000000111022302462516*y^3 + 1.94182274104900*y^2 - 0.836095800000000*y + 0.0900000000000000 
     1084            1.00000000000000*y^20 - 2.78698600000000*y^11 + 0.600000000000000*y^10 + 1.11022302462516e-16*y^8 - 1.11022302462516e-16*y^6 - 1.11022302462516e-16*y^3 + 1.94182274104900*y^2 - 0.836095800000000*y + 0.0900000000000000 
    10451085            sage: f._mul_fateman(f) 
    10461086            1.00000000000000*y^20 - 2.78698600000000*y^11 + 0.600000000000000*y^10 + 1.94182274104900*y^2 - 0.836095800000000*y + 0.0900000000000000 
     
    19642004            +Infinity 
    19652005        """ 
    1966         return infinity 
     2006        return infinity.infinity 
    19672007 
    19682008    def padded_list(self, n=None): 
     
    23502390        at the end of the docstring about this. 
    23512391 
    2352         If the output ring is a RealIntervalField of a given 
    2353         precision, then the answer will always be correct (or an 
    2354         exception will be raised, if a case is not implemented).  Each 
    2355         root will be contained in one of the returned intervals, 
    2356         and the intervals will be disjoint.  (The returned intervals 
    2357         may be of higher precision than the specified output ring.) 
     2392        If the output ring is a RealIntervalField or 
     2393        ComplexIntervalField of a given precision, then the answer 
     2394        will always be correct (or an exception will be raised, if a 
     2395        case is not implemented).  Each root will be contained in one 
     2396        of the returned intervals, and the intervals will be disjoint. 
     2397        (The returned intervals may be of higher precision than the 
     2398        specified output ring.) 
    23582399         
    23592400        At the end of this docstring (after the examples) is a description 
     
    24252466            sage: f = x^10 - 2*(5*x-1)^2 
    24262467            sage: f.roots(multiplicities=False) 
    2427             [-1.6772670339941..., 0.199954796285..., 0.200045306115..., 1.5763035161844...] 
     2468            [-1.6772670339941..., 0.19995479628..., 0.200045306115..., 1.5763035161844...] 
    24282469 
    24292470            sage: x = CC['x'].0 
     
    24402481            [(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)] 
    24412482 
    2442         An example where the base ring doesn't have a factorization 
    2443         algorithm (yet).  Note that this is currently done via naive 
    2444         enumeration, so could be very slow: 
     2483        A couple of examples where the base ring doesn't have a 
     2484        factorization algorithm (yet).  Note that this is currently 
     2485        done via naive enumeration, so could be very slow: 
    24452486            sage: R = Integers(6) 
    24462487            sage: S.<x> = R['x'] 
     
    24522493            sage: p.roots(multiplicities=False) 
    24532494            [1, 5] 
     2495            sage: R = Integers(9) 
     2496            sage: A = PolynomialRing(R, 'y') 
     2497            sage: y = A.gen() 
     2498            sage: f = 10*y^2 - y^3 - 9 
     2499            sage: f.roots(multiplicities=False) 
     2500            [0, 1, 3, 6] 
    24542501 
    24552502        An example over the complex double field (where root finding 
     
    25112558            sage: f.roots(ring=RIF, multiplicities=False) 
    25122559            [[-0.618033988749894848204586834365642 .. -0.618033988749894848204586834365629], [0.999999999999999999999999999999987 .. 1.00000000000000000000000000000003], [1.61803398874989484820458683436561 .. 1.61803398874989484820458683436565]] 
     2560 
     2561        Examples using complex root isolation: 
     2562            sage: x = polygen(ZZ) 
     2563            sage: p = x^5 - x - 1 
     2564            sage: p.roots() 
     2565            [] 
     2566            sage: p.roots(ring=CIF) 
     2567            [([1.1673039782614185 .. 1.1673039782614188], 1), ([0.18123244446987518 .. 0.18123244446987558] + [1.0839541013177103 .. 1.0839541013177110]*I, 1), ([0.181232444469875... .. 0.1812324444698755...] - [1.083954101317710... .. 1.0839541013177110]*I, 1), ([-0.76488443360058489 .. -0.76488443360058455] + [0.35247154603172609 .. 0.35247154603172643]*I, 1), ([-0.76488443360058489 .. -0.76488443360058455] - [0.35247154603172609 .. 0.35247154603172643]*I, 1)] 
     2568            sage: p.roots(ring=ComplexIntervalField(200)) 
     2569            [([1.1673039782614186842560458998548421807205603715254890391400816 .. 1.1673039782614186842560458998548421807205603715254890391400829], 1), ([0.18123244446987538390180023778112063996871646618462304743773153 .. 0.18123244446987538390180023778112063996871646618462304743773341] + [1.0839541013177106684303444929807665742736402431551156543011306 .. 1.0839541013177106684303444929807665742736402431551156543011344]*I, 1), ([0.18123244446987538390180023778112063996871646618462304743773153 .. 0.18123244446987538390180023778112063996871646618462304743773341] - [1.0839541013177106684303444929807665742736402431551156543011306 .. 1.0839541013177106684303444929807665742736402431551156543011344]*I, 1), ([-0.76488443360058472602982318770854173032899665194736756700777454 .. -0.76488443360058472602982318770854173032899665194736756700777...] + [0.35247154603172624931794709140258105439420648082424733283769... .. 0.35247154603172624931794709140258105439420648082424733283769...]*I, 1), ([-0.76488443360058472602982318770854173032899665194736756700777454 .. -0.76488443360058472602982318770854173032899665194736756700777204] - [0.35247154603172624931794709140258105439420648082424733283769122 .. 0.35247154603172624931794709140258105439420648082424733283769341]*I, 1)] 
     2570            sage: rts = p.roots(ring=QQbar); rts 
     2571            [([1.1673039782614185 .. 1.1673039782614188], 1), ([0.18123244446987538 .. 0.18123244446987541] + [1.0839541013177105 .. 1.0839541013177108]*I, 1), ([0.18123244446987538 .. 0.18123244446987541] - [1.0839541013177105 .. 1.0839541013177108]*I, 1), ([-0.76488443360058478 .. -0.76488443360058466] + [0.35247154603172620 .. 0.35247154603172626]*I, 1), ([-0.76488443360058478 .. -0.76488443360058466] - [0.35247154603172620 .. 0.35247154603172626]*I, 1)] 
     2572            sage: p.roots(ring=AA) 
     2573            [([1.1673039782614185 .. 1.1673039782614188], 1)] 
     2574            sage: p = (x - rts[1][0])^2 * (x^2 + x + 1) 
     2575            sage: p.roots(ring=QQbar) 
     2576            [([-0.50000000000000012 .. -0.49999999999999994] + [0.86602540378443859 .. 0.86602540378443871]*I, 1), ([-0.50000000000000000 .. -0.50000000000000000] - [0.86602540378443859 .. 0.86602540378443871]*I, 1), ([0.18123244446987538 .. 0.18123244446987541] + [1.0839541013177105 .. 1.0839541013177108]*I, 2)] 
     2577            sage: p.roots(ring=CIF) 
     2578            [([-0.50000000000000012 .. -0.49999999999999994] + [0.86602540378443859 .. 0.86602540378443871]*I, 1), ([-0.50000000000000000 .. -0.50000000000000000] - [0.86602540378443859 .. 0.86602540378443871]*I, 1), ([0.18123244446987538 .. 0.18123244446987541] + [1.0839541013177105 .. 1.0839541013177108]*I, 2)] 
     2579 
     2580        Note that coefficients in a number field with defining polynomial 
     2581        x^2 + 1 are considered to be Gaussian rationals (with the generator 
     2582        mapping to +I), if you ask for complex roots. 
     2583 
     2584            sage: K.<im> = NumberField(x^2 + 1) 
     2585            sage: y = polygen(K) 
     2586            sage: p = y^4 - 2 - im 
     2587            sage: p.roots(ring=CC) 
     2588            [(-1.2146389322441... - 0.14142505258239...*I, 1), (-0.14142505258239... + 1.2146389322441...*I, 1), (0.14142505258239... - 1.2146389322441...*I, 1), (1.2146389322441... + 0.14142505258239...*I, 1)] 
     2589            sage: p = p^2 * (y^2 - 2) 
     2590            sage: p.roots(ring=CIF) 
     2591            [([-1.4142135623730952 .. -1.4142135623730949], 1), ([1.4142135623730949 .. 1.4142135623730952], 1), ([-1.2146389322441827 .. -1.2146389322441821] - [0.1414250525823937... .. 0.1414250525823939...]*I, 2), ([-0.14142505258239399 .. -0.14142505258239376] + [1.2146389322441821 .. 1.2146389322441827]*I, 2), ([0.14142505258239376 .. 0.14142505258239399] - [1.2146389322441821 .. 1.2146389322441827]*I, 2), ([1.2146389322441821 .. 1.2146389322441827] + [0.14142505258239376 .. 0.14142505258239399]*I, 2)] 
    25132592 
    25142593        There are many combinations of floating-point input and output 
     
    25422621 
    25432622        Note that we can find the roots of a polynomial with 
    2544         algebraic real coefficients: 
     2623        algebraic coefficients: 
    25452624         
    25462625            sage: rt2 = sqrt(AA(2)) 
     
    25582637        Algorithms used: 
    25592638 
    2560         For brevity, we will use RR to mean any RealField of any precision; 
    2561         similarly for CC and CIF. 
     2639        For brevity, we will use RR to mean any RealField of any 
     2640        precision; similarly for RIF, CC, and CIF.  Since Sage has no 
     2641        specific implementation of Gaussian rationals (or of number 
     2642        fields with embedding, at all), when we refer to Gaussian 
     2643        rationals below we will accept any number field with defining 
     2644        polynomial x^2+1, mapping the field generator to +I. 
    25622645 
    25632646        We call the base ring of the polynomial K, and the ring given 
     
    25782661        this method gives.) 
    25792662 
    2580         If L is floating-point and K is not, then we attempt to 
    2581         change the polynomial ring to L (using .change_ring()) 
    2582         (or, if L is complex, to the corresponding real field). 
    2583         Then we use either Pari or numpy as specified above. 
     2663        If L is QQbar or CIF, and K is ZZ, QQ, AA, QQbar, or the 
     2664        Gaussian rationals, then the root isolation algorithm 
     2665        sage.rings.polynomial.complex_roots.complex_roots() is used. 
     2666        (You can call complex_roots() directly to get more control 
     2667        than this method gives.) 
     2668 
     2669        If L is AA and K is QQbar or the Gaussian rationals, then 
     2670        complex_roots() is used (as above) to find roots in QQbar, 
     2671        then these roots are filtered to select only the real roots. 
     2672 
     2673        If L is floating-point and K is not, then we attempt to change 
     2674        the polynomial ring to L (using .change_ring()) (or, if L is 
     2675        complex and K is not, to the corresponding real field).  Then 
     2676        we use either Pari or numpy as specified above. 
    25842677 
    25852678        For all other cases where K is different than L, we just use 
    25862679        .change_ring(L) and proceed as below. 
    25872680 
    2588         The next method is to attempt to factor the polynomial. 
    2589         If this succeeds, then for every degree-one factor a*x+b, we 
    2590         add -b/a as a root. 
    2591  
    2592         If factoring over K is not implemented, and K is finite, then 
    2593         we find the roots by enumerating all elements of K and checking 
    2594         whether the polynomial evaluates to zero at that value. 
     2681        The next method, which is used if K is an integral domain, is 
     2682        to attempt to factor the polynomial.  If this succeeds, then 
     2683        for every degree-one factor a*x+b, we add -b/a as a root (as 
     2684        long as this quotient is actually in the desired ring). 
     2685 
     2686        If factoring over K is not implemented (or K is not an 
     2687        integral domain), and K is finite, then we find the roots by 
     2688        enumerating all elements of K and checking whether the 
     2689        polynomial evaluates to zero at that value. 
    25952690         
    25962691 
     
    26182713        if L is None: L = K 
    26192714         
     2715        late_import() 
     2716 
    26202717        input_fp = (is_RealField(K) 
    26212718                    or is_ComplexField(K)  
     
    26302727        output_complex = (is_ComplexField(L) 
    26312728                          or is_ComplexDoubleField(L)) 
     2729        input_gaussian = (isinstance(K, NumberField_quadratic) 
     2730                          and list(K.polynomial()) == [1, 0, 1]) 
    26322731 
    26332732        if input_fp and output_fp: 
     
    26892788                return rts 
    26902789 
    2691         late_import() 
    2692  
    2693         if L != K or is_AlgebraicRealField(L): 
    2694             # So far, the only "special" implementation is for K exact 
    2695             # and L either AA or a real interval field. 
     2790        if L != K or is_AlgebraicField_common(L): 
     2791            # So far, the only "special" implementations are for real 
     2792            # and complex root isolation. 
    26962793            if (is_IntegerRing(K) or is_RationalField(K) 
    26972794                or is_AlgebraicRealField(K)) and \ 
     
    27242821                    return [rt for (rt, mult) in rts] 
    27252822 
    2726             if output_fp and output_complex: 
     2823            if (is_IntegerRing(K) or is_RationalField(K) 
     2824                or is_AlgebraicField_common(K) or input_gaussian) and \ 
     2825                (is_ComplexIntervalField(L) or is_AlgebraicField_common(L)): 
     2826 
     2827                from sage.rings.polynomial.complex_roots import complex_roots 
     2828 
     2829                if is_ComplexIntervalField(L): 
     2830                    rts = complex_roots(self, min_prec=L.prec()) 
     2831                elif is_AlgebraicField(L): 
     2832                    rts = complex_roots(self, retval='algebraic') 
     2833                else: 
     2834                    rts = complex_roots(self, retval='algebraic_real') 
     2835 
     2836                if multiplicities: 
     2837                    return rts 
     2838                else: 
     2839                    return [rt for (rt, mult) in rts] 
     2840 
     2841            if output_fp and output_complex and not input_gaussian: 
    27272842                # If we want the complex roots, and the input is not 
    2728                 # floating point, we convert to a real polynomial. 
    2729                 # I think this works for now, because there are no 
    2730                 # non-floating-point complex types in Sage.  Hopefully 
    2731                 # someday we will have Gaussian integers and rationals, 
    2732                 # and this will have to change then. 
     2843                # floating point, we convert to a real polynomial 
     2844                # (except when the input coefficients are Gaussian rationals). 
    27332845                if is_ComplexDoubleField(L): 
    27342846                    real_field = RDF 
     
    27412853 
    27422854        try: 
    2743             rts = self.factor() 
     2855            if K.is_integral_domain(): 
     2856                rts = self.factor() 
     2857            else: 
     2858                raise NotImplementedError 
    27442859        except NotImplementedError: 
    27452860            if K.is_finite(): 
     
    28752990 
    28762991        if not self: 
    2877             return infinity 
    2878  
    2879         if p is infinity: 
     2992            return infinity.infinity 
     2993 
     2994        if p is infinity.infinity: 
    28802995            return -self.degree() 
    28812996 
     
    31263241         
    31273242        coeffs = self.coeffs() 
    3128         if p == infinity: 
     3243        if p == infinity.infinity: 
    31293244            return RR(max([abs(i) for i in coeffs])) 
    31303245         
Note: See TracChangeset for help on using the changeset viewer.