Subject: symbolic subscript of literal list or matrix
From: Barton Willis
Date: Tue, 24 Jul 2007 14:52:15 -0500
-----maxima-bounces at math.utexas.edu wrote: -----
>> Might a : [1, 2, 3]; a[k] => a[k] be better handled via
>> a user-defined simplifying function?
>
>Dunno about that, but two possible workarounds are
>either to make L a declared array, or write 'L[k] (and
>somehow cause evaluation later).
I doubt that this will catch on; nevertheless:
(%i1) load("simplifying.lisp")$
(%i2) simp_part(x,k) := if integerp(k) and listp(x) then inpart(x,k) else
simpfuncall('xpart,x,k);
simplifying('xpart, simp_part);
(%o2) simp_part(x,k):=if integerp(k) and listp(x) then inpart(x,k) else
simpfuncall('xpart,x,k)
(%o3) xpart
(%i4) l : [1,2,3,4,5]$
(%i5) sum(xpart(l,k),k,1,5);
(%o5) 15
(%i6) sum(xpart(l,k),k,1,n);
(%o6) sum(xpart([1,2,3,4,5],k),k,1,n)
(%i7) subst(n=5,%);
(%o7) 15
(%i10) sum(xpart(ll,k),k,1,n);
(%o10) sum(xpart(ll,k),k,1,n)
(%i11) subst([ll = l, n = 5],%);
(%o11) 15
Barton