On Tue, Feb 24, 2015 at 2:44 PM, John Peterson <[email protected]> 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 and what you found seems like a bug. SymPy should be able to use the fact that "f" is real. Ondrej -- 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/CADDwiVBO2Y9yr6WOZOd769W%2BY1%3DPxdYp%3DDnHE4waFEHiLW56Hw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
