Rose, This is a very common error: the symbol I denotes a symbolic square root of -1 and not a numerical complex number. To use it as a numerical constant you need to coerce it into the complex field CC. For example:
sage: i=CC(I) sage: z=4+5*i sage: z.norm() 41.0000000000000 sage: z.norm().sqrt() 6.40312423743285 I hope this helps. John Cremona 2008/5/25 Rose <[EMAIL PROTECTED]>: > > Hi, > > I use the function abs to know the distance between two > ComplexNumbers. Sometimes it returns a RealNumber, but sometimes it > returns a SymbolicComposition. When it returns SymbolicComposition, I > can not use it in a function expecting a RealNumber, and does not work > when I try to cast it myself (with RR). > > Is there something I misunderstand? > Anyway, may-you sugest a workarround? > > > Rose > > p.s. It fails also with sqrt(norm(z)). > > example: > > sage:z.rayon() > 0.333333333333333 > > sage:z.rayon > abs((1.414213562373095*(1.414213562373095*I + 1) + > 1.00000000000000*I)/(1.414213562373095 - > 1.00000000000000*I*(1.414213562373095*I + 1)) - 1.414213562373095*I) > > sage:type(z.rayon()) > <class 'sage.calculus.calculus.SymbolicComposition'> > > sage:RR(z.rayon()) > Traceback (click to the left for traceback) > ... > TypeError > > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/home/rosie/.sage/sage_notebook/worksheets/admin/1/code/ > 59.py", line 6, in <module> > RR(z.rayon()) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sympy/plotting/", line 1, in <module> > > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 6066, in > _mpfr_ > x = f(g._mpfr_(field)) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 3924, in > _mpfr_ > return field(self._obj) > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4703, in > _convert > return typ(g) > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4749, in > _mpfr_ > return self._convert(field) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 4697, in > _convert > fops = [typ(op) for op in self._operands] > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/calculus/calculus.py", line 3924, in > _mpfr_ > return field(self._obj) > File "real_mpfr.pyx", line 299, in > sage.rings.real_mpfr.RealField.__call__ (sage/rings/real_mpfr.c:3108) > File "/home/rosie/sage-3.0.1-ubuntu32-intel-sse2-i686-Linux/local/ > lib/python2.5/site-packages/sage/functions/constants.py", line 856, in > _mpfr_ > raise TypeError > TypeError > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
