ggrafendorfer wrote:
> Hi Jason,
> thanks for your suggestion and your detailed answer,
>
> but actually I did not start this thread for performance reasons,
> I did start it to ask why "i^2" is not treated like an exact symbolic
> expression in sage:
>
> ----------------------------------------------------------------------
> | Sage Version 3.2, Release Date: 2008-11-20 |
> | Type notebook() for the GUI, and license() for information. |
> ----------------------------------------------------------------------
>
> sage: i^2
> -1
> sage: CDF(_)
> -1.0 + 1.22460635382e-16*I
>
>
> and I was wondering if this is a bug, obviously it is not, but I still
> don't understand it :-)
Okay. What's happening here is what Robert pointed out before. The
simplification of i^2 == -1 takes place upon *printing* i^2. Thus,
CDF(_) is literally doing CDF(i^2), not CDF(-1). Maybe this will help:
sage: x=i^2
sage: x
-1
sage: type(x)
<class 'sage.calculus.calculus.SymbolicArithmetic'>
sage: x.__dict__
{'_binary': True,
'_l_assoc': False,
'_operands': [I, 2],
'_operator': <built-in function pow>,
'_precedence': 3000,
'_r_assoc': True,
'_simp': -1,
'_unary': False}
You can see that, although x prints as "-1", it really internally is
still "i^2" (see the _operator, which is the power operator, and the
_operands, which are I and 2, i.e., I^2). So CDF(x) is *not* CDF(-1),
but rather is CDF(I^2), and so we run into the numerical problems that
we dealt with earlier.
If instead, we do:
sage: x=simplify(i^2)
sage: type(x)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: CDF(x)
-1.0
Notice now that x is a SymbolicConstant (i.e., -1), so CDF(x) gives us
back the -1 floating point number we expect.
Jason
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---