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

12 views

### Juan Luis Cano Rodríguez

Apr 2, 2012, 8:40:17 AM4/2/12
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

Apr 2, 2012, 2:55:55 PM4/2/12
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