At the beginning of the nVenn procedure, we want to build a Venn diagram with n sets. This means that we need to find closed curves that intersect to give all the possible regions of the diagram. With the help of boolean chain decomposition, we can accomplish this with simple curves by starting with a particular ordering of the regions themselves.
One example: the chain 0010011 gives information about 7 sets. Reading from left to right, this means that the region belogs to sets 3, 6 and 7 (positions of the 1s) and does not belong to any other region. The corresponding m-chain would be ( ( ) ( ( ) ) . Therefore, the first zero from the left is unmatched, and the rest of the positions are matched (as shown in colors).
First, the description of the algorithm. It may be confusing, but afterwards we will see it in action.
The FillColumn procedure ensures that, if a region has a 1 at any position, every region above also has a one at that position. For this reason, the final curves for the sets are easy to generate.
Click repeatedly on the figure below to see each step in action for . At each step, the blue V locates the active chain in the algorithm. The bit under consideration is in red.
This algorithm works for any number of groups. If you want to see what a larger Venn diagram looks like, you can click here for . The animation will be automatic. Warning: the animation with more than 7 sets may be too complex for some devices.
In the nVenn algorithm, the program places circles inside each region. The area of those circles is proportional to the number of elements in its region. Then, the lines shrink to adapt to those circles as shown in the video (the viewport zooms as the figure shrinks):