symbolic subscript of literal list or matrix



On 7/24/07, Barton Willis <willisb at unk.edu> wrote:

> >> > I would like to change it so that a subscript expression is returned.
> >> > E.g. a : [1, 2, 3]; a[k] => a[k]
>
> What problem does this solve?

I bumped into it in the following example, which I don't consider far-fetched.

L : [1, 2, 3, 4, 5];
'sum (L[k], k, 1, 5);
=>
Subscript must be an integer:
g15913

> Might this scheme just make errors happen later instead of sooner?

Well, I don't feel much obligation to protect the user from himself.
You know the old saying: preventing stupidity prevents cleverness as well.

> Had the LU code not immediately given array out of bounds errors,
> I might still be debugging.

It's OK by me if L[k] => error when k is provably not in the
set of indices of L.

> 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).

> Also what happens with things like a : [1, 2, 3]; a[%pi]?
> Or with assume(k > 5), a : [1,2,3], a[k]?

In these examples, the would-be indices are provably
not in the set of indices, so these should yield errors.

> Is it worth the effort to get such things to work reasonably?

Yes. I'm willing to do the work if you're willing to approve it.

best
Robert