Search code examples
maxima

Select the elements at even indexes in maxima


In maxima, "sublist" allows you to select certain elements of a list with different criterions. I'd like to select the elements at even indexes. I've thought about something like

sublist([1,2,4,5,7,8],evenp(sublist_indices()));

but obviously it doesn't work. How can I do it without writing down a for loop?


Solution

  • Well, how about something like:

    (%i2) L : [a, b, c, d, e, f, g];
    (%o2)                        [a, b, c, d, e, f, g]
    (%i3) makelist (L[2*i], i, 1, floor (length(L) / 2));
    (%o3)                              [b, d, f]