On 06/14/2014 12:43 AM, [email protected] wrote:
> I am coming up to speed on Python, Sympy, and Sage by doing some simple
> problems on all three. Sympy has an option for its expand function,
> complex=True, that has made some of my expressions easier to read/use.
> I'm working with quotients of complex numbers. This option allows Sympy
> to return expressions that look like a + bi broadly speaking with nice
> relations for a and b. With Sage so far, I can't seem to get the
> equivalent level of expansion.
>
> I'd like to ask if there is a way to invoke that complex=True or its
> equivalent within Sage. I've done a bit of searching but so far the
> answer has not jumped out at me. I also tried the other support system
> but don't have enough points to post.
>
The sage expand() function doesn't use sympy. However, we have the
ability to send symbolic expressions back and forth between sage and
sympy, so it is possible.
First thing you should do is open a trac ticket with a feature request.
It should be possible to add the "complex" parameter to the sage
expand() function using sympy.
Second, for a workaround, you can do the following:
sage: x = SR.symbol('x')
sage: x._sympy_().expand()
x
sage: x._sympy_().expand(complex = True)
re(x) + I*im(x)
This will give you the *visual* representation that you want, but it
isn't very convenient to work with. It looks like nobody's told sage how
to convert the sympy im() function back into a sage expression yet:
sage: x._sympy_().expand(complex = True)._sage_()
...
AttributeError: 'im' object has no attribute '_sage_'
This wouldn't be super difficult to do, though; the following already
works in sage:
sage: x.real_part() + I*x.imag_part()
I*imag_part(x) + real_part(x)
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.