Post Reply 
BUG[?]: ΣLIST, ΠLIST with verrrry short lists
12-25-2015, 06:38 AM
Post: #9
RE: BUG[?]: ΣLIST, ΠLIST with verrrry short lists
(12-24-2015 07:57 PM)StephenG1CMZ Wrote:  One can use invalid dimension, but the way I was thinking, anyone calling Summation expects a number - or if that cannot be produced, whether because of an index issue or an overflow, a NaN.

(I have never summed rather than concatenated strings, so I am presuming a numeric result...so that might be inappropriate for non-numeric summations).

Of course, unless one can detect the error and continue, it makes little practical difference - and makes simply returning 0 seem preferable.

One question: if one do do a summation of strings, can one also do a product of strings?!
Merry Xmas all.

I used strings because it was very clear as an example. If you like numbers, then think about a list of 3x3 matrices. If your code is expecting a 3x3 matrix as a result of the sum, then shouldn't the sum of an empty list return a 3x3 matrix filled with zeros? Returning a scalar 0 would make your code fail, so you'd have to consider the empty list as a special case.
Same thing for the product, it should return a 3x3 identity matrix.
In general, you'd have to return the zero vector of whatever vector space you are defining the addition on. But from an empty list given as an argument, the command has not enough information to provide that resulting zero vector.
It's more consistent to have the user trap the error and return whatever zero vector he needs, than trying to provide an answer that's only good for one particular case.
By the way, there's a very simple trick to avoid all this: simply append one extra element to the list, being the zero vector (or unity for the product).
Then an empty list will no longer be empty, and it will return the appropriate type and size of zero. For obvious reasons, the extra element won't alter the result of the summation or product when the list is not empty.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: BUG[?]: ΣLIST, ΠLIST with verrrry short lists - Claudio L. - 12-25-2015 06:38 AM



User(s) browsing this thread: 1 Guest(s)