Updates:
        Status: Accepted

Comment #1 on issue 1964 by asmeurer: as_real_imag for Piecewise does not give correct answer
http://code.google.com/p/sympy/issues/detail?id=1964

I get the following in master:


In [1]: x = Symbol('x', real=True)

In [2]: a = 2*I*(3*sin(4*x)-3*sin(4*x)*Piecewise((2.0, x<0), (1.0, 0 <= x)))

In [3]: a.as_real_imag()
Out[3]:
⎛-6⋅ⅈ⋅⎛ⅈ⋅im⎛⎧2.0  for x < 0⎞ + re⎛⎧2.0  for x < 0⎞⎞⋅sin(4⋅x), 6⋅sin(4⋅x)⎞
⎜     ⎜    ⎜⎨              ⎟     ⎜⎨              ⎟⎟                     ⎟
⎝     ⎝    ⎝⎩1.0  for 0 ≤ x⎠     ⎝⎩1.0  for 0 ≤ x⎠⎠                     ⎠

In [4]: re(a)
Out[4]:
-im⎛2⋅⎛3⋅sin(4⋅x) - 3⋅sin(4⋅x)⋅⎧2.0  for x < 0⎞⎞
   ⎜  ⎜                        ⎨              ⎟⎟
   ⎝  ⎝                        ⎩1.0  for 0 ≤ x⎠⎠

In [5]: im(a)
Out[5]:
re⎛2⋅⎛3⋅sin(4⋅x) - 3⋅sin(4⋅x)⋅⎧2.0  for x < 0⎞⎞
  ⎜  ⎜                        ⎨              ⎟⎟
  ⎝  ⎝                        ⎩1.0  for 0 ≤ x⎠⎠


In Maple (assuming x is real):

Re(a);
                       6 sin(4 x) / / 0.      x < 0 \
                                  |{                |
                                  \ \ 0.      0 <= x/
Im(a);
                6 sin(4 x) - 6 sin(4 x) / / 2.0      x < 0 \
                                        |{                 |
                                        \ \ 1.0      0 <= x/

But not assuming x is real:


Re(a);
               6 Im/-sin(4 x) + sin(4 x) / / 2.0      x < 0 \\
                   |                     |{                 ||
                   \                     \ \ 1.0      0 <= x//
Im(a);
              -6 Re/-sin(4 x) + sin(4 x) / / 2.0      x < 0 \\
                   |                     |{                 ||
                   \                     \ \ 1.0      0 <= x//

So I think SymPy is just not doing enough assumptions simplification. Someone else should do some closer debugging.

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to