"Subsets" (Incremental Object)
IncrementalObject["Subsets"] [list]
creates an object that incrementally returns values that are subsets of list.
IncrementalObject["Subsets"] [list,n]
creates an object that incrementally returns values that are subsets of list of at most length n.
IncrementalObject["Subsets"][list,{n}]
creates an object that incrementally returns values that are subsets of list of length n.
IncrementalObject["Subsets"][list,{nmin,nmax}]
creates an object that incrementally returns values that are subsets of list of length between nmin and nmax.
IncrementalObject["Subsets"][list,nspec,s]
creates an object that incrementally returns values that are subsets of list limiting the results to the first s subsets.
IncrementalObject["Subsets"][list,nspec,{smin,smax}]
creates an object that incrementally returns values that are subsets of list running from positions smin to smax.
Examples
open all close allBasic Examples (1)
Create a new "Subsets" incremental object:
obj = IncrementalObject["Subsets"][{a, b}]NextValue[obj]NextValue[obj]NextValue[obj]NextValue[obj]There are no more values, and a failure object is returned:
NextValue[obj]Scope (5)
An incremental object can be used in Table:
obj = IncrementalObject["Subsets"][{a, b, c}, {2}];
Table[e, {e, obj}]An incremental object can be used in Do:
obj = IncrementalObject["Subsets"][{a, b, c}, {2}];
Do[Echo[e], {e, obj}]Subsets can be processed incrementally even if the total number of permutations is very long:
obj = IncrementalObject["Subsets"][Range[50], {4}];
Do[NextValue[obj], 10000]NextValue[obj]Subsets can be processed incrementally even if the total number is very long:
obj = IncrementalObject["Subsets"][Range[50], {4}];
Do[NextValue[obj], 10000]NextValue[obj]Processing subsets incrementally uses very significantly less memory:
(obj = IncrementalObject["Select"][IncrementalObject["Subsets"][Range[20]], !OrderedQ[#]&];
Table[elem, {elem, obj}])//MaxMemoryUsedSelect[Subsets[Range[20]], !OrderedQ[#]&]//MaxMemoryUsedProperties & Relations (3)
The values return by a "Subsets" incremental object are the same as those returned by Subsets.
obj = IncrementalObject["Subsets"][{a, b, c, d}, 2];
Table[e, {e, obj}]Subsets[{a, b, c, d}, 2]InputForm (1)
InputForm returns the serialized contents of a "Subsets" incremental object:
InputForm[IncrementalObject["Subsets"][{a, b, c}, 2]]This serialized form can be used to recreate the incremental object:
IncrementalObject["Subsets", {"Initial" :> True, "CountData" :> {1, 1, -1}, "Length" :> 3, "KData" :> {0, 0, 2}, "Data" :> {}, "Source" :> {a, b, c}}]SameQ (1)
SameQ can be used to test whether two incremental objects contain the same sequence at the same position:
obj1 = IncrementalObject["Subsets"][{a, b, c, d}];
obj2 = IncrementalObject["Subsets"][{a, b, c, d}];
obj1 === obj2If one objects moves to the next value, the two objects are no longer the same:
NextValue[obj1];
obj1 === obj2Advancing the other object means that they are both now the same:
NextValue[obj2];
obj1 === obj2See Also
Related Guides
History
Introduced in 2026 (15.0)