Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluating set expressions

Tags:

c++

c

set

I have a universe of elements organized into n non-disjoint sets. I have m expressions built using these sets, using union/intersection/difference operators. So given an element, I need to evaluate these m expressions, to find out which of the "derived" sets contain the element. I do not want to compute the "derived" set because it will be very time and space inefficient. Is there a way to say whether an element will lie in one of the derived sets just by looking at its expression? For e.g. if the expression is C = A U B and the element lies in set A, then i can say that it will lie in set C. Are there any C libraries to perform computations of this nature?

like image 255
Oceanic Avatar asked Oct 07 '22 18:10

Oceanic


1 Answers

if im not mistake, let e = the element

replace each set A, B with true if e is in the set, false if its not. Then, convert the set operators to their logical equivalents, and evaluate the expression as boolean. It should all map well to boolean operators, even xor and stuff.

for example, if e is in both A B, but not D

C = (A U B) xor D

it would be in C because

    C = (true or true) xor false
->      (true)        xor false
-> true

That could be pretty fast if you can quickly find if an element is in a set

like image 114
goat Avatar answered Oct 10 '22 09:10

goat