Assuming your set elements are all positive integers, you could convert the sets to a tally form, and then use Internal`ListMin to prune sets. (I gave a variation of this approach in this answer, but in that question minimal subsets were desired instead of maximal subsets). Here is an example using this idea:
lst = {{1, 5}, {2, 5}, {6, 8}, {6, 8, 9}};
i = Total[
Replace[lst, s_ :> UnitVector[9, s], {2}],
{2}
]
{{1, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1,
0, 1, 0}, {0, 0, 0, 0, 0, 1, 0, 1, 1}}
Then:
r = -Internal`ListMin[-i]
{{0, 0, 0, 0, 0, 1, 0, 1, 1}, {1, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 0,
0, 0, 0}}
Converting back to sets:
Pick[Range[9], #, 1]& /@ r
{{6, 8, 9}, {1, 5}, {2, 5}}
To package this up as a function (and support multisets), I will introduce two helper functions:
fromSets[sets_] := With[{m = Max[sets]},
Total[
Replace[sets, s_ :> UnitVector[m, s], {2}],
{2}
]
]
toSets[lists_] := (Flatten @ MapIndexed[ConstantArray[#2[[1]], #1]&, #]&) /@ lists
For example:
fromSets[{{2,4}, {1,2,2,4}, {1,1,3}}]
toSets[%]
{{0, 1, 0, 1}, {1, 2, 0, 1}, {2, 0, 1, 0}}
{{2, 4}, {1, 2, 2, 4}, {1, 1, 3}}
Then, a function that selects maximal sets would be:
maximal[sets_] := toSets @ -Internal`ListMin[-fromSets @ sets]
Your example:
maximal[{{1, 5}, {2, 5}, {6, 8}, {6, 8, 9}}]
{{6, 8, 9}, {1, 5}, {2, 5}}
@Roman's example with a multiset:
maximal[{{1, 5}, {2, 5}, {6, 8}, {6, 8, 9}, {1, 1}}]
{{6, 8, 9}, {1, 5}, {2, 5}, {1, 1}}
Using Internal`ListMin should be orders of magnitude faster than the other answers for large lists of sets.
SubsetQdoes not account for multiplicity of elements." Thanks @hadesth – Roman Jan 01 '21 at 18:25lst = {{1}, {1}, {2}}then according to the description the result should be{{2}}, not{{1}, {2}}. "[...] remove all the sublists which is any other's subset" – Roman Jan 01 '21 at 19:09