On 29-Aug-08, at 11:47 AM, John Cremona wrote:
> > If f is a real polynomial then f.roots(RR) gives the real roots, and > f.roots(CC) gives the complex (including real) roots. Is there a > fool-proof way of getting at the non-real roots? (You may assume that > the coefficients of f are exact, perhaps they are rationals, so the > questions is certainly well-defined.) > > But now I need it again in the context of K.embeddings(L) for K a > number field. With a little work, Carl Witty's marvelous QQbar implementation could help. His code will do the "doubling precision" part for you, and you can ask if any particular root is real -- but I found some bugs doing this, shown below. Also, you could probably be certain that roots(QQbar) - roots(AA) would work. Nick {{{ sage: t = (ZZ['x'].0^2 - 2).roots(QQbar)[0][0] sage: t.real() [-1.4142135623730952 .. -1.4142135623730949] sage: t.real() == t --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/<ipython console> in <module>() /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/element.pyx in sage.structure.element.Element.__richcmp__ (sage/structure/element.c: 4819)() /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/element.pyx in sage.structure.element.Element._richcmp (sage/structure/element.c:4404) () /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/element.pyx in sage.structure.element.Element._richcmp_ (sage/structure/element.c: 4255)() /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/element.pyx in sage.structure.element.Element._richcmp (sage/structure/element.c:4714) () /Users/ncalexan/sage-3.0.6/local/lib/python2.5/site-packages/sage/ rings/qqbar.py in __cmp__(self, other) 2444 """ 2445 if self is other: return 0 -> 2446 rcmp = cmp(self.real(), other.real()) 2447 if rcmp != 0: 2448 return rcmp /Users/ncalexan/sage-3.0.6/local/lib/python2.5/site-packages/sage/ rings/qqbar.py in real(self) 2680 2681 def real(self): -> 2682 return AlgebraicReal(self._descr.real(self)) 2683 2684 def imag(self): /Users/ncalexan/sage-3.0.6/local/lib/python2.5/site-packages/sage/ rings/qqbar.py in real(self, n) 1805 1806 def real(self, n): -> 1807 if self.is_complex(): 1808 return ANUnaryExpr(n, 'real') 1809 else: AttributeError: 'ANUnaryExpr' object has no attribute 'is_complex' sage: t.is_complex() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/<ipython console> in <module>() AttributeError: 'AlgebraicNumber' object has no attribute 'is_complex' sage: t [-1.4142135623730952 .. -1.4142135623730949] sage: t.real() [-1.4142135623730952 .. -1.4142135623730949] sage: t.complex() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /Users/ncalexan/Devel/Squeak-3.10-1/platforms/unix/bld/<ipython console> in <module>() AttributeError: 'AlgebraicNumber' object has no attribute 'complex' sage: t.imag() [0.00000000000000000 .. 0.00000000000000000] sage: t.imag() == 0 True }}} --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---