Doing Operations with Sets
Numbers have operations such as addition and multiplication. Sets have operations too.
Suppose
\[ A=\{1,2,3,4\} \]and
\[ B=\{3,4,5,6\}. \]We might ask:
- Which elements occur in either set?
- Which elements occur in both sets?
- Which elements occur in \(A\) but not \(B\)?
- Which allowed elements are outside \(A\)?
Those questions lead respectively to union, intersection, difference, and complement.
The notation is new, but the ideas are familiar: combine, overlap, remove, and exclude.
Union
The union of two sets contains every element belonging to the first set, the second set, or both.
The symbol for union is
\[ \cup \]so we write
\[ A\cup B. \]If
\[ A=\{1,2,3,4\} \]and
\[ B=\{3,4,5,6\}, \]then
\[ A\cup B=\{1,2,3,4,5,6\}. \]The repeated elements \(3\) and \(4\) are written only once because sets contain distinct elements.
Membership Definition
More precisely,
\[ x\in A\cup B \]when
\[ x\in A \quad\text{or}\quad x\in B. \]Here or is inclusive: an element may belong to \(A\), to \(B\), or to both.
A useful verbal shortcut is:
\[ \boxed{A\cup B=\text{everything in }A\text{ or }B} \]Intersection
The intersection of two sets contains only the elements that belong to both sets.
The symbol is
\[ \cap \]so we write
\[ A\cap B. \]Using
\[ A=\{1,2,3,4\} \]and
\[ B=\{3,4,5,6\}, \]we obtain
\[ A\cap B=\{3,4\}. \]These are the elements shared by the two sets.
Membership Definition
\[ x\in A\cap B \]exactly when
\[ x\in A \quad\text{and}\quad x\in B. \]A useful verbal shortcut is:
\[ \boxed{A\cap B=\text{everything common to both}} \]Disjoint Sets
If two sets have no common elements, their intersection is empty.
For example,
\[ \{1,3,5\}\cap\{2,4,6\}=\varnothing. \]Sets with no common elements are called disjoint sets.
Set Difference
The difference of two sets removes from the first set everything that belongs to the second.
We may write
\[ A\setminus B. \]If
\[ A=\{1,2,3,4\} \]and
\[ B=\{3,4,5,6\}, \]then
\[ A\setminus B=\{1,2\}. \]We begin with \(A\) and remove the elements that also occur in \(B\).
In the opposite direction,
\[ B\setminus A=\{5,6\}. \]Therefore, in general,
\[ A\setminus B\neq B\setminus A. \]Membership Definition
\[ x\in A\setminus B \]exactly when
\[ x\in A \quad\text{and}\quad x\notin B. \]A useful verbal shortcut is:
\[ \boxed{A\setminus B=\text{everything in }A\text{ except what is in }B} \]This Is Not Numerical Subtraction
The word difference is also used for subtraction, but set difference does not subtract the numerical values of elements.
For example,
\[ \{2,5,8\}\setminus\{5\}=\{2,8\}, \]not some arithmetic result involving \(2-5\) or \(8-5\).
Complement
A complement describes everything under consideration that does not belong to a particular set.
For this operation, we must know the larger collection in which we are working. This larger set is often called the universal set and written \(U\).
Suppose
\[ U=\{1,2,3,4,5,6,7,8\} \]and
\[ A=\{2,4,6,8\}. \]The complement of \(A\) is
\[ A^c=\{1,3,5,7\}. \]Equivalently,
\[ A^c=U\setminus A. \]Membership Definition
Assuming \(x\in U\),
\[ x\in A^c \]exactly when
\[ x\notin A. \]A useful verbal shortcut is:
\[ \boxed{A^c=\text{everything in }U\text{ that is outside }A} \]The Universal Set Matters
A complement cannot be interpreted correctly without knowing what universe of objects is being considered.
For example, if
\[ A=\{2,4\}, \]then its complement will be different depending on whether the universal set is
\[ U=\{1,2,3,4,5\} \]or
\[ U=\mathbb{Z}. \]Complement is therefore always relative to a larger set.
Set Operations and Logic
Set operations connect directly with logical statements.
Suppose membership in \(A\) means that condition \(P\) is true, while membership in \(B\) means that condition \(Q\) is true.
Then:
\[ A\cup B \]corresponds to
\[ P\text{ or }Q, \]while
\[ A\cap B \]corresponds to
\[ P\text{ and }Q. \]Likewise,
\[ A^c \]corresponds to
\[ \text{not }P. \]And
\[ A\setminus B \]corresponds to
\[ P\text{ and not }Q. \]This is an important bridge between set theory and logic:
\[ \boxed{ \begin{aligned} \cup &\longleftrightarrow \text{or},\\ \cap &\longleftrightarrow \text{and},\\ {}^c &\longleftrightarrow \text{not}. \end{aligned} } \]The same structure will appear later in inequalities, probability, computer logic, database searches, and programming conditions.
Set Operations with Intervals
Intervals on the number line are sets, so the same operations apply to them.
Let
\[ A=[-2,4] \]and
\[ B=[1,7]. \]Union
Together, the intervals cover every number from \(-2\) through \(7\):
\[ A\cup B=[-2,7]. \]Intersection
The overlap runs from \(1\) through \(4\):
\[ A\cap B=[1,4]. \]Difference
The portion of \(A\) not contained in \(B\) is
\[ A\setminus B=[-2,1). \]Notice that \(1\) is excluded because \(1\in B\).
Complement
If the universal set is \(\mathbb{R}\), then
\[ A^c=(-\infty,-2)\cup(4,\infty). \]This connects set notation directly with the interval notation used for inequalities and domains.
Laws of Set Operations
Set operations obey structural rules similar to the properties of arithmetic.
Commutative Laws
\[ A\cup B=B\cup A \] \[ A\cap B=B\cap A \]The order of two sets does not matter for union or intersection.
Associative Laws
\[ (A\cup B)\cup C=A\cup(B\cup C) \] \[ (A\cap B)\cap C=A\cap(B\cap C) \]Grouping does not matter when we repeatedly use the same operation.
Distributive Laws
\[ A\cap(B\cup C) = (A\cap B)\cup(A\cap C) \]and
\[ A\cup(B\cap C) = (A\cup B)\cap(A\cup C). \]Notice something interesting: union distributes over intersection, and intersection distributes over union.
Idempotent Laws
\[ A\cup A=A \] \[ A\cap A=A. \]Combining a set with itself does not create anything new.
Identity Laws
\[ A\cup\varnothing=A \] \[ A\cap U=A. \]Complement Laws
\[ A\cup A^c=U \] \[ A\cap A^c=\varnothing \] \[ (A^c)^c=A. \]These laws are useful because set expressions can be manipulated and simplified much like algebraic expressions.
De Morgan's Laws
Complementing a union or intersection produces an important pair of rules known as De Morgan's laws.
\[ \boxed{(A\cup B)^c=A^c\cap B^c} \]and
\[ \boxed{(A\cap B)^c=A^c\cup B^c}. \]The first says:
To be outside \(A\cup B\), an element must be outside \(A\) and outside \(B\).
The second says:
To be outside \(A\cap B\), an element only needs to be outside \(A\) or outside \(B\).
A Familiar Language Example
Suppose a student must be both
- at least \(18\) years old, and
- enrolled in the course.
Failing that combined requirement means the student is
- not at least \(18\), or
- not enrolled,
or both.
That is the logical structure behind
\[ (A\cap B)^c=A^c\cup B^c. \]De Morgan's laws therefore belong not only to set theory but also to logic, programming, probability, and circuit design.
Counting a Union
Suppose \(A\) and \(B\) are finite sets.
A first instinct might be to count the elements of both sets by adding
\[ |A|+|B|. \]But if the sets overlap, elements in the intersection have now been counted twice.
To correct that duplication, subtract the intersection once:
\[ \boxed{ |A\cup B| = |A|+|B|-|A\cap B| } \]This is the simplest form of the inclusion-exclusion principle.
Example
Suppose \(25\) students study French, \(18\) study Spanish, and \(7\) study both.
The number studying at least one of the languages is
\[ 25+18-7=36. \]Therefore,
\[ |F\cup S|=36. \]We added both groups and then removed one copy of the students who had been counted twice.
Practical Applications
Database Searches
Suppose a company database contains the sets
\[ A=\{\text{customers in Washington}\} \]and
\[ B=\{\text{customers with active subscriptions}\}. \]Then
\[ A\cap B \]represents customers who are both in Washington and actively subscribed.
Meanwhile,
\[ A\setminus B \]represents Washington customers without an active subscription.
Scheduling
If \(A\) is the set of times you are available and \(B\) is the set of times another person is available, then
\[ A\cap B \]contains the possible meeting times.
Probability
If \(A\) and \(B\) are events, then
\[ A\cup B \]means that at least one of the events occurs, while
\[ A\cap B \]means that both occur.
The complement
\[ A^c \]means that event \(A\) does not occur.
Solving Inequalities
Consider
\[ x<-2 \quad\text{or}\quad x>3. \]The solution set is the union
\[ (-\infty,-2)\cup(3,\infty). \]Set operations give us a precise language for combining separate parts of a solution.
Computer Permissions
Suppose \(A\) contains users permitted to read a file and \(B\) contains users permitted to edit it.
Then
\[ A\cap B \]contains users with both permissions, while
\[ A\setminus B \]contains users who may read but not edit.
Worked Examples
Example 1: Four Operations
Let
\[ A=\{1,2,3,4,5\} \]and
\[ B=\{4,5,6,7\}. \]The union is
\[ A\cup B=\{1,2,3,4,5,6,7\}. \]The intersection is
\[ A\cap B=\{4,5\}. \]The difference is
\[ A\setminus B=\{1,2,3\}. \]In the other direction,
\[ B\setminus A=\{6,7\}. \]Example 2: Finding a Complement
Let
\[ U=\{1,2,3,4,5,6,7,8,9,10\} \]and let
\[ E=\{2,4,6,8,10\}. \]Then
\[ E^c=\{1,3,5,7,9\}. \]Example 3: Three Sets
Let
\[ A=\{1,2,3,4\}, \qquad B=\{3,4,5\}, \qquad C=\{4,5,6\}. \]Evaluate
\[ A\cap(B\cup C). \]First find
\[ B\cup C=\{3,4,5,6\}. \]Then intersect with \(A\):
\[ A\cap(B\cup C)=\{3,4\}. \]We could also use the distributive law:
\[ (A\cap B)\cup(A\cap C). \]Since
\[ A\cap B=\{3,4\} \]and
\[ A\cap C=\{4\}, \]we get
\[ \{3,4\}\cup\{4\}=\{3,4\}. \]Example 4: Set Difference with Intervals
Let
\[ A=[0,10] \]and
\[ B=[4,7]. \]Then
\[ A\setminus B=[0,4)\cup(7,10]. \]The endpoints \(4\) and \(7\) are removed because they belong to \(B\).
Example 5: Inclusion-Exclusion
A workplace survey finds that \(60\) employees use spreadsheet software, \(45\) use database software, and \(20\) use both.
The number who use at least one is
\[ 60+45-20=85. \]Therefore,
\[ \boxed{|S\cup D|=85}. \]Common Errors
1. Counting Shared Elements Twice in a Union
If
\[ A=\{1,2,3\} \]and
\[ B=\{3,4,5\}, \]then
\[ A\cup B=\{1,2,3,4,5\}, \]not
\[ \{1,2,3,3,4,5\}. \]2. Confusing Union and Intersection
Remember:
\[ \cup\quad\text{means combine} \]while
\[ \cap\quad\text{means overlap}. \]3. Reversing Set Difference
\[ A\setminus B \]and
\[ B\setminus A \]are generally different.
Always begin with the set written first.
4. Taking a Complement without a Universe
The statement \(A^c\) only has meaning relative to some universal set \(U\).
5. Treating “Or” as Exclusive
In the definition of union, “\(A\) or \(B\)” includes elements that belong to both.
6. Forgetting Endpoint Membership
When using intervals, decide carefully whether each endpoint remains after a union, intersection, or difference.
Practice
Let
\[ U=\{1,2,3,4,5,6,7,8,9,10\}, \] \[ A=\{1,2,3,4,5\}, \]and
\[ B=\{4,5,6,7\}. \]Find:
- \(A\cup B\)
- \(A\cap B\)
- \(A\setminus B\)
- \(B\setminus A\)
- \(A^c\)
- \((A\cup B)^c\)
Check Answers
- \[ A\cup B=\{1,2,3,4,5,6,7\}. \]
- \[ A\cap B=\{4,5\}. \]
- \[ A\setminus B=\{1,2,3\}. \]
- \[ B\setminus A=\{6,7\}. \]
- \[ A^c=\{6,7,8,9,10\}. \]
- Since \[ A\cup B=\{1,2,3,4,5,6,7\}, \] we have \[ (A\cup B)^c=\{8,9,10\}. \]
Interval Practice
Let
\[ A=(-3,5] \]and
\[ B=[2,8). \]Find:
- \(A\cup B\)
- \(A\cap B\)
- \(A\setminus B\)
Check Answers
- \[ A\cup B=(-3,8). \]
- \[ A\cap B=[2,5]. \]
- \[ A\setminus B=(-3,2). \]
Counting Practice
At a school, \(42\) students participate in music, \(31\) participate in sports, and \(14\) participate in both.
How many participate in at least one of the two activities?
Check Answer
Use inclusion-exclusion:
\[ |M\cup S| = |M|+|S|-|M\cap S|. \] \[ 42+31-14=59. \]Therefore,
\[ \boxed{59} \]students participate in at least one activity.
The Deeper Idea
Set operations give us a compact way to build complicated conditions from simple ones.
If \(A\) represents one condition and \(B\) another, then
\[ A\cup B \]means one condition or the other,
\[ A\cap B \]means both conditions,
\[ A\setminus B \]means the first condition without the second, and
\[ A^c \]means the first condition is not satisfied.
That gives us a reusable mathematical language:
\[ \boxed{ \text{conditions} \longleftrightarrow \text{sets} \longleftrightarrow \text{set operations} } \]As mathematics becomes more advanced, this same toolkit will continue appearing in logic, probability, functions, topology, databases, combinatorics, and mathematical analysis.
Summary
- The union \[ A\cup B \] contains elements belonging to \(A\), \(B\), or both.
- The intersection \[ A\cap B \] contains elements belonging to both sets.
- The difference \[ A\setminus B \] contains elements of \(A\) that are not in \(B\).
- The complement \[ A^c \] contains elements of the universal set \(U\) that are not in \(A\).
- If \[ A\cap B=\varnothing, \] then \(A\) and \(B\) are disjoint.
- Union corresponds naturally to logical or.
- Intersection corresponds naturally to logical and.
- Complement corresponds naturally to logical not.
- De Morgan's laws are \[ (A\cup B)^c=A^c\cap B^c \] and \[ (A\cap B)^c=A^c\cup B^c. \]
- For finite sets, \[ |A\cup B| = |A|+|B|-|A\cap B|. \]
These operations turn sets from passive collections into working mathematical tools. They let us combine conditions, isolate overlaps, remove unwanted cases, and describe everything outside a chosen set.
Sets, Relations, and Functions
- Previous: Subsets, Equality, and Power Sets
- Sets, Relations, and Functions — return to the lesson directory.