On Tuesday, February 24, 2015 at 2:55:28 PM UTC-7, Ondřej Čertík wrote:
>
> On Tue, Feb 24, 2015 at 2:44 PM, John Peterson <[email protected] 
> <javascript:>> wrote: 
> > 
> > 
> > On Friday, February 13, 2015 at 1:18:56 PM UTC-7, chaowen guo wrote: 
> >> 
> >> I run the following code in ipython3 notebook: 
> >> 
> >> import sympy 
> >> x=sympy.symbols("x",real=True) 
> >> f=sympy.symbols("f",cls=sympy.Function,real=True) 
> >> sympy.Abs(f(x)).diff(x) 
> >> 
> >> and expect that the answer is just df(x)/dx. However, sympy still treat 
> >> the function f is a complex function. 
> >> 
> >> So how to tell sympy that f is a real function? 
> > 
> > 
> > 
> > I would also like to know if there's a way to do this...  "real=True" 
> does 
> > not seem to have any special meaning for Functions. 
> > 
> > Here's an equivalent test case: 
> > 
> >> #!/usr/bin/env python 
> >> from sympy import * 
> >> X = Symbol('X', real=True) 
> >> f = Function('f', real=True)(X) 
> >> g = Function('g', real=True)(X) 
> >> print diff (abs(f-g), X) 
> > 
> > 
> > The output is: 
> > 
> >> ((re(f(X)) - re(g(X)))*(re(Derivative(f(X), X)) - re(Derivative(g(X), 
> X))) 
> >> + (im(f(X)) - im(g(X)))*(im(Derivative(f(X), X)) - im(Derivative(g(X), 
> >> X))))/Abs(f(X) - g(X)) 
> > 
> > 
> > Note that a possible workaround is with subs: 
> > 
> >> print diff (abs(f-g), X).subs([(im(f),0), 
> >>                                (im(g),0), 
> >>                                (re(f),f), 
> >>                                (re(g),g), 
> >>                                (re(Derivative(f, X)), Derivative(f, 
> X)), 
> >>                                (re(Derivative(g, X)), Derivative(g, 
> X))]) 
> > 
> > 
> > Which prints: 
> > 
> >> (f(X) - g(X))*(Derivative(f(X), X) - Derivative(g(X), X))/Abs(f(X) - 
> g(X)) 
>
> We have an issue for what diff(abs(x), x) should be: 
>
> https://github.com/sympy/sympy/issues/8502 
>

Yes, I came across this while searching for solutions to my issue.  Very 
interesting!

Actually I'm not too concerned about exactly what form of the derivative is 
used, only that re() and im() don't appear for Functions declared to be 
real.
 

and what you found seems like a bug. SymPy should be able to use the 
> fact that "f" is real. 


OK. If you want me to, I can move this over to an issue at GitHub...

 

-- 
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/03c7a2bd-5031-41d3-96e0-5f95aae12ce8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to