question about sublist



Thanks to all who responded.

I was trying to find a way to use the built-in sublist and lambda
functions.

Please see the attached file.

The function 'j_sublist' is the routine which Jaime suggested.

The function 'li_2' makes a list of pairs out of a given list.

The function pos_2 uses 'sublist' and 'lambda'.

It seems to work very fast.

The slow part becomes making the routine li_2.

Is there a function which selects indexed list elements to feed to
lambda?

TIA,
  -sen



  ---------------------------------------------------------------------------
  | Sheldon E. Newhouse            |    e-mail: sen1 at math.msu.edu           |
  | Mathematics Department         |       				   |
  | Michigan State University      | telephone: 517-355-9684                |
  | E. Lansing, MI 48824-1027 USA  |       FAX: 517-432-1562                |
  ---------------------------------------------------------------------------

On Tue, 17 Apr 2007, Jaime E. Villate wrote:

> On Tue, 2007-04-17 at 11:08 -0400, Stavros Macrakis wrote:
>> This will work, but using indexing to access elements of a Maxima list
>> is not very efficient; each index operation x[i] takes O(i) time.
> thanks for the tip. I didn't know that.
> Jaime
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
-------------- next part --------------
showtime: all;

xrl(i):= makelist(random(10.0)-5,j,1,i);


j_sublist(x):= block([l: [], prev: x[1]], for i:2 thru length(x) do
        (if prev*x[i] > 0 then l: cons(prev,l), prev:x[i]), reverse(l));

pos(list):= sublist(list, lambda([list], list > 0))$

li_2(list):= makelist([list[i],list[i+1]],i,1, length(list) -1)$

pos_2(list):= 
     sublist(list, lambda([x],x[1]*x[2] > 0))$