Implicit Sum and linear functions



On Fri, May 23, 2008 at 8:56 AM, Paulo Grahl <pgrahl at gmail.com> wrote:

> The only problem is that I couldn?t find yet a good place to learn how to make a
> more advanced use of it.

Well, the only thing I can suggest is to take a look at the tutorials at:
http://maxima.sourceforge.net/documentation.html
Each tutorial handles some different topics, so in aggregate perhaps
they cover all the bases ....

> For instance, It took me a while to realize that
> the commands `tellsimp? and `tellsimpafter? only work after `matchdeclare?.
> I couldn?t find this info in Maxima?s manual or in any of the tutorials (I
> might have overlooked it, though).

I dumped everything I could figure out about matchdeclare
and tellsimpafter into the reference manual descriptions.
? matchdeclare and ? tellsimpafter should find it.

> E ('sum (h (k,j), k, 1, n));
>  => 'sum (E (h (k,j)), k, 1, n)
> I know that E(h(k,j)) = a for k=j and E(h(k,j))=b for k<>j, where `a` and
> `b` are constants, and j in [1,n]
> I would like to have
> 'sum (E (h (k,j)), k, 1, n) evaluated to
> => a+b*(n-1).

Perhaps kron_delta (Kronecker delta) is useful here.
S.t. like subst(E(h(i, j)) = a*kron_delta(i, j) + b*(1 - kron_delta(i,
j)), expr)
where expr is 'sum(E(h(i, j)), i, 1, n) or something.

Some further declarations are needed to reduce a sum of kron_delta.
sum by default doesn't appear to know about kron_delta.

declare (sum, linear);
matchdeclare ([ii, jj], symbolp, [ii0, ii1], all);
simp : false;
tellsimp ('sum (kron_delta (ii, jj), ii, ii0, ii1), if jj=ii then ii1
- ii0 + 1 else if ii0 <= j and j <= ii1 then 1 else 0);
simp : true;

then we can get the following:

'sum (E (h (i, j)), i, 1, n);
foo : subst (E (h (i, j)) = a * kron_delta (i, j) + b * (1 -
kron_delta (i, j)), %);
 => b*(n-(if 1 <= j and j <= n then 1 else 0))
 +(if 1 <= j and j <= n then 1 else 0)*a
assume (j>=1 and j<=n);
''foo;
 => b*(n-1)+a
forget (j>=1 and j<=n);

Maxima makes the assumptions about a summation index
automatically, so if the sum over i is within a sum over j we get this:

'sum ('sum (E (h (i, j)), i, 1, n), j, 1, n);
subst (E (h (i, j)) = a * kron_delta (i, j) + b * (1 - kron_delta (i, j)), %);
 => b*(n^2-'sum(if 1 <= j and j <= n then 1 else 0,j,1,n))
 +('sum(if 1 <= j and j <= n then 1 else 0,j,1,n))*a
%, nouns;
 => b*(n^2-n)+a*n

This much seems OK but there are additional complications
which are not accounted for.

HTH

Robert Dodier