# How can I condense this code?

Here is part of a code I wrote:

Select[Subsets[Range[16]],
MemberQ[#, 2] && !
ContainsAll[
Level[Position[ζ[[All, 2]], 1], {2}]][#] ∨
MemberQ[#, 3] && !
ContainsAll[
Level[Position[ζ[[All, 3]], 1], {2}]][#] ∨
MemberQ[#, 4] && !
ContainsAll[
Level[Position[ζ[[All, 4]], 1], {2}]][#] ∨
MemberQ[#, 5] && !
ContainsAll[
Level[Position[ζ[[All, 5]], 1], {2}]][#] ∨
MemberQ[#, 6] && !
ContainsAll[
Level[Position[ζ[[All, 6]], 1], {2}]][#] ∨
MemberQ[#, 7] && !
ContainsAll[
Level[Position[ζ[[All, 7]], 1], {2}]][#] ∨
MemberQ[#, 8] && !
ContainsAll[
Level[Position[ζ[[All, 8]], 1], {2}]][#] ∨
MemberQ[#, 9] && !
ContainsAll[
Level[Position[ζ[[All, 9]], 1], {2}]][#] ∨
MemberQ[#, 10] && !
ContainsAll[
Level[Position[ζ[[All, 10]], 1], {2}]][#] ∨
MemberQ[#, 11] && !
ContainsAll[
Level[Position[ζ[[All, 11]], 1], {2}]][#] ∨
MemberQ[#, 12] && !
ContainsAll[
Level[Position[ζ[[All, 12]], 1], {2}]][#] ∨
MemberQ[#, 13] && !
ContainsAll[
Level[Position[ζ[[All, 13]], 1], {2}]][#] ∨
MemberQ[#, 14] && !
ContainsAll[
Level[Position[ζ[[All, 14]], 1], {2}]][#] ∨
MemberQ[#, 15] && !
ContainsAll[
Level[Position[ζ[[All, 15]], 1], {2}]][#] ∨
MemberQ[#, 16] && !
ContainsAll[
Level[Position[ζ[[All, 16]], 1], {2}]][#] &]];


Is there a way to condense all the "or" commands into a single line?

• Could you add an explanation of your logic in words? What properties are you trying to express to retain some subsets? – MarcoB Jan 15 at 13:29
• Yes, Thank you. Here $\zeta$ is a 16 X 16, {0,1} matrix representing a poset. This part of the code gives me the (complement of ) order ideal of $\zeta$. I just don't want to have to write essentially the same line multiple times when applying the code to various sizes of posets. – geoffrey Jan 15 at 14:15
• Sounds like one would use some sparse matrix arithmetric or Graph... A poset is basically a tree (or a forest), right? Unfortunately I do not have the time to find out what an order ideal is. Can you please explain that in short, non expert terms? And a concrete example for ζ to play with would be great. – Henrik Schumacher Jan 15 at 14:20
• I got the faint idea that TopologicalSort[Graph[ζ]] might bring you closer to the solution... – Henrik Schumacher Jan 15 at 14:23
• @geoffrey thank you for the explanation, but unfortunately that was completely over my head. What I meant was for you to tell us what properties of each subset you are targeting in plain language. Something like, it should contain this and have that other simple property, but not that. – MarcoB Jan 15 at 14:29

nzp = SparseArray[Transpose @ ζ]["AdjacencyLists"];

selector1 = Function[x, Or @@
(MemberQ[x, #] && Length[Complement[nzp[[#]], x]] >= 1 & /@ Range[2, 16])];

Select[Subsets[Range[16]], selector1]


Alternatively,

selector2 = Function[x,  Or @@
(MemberQ[x, #] && ! ContainsAll[x, nzp[[#]]] & /@ Range[2, 16])];

Select[Subsets[Range[16]], selector2] == Select[Subsets[Range[16]], selector1]

True