Status: Valid
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 3329 by [email protected]: as_real_imag() does not go deep enough
http://code.google.com/p/sympy/issues/detail?id=3329

In [63]: r = Symbol('r', real=True)

In [64]: i = Symbol('i', imaginary=True)

In [69]: re(i*r*x)
Out[69]: r⋅re(i⋅x)

In [70]: im(i*r*x)
Out[70]: r⋅im(i⋅x)

In [71]: (i*r*x).as_real_imag()
Out[71]: (r⋅re(i⋅x), r⋅im(i⋅x))

In [72]: (i*r*x).as_real_imag(deep=True)
Out[72]: (r⋅re(i⋅x), r⋅im(i⋅x))

The i*x can be expanded.  expand(complex=True) gets it right

In [65]: (i*r*x).expand(complex=True)
Out[65]: i⋅r⋅re(x) + ⅈ⋅i⋅r⋅im(x)

In [66]: re((i*r*x).expand(complex=True))
Out[66]: ⅈ⋅i⋅r⋅im(x)

In [67]: im((i*r*x).expand(complex=True))
Out[67]: -ⅈ⋅i⋅r⋅re(x)

In [68]: (i*r*x).expand(complex=True).as_real_imag()
Out[68]: (ⅈ⋅i⋅r⋅im(x), -ⅈ⋅i⋅r⋅re(x))

I believe the problem is in Mul.as_real_imag, but my attempts to fix it only resulted in recursion errors. Probably the whole thing needs to be refactored like expand from https://github.com/sympy/sympy/pull/1431.

Note that expand(complex=True) is nothing more than a wrapper around as_real_imag, but expand recurses all the way in the expression tree.

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
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/sympy-issues?hl=en.

Reply via email to