Decide what counts as the same object
A set records membership rather than position or repetition. Let A contain users with read permission and B contain users with edit permission. Their intersection contains users who have both permissions. Repeating a user identifier in an input list does not add a new member to the mathematical set. If order or multiplicity matters, use a sequence or multiset and make that distinction explicit in the program.
Correct a count that includes overlap
Suppose A has eight users, B has five, and three users belong to both. The union has eight plus five minus three, or ten users. Adding the sizes alone counts the overlapping users twice. Subtracting the intersection once restores one count per person. This reasoning is useful when interpreting database joins: the number of result rows need not equal the number of distinct users represented by those rows.
Inspect the properties of a relation
A relation specifies which ordered pairs satisfy a condition. On an appropriate collection of employees, belonging to the same department can define an equivalence relation: it is reflexive, symmetric, and transitive. Being the manager of someone is usually not symmetric. Network reachability is not necessarily symmetric either, because policy or routing may allow only one direction. Check each property from its definition rather than assuming that a familiar name guarantees it.
Separate selection from assignment of roles
Choosing two representatives from five people gives ten outcomes when order does not matter. One way to derive the result is to count five times four ordered selections, then divide by two because each pair appears in both orders. Choosing a president and a vice president instead gives twenty outcomes because exchanging roles changes the result. Before using a formula, state whether repetition is allowed, whether order matters, and which constraints apply to the selected objects.
Name the object being counted
The number of permission-grant events differs from the number of users who currently hold permission. Granting a permission to the same identifier twice can create two audit events while still representing one user. Write rules such as deduplicating identifiers or distinguishing assigned roles before calculating a result. Compare a small hand-worked example with the program’s output so that a count of rows is not silently substituted for a count of people.
Count identities rather than rows by accident
Let A={1,2,3,4} contain readers and B={3,4,5} contain editors. Their union has five people, their intersection has two, and A minus B contains readers 1 and 2 only. These are three different questions over the same data. Repeated grant events for user 3 do not create more current users, although they remain distinct audit events. Removing duplicates is therefore correct for one report and destructive for another. Specify whether an output item represents a person, an event, or a person-permission pair. Then construct a small expected result explicitly, including identities present in both inputs. This prevents a technically valid aggregation from silently answering a different business question.
Restore the triple overlap
For three sets, adding their sizes counts someone belonging to all three sets three times. Subtracting all three pairwise intersections removes that person three times, leaving zero. Add the triple intersection once to restore the required count of one. If each set has size 4, each pairwise intersection has size 2, and the triple intersection has size 1, the union has 12−6+1=7 members. Pairwise intersections here include members who also belong to the third set. They are not counts of people belonging to exactly two groups. Trace one representative member through the arithmetic before applying inclusion–exclusion to a larger dataset. The formula depends on these definitions, not only on a pattern of alternating signs.
Find a counterexample to transitivity
The relation “belongs to the same department” needs a precise membership model. If everyone belongs to exactly one department, it defines an equivalence relation over that population. If multiple memberships are allowed and the relation means “shares at least one department,” transitivity can fail. Alice belongs to Sales, Bob to Sales and Engineering, and Carol to Engineering. Alice relates to Bob and Bob to Carol, while Alice does not relate to Carol. A familiar name does not preserve a mathematical property when the definition changes. Draw the actual ordered pairs and test the implication required by each property. Also distinguish diagrams that omit self-loops for readability from a relation that genuinely lacks reflexive pairs.
Apply a constraint to combinations and assignments
There are ten unordered pairs from five people. If two particular people must not be selected together, exactly one pair is forbidden, leaving nine. If the positions are president and vice president, there are twenty assignments and two forbidden assignments, leaving eighteen. The excluded event is the same informal rule, but its representation changes when roles become distinguishable. Enumerating small cases is a useful implementation check: sort each unordered pair into a canonical representation, or retain role positions for assignments. Matching a small enumeration does not prove the formula for every population size. A general argument must still explain multiplicity and whether excluded cases overlap with each other.