# [Maxima] List and Array indexing

Rupert Swarbrick rswarbrick at gmail.com
Mon May 14 16:24:26 CDT 2012

```Evgeniy Maevskiy <emaevskiy at mail.ru> writes:
> Good day for all.
>
> There are some problems...
>
> kill(x,a)\$
> x:makelist(x[2*k/(k^2+1)],k,-2,3);
> x[1]:a\$
> x;
> x[0];
> x[-4/5];
> listp(x);
> arrayinfo(x);
>
> kill(x,a)\$
> x[1]:a\$
> x:makelist(x[2*k/(k^2+1)],k,-2,3);
> x[1];
> x[0];
> x[-4/5];
> listp(x);
> arrayinfo(x);
>
> Can somebody explain to me the logic of indexing?
>
> Thanks.

Firstly: you have sent a reasonably aggravating message. It's a lot
easier for others on the list to respond to a message of the form "I did
A, expecting B but C happened. Why? or How can I get B instead?" Asking
such questions might make it more likely that you get responses to what

expressions like x[k] get treated specially. The first example you give
is not particularly confusing. Notice that when you say x[1]: a, you are
saying "take the list stored at x and stick a in its first element"
(remember Maxima uses 1-based indexing). The statement, x[0] yields an
error, because you are asking for an element that doesn't exist in the
list. Similarly for x[-4/5].

In the second example, you set up a hashed array in x with your second
line. Then the following line is really odd: I didn't know that Maxima
even let the user do that. What you have done is set up a situation
where x on its own refers to the list, but x[anything] is a subscripted
array element.

Anyway, that's what happens in your "problems". Now you have to explain
what you were expecting and why you think what you get is
wrong. Although I'm pretty certain it won't make any difference in this
case, it's generally also a good idea to let us know what version of
Maxima you are using. And possibly to show input / output. That would be
nice.

Rupert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20120514/4377edfc/attachment-0001.pgp>
```