symengine / SymEngine.jl

Julia wrappers of SymEngine
MIT License
192 stars 43 forks source link

Substitution inside derivatives is inconsistent #216

Open Gyoshi opened 4 years ago

Gyoshi commented 4 years ago

There is an inconsistency when substituting things in an expression where they are being differentiated:

@vars x
@funs f, g
gee = diff(f(x), x)
diff(g(x), x)(g(x)=>1) # 0
diff(gee, x)(gee=>1) # f_xx

Here we can imagine that g = f', and so the last two lines should be equivalent. It makes sense that if an expression is constant its derivative becomes 0, so this should be the case also when the expression is itself a derivative. Though multivariate functions does make it a bit more complicated.

Of course, there are similar issues of substituting more complicated expressions such as

(3x + 3f(x))(x+f(x)=>1) # substitution does nothing

And this seems to me quite a bit harder to solve, so perhaps I should just accept that substituting anything more complicated than a single variable or function will not always work.