Again $table function, speed/functionality improved



On 13. May, 2009, at 4:12 PM, reyssat wrote:

> Hi,
>
> I didn't follow this thread but just have two ideas about features  
> that could be useful in table ; maybe they are already implemented  
> or discarded ; if so, sorry for the noise :
> 1/ iterators described by a list : table(my_f(i), i in my_list).  
> Could it be better, faster, more general... than map ? Or used in  
> another way ?
This is already possible via:
table( f(i), [i, my_list]);
I was quite surprised when I found out it works faster than 'map':
---------------------
%i16: f(x) := (x+1);
Evaluation took 0.0000 seconds (0.0000 elapsed) using 0 bytes.
%o16: f(x):=x+1
%i17: mylist:table(i,[i,1000000])$
Evaluation took 1.1870 seconds (1.3640 elapsed) using 7.630 MB.
%i18: map( f, mylist)$
Evaluation took 9.3460 seconds (9.5900 elapsed) using 198.367 MB.
%i19: table( f(x), [x, mylist])$
Evaluation took 6.5300 seconds (6.7360 elapsed) using 129.703 MB.
---------------------

> 2/ iterators satisfying a property : table(p^2, pmax ,primep). The  
> idea is to save memory (and ease of progrmaming) by comparison with  
> extracting a small sublist from a huge uninteresting list.
I think this doesn't fit into table very well, but other tools for  
doing this (not only sublist) could be introduced into maxima -  
perhaps in a more general way than
> table(p^2, pmax ,primep)
Mathematica has very interesting functions for this task (Sow and Reap):
http://reference.wolfram.com/mathematica/tutorial/ 
CollectingExpressionsDuringEvaluation.html
This would be easy to implement in Maxima. Then you could just type
reap( for i:1 thru imax do (if primep(i) then sow(i^2)) );
and voila a nice list of squares... I think this is an exelent way  
(and much more flexible than just extending table function) for doing  
this things. You can also write complicated programs with sow() in  
arbitrary places and then call
reap( my_complicated_program() ); and get the list of values... very  
flexible tool.

Is there any interest for reap/sow ? I think it's very easy to do  
(using a global variable), I think I could write these two..


> Related to this : is your code for table of any interest to improve  
> the sublist function ?
Improve in what direction?

> Eric Reyssat