0

Oftentimes I am searching for the first item in a sequence that satisfies some property. For example, consider the subsets of prime numbers whose total is prime. To start generate them, we could naively try Subsets[Range[100]], which fails (as it should) yielding the message:

Subsets::toomany: The number of subsets (1267650600228229401496703205376) is too 
large; it must be a machine integer. >>

But is it too much to ask for a list of the first 500 subsets (by any canonical ordering), or perhaps just the nth subset?

Ok, so I found the following in the details section, which gives (if possible) the sth subset:

Subsets[list, nspec, {s}]

But sadly, this is not at all what I need - according to the docs:

Subsets[list, nspec, spec] gives the same result as Take[Subsets[list, nspec], spec], provided that the elements specified by spec are present.

So Mathematica performs the entire computation and only when finished (and it won't finish) does it perform a Take at the end. I would appreciate some guidance as to the preferred tactics when dealing with this problem of , i.e. "how to tell Mathematica start processing the intermediate results on the fly" (like you can with AsynchronousTaskObject and friends).

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
M.R.
  • 31,425
  • 8
  • 90
  • 281
  • 1
  • 2
    What are you talking about? The docs make it clear: it gets the same results, NOT that it does the same thing (do the work, then select). Try eg Subsets[Range@1000, All, {1*^100, 1*^100 + 10}], works fine. – ciao Jul 31 '15 at 03:08
  • The 1st item in a list of all subsets of the prime numbers in canonical order for which the elements total to a prime is the set {2}. I make this comment to suggest you might want to place constraints of the size of the subsets. – m_goldberg Jul 31 '15 at 04:09
  • 1
    @Mr.Wizard: Whoa - is that a bug in SE? I marked the question for close based on "...easily found in the documentaton...", not as duplicate (though I'd agree). Or did I mark it as the latter, and need to cut back on the opium consumption? – ciao Jul 31 '15 at 05:03
  • @ciao You did not mark as a duplicate. Unfortunately the banner incorrectly asserts that all close votes are for the same reason. I know this has come up on Meta Stack Exchange if you care to search for it. It seems to be "intended behavior" even if it is false. :-/ – Mr.Wizard Jul 31 '15 at 05:08
  • @ciao Here are some links for you: (926), (2519), (54917). Of note, in some cases the votes are differentiated: (188688) – Mr.Wizard Jul 31 '15 at 05:15
  • @Mr.Wizard: Cheers, will check them out... – ciao Jul 31 '15 at 05:21

0 Answers0