New function - makelist alternative: table()ing Lisp ECL 9.4.1
Subject: New function - makelist alternative: table()ing Lisp ECL 9.4.1
From: Oliver Kullmann
Date: Sun, 10 May 2009 19:51:08 +0100
Hi,
create_list is the function to be used:
Maxima 5.18.1 http://maxima.ibuted under the GNU Public License. See the file COPYING..net
Using Lisp ECL 9.4.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) makelist(i,i,1,1000000)$
Evaluation took 22.2890 seconds (22.4950 elapsed)
(%i2) makelist(i,i,1,1000000)$
Evaluation took 24.7490 seconds (24.8120 elapsed)
(%i3) create_list(i,i,1,1000000)$
Evaluation took 1.3010 seconds (1.3050 elapsed)
(%i4) create_list(i,i,1,1000000)$
Evaluation took 1.2680 seconds (1.2960 elapsed)
create_list is also rather powerful; and the speed-up is enormous once
nested lists are created like create_list([i,j], i,1,1000, j,1,1000).
Oliver
On Sun, May 10, 2009 at 11:09:33AM +0200, ?y of William Schelter. Lenar?i? 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 eport() provides bug reporting information.. 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 $make-list 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.Edo
> http://www.math.utexas.eate_list(i,i,1,1000000)$/mailman/listinfo/maxima
--
Dr. Oliver Kullmann
Computer Science Department
Swansea University
Faraday Building, Singleton Park
Swansea SA2 8PP, UK
http://cs.swan.ac.uk/~csoliver/