New function - makelist alternative: table()



Looks like a good idea. Here are some comments..

But Table[i,{i,10,0,-1}] works for Mathematica. Will your program work 
with negative step?

Another thought would be to extend for ...do   based on Lisp's extensive 
iteration "loop"  macro using keywords.  e.g.

for i:1 thru 10 step -1 collect i    .... which is sort of the same as 
table??


for i:1 thru 10 sum i   ....                 like sum(i,i,1,10) except 
no effort for closed form?
for i:1 thru 10 product i
for i:1 thru 10 maximize f(i)
for i:1 thru 10 count oddp(f(i))
for i:1 thru 10 until f(i)>2 do print(g(i))

for r in [a,b,c].

Of course the recently identified bug in the step value should be fixed..

While Mathematica has many nice features, its syntax is hardly its high 
point. In fact it tends to be cryptic. 
It it Lisp-like in promoting functional application, but uses   
f[g[x,y]]  instead of (f (g x y)).  That's OK with
me as a lisp programmer.  I don't like the infix operators of mysterious 
precedence, like =,==, ===, _ , __, ___, #,& ,@, /, //, ./, ....

Or maybe just have iterators optionally like  [index=i, first=0, 
last=10,step=1, direction=up]  instead of [i,0,10,1].
Could be [i,last=10].




RJF



there are many variations.
see
http://www.ai.sri.com/~pkarp/loop.html


for ?iga Lenarc(ic( wrote:
> Hi Maxima users and developers!
>
> Dissatisfied with makelist inflexibility, I wrote my own function, 
> table() in lisp. It more or less covers all the features of 
> Mathematica's Table[] function (hence the name :) ).
>
> I would like this function to be included into Maxima src. How can I 
> do that? I'm will write function documentation and unit tests (if they 
> are required).
> Function was based on my inspection of $makelist function, but after 
> Andrej's tips, I used (mbindings) instead of $ev for evaluation and 
> function is now much faster than $makelist.
>
> Compare:
> %i4: makelist(i,i,1,1000000)$
> Evaluation took 9.4030 seconds (9.7420 elapsed) using 259.399 MB.
> %i7: table(i,[i,1000000])$
> Evaluation took 2.9870 seconds (3.2280 elapsed) using 83.925 MB.
> The result is the same.
>
> Table is not only faster than $makelist, but also more featureful. To 
> be precise - $makelist covers only a small subset of table's features. 
> Copy paste from table.lisp:
> ;; From Maxima function can be called in the form:
> ;; table(expression, iterator1, iterator2,...);
> ;; At least one iterator is needed, further iterators are optional.
> ;; Iterators can have different forms.
> ;;
> ;; [number]
> ;; Evaluates expression 'number' times, where 'number' is a positive 
> integer and
> ;; produces a Maxima list of evaluated expressions.
> ;;
> ;; [variable, initial, end, step]
> ;; Returns a list of evaluated expressions where 'variable' (a symbol) 
> is set
> ;; to a value. First element of the returned list is expression evaluated
> ;; with variable set to initial. i-th element of the returned list is 
> expression
> ;; evaluated with variable set to 'initial' + (i-1)*step. Last element 
> of the list is
> ;; expression evaluated with variable set to value which is less or 
> equal to 'end'.
> ;; 'initial', 'end' and 'step' can be integers or floating point numbers.
> ;;
> ;; [variable, initial, end]
> ;; This iterator uses a step of 1 and is equal to [variable, initial, 
> end, 1].
> ;;
> ;; [variable, end]
> ;; This iterator uses a step of 1 and initial value is also 1, 
> therefore it's
> ;; equal to iterator [variable, 1, end, 1].
>
> It is much easier to use than makelist, for instance a plot of a sine 
> + noise:
> plot2d( [discrete, table([t, sin(t)+random(0.2)], [t,0,10,0.1])] );
>
> Not only lisp numbers - also maxima numbers can be used:
> table(i, [i,1,10, 1/2]);
>
> Makelist can be sped up by defining (just for fun)
> makelist(a,b,c,d) := table(a, [b,c,d]);
>
> I attached table.lisp. The name of the function can be changed, but 
> table is fine by me, since it's short, and syntax is the same as for 
> Table[].
>
> If you find any bugs or have any suggestions about the code, please 
> tell, I will fix it.
>
>
>
> Regards,
> Ziga Lenarcic
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>