Jaime E. Villate wrote:
>On Tue, 2007-04-17 at 07:57 -0700, Daniel Lakeland wrote:
>
>
>>The fastest way to execute this type of loop is to
>>keep two variables which store the first and the second element, and
>>then to step them through the list at each iteration until the second
>>one steps off the list.
>>
>>
>isn't that what I just did ? :)
>
no, if I am looking at the right piece of email,
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));
what you do here is you take a list x, and for each value of i, you start at the beginning of the list and count out i items. Twice. So if x is of length n, you do n^2 work, just finding the elements.
stepping through the list taking successive "rest" parts would take linear work.
RJF
>Jaime
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
>
>