oldk1331 wrote:
> 
> > Yes it is resonable.  My only doubts is that as you
> > noticed there is only one place that currently uses
> > two argument 'last', so I am not sure how useful
> > is extending this functionality by adding new 'last'.
> 
> This is how I notice this:
> 
> I read about an algorithm that "scan once to find the
> nth last element", the solution is to use 2 pointers.
> I tested and in the List case, it's much slower than
> elt(a, #a - n).

You probably mean faster -- if "scan once" is slower
why to use it?  But there should not be much difference:
you need to traverse list to the end anyway and the
second pointer has to traverse to correct place.  There
may be gain if list is long and n relatively small as
then second scan can use elements from cache fetched
by firts scan.  But again that looks like rare case.

> So, the reason to have these functions which operates
> from backward is to achieve performance by using the
> scan once algorithm.  I don't know for aggregates other
> than List, if it's actually faster.
> 
> Other than performance concerns, it's nice to have
> functions to operate from backwards instead of writing
> one's own.  I was thinking : delete(a, n), when n < minIndex a,
> delete (minIndex(a) - n)th last element.
> 
> Removing last few elements is pretty common in statistic,
> I think.

If you care about performance of operations on last
elements of lists, than you are using wrong algorithm
or wrong data structure.  For convenience we may
provide such operations, but OTOH by not providing
them we may motiviate user to use more appropriate
data structures like doubly-linked lists or arrays,
or better algorithms, for example working on reversed
list.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to