It looks like some parts of the assumptions could be improved here.

Probably the simplest way to get what you want is to blanket replace all
instances of re() with the identity function and im() with 0, like

In [21]: print(a.replace(re, Id).replace(im, lambda x: 0))
Derivative(f(x), x)*Subs(Derivative(_xi_2, _xi_2), (_xi_2,),
(Derivative(f(x), x),))/Abs(Derivative(f(x), x))

In [22]: print(a.replace(re, Id).replace(im, lambda x: 0).doit())
Derivative(f(x), x)/Abs(Derivative(f(x), x))

Aaron Meurer

On Tue, Aug 11, 2015 at 6:07 PM, chaowen guo <[email protected]> wrote:

> Hi:
>
> source code:
> import sympy
> x=sympy.symbols('x',real=True)
> f=sympy.symbols('f',cls=sympy.Function)
> f.is_real=True
> a=sympy.Abs(f(x).diff(x)).diff(f(x).diff(x))
> a
>
> the output is:
>
> (re(Derivative(f(x), x))*Subs(Derivative(re(_xi_2), _xi_2), (_xi_2,), 
> (Derivative(f(x), x),)) + im(Derivative(f(x), x))*Subs(Derivative(im(_xi_2), 
> _xi_2), (_xi_2,), (Derivative(f(x), x),)))/Abs(Derivative(f(x), x))
>
>
> the imaginary part still exist. Obviously, sympy does not think
> f(x).diff(x) is real. So I try:
> sympy.refine(a,sympy.Q.real(f(x).diff(x)))
> but the output remains the same. So how to tell sympy that f(x).diff(x) is
> real?
>
> More weird stuff is:
> f(x).diff(f(x))
> the output is 1
>
> but:
> sympy.Abs(f(x)).diff(f(x))
> the output is:
>
> f(x)*Subs(Derivative(re(_xi_2), _xi_2), (_xi_2,), (f(x),))/Abs(f(x))
> why sympy is not smart enough to simplify it to f(x)/Abs(f(x))?
>
> I use python3.4 and sympy 0.7.6
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" 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/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/2deb519b-9cdd-4b2e-93d7-f3f252ff8fc6%40googlegroups.com
> <https://groups.google.com/d/msgid/sympy/2deb519b-9cdd-4b2e-93d7-f3f252ff8fc6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" 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/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6JDUz1Pj%3Dof2g9n-Ayhws0t1TGWejg5KZ_A5NdRFa-BgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to