Function refine doesn't work with re(x) and im(x)

13 views
Skip to first unread message

Juan Luis Cano Rodríguez

unread,
Apr 2, 2012, 8:40:17 AM4/2/12
to sy...@googlegroups.com
An expression can be simplified adding assumptions a posteriori using the refine() function:

  In [33]: refine(sqrt(x ** 2), Q.real(x))
  Out[33]: │x│

but this doesn't seem to work in the complex case when the re() and im() functions are involved:

  In [37]: refine(im(x), Q.real(x))  # I expect 0
  Out[37]: im(x)
  
  In [38]: refine(re(x), Q.real(x))  # I expect x
  Out[38]: re(x)

  In [39]: refine(re(x), Q.imaginary(x))
  Out[39]: re(x)
  
  In [40]: refine(im(x), Q.imaginary(x))
  Out[40]: im(x)

Is this a bug or am I missing something? 

Tom Bachmann

unread,
Apr 2, 2012, 2:55:55 PM4/2/12
to sy...@googlegroups.com
On 02.04.2012 13:40, Juan Luis Cano Rodríguez wrote:
> An expression can be simplified adding assumptions /a posteriori/ using

> the refine() function:
>
> In [33]: refine(sqrt(x ** 2), Q.real(x))
> Out[33]: │x│
>
> but this doesn't seem to work in the complex case when the re() and im()
> functions are involved:
>
> In [37]: refine(im(x), Q.real(x)) # I expect 0
> Out[37]: im(x)
> In [38]: refine(re(x), Q.real(x)) # I expect x
> Out[38]: re(x)
>
> In [39]: refine(re(x), Q.imaginary(x))
> Out[39]: re(x)
> In [40]: refine(im(x), Q.imaginary(x))
> Out[40]: im(x)
>
> Is this a bug or am I missing something?
>

I believe the whole Q.ask / refine / new assumptions stuff has never
been fully incorporated / implemented. So my default is not to expect
any of this to work. But I may be wrong.

> --
> You received this message because you are subscribed to the Google
> Groups "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/Knpy95uKwY8J.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

Reply all
Reply to author
Forward
0 new messages