Derivative of Indexed by index: does it make sense?

77 views
Skip to first unread message

Francesco Bonazzi

unread,
Jan 26, 2017, 4:32:46 AM1/26/17
to sympy
Just a question:

We currently only have indexed derivatives by indexed objects:

>>> A[i].diff(A[j])
KroneckerDelta(i, j)

But, does it make sense to derive an indexed symbol by the index?

>>> A[i].diff(i)
A
[1]

>>> A[i**2].diff(i)
A
[2*i]

Currently the aforementioned operations return 0.

I thought we could add this kind of operation, but I'm not sure if it makes sense. Indices are supposed to be integers, but indices can also be any kind of expression.

Björn Dahlgren

unread,
Jan 26, 2017, 11:04:01 AM1/26/17
to sympy


On Thursday, 26 January 2017 10:32:46 UTC+1, Francesco Bonazzi wrote:

But, does it make sense to derive an indexed symbol by the index?


Do you have an applied example where this would help? If it simplifies users' code I think that would be an argument for it.

Francesco Bonazzi

unread,
Jan 26, 2017, 1:06:27 PM1/26/17
to sympy
This could solve the issue https://github.com/sympy/sympy/issues/11444

Expr.is_constant() checks whether the expression derivative by its free symbols is nonzero. Unfortunately A[i].diff(i) currently gives 0.

Free symbols of A[i] are A and i.



On Thursday, 26 January 2017 17:04:01 UTC+1, Björn Dahlgren wrote:

Do you have an applied example where this would help? If it simplifies users' code I think that would be an argument for it.

 Not really, indices are supposed to be integers, the derivative doesn't make any sense. On the other hand integer symbols are still derivable in SymPy.

Furthermore, nothing forbids to use indexed objects as very strange functions.

Aaron Meurer

unread,
Jan 26, 2017, 2:40:10 PM1/26/17
to sy...@googlegroups.com
I don't think it makes sense. The index is a discrete variable, but
derivatives only make sense for continuous variables.

Aaron Meurer
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/b3729b12-0fbd-4fa2-ab6a-c944fef19f11%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Björn Dahlgren

unread,
Jan 29, 2017, 7:12:32 AM1/29/17
to sympy


On Thursday, 26 January 2017 20:40:10 UTC+1, Aaron Meurer wrote:
I don't think it makes sense. The index is a discrete variable, but
derivatives only make sense for continuous variables.


I agree with Aaron, I think making the Expr.is_constant method aware of Indexed would be the preferred path.

Aaron Meurer

unread,
Jan 29, 2017, 7:51:05 PM1/29/17
to sy...@googlegroups.com
Perhaps the derivative should raise an exception and is_constant should ignore the derivative check if the derivative raises an exception. 

Aaron Meurer 

--
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 sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.

Francesco Bonazzi

unread,
Jan 30, 2017, 4:43:22 AM1/30/17
to sympy


On Monday, 30 January 2017 01:51:05 UTC+1, Aaron Meurer wrote:
Perhaps the derivative should raise an exception and is_constant should ignore the derivative check if the derivative raises an exception.

https://github.com/sympy/sympy/pull/12109

I made the derivative return S.NaN in case the symbol appears in the indices. It appears to work.
Reply all
Reply to author
Forward
0 new messages