Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • $\begingroup$ Looks like your method is five times faster than the next best! Can you give some insight into why this is? Thanks! $\endgroup$ Commented Mar 27, 2019 at 15:34
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Mar 27, 2019 at 15:37
  • 1
    $\begingroup$ @mjw, And[] does short-circuit evaluation. $\endgroup$ Commented Mar 27, 2019 at 15:41
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Mar 27, 2019 at 16:03
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Mar 27, 2019 at 16:06