Again $table function, speed/functionality improved
Subject: Again $table function, speed/functionality improved
From: reyssat
Date: Wed, 13 May 2009 16:12:10 +0200
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 ?
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. Related to
this : is your code for table of any interest to improve the sublist
function ?
Eric Reyssat
?iga Lenarc(ic( a ?crit :
> Hello again!
>
> I've made many corrections to my $table function and now I feel it's
> ready to be included into Maxima. I haven't written the documentation
> yet (beside the comment in lisp file), but will do so ...
>
> See attachment for sourcefile 'table.lisp'.
>
> Table can now handle all the cases $makelist does, except the ones
> where the variable is not a sybol:
> table( a[i], [ a[i], 5]); doesn't work
> I've decided not to support this case, since it complicates the
> program severely while adding really marginal improvement featurewise
> (you can always subst() a[i] to a 'symbol').
> table(i, [i, a[i], a[i] + 5 , 0.2]); now works correctly. (The
> requirement is that (end - start) evaluates to a $numberp expression).
>
> I've changed the behaviour, so there are empty lists returned instead
> of errors for many cases. Example:
> table( random(1.0), [-4]);
> table( i, [i, 1, 10, -1]);
> ...
>
> I've revised the evaluating part of iterators - instead of using
> 'mbinding' for each evaluation of expression, it is now used only once
> per iterator, to provide the safety. After that, values are set via
> (setf (symbol-value var) value). The $table overhead has severely
> decreased (!) and $table is now faster than $create_list (!!).
> Besides, $table offers even faster iteration, when you don't need a
> bound variable, for instance:
>
> %i92: table(random(1.0), [10^6])$
> Evaluation took 4.2030 seconds (4.4250 elapsed) using 283.225 MB.
> %i95: table(random(1.0), [i, 10^6])$
> Evaluation took 5.5540 seconds (5.7890 elapsed) using 283.248 MB.
> %i94: create_list(random(1.0), i, 1, 10^6)$
> Evaluation took 6.0090 seconds (6.0200 elapsed) using 298.482 MB.
>
> When the expression is 'cheaper' than 'random(1.0)', the difference is
> bigger ofcourse.
>
> %i109: table(0, [10^6])$
> Evaluation took 0.0430 seconds (0.0430 elapsed) using 7.629 MB.
> %i102: table(0, [i, 10^6])$
> Evaluation took 0.8490 seconds (0.8490 elapsed) using 7.633 MB.
> %i105: create_list(0, i, 1, 10^6)$
> Evaluation took 1.1200 seconds (1.1270 elapsed) using 22.888 MB.
>
> So there you go.. $table as a $makelist and $create_list replacement
> is ready. It's faster, more featureful, and more correct than
> $create_list. Besides of the difference of outputs of
> create_list([i,j], i, 1, 4, j, 1, 4);
> table([i,j], [i,4], [j,4] );
> all bases are covered. I would tackle this with extending $flatten's
> functionality - to allow list flattening to a certain level.
>
> Any comments on $table implementation? Any comments on the function
> name? Anything needs changing before this gets into Maxima?
>
> A similar function could be written for arrays - if Maxima ever gets a
> better array support (like amatrix package).
>
>
>
>
> Regards,
> Ziga Lenarcic
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>