Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain rule fails on real, imag, conj, with non-real symbolic functions #1011

Open
amilsted opened this issue Nov 14, 2023 · 1 comment
Open

Comments

@amilsted
Copy link

amilsted commented Nov 14, 2023

julia> using Symbolics

julia> using SymbolicUtils

julia> @syms x::Real f(::Real)::Number
(x, f)

julia> Symbolics.derivative(cos(f(x)), x)    # so far so good
-Differential(x)(f(x))*sin(f(x))

julia> Symbolics.derivative(conj(f(x)), x)   # Symbolics doesn't know how to differentiate these,
Differential(x)(conj(f(x)))*Differential(x)(f(x))

julia> Symbolics.derivative(imag(f(x)), x)   # and it's so upset
Differential(x)(imag(f(x)))*Differential(x)(f(x))

julia> Symbolics.derivative(real(f(x)), x)   # it gets the chain rule wrong
Differential(x)(real(f(x)))*Differential(x)(f(x))

Btw, I am using Numberfor f here to represent a function that might be complex. Same thing happens for f(::Real)::Complex. I am not using Complex{Num} because I do not want to split real and imaginary parts.

@amilsted amilsted changed the title Chain rule fails on real, imag, conj, with Sym{Num} Chain rule fails on real, imag, conj, with symbolic Number Nov 14, 2023
@amilsted
Copy link
Author

Relatedly, it would be very nice if we could add rules for D(x)(conj(f(x))) -> conj(D(x)(f(x))) and similar for complex f but real x.

@amilsted amilsted changed the title Chain rule fails on real, imag, conj, with symbolic Number Chain rule fails on real, imag, conj, with non-real symbolic functions Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant