source: sage/rings/number_field/number_field_element.pyx @ 6240:bdf3e9f84f38

Revision 6240:bdf3e9f84f38, 46.9 KB checked in by William Stein <wstein@…>, 6 years ago (diff)

merge

Line 
1"""
2Number Field Elements
3
4AUTHORS:
5    -- William Stein version before it got cython'd
6    -- Joel B. Mohler (2007-03-09): First reimplementation into cython
7    -- William Stein (2007-09-04): add doctests
8"""
9
10# TODO -- relative extensions need to be completely rewritten, so one
11# can get easy access to representation of elements in their relative
12# form.  Functions like matrix below can't be done until relative
13# extensions are re-written this way.  Also there needs to be class
14# hierarchy for number field elements, integers, etc.  This is a
15# nontrivial project, and it needs somebody to attack it.  I'm amazed
16# how long this has gone unattacked.
17
18# Relative elements need to be a derived class or something.  This is
19# terrible as it is now.
20
21#*****************************************************************************
22#       Copyright (C) 2004, 2007 William Stein <wstein@gmail.com>
23#
24#  Distributed under the terms of the GNU General Public License (GPL)
25#
26#    This code is distributed in the hope that it will be useful,
27#    but WITHOUT ANY WARRANTY; without even the implied warranty of
28#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29#    General Public License for more details.
30#
31#  The full text of the GPL is available at:
32#
33#                  http://www.gnu.org/licenses/
34#*****************************************************************************
35
36import operator
37
38include "../../ext/stdsage.pxi"
39include '../../ext/interrupt.pxi'
40
41import sage.rings.field_element
42import sage.rings.infinity
43import sage.rings.polynomial.polynomial_element
44import sage.rings.polynomial.polynomial_ring
45import sage.rings.rational_field
46import sage.rings.rational
47import sage.rings.integer_ring
48import sage.rings.integer
49import sage.rings.arith
50
51import sage.rings.number_field.number_field
52
53from sage.libs.ntl.ntl cimport ntl_ZZ, ntl_ZZX
54from sage.rings.integer_ring cimport IntegerRing_class
55
56from sage.libs.all import pari_gen
57from sage.libs.pari.gen import PariError
58
59QQ = sage.rings.rational_field.QQ
60ZZ = sage.rings.integer_ring.ZZ
61Integer_sage = sage.rings.integer.Integer
62
63def is_NumberFieldElement(x):
64    """
65    Return True if x is of type NumberFieldElement, i.e., an
66    element of a number field.
67
68    EXAMPLES:
69        sage: is_NumberFieldElement(2)
70        False
71        sage: k.<a> = NumberField(x^7 + 17*x + 1)
72        sage: is_NumberFieldElement(a+1)
73        True
74    """
75    return PY_TYPE_CHECK(x, NumberFieldElement)
76
77def __create__NumberFieldElement_version0(parent, poly):
78    """
79    Used in unpickling elements of number fields.
80
81    EXAMPLES:
82    Since this is just used in unpickling, we unpickle.
83   
84        sage: k.<a> = NumberField(x^3 - 2)
85        sage: loads(dumps(a+1)) == a + 1
86        True       
87    """
88    return NumberFieldElement(parent, poly)
89
90cdef class NumberFieldElement(FieldElement):
91    """
92    An element of a number field.
93
94    EXAMPLES:
95        sage: k.<a> = NumberField(x^3 + x + 1)
96        sage: a^3
97        -a - 1       
98    """
99    cdef NumberFieldElement _new(self):
100        """
101        Quickly creates a new initialized NumberFieldElement with the same parent as self.
102        """
103        cdef NumberFieldElement x
104        x = PY_NEW(NumberFieldElement)
105        x._parent = self._parent
106        return x
107
108    def __init__(self, parent, f):
109        """
110        INPUT:
111            parent -- a number field
112            f -- defines an element of a number field.
113
114        EXAMPLES:
115        The following examples illustrate creation of elements of
116        number fields, and some basic arithmetic.
117
118        First we define a polynomial over Q.
119            sage: R.<x> = PolynomialRing(QQ)
120            sage: f = x^2 + 1
121
122        Next we use f to define the number field.
123            sage: K.<a> = NumberField(f); K
124            Number Field in a with defining polynomial x^2 + 1
125            sage: a = K.gen()
126            sage: a^2
127            -1
128            sage: (a+1)^2
129            2*a
130            sage: a^2
131            -1
132            sage: z = K(5); 1/z
133            1/5
134
135        We create a cube root of 2.
136            sage: K.<b> = NumberField(x^3 - 2)
137            sage: b = K.gen()
138            sage: b^3
139            2
140            sage: (b^2 + b + 1)^3
141            12*b^2 + 15*b + 19
142
143        This example illustrates save and load:
144            sage: K.<a> = NumberField(x^17 - 2)
145            sage: s = a^15 - 19*a + 3
146            sage: loads(s.dumps()) == s
147            True
148        """
149        sage.rings.field_element.FieldElement.__init__(self, parent)
150
151        cdef ZZ_c coeff
152        if isinstance(f, (int, long, Integer_sage)):
153            # set it up and exit immediately
154            # fast pathway
155            (<Integer>ZZ(f))._to_ZZ(&coeff)
156            SetCoeff( self.__numerator, 0, coeff )
157            conv_ZZ_int( self.__denominator, 1 )
158            return
159
160        ppr = parent.polynomial_ring()
161        if isinstance(parent, sage.rings.number_field.number_field.NumberField_extension):
162            ppr = parent.base_field().polynomial_ring()
163
164        if isinstance(f, pari_gen):
165            f = f.lift()
166            f = ppr(f)
167        if not isinstance(f, sage.rings.polynomial.polynomial_element.Polynomial):
168            f = ppr(f)
169        if f.degree() >= parent.degree():
170            if isinstance(parent, sage.rings.number_field.number_field.NumberField_extension):
171                f %= parent.absolute_polynomial()
172            else:
173                f %= parent.polynomial()
174
175        # Set Denominator
176        den = f.denominator()
177        (<Integer>ZZ(den))._to_ZZ(&self.__denominator)
178
179        cdef long i
180        num = f * den
181        for i from 0 <= i <= num.degree():
182            (<Integer>ZZ(num[i]))._to_ZZ(&coeff)
183            SetCoeff( self.__numerator, i, coeff )
184
185    def __alloc__(self):
186        ZZX_construct(&self.__numerator)
187        ZZ_construct(&self.__denominator)
188
189    def __dealloc__(self):
190        ZZX_destruct(&self.__numerator)
191        ZZ_destruct(&self.__denominator)
192
193    def _lift_cyclotomic_element(self, new_parent):
194        """
195        Creates an element of the passed field from this field.  This
196        is specific to creating elements in a cyclotomic field from
197        elements in another cyclotomic field.  This function aims to
198        make this common coercion extremely fast!
199
200        EXAMPLES:
201            sage: C.<zeta5>=CyclotomicField(5)
202            sage: CyclotomicField(10)(zeta5+1)  # The function _lift_cyclotomic_element does the heavy lifting in the background
203            zeta10^2 + 1
204            sage: (zeta5+1)._lift_cyclotomic_element(CyclotomicField(10))  # There is rarely a purpose to call this function directly
205            zeta10^2 + 1
206
207        AUTHOR:
208            Joel B. Mohler
209        """
210        # Right now, I'm a little confused why quadratic extension fields have a zeta_order function
211        # I would rather they not have this function since I don't want to do this isinstance check here.
212        if not isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_cyclotomic) or not isinstance(new_parent, sage.rings.number_field.number_field.NumberField_cyclotomic):
213            raise TypeError, "The field and the new parent field must both be cyclotomic fields."
214
215        try:
216            small_order = self.parent().zeta_order()
217            large_order = new_parent.zeta_order()
218        except AttributeError:
219            raise TypeError, "The field and the new parent field must both be cyclotomic fields."
220
221        try:
222            _rel = ZZ(large_order / small_order)
223        except TypeError:
224            raise TypeError, "The zeta_order of the new field must be a multiple of the zeta_order of the original."
225
226        cdef NumberFieldElement x
227        x = PY_NEW(NumberFieldElement)
228        x._parent = <ParentWithBase>new_parent
229        x.__denominator = self.__denominator
230        cdef ZZX_c result
231        cdef ZZ_c tmp
232        cdef int i
233        cdef int rel = _rel
234        cdef ntl_ZZX _num
235        cdef ntl_ZZ _den
236        _num, _den = new_parent.polynomial_ntl()
237        for i from 0 <= i <= deg(self.__numerator):
238            GetCoeff(tmp, self.__numerator, i)
239            SetCoeff(result, i*rel, tmp)
240        rem_ZZX(x.__numerator, result, _num.x[0])
241        return x
242
243    def __reduce__(self):
244        """
245        Used in pickling number field elements.
246
247        EXAMPLES:
248            sage: k.<a> = NumberField(x^3 - 17*x^2 + 1)
249            sage: t = a.__reduce__(); t
250            (<built-in function __create__NumberFieldElement_version0>, (Number Field in a with defining polynomial x^3 - 17*x^2 + 1, x))
251            sage: t[0](*t[1]) == a
252            True       
253        """
254        return __create__NumberFieldElement_version0, \
255               (self.parent(), self.polynomial())
256
257    def __repr__(self):
258        """
259        String representation of this number field element,
260        which is just a polynomial in the generator.
261
262        EXAMPLES:
263            sage: k.<a> = NumberField(x^2 + 2)
264            sage: b = (2/3)*a + 3/5
265            sage: b.__repr__()
266            '2/3*a + 3/5'       
267        """
268        x = self.polynomial()
269        return str(x).replace(x.parent().variable_name(),self.parent().variable_name())
270
271    def _im_gens_(self, codomain, im_gens):
272        """
273        This is used in computing homomorphisms between number fields.
274
275        EXAMPLES:
276            sage: k.<a> = NumberField(x^2 - 2)
277            sage: m.<b> = NumberField(x^4 - 2)
278            sage: phi = k.hom([b^2])
279            sage: phi(a+1)
280            b^2 + 1
281            sage: (a+1)._im_gens_(m, [b^2])
282            b^2 + 1       
283        """
284        # NOTE -- if you ever want to change this so relative number fields are
285        # in terms of a root of a poly.
286        # The issue is that elements of a relative number field are represented in terms
287        # of a generator for the absolute field.  However the morphism gives the image
288        # of gen, which need not be a generator for the absolute field.  The morphism
289        # has to be *over* the relative element.
290        return codomain(self.polynomial()(im_gens[0]))
291
292    def _latex_(self):
293        """
294        Returns the latex representation for this element.
295
296        EXAMPLES:
297            sage: C,zeta12=CyclotomicField(12).objgen()
298            sage: latex(zeta12^4-zeta12)
299            \zeta_{12}^{2} - \zeta_{12} - 1
300        """
301        return self.polynomial()._latex_(name=self.parent().latex_variable_name())
302
303    def _pari_(self, var='x'):
304        """
305        Return PARI C-library object corresponding to self.
306
307        EXAMPLES:
308            sage: k.<j> = QuadraticField(-1)
309            sage: j._pari_('j')
310            Mod(j, j^2 + 1)
311            sage: pari(j)
312            Mod(x, x^2 + 1)
313
314            sage: y = QQ['y'].gen()
315            sage: k.<j> = NumberField(y^3 - 2)
316            sage: pari(j)
317            Mod(x, x^3 - 2)
318
319        By default the variable name is 'x', since in PARI many variable
320        names are reserved:
321            sage: theta = polygen(QQ, 'theta')
322            sage: M.<theta> = NumberField(theta^2 + 1)
323            sage: pari(theta)
324            Mod(x, x^2 + 1)
325
326        If you try do coerce a generator called I to PARI, hell may
327        break loose:
328            sage: k.<I> = QuadraticField(-1)
329            sage: I._pari_('I')
330            Traceback (most recent call last):
331            ...
332            PariError: forbidden (45)
333
334        Instead, request the variable be named different for the coercion:
335            sage: pari(I)
336            Mod(x, x^2 + 1)
337            sage: I._pari_('i')
338            Mod(i, i^2 + 1)
339            sage: I._pari_('II')
340            Mod(II, II^2 + 1)
341        """
342        try:
343            return self.__pari[var]
344        except KeyError:
345            pass
346        except TypeError:
347            self.__pari = {}
348        if var is None:
349            var = self.parent().variable_name()
350        if isinstance(self.parent(),
351                      sage.rings.number_field.number_field.NumberField_extension):
352            f = self.polynomial()._pari_()
353            g = str(self.parent().pari_polynomial())
354            base = self.parent().base_ring()
355            gsub = base.gen()._pari_()
356            gsub = str(gsub).replace('x', "y")
357            g = g.replace("y", gsub)
358        else:
359            f = self.polynomial()._pari_()
360            gp = self.parent().polynomial()
361            if gp.name() != 'x':
362                gp = gp.change_variable_name('x')
363            g = gp._pari_()
364            gv = str(gp.parent().gen())
365            if var != 'x':
366                f = f.subst("x",var)
367            if var != gv:
368                g = g.subst(gv, var)
369        h = f.Mod(g)
370        self.__pari[var] = h
371        return h
372
373    def _pari_init_(self, var='x'):
374        """
375        Return GP/PARI string representation of self. This is used for
376        converting this number field element to GP/PARI.  The returned
377        string defines a pari Mod in the variable is var, which is by
378        default 'x' -- not the name of the generator of the number
379        field.
380
381        INPUT:
382            var -- (default: 'x') the variable of the pari Mod.
383
384        EXAMPLES:
385            sage: K.<a> = NumberField(x^5 - x - 1)
386            sage: ((1 + 1/3*a)^4)._pari_init_()
387            'Mod(1/81*x^4 + 4/27*x^3 + 2/3*x^2 + 4/3*x + 1, x^5 - x - 1)'
388            sage: ((1 + 1/3*a)^4)._pari_init_('a')
389            'Mod(1/81*a^4 + 4/27*a^3 + 2/3*a^2 + 4/3*a + 1, a^5 - a - 1)'
390
391        Note that _pari_init_ can fail because of reserved words in PARI,
392        and since it actually works by obtaining the PARI representation
393        of something.
394            sage: K.<theta> = NumberField(x^5 - x - 1)
395            sage: b = (1/2 - 2/3*theta)^3; b
396            -8/27*theta^3 + 2/3*theta^2 - 1/2*theta + 1/8
397            sage: b._pari_init_('theta')
398            Traceback (most recent call last):
399            ...
400            PariError: unexpected character (2)
401
402        Fortunately pari_init returns everything in terms of x by default.
403            sage: pari(b)
404            Mod(-8/27*x^3 + 2/3*x^2 - 1/2*x + 1/8, x^5 - x - 1)
405        """
406        return repr(self._pari_(var=var))
407##         if var == None:
408##             var = self.parent().variable_name()
409##         if isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_extension):
410##             f = self.polynomial()._pari_()
411##             g = str(self.parent().pari_relative_polynomial())
412##             base = self.parent().base_ring()
413##             gsub = base.gen()._pari_()
414##             gsub = str(gsub).replace(base.variable_name(), "y")
415##             g = g.replace("y", gsub)
416##         else:
417##             f = str(self.polynomial()).replace("x",var)
418##             g = str(self.parent().polynomial()).replace("x",var)
419##         return 'Mod(%s, %s)'%(f,g)
420
421    def __getitem__(self, n):
422        """
423        Return the n-th coefficient of this number field element, written
424        as a polynomial in the generator.
425
426        Note that $n$ must be between 0 and $d-1$, where $d$ is the
427        degree of the number field.
428
429        EXAMPLES:
430            sage: m.<b> = NumberField(x^4 - 1789)
431            sage: c = (2/3-4/5*b)^3; c
432            -64/125*b^3 + 32/25*b^2 - 16/15*b + 8/27
433            sage: c[0]
434            8/27
435            sage: c[2]
436            32/25
437            sage: c[3]
438            -64/125
439
440        We illustrate bounds checking:
441            sage: c[-1]
442            Traceback (most recent call last):
443            ...
444            IndexError: index must be between 0 and degree minus 1.
445            sage: c[4]
446            Traceback (most recent call last):
447            ...
448            IndexError: index must be between 0 and degree minus 1.
449
450        The list method implicitly calls __getitem__:
451            sage: list(c)
452            [8/27, -16/15, 32/25, -64/125]
453            sage: m(list(c)) == c
454            True           
455        """
456        if n < 0 or n >= self.parent().degree():     # make this faster.
457            raise IndexError, "index must be between 0 and degree minus 1."
458        return self.polynomial()[n]
459
460    cdef int _cmp_c_impl(left, sage.structure.element.Element right) except -2:
461        cdef NumberFieldElement _right = right
462        return not (ZZX_equal(&left.__numerator, &_right.__numerator) and ZZ_equal(&left.__denominator, &_right.__denominator))
463
464    def __abs__(self):
465        r"""
466        Return the numerical absolute value of this number field
467        element with respect to the first archimedean embedding, to 53
468        bits of precision.
469
470        This is the \code{abs( )} Python function.  If you want a different
471        embedding or precision, use \code{self.abs(...)}.
472
473        EXAMPLES:
474            sage: k.<a> = NumberField(x^3 - 2)
475            sage: abs(a)
476            1.25992104989487
477            sage: abs(a)^3
478            2.00000000000000
479            sage: a.abs(prec=128)
480            1.2599210498948731647672106072782283506       
481        """
482        return self.abs(prec=53, i=0)
483
484    def abs(self, prec=53, i=0):
485        """
486        Return the absolute value of this element with respect to the
487        ith complex embedding of parent, to the given precision.
488
489        INPUT:
490            prec -- (default: 53) integer bits of precision
491            i -- (default: ) integer, which embedding to use
492
493        EXAMPLES:
494            sage: z = CyclotomicField(7).gen()
495            sage: abs(z)
496            1.00000000000000
497            sage: abs(z^2 + 17*z - 3)
498            16.0604426799931
499            sage: K.<a> = NumberField(x^3+17)
500            sage: abs(a)
501            2.57128159065824
502            sage: a.abs(prec=100)
503            2.5712815906582353554531872087
504            sage: a.abs(prec=100,i=1)
505            2.5712815906582353554531872087
506            sage: a.abs(100, 2)
507            2.5712815906582353554531872087
508
509        Here's one where the absolute value depends on the embedding.
510            sage: K.<b> = NumberField(x^2-2)
511            sage: a = 1 + b
512            sage: a.abs(i=0)
513            2.41421356237309
514            sage: a.abs(i=1)
515            0.414213562373095
516        """
517        P = self.parent().complex_embeddings(prec)[i]
518        return abs(P(self))
519
520    def complex_embeddings(self, prec=53):
521        """
522        Return the images of this element in the floating point
523        complex numbers, to the given bits of precision.
524
525        INPUT:
526            prec -- integer (default: 53) bits of precision
527
528        EXAMPLES:
529            sage: k.<a> = NumberField(x^3 - 2)
530            sage: a.complex_embeddings()
531            [1.25992104989487, -0.629960524947437 + 1.09112363597172*I, -0.629960524947437 - 1.09112363597172*I]
532            sage: a.complex_embeddings(10)
533            [1.3, -0.63 + 1.1*I, -0.63 - 1.1*I]
534            sage: a.complex_embeddings(100)
535            [1.2599210498948731647672106073, -0.62996052494743658238360530364 + 1.0911236359717214035600726142*I, -0.62996052494743658238360530364 - 1.0911236359717214035600726142*I]
536        """
537        phi = self.parent().complex_embeddings(prec)
538        return [f(self) for f in phi]
539
540    def complex_embedding(self, prec=53, i=0):
541        """
542        Return the i-th embedding of self in the complex numbers, to
543        the given precision.
544
545        EXAMPLES:
546            sage: k.<a> = NumberField(x^3 - 2)
547            sage: a.complex_embedding()
548            1.25992104989487
549            sage: a.complex_embedding(10)
550            1.3
551            sage: a.complex_embedding(100)
552            1.2599210498948731647672106073
553            sage: a.complex_embedding(20, 1)
554            -0.62996 + 1.0911*I
555            sage: a.complex_embedding(20, 2)
556            -0.62996 - 1.0911*I
557        """
558        return self.parent().complex_embeddings(prec)[i](self)
559
560    def is_square(self, root=False):
561        """
562        Return True if self is a square in its parent number field and
563        otherwise return False.
564
565        INPUT:
566            root -- if True, also return a square root (or None if self
567                    is not a perfect square)
568
569        EXAMPLES:
570            sage: m.<b> = NumberField(x^4 - 1789)
571            sage: b.is_square()
572            False
573            sage: c = (2/3*b + 5)^2; c
574            4/9*b^2 + 20/3*b + 25
575            sage: c.is_square()
576            True
577            sage: c.is_square(True)
578            (True, 2/3*b + 5)
579
580        We also test the functional notation.
581            sage: is_square(c, True)
582            (True, 2/3*b + 5)
583            sage: is_square(c)
584            True
585            sage: is_square(c+1)
586            False
587        """
588        v = self.sqrt(all=True)
589        t = len(v) > 0
590        if root:
591            if t:
592                return t, v[0]
593            else:
594                return False, None
595        else:
596            return t
597       
598    def sqrt(self, all=False):
599        """
600        Returns the square root of this number in the given number field.
601       
602        EXAMPLES:
603            sage: K.<a> = NumberField(x^2 - 3)
604            sage: K(3).sqrt()
605            a
606            sage: K(3).sqrt(all=True)
607            [a, -a]
608            sage: K(a^10).sqrt()
609            9*a
610            sage: K(49).sqrt()
611            7
612            sage: K(1+a).sqrt()
613            Traceback (most recent call last):
614            ...
615            ValueError: a + 1 not a square in Number Field in a with defining polynomial x^2 - 3
616            sage: K(0).sqrt()
617            0
618            sage: K((7+a)^2).sqrt(all=True)
619            [a + 7, -a - 7]
620           
621            sage: K.<a> = CyclotomicField(7)
622            sage: a.sqrt() 
623            a^4
624           
625            sage: K.<a> = NumberField(x^5 - x + 1)
626            sage: (a^4 + a^2 - 3*a + 2).sqrt()
627            a^3 - a^2
628
629        ALGORITHM:
630            Use Pari to factor $x^2$ - \code{self} in K.
631           
632        """
633        # For now, use pari's factoring abilities
634        R = sage.rings.polynomial.polynomial_ring.PolynomialRing(self._parent, 't')
635        f = R([-self, 0, 1])
636        roots = f.roots()
637        if all:
638            return [r[0] for r in roots]
639        elif len(roots) > 0:
640            return roots[0][0]
641        else:
642            raise ValueError, "%s not a square in %s"%(self, self._parent)
643
644    cdef void _reduce_c_(self):
645        """
646        Pull out common factors from the numerator and denominator!
647        """
648        cdef ZZ_c gcd
649        cdef ZZ_c t1
650        cdef ZZX_c t2
651        content(t1, self.__numerator)
652        GCD_ZZ(gcd, t1, self.__denominator)
653        if sign(gcd) != sign(self.__denominator):
654            negate(t1, gcd)
655            gcd = t1
656        div_ZZX_ZZ(t2, self.__numerator, gcd)
657        div_ZZ_ZZ(t1, self.__denominator, gcd)
658        self.__numerator = t2
659        self.__denominator = t1
660
661    cdef ModuleElement _add_c_impl(self, ModuleElement right):
662        cdef NumberFieldElement x
663        cdef NumberFieldElement _right = right
664        x = self._new()
665        mul_ZZ(x.__denominator, self.__denominator, _right.__denominator)
666        cdef ZZX_c t1, t2
667        mul_ZZX_ZZ(t1, self.__numerator, _right.__denominator)
668        mul_ZZX_ZZ(t2, _right.__numerator, self.__denominator)
669        add_ZZX(x.__numerator, t1, t2)
670        x._reduce_c_()
671        return x
672
673    cdef ModuleElement _sub_c_impl(self, ModuleElement right):
674        cdef NumberFieldElement x
675        cdef NumberFieldElement _right = right
676        x = self._new()
677        mul_ZZ(x.__denominator, self.__denominator, _right.__denominator)
678        cdef ZZX_c t1, t2
679        mul_ZZX_ZZ(t1, self.__numerator, _right.__denominator)
680        mul_ZZX_ZZ(t2, _right.__numerator, self.__denominator)
681        sub_ZZX(x.__numerator, t1, t2)
682        x._reduce_c_()
683        return x
684
685    cdef RingElement _mul_c_impl(self, RingElement right):
686        """
687        Returns the product of self and other as elements of a number field.
688
689        EXAMPLES:
690            sage: C.<zeta12>=CyclotomicField(12)
691            sage: zeta12*zeta12^11
692            1
693            sage: G.<a> = NumberField(x^3 + 2/3*x + 1)
694            sage: a^3
695            -2/3*a - 1
696            sage: a^3+a
697            1/3*a - 1
698        """
699        cdef NumberFieldElement x
700        cdef NumberFieldElement _right = right
701        cdef ZZX_c temp
702        cdef ZZ_c temp1
703        cdef ZZ_c parent_den
704        cdef ZZX_c parent_num
705        self._parent_poly_c_( &parent_num, &parent_den )
706        x = self._new()
707        _sig_on
708        # MulMod doesn't handle non-monic polynomials.
709        # Therefore, we handle the non-monic case entirely separately.
710        if ZZX_is_monic( &parent_num ):
711            mul_ZZ(x.__denominator, self.__denominator, _right.__denominator)
712            MulMod_ZZX(x.__numerator, self.__numerator, _right.__numerator, parent_num)
713        else:
714            mul_ZZ(x.__denominator, self.__denominator, _right.__denominator)
715            mul_ZZX(x.__numerator, self.__numerator, _right.__numerator)
716            if ZZX_degree(&x.__numerator) >= ZZX_degree(&parent_num):
717                mul_ZZX_ZZ( x.__numerator, x.__numerator, parent_den )
718                mul_ZZX_ZZ( temp, parent_num, x.__denominator )
719                power_ZZ(temp1,LeadCoeff_ZZX(temp),ZZX_degree(&x.__numerator)-ZZX_degree(&parent_num)+1)
720                PseudoRem_ZZX(x.__numerator, x.__numerator, temp)
721                mul_ZZ(x.__denominator, x.__denominator, parent_den)
722                mul_ZZ(x.__denominator, x.__denominator, temp1)
723        _sig_off
724        x._reduce_c_()
725        return x
726
727        #NOTES: In LiDIA, they build a multiplication table for the
728        #number field, so it's not necessary to reduce modulo the
729        #defining polynomial every time:
730        #     src/number_fields/algebraic_num/order.cc: compute_table
731        # but asymptotically fast poly multiplication means it's
732        # actually faster to *not* build a table!?!
733
734    cdef RingElement _div_c_impl(self, RingElement right):
735        """
736        Returns the quotient of self and other as elements of a number field.
737
738        EXAMPLES:
739            sage: C.<I>=CyclotomicField(4)
740            sage: 1/I
741            -I
742            sage: I/0
743            Traceback (most recent call last):
744            ...
745            ZeroDivisionError: Number field element division by zero
746           
747            sage: G.<a> = NumberField(x^3 + 2/3*x + 1)
748            sage: a/a
749            1
750            sage: 1/a
751            -a^2 - 2/3
752            sage: a/0
753            Traceback (most recent call last):
754            ...
755            ZeroDivisionError: Number field element division by zero
756        """
757        cdef NumberFieldElement x
758        cdef NumberFieldElement _right = right
759        cdef ZZX_c inv_num
760        cdef ZZ_c inv_den
761        cdef ZZ_c parent_den
762        cdef ZZX_c parent_num
763        cdef ZZX_c temp
764        cdef ZZ_c temp1
765        if not _right:
766            raise ZeroDivisionError, "Number field element division by zero"
767        self._parent_poly_c_( &parent_num, &parent_den )
768        x = self._new()
769        _sig_on
770        _right._invert_c_(&inv_num, &inv_den)
771        if ZZX_is_monic( &parent_num ):
772            mul_ZZ(x.__denominator, self.__denominator, inv_den)
773            MulMod_ZZX(x.__numerator, self.__numerator, inv_num, parent_num)
774        else:
775            mul_ZZ(x.__denominator, self.__denominator, inv_den)
776            mul_ZZX(x.__numerator, self.__numerator, inv_num)
777            if ZZX_degree(&x.__numerator) >= ZZX_degree(&parent_num):
778                mul_ZZX_ZZ( x.__numerator, x.__numerator, parent_den )
779                mul_ZZX_ZZ( temp, parent_num, x.__denominator )
780                power_ZZ(temp1,LeadCoeff_ZZX(temp),ZZX_degree(&x.__numerator)-ZZX_degree(&parent_num)+1)
781                PseudoRem_ZZX(x.__numerator, x.__numerator, temp)
782                mul_ZZ(x.__denominator, x.__denominator, parent_den)
783                mul_ZZ(x.__denominator, x.__denominator, temp1)
784        x._reduce_c_()
785        _sig_off
786        return x
787
788    def __floordiv__(self, other):
789        """
790        Return the quotient of self and other.  Since these are field
791        elements the floor division is exactly the same as usual
792        division.
793
794        EXAMPLES:
795            sage: m.<b> = NumberField(x^4 + x^2 + 2/3)
796            sage: c = (1+b) // (1-b); c
797            3/4*b^3 + 3/4*b^2 + 3/2*b + 1/2
798            sage: (1+b) / (1-b) == c
799            True
800            sage: c * (1-b)
801            b + 1       
802        """
803        return self / other
804
805    def __nonzero__(self):
806        """
807        Return True if this number field element is nonzero.
808
809        EXAMPLES:
810            sage: m.<b> = CyclotomicField(17)
811            sage: m(0).__nonzero__()
812            False
813            sage: b.__nonzero__()
814            True
815
816        Nonzero is used by the bool command:
817            sage: bool(b + 1)
818            True
819            sage: bool(m(0))
820            False
821        """
822        return not IsZero_ZZX(self.__numerator)
823
824    cdef ModuleElement _neg_c_impl(self):
825        cdef NumberFieldElement x
826        x = self._new()
827        mul_ZZX_long(x.__numerator, self.__numerator, -1)
828        x.__denominator = self.__denominator
829        return x
830
831    def __int__(self):
832        """
833        Attempt to convert this number field element to a Python integer,
834        if possible.
835       
836        EXAMPLES:
837            sage: C.<I>=CyclotomicField(4)
838            sage: int(1/I)
839            Traceback (most recent call last):
840            ...
841            TypeError: cannot coerce nonconstant polynomial to int
842            sage: int(I*I)
843            -1
844
845            sage: K.<a> = NumberField(x^10 - x - 1)
846            sage: int(a)
847            Traceback (most recent call last):
848            ...
849            TypeError: cannot coerce nonconstant polynomial to int
850            sage: int(K(9390283))
851            9390283
852
853        The semantics are like in Python, so the value does not have
854        to preserved.
855            sage: int(K(393/29))
856            13           
857        """
858        return int(self.polynomial())
859
860    def __long__(self):
861        """
862        Attempt to convert this number field element to a Python long,
863        if possible.
864       
865        EXAMPLES:
866            sage: K.<a> = NumberField(x^10 - x - 1)
867            sage: long(a)
868            Traceback (most recent call last):
869            ...
870            TypeError: cannot coerce nonconstant polynomial to long
871            sage: long(K(1234))
872            1234L
873
874        The value does not have to be preserved, in the case of fractions.
875            sage: long(K(393/29))
876            13L       
877        """
878        return long(self.polynomial())
879
880    cdef void _parent_poly_c_(self, ZZX_c *num, ZZ_c *den):
881        cdef long i
882        cdef ZZ_c coeff
883        cdef ntl_ZZX _num
884        cdef ntl_ZZ _den
885        if isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_extension):
886            # ugly temp code
887            f = self.parent().absolute_polynomial()
888
889            __den = f.denominator()
890            (<Integer>ZZ(__den))._to_ZZ(den)
891
892            __num = f * __den
893            for i from 0 <= i <= __num.degree():
894                (<Integer>ZZ(__num[i]))._to_ZZ(&coeff)
895                SetCoeff( num[0], i, coeff )
896        else:
897            _num, _den = self.parent().polynomial_ntl()
898            num[0] = _num.x[0]
899            den[0] = _den.x[0]
900
901    cdef void _invert_c_(self, ZZX_c *num, ZZ_c *den):
902        """
903        Computes the numerator and denominator of the multiplicative inverse of this element.
904
905        Suppose that this element is x/d and the parent mod'ding polynomial is M/D.  The NTL function
906        XGCD( r, s, t, a, b ) computes r,s,t such that $r=s*a+t*b$.  We compute
907        XGCD( r, s, t, x*D, M*d ) and set
908        num=s*D*d
909        den=r
910
911        EXAMPLES:
912            I'd love to, but since we are dealing with c-types, I can't at this level.
913            Check __invert__ for doc-tests that rely on this functionality.
914        """
915        cdef ZZ_c parent_den
916        cdef ZZX_c parent_num
917        self._parent_poly_c_( &parent_num, &parent_den )
918
919        cdef ZZX_c t # unneeded except to be there
920        cdef ZZX_c a, b
921        mul_ZZX_ZZ( a, self.__numerator, parent_den )
922        mul_ZZX_ZZ( b, parent_num, self.__denominator )
923        XGCD_ZZX( den[0], num[0],  t, a, b, 1 )
924        mul_ZZX_ZZ( num[0], num[0], parent_den )
925        mul_ZZX_ZZ( num[0], num[0], self.__denominator )
926
927    def __invert__(self):
928        """
929        Returns the multiplicative inverse of self in the number field.
930
931        EXAMPLES:
932            sage: C.<I>=CyclotomicField(4)
933            sage: ~I
934            -I
935            sage: (2*I).__invert__()
936            -1/2*I
937        """
938        if IsZero_ZZX(self.__numerator):
939            raise ZeroDivisionError
940        cdef NumberFieldElement x
941        x = self._new()
942        self._invert_c_(&x.__numerator, &x.__denominator)
943        x._reduce_c_()
944        return x
945#        K = self.parent()
946#        quotient = K(1)._pari_('x') / self._pari_('x')
947#        if isinstance(K, sage.rings.number_field.number_field.NumberField_extension):
948#            return K(K.pari_rnf().rnfeltreltoabs(quotient))
949#        else:
950#            return K(quotient)
951
952    def _integer_(self):
953        """
954        Returns a rational integer if this element is actually a rational integer.
955
956        EXAMPLES:
957            sage: C.<I>=CyclotomicField(4)
958            sage: (~I)._integer_()
959            Traceback (most recent call last):
960            ...
961            TypeError: Unable to coerce -I to an integer
962            sage: (2*I*I)._integer_()
963            -2
964        """
965        if deg(self.__numerator) >= 1:
966            raise TypeError, "Unable to coerce %s to an integer"%self
967        return ZZ(self._rational_())
968
969    def _rational_(self):
970        """
971        Returns a rational number if this element is actually a rational number.
972
973        EXAMPLES:
974            sage: C.<I>=CyclotomicField(4)
975            sage: (~I)._rational_()
976            Traceback (most recent call last):
977            ...
978            TypeError: Unable to coerce -I to a rational
979            sage: (I*I/2)._rational_()
980            -1/2
981        """
982        if deg(self.__numerator) >= 1:
983            raise TypeError, "Unable to coerce %s to a rational"%self
984        cdef Integer num
985        num = PY_NEW(Integer)
986        ZZX_getitem_as_mpz(&num.value, &self.__numerator, 0)
987        return num / (<IntegerRing_class>ZZ)._coerce_ZZ(&self.__denominator)
988
989    def conjugate(self):
990        """
991        Return the complex conjugate of the number field element.  Currently,
992        this is implemented for cyclotomic fields and quadratic extensions of Q. 
993        It seems likely that there are other number fields for which the idea of
994        a conjugate would be easy to compute.
995
996        EXAMPLES:
997            sage: k.<I> = QuadraticField(-1)
998            sage: I.conjugate()
999            -I
1000            sage: (I/(1+I)).conjugate()
1001            -1/2*I + 1/2
1002            sage: z6=CyclotomicField(6).gen(0)
1003            sage: (2*z6).conjugate()
1004            -2*zeta6 + 2
1005
1006            sage: K.<b> = NumberField(x^3 - 2)
1007            sage: b.conjugate()
1008            Traceback (most recent call last):
1009            ...
1010            NotImplementedError: complex conjugation is not implemented (or doesn't make sense).
1011        """
1012        coeffs = self.parent().polynomial().list()
1013        if len(coeffs) == 3 and coeffs[2] == 1 and coeffs[1] == 0:
1014            # polynomial looks like x^2+d
1015            # i.e. we live in a quadratic extension of QQ
1016            if coeffs[0] > 0:
1017                gen = self.parent().gen()
1018                return self.polynomial()(-gen)
1019            else:
1020                return self
1021        elif isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_cyclotomic):
1022            # We are in a cyclotomic field
1023            # Replace the generator zeta_n with (zeta_n)^(n-1)
1024            gen = self.parent().gen()
1025            return self.polynomial()(gen ** (gen.multiplicative_order()-1))
1026        else:
1027            raise NotImplementedError, "complex conjugation is not implemented (or doesn't make sense)."
1028
1029    def polynomial(self):
1030        """
1031        Return the underlyling polynomial corresponding to this
1032        number field element.
1033
1034        The resulting polynomial is currently *not* cached.
1035
1036        EXAMPLES:
1037            sage: K.<a> = NumberField(x^5 - x - 1)
1038            sage: f = (-2/3 + 1/3*a)^4; f
1039            1/81*a^4 - 8/81*a^3 + 8/27*a^2 - 32/81*a + 16/81
1040            sage: g = f.polynomial(); g
1041            1/81*x^4 - 8/81*x^3 + 8/27*x^2 - 32/81*x + 16/81
1042            sage: parent(g)
1043            Univariate Polynomial Ring in x over Rational Field
1044
1045        Note that the result of this function is not cached (should this
1046        be changed?):
1047            sage: g is f.polynomial()
1048            False       
1049        """
1050        coeffs = []
1051        cdef Integer den = (<IntegerRing_class>ZZ)._coerce_ZZ(&self.__denominator)
1052        cdef Integer numCoeff
1053        cdef int i
1054        for i from 0 <= i <= deg(self.__numerator):
1055            numCoeff = PY_NEW(Integer)
1056            ZZX_getitem_as_mpz(&numCoeff.value, &self.__numerator, i)
1057            coeffs.append( numCoeff / den )
1058        return QQ['x'](coeffs)
1059
1060    def denominator(self):
1061        """
1062        Return the denominator of this element, which is by definition
1063        the denominator of the corresponding polynomial
1064        representation.  I.e., elements of number fields are
1065        represented as a polynomial (in reduced form) modulo the
1066        modulus of the number field, and the denominator is the
1067        denominator of this polynomial.
1068
1069        EXAMPLES:
1070            sage: K.<z> = CyclotomicField(3)
1071            sage: a = 1/3 + (1/5)*z
1072            sage: print a.denominator()
1073            15
1074        """
1075        return (<IntegerRing_class>ZZ)._coerce_ZZ(&self.__denominator)
1076
1077    def _set_multiplicative_order(self, n):
1078        """
1079        Set the multiplicative order of this number field element.
1080
1081        WARNING -- use with caution -- only for internal use!  End
1082        users should never call this unless they have a very good
1083        reason to do so.
1084
1085        EXAMPLES:
1086            sage: K.<a> = NumberField(x^2 + x + 1)
1087            sage: a._set_multiplicative_order(3)
1088            sage: a.multiplicative_order()
1089            3
1090
1091        You can be evil with this so be careful.  That's why the function
1092        name begins with an underscore.
1093            sage: a._set_multiplicative_order(389)
1094            sage: a.multiplicative_order()
1095            389       
1096        """
1097        self.__multiplicative_order = n
1098
1099    def multiplicative_order(self):
1100        """
1101        Return the multiplicative order of this number field element.
1102
1103        EXAMPLES:
1104            sage: K.<z> = CyclotomicField(5)
1105            sage: z.multiplicative_order()
1106            5
1107            sage: (-z).multiplicative_order()
1108            10
1109            sage: (1+z).multiplicative_order()
1110            +Infinity       
1111        """
1112        if self.__multiplicative_order is not None:
1113            return self.__multiplicative_order
1114
1115        if deg(self.__numerator) == 0:
1116            if self._rational_() == 1:
1117                self.__multiplicative_order = 1
1118                return self.__multiplicative_order
1119            if self._rational_() == -1:
1120                self.__multiplicative_order = 2
1121                return self.__multiplicative_order
1122
1123        if isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_cyclotomic):
1124            t = self.parent()._multiplicative_order_table()
1125            f = self.polynomial()
1126            if t.has_key(f):
1127                self.__multiplicative_order = t[f]
1128                return self.__multiplicative_order
1129
1130        ####################################################################
1131        # VERY DUMB Algorithm to compute the multiplicative_order of
1132        # an element x of a number field K.
1133        #
1134        # 1. Find an integer B such that if n>=B then phi(n) > deg(K).
1135        #    For this use that for n>6 we have phi(n) >= log_2(n)
1136        #    (to see this think about the worst prime factorization
1137        #    in the multiplicative formula for phi.)
1138        # 2. Compute x, x^2, ..., x^B in order to determine the multiplicative_order.
1139        #
1140        # todo-- Alternative: Only do the above if we don't require an optional
1141        # argument which gives a multiple of the order, which is usually
1142        # something available in any actual application.
1143        #
1144        # BETTER TODO: Factor cyclotomic polynomials over K to determine
1145        # possible orders of elements?  Is there something even better?
1146        #
1147        ####################################################################
1148        d = self.parent().degree()
1149        B = max(7, 2**d+1)
1150        x = self
1151        i = 1
1152        while i < B:
1153            if x == 1:
1154                self.__multiplicative_order = i
1155                return self.__multiplicative_order
1156            x *= self
1157            i += 1
1158
1159        # it must have infinite order
1160        self.__multiplicative_order = sage.rings.infinity.infinity
1161        return self.__multiplicative_order
1162
1163    def trace(self):
1164        """
1165        Return the trace of this number field element.
1166
1167        EXAMPLES:
1168            sage: K.<a> = NumberField(x^3 -132/7*x^2 + x + 1); K
1169            Number Field in a with defining polynomial x^3 - 132/7*x^2 + x + 1
1170            sage: a.trace()
1171            132/7
1172            sage: (a+1).trace() == a.trace() + 3
1173            True       
1174        """
1175        K = self.parent().base_ring()
1176        return K(self._pari_('x').trace())
1177
1178    def norm(self):
1179        """
1180        Return the norm of this number field element.
1181
1182        EXAMPLES:
1183            sage: K.<a> = NumberField(x^3 + x^2 + x + -132/7); K
1184            Number Field in a with defining polynomial x^3 + x^2 + x - 132/7
1185            sage: a.norm()
1186            132/7
1187            sage: K(0).norm()
1188            0       
1189        """
1190        K = self.parent().base_ring()
1191        return K(self._pari_('x').norm())
1192
1193    def charpoly(self, var='x'):
1194        r"""
1195        The characteristic polynomial of this element over $\Q$.
1196
1197        EXAMPLES:
1198
1199        We compute the charpoly of cube root of $3$.
1200
1201            sage: R.<x> = QQ[]
1202            sage: K.<a> = NumberField(x^3-2)
1203            sage: a.charpoly('x')
1204            x^3 - 2
1205
1206        We construct a relative extension and find the characteristic
1207        polynomial over $\Q$.
1208
1209            sage: S.<X> = K[]
1210            sage: L.<b> = NumberField(X^3 + 17); L
1211            Number Field in b with defining polynomial X^3 + 17 over its base field
1212            sage: a = L.0; a
1213            b
1214            sage: a.charpoly('x')
1215            x^9 + 57*x^6 + 165*x^3 + 6859
1216            sage: a.charpoly('y')
1217            y^9 + 57*y^6 + 165*y^3 + 6859
1218        """
1219        R = self.parent().base_ring()[var]
1220        if not isinstance(self.parent(), sage.rings.number_field.number_field.NumberField_extension):
1221            return R(self._pari_('x').charpoly())
1222        else:
1223            g = self.polynomial()  # in QQ[x]
1224            f = self.parent().pari_polynomial()  # # field is QQ[x]/(f)
1225            return R( (g._pari_().Mod(f)).charpoly() )
1226
1227## This might be useful for computing relative charpoly.
1228## BUT -- currently I don't even know how to view elements
1229## as being in terms of the right thing, i.e., this code
1230## below as is lies.
1231##             nf = self.parent()._pari_base_nf()
1232##             prp = self.parent().pari_relative_polynomial()
1233##             elt = str(self.polynomial()._pari_())
1234##             return R(nf.rnfcharpoly(prp, elt))
1235##         # return self.matrix().charpoly('x')
1236
1237    def minpoly(self, var='x'):
1238        """
1239        Return the minimal polynomial of this number field element.
1240
1241        EXAMPLES:
1242            sage: K.<a> = NumberField(x^2+3)
1243            sage: a.minpoly('x')
1244            x^2 + 3
1245            sage: R.<X> = K['X']
1246            sage: L.<b> = K.extension(X^2-(22 + a))
1247            sage: b.minpoly('t')
1248            t^4 + (-44)*t^2 + 487
1249            sage: b^2 - (22+a)
1250            0       
1251        """
1252        return self.charpoly(var).radical() # square free part of charpoly
1253
1254    def is_integral(self):
1255        r"""
1256        Determine if a number is in the ring of integers
1257        of this number field.
1258       
1259        EXAMPLES:
1260            sage: K.<a> = NumberField(x^2 + 23, 'a')
1261            sage: a.is_integral()
1262            True
1263            sage: t = (1+a)/2
1264            sage: t.is_integral()
1265            True
1266            sage: t.minpoly()
1267            x^2 - x + 6
1268            sage: t = a/2
1269            sage: t.is_integral()
1270            False
1271            sage: t.minpoly()
1272            x^2 + 23/4
1273        """
1274        return all([a in ZZ for a in self.minpoly()])
1275
1276    def matrix(self):
1277        r"""
1278        The matrix of right multiplication by the element on the power
1279        basis $1, x, x^2, \ldots, x^{d-1}$ for the number field.  Thus
1280        the {\em rows} of this matrix give the images of each of the $x^i$.
1281
1282        EXAMPLES:
1283
1284        Regular number field:
1285            sage: K.<a> = NumberField(QQ['x'].0^3 - 5)
1286            sage: M = a.matrix(); M
1287            [0 1 0]
1288            [0 0 1]
1289            [5 0 0]
1290            sage: M.base_ring() is QQ
1291            True
1292
1293        """
1294##         Relative number field:
1295##             sage: L.<b> = K.extension(K['x'].0^2 - 2)
1296##             sage: 1*b, b*b, b**3, b**6
1297##             (b, b^2, b^3, 6*b^4 - 10*b^3 - 12*b^2 - 60*b - 17)
1298##             sage: L.pari_rnf().rnfeltabstorel(b._pari_())
1299##             x - y
1300##             sage: L.pari_rnf().rnfeltabstorel((b**2)._pari_())
1301##             2
1302##             sage: M = b.matrix(); M
1303##             [0 1]
1304##             [3 0]
1305##             sage: M.base_ring() is K
1306##             True
1307
1308#         Absolute number field:
1309#             sage: M = L.absolute_field().gen().matrix(); M
1310#             [  0   1   0   0   0   0]
1311#             [  0   0   1   0   0   0]
1312#             [  0   0   0   1   0   0]
1313#             [  0   0   0   0   1   0]
1314#             [  0   0   0   0   0   1]
1315#             [  2 -90 -27 -10   9   0]
1316#             sage: M.base_ring() is QQ
1317#             True
1318
1319#         More complicated relative number field:
1320#             sage: L.<b> = K.extension(K['x'].0^2 - a); L
1321#             Extension by x^2 + -a of the Number Field in a with defining polynomial x^3 - 5
1322#             sage: M = b.matrix(); M
1323#             [0 1]
1324#             [a 0]
1325#             sage: M.base_ring()
1326#             sage: M.base_ring() is K
1327#             True
1328        # Mutiply each power of field generator on
1329        # the left by this element; make matrix
1330        # whose rows are the coefficients of the result,
1331        # and transpose.
1332        if self.__matrix is None:
1333            K = self.parent()
1334            v = []
1335            x = K.gen()
1336            a = K(1)
1337            d = K.degree()
1338            for n in range(d):
1339                v += (a*self).list()
1340                a *= x
1341            k = K.base_ring()
1342            import sage.matrix.matrix_space
1343            M = sage.matrix.matrix_space.MatrixSpace(k, d)
1344            self.__matrix = M(v)
1345        return self.__matrix
1346
1347    def list(self):
1348        """
1349        EXAMPLE:
1350            sage: K.<z> = CyclotomicField(3)
1351            sage: (2+3/5*z).list()
1352            [2, 3/5]
1353            sage: (5*z).list()
1354            [0, 5]
1355            sage: K(3).list()
1356            [3, 0]
1357        """
1358        P = self.parent()
1359        # The algorithm below is total nonsense, unless the parent of self is an
1360        # absolute extension.
1361        if isinstance(P, sage.rings.number_field.number_field.NumberField_extension):
1362            raise NotImplementedError
1363        n = self.parent().degree()
1364        v = self.polynomial().list()[:n]
1365        z = sage.rings.rational.Rational(0)
1366        return v + [z]*(n - len(v))
Note: See TracBrowser for help on using the repository browser.