I have a question I am hoping someone here can help me with. let's say we have a bunch of atomic groups (cannot be broken down further), i will give each of them a bit mask. we also have a bunch of users, and each one has a binary value that tells us which atomic groups the user is in. Example:

Groups

G1 - 00001 - (1)

G2 - 00010 - (2)

G3 - 00100 - (4)

G4 - 01000 - ( 8 )

G5 - 10000 - (16)

Users

U1 - 00011 - User is in groups 1 and 2

U2 - 01100 - in groups 3 and 4

U3 - 00010 - in group 2

U4 - 10000 - in group 5

U5 - 01011 - in groups 1, 2, 4

Now we also have groups of groups which are composed of some basic formula. For Example:

Groups of Groups

GG1 - (G1 && G2) || G3

GG2 - (G2 || G3) && (G1 && G4)

GG3 - (G1 && (G2 || G3)) || G5

Now I want to be able to determine all the users that satisfy the conditions for GG1, GG2 and GG3. So based on the above examples, we have:

Users in GG1: U1, U2, U5

Users in GG2: U5

Users in GG3: U1, U4, U5

How can I algorithmically determine this? The groups, users and groups of groups are stored as you see above. Given a user's binary value I need to be able to "plug" it into the GG formula and determine if it is true or not. Do I have to break apart the GG formulas and dynamically map them into if statements? I am hoping for an easier way since they could possibly get complicated.

Thanks for any help.