# [Maxima] New function - makelist alternative: table()

Žiga Lenarčič ziga.lenarcic at gmail.com
Sun May 10 04:09:33 CDT 2009

```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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: table.lisp
Type: application/octet-stream
Size: 12020 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20090510/71584660/attachment.obj
-------------- next part --------------

Regards,
Ziga Lenarcic

```

More information about the Maxima mailing list