Intelligent approach for differentiation through sums?
Subject: Intelligent approach for differentiation through sums?
From: Mike Valenzuela
Date: Tue, 19 Feb 2013 15:07:43 -0700
Hello,
I am trying to figure out how to implement some rules that will allow
differentiation under (finite) sums.
Example of my goal:
(1) : diffthru( sum(p[i] * x[i]^2, i, 1, I), x[k] ) --->
(2) : sum( diff(p[i] * (x[i]^2, x[i]) * kron_delta[i,k] ) --->
(3) : sum(2 * p[i] * x[i] * kron_delta[i,k], i, 1, I) --->
(4) : 2 * p[k] * x[k]
I realize that several assumptions are required for this to work. First,
the sum should be finite, because wonky things can happen if (I-->infinity).
Second, (1 <= k <= I). Also, I am not certain the form that I wrote step
(2) in is entirely correct.
I only have the utmost simple case working now:
%i1: matchdeclare([xx, ii, jj], atom)$
%i2: tellsimp(diffthru(xx[ii], xx[jj]), kron_delta(ii,jj))$
%i3: diffthru( x[i], x[k] );
%o3: kron_delta(i, k)
Obviously I would like this to work on the following examples:
diffthru( sum(sum( x[i] * A[i,j], i, 1, I), j, 1, J), x[l]);
diffthru( sum(p[i]*x[i],i, 1, I)^2, x[l]);
diffthru( sum((1-p[i])*x[i], i, 1, I) * sum(p[i]*f(x[i]), i, 1, I), x[l])
In general there are objectives:
(a) A diffthru function which can travel inside even multiple sums.
(b) This function should offload the differentiation to diff, but multiply
by the corresponding kron_delta function when possible (if this is even the
correct approach).
(c) Simplify sums where the sum index appears in a Kronecker delta function.
I do not know if I should continue using tellsimp, if I should use the
simplifying package, if I should use some subst function, or anything else.
Thanks in advance for any advice.