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 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. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)