Skip to main content
11 events
when toggle format what by license comment
Mar 27, 2019 at 17:26 comment added DrMrstheMonarch Ahh, this is an interesting test on timings and on the differences which may or may not be faster. intriguing! thanks for that.
Mar 27, 2019 at 16:06 comment added J. M.'s missing motivation @Roman, I do not believe that any lazy evaluation is being done. My comment was more to point out that an evaluation like And[True, True, False, True, True, ... True] will finish at once (and similar remarks apply for Or[]). Perhaps one can judiciously use Catch[]/Throw[]if an early-return test for long lists is desired.
Mar 27, 2019 at 16:03 comment added mjw @Bob, Thank you for your edit. Why, though, does it take longer for your method to work when there is a negative entry? I would have thought that in each case, it would take the same amount of time to go through the whole list.
Mar 27, 2019 at 15:53 history edited Bob Hanlon CC BY-SA 4.0
Added test of effect of encountering a negative value early in the list
Mar 27, 2019 at 15:48 history edited Bob Hanlon CC BY-SA 4.0
Added test of effect of encountering a negative value early in the list
Mar 27, 2019 at 15:48 comment added Roman @J.M.isslightlypensive the short-circuit only works efficiently if the listable Positive is evaluated lazily. Do you happen to know if Mathematica does any lazy evaluation internally when it detects a condition like what's done in Bob's solution? That would be great to construct efficient algorithms.
Mar 27, 2019 at 15:45 comment added mjw @J. M. Thank you! I see. So are the other methods (not using And[]) actually going through the whole list?
Mar 27, 2019 at 15:41 comment added J. M.'s missing motivation @mjw, And[] does short-circuit evaluation.
Mar 27, 2019 at 15:37 comment added mjw Also, and I guess this depends on the probability of any entry being negative, it may make sense for the algorithm to stop as soon as it finds a negative (or non-positive) element in the list.
Mar 27, 2019 at 15:34 comment added mjw Looks like your method is five times faster than the next best! Can you give some insight into why this is? Thanks!
Mar 27, 2019 at 15:19 history answered Bob Hanlon CC BY-SA 4.0