def parse_imaginary_real(expression): """ It takes an expression and parse correctly the imaginary and real part of first derivatives of a real or imaginary function. This function works only for first derivatives. It could be extended easily to work with second or higher order derivatives as well. """ all_variables = globals() # Get the variables that are functions all_functions = [x for x in all_variables.values() if isinstance(x, sy.Function)] new_exp = expression for f in all_functions: if f.is_real: elif f.is_imaginary: return new_expThere is an open issue about this https://github.com/sympy/sympy/issues/11868.
Aaron Meurer
On Fri, Feb 28, 2020 at 12:00 PM Lorenzo Monacelli
<lorenzo92...@gmail.com> wrote:
>
> Dear all,
> I have a complex expression and I want to separate imaginary and real part, however I noticed that when I have derivatives on a function, the real and imaginary part separation does not work properly:
>
> t = sy.Symbol("t", real = True)
> f = sy.Function("f", real = True)(t)
>
> Then if I ask sympy the imaginary part of f, it correctly returns 0, however if I ask the immaginary part of the derivative of f, it is not able to see that it is zero:
>
> sy.im(f) # this is zero (ok!)
> sy.im(sy.diff(f, t)) # does not simplify to zero
>
> How can I force sympy to set automatically the derivative of f to real numbers?
> Thanks in advance for the help,
> Bests,
> Lorenzo
>
> --
> 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 sy...@googlegroups.com.
def parse_imaginary_real(expression): """ It takes an expression and parse correctly the imaginary and real part of first derivatives of a real or imaginary function. This function works only for first derivatives. It could be extended easily to work with second or higher order derivatives as well. """ all_variables = globals() # Get the variables that are functions all_functions = [x for x in all_variables.values() if isinstance(x, sy.Function)] new_exp = expression for f in all_functions: if f.is_real: