Question: Reducing FP round off and catastrophic cancellation by sorting Array in place and the cover on the ArrayTools[Alias] chainsaw

Hello Maple wizards,

I am working with thousands of fairly large (at least 11K nonzero entries) strictly lower triangular Arrays containing positive and negative floating point numbers, including float(1,infinity). The Arrays are the same size and each one can be processed independently, so I hope to avoid a space explosion by having each Array overwrite the previous one -- lhs(entry) and all that. I do see a steady leakage not recovered by gc, but that's not tonight's question.

This is not very sexy math; for each Array I want to add the entries with minimal floating point error, to check (1) how much worse the error is than if I simply use ArrayTools[AddAlongDimensions] twice to collapse the Array into a scalar, and (2) how much precision I will lose if I use hfloat for speed.

To that end, I have stored the entries into a 1-dimensional Array, and hop to use Maple's sort() function to arrange the entries to be add()'d in order of increasing absolute value. Wizards, I have three questions:

Question 1: Is there a syntax for keep sort from allocating new storage for its output? If "MyArray := sort(MyArray)" is allocating 11K extended precision elements on every call, and then throwing storage for the old 11K entries on a free chain, I'm going to need awesome garbage collection.

Question 2: In some cases the matrix will contain quite a few zeros. Probably not enough to justify a sparse storage case, but removing them from the sort could provide a nice speedup. Because there are many of these, I would like to avoid the storage explosion assocated with allocating shorter Arrays without the zeros.  I'm tempted to try the ArrayTools[Alias] function on this 1-dimension Array to create a shorter aliased version of the Array to pass to sort(), but the warnings about altering the entries causing Maple to crash concern me. Any suggestions on the safety of sending an aliased version of the Array (without the zeros) to sort()?

Question 3: The statement

    SortedArray := sort (UnsortedArray, (a,b)->evalb(abs(a)<=abs(b)):

fails with the complaint

      Error, sort: 2nd argument must be a function that always returns true or false

How can I persuade Maple that the function (a,b)->evalb(abs(a)<=abs(b)) will produce true of false -- perhaps it has a FAIL outputs that I'm ignoring. Left quotes didn't seem to help. The frustrating part is that it works just find when entered as a command on a [> worksheet.

Thanks in advance for your suggestions and insight. You rock, you know.

 - Jimmy

Please Wait...