1 / 45

MA2011/MA2211 Discrete Mathematics

Week 5: Set Theory

From Logic to Sets: Building the Foundation of Computer Science

Learning Journey: Week 5

Module 1: Introduction

  • Why sets matter in CS
  • Real-world applications
  • Our running example

Module 2: Foundations

  • What is a set?
  • Set notation
  • Membership & cardinality

Module 3: Relationships

  • Subsets
  • Set equality
  • The empty set

Module 4: Operations

  • Union (∪)
  • Intersection (∩)
  • Difference (\)
  • Complement (')

Module 5: Set Laws

  • Connection to logic
  • Proving set equality
  • De Morgan's laws

Module 6: Advanced Topics

  • Power sets
  • Cartesian products
  • Inclusion-exclusion

Module 1: Why Sets Matter in Computer Science

Sets are everywhere in computing:

Databases

• Tables are sets of records

• SQL queries use set operations

• JOIN = Cartesian product

• UNION, INTERSECT, EXCEPT

Programming

• Collections: Set, HashSet, TreeSet

• Unique elements

• Fast membership testing

• Remove duplicates

Algorithms

• Graph vertices and edges

• State spaces in AI

• Visited nodes tracking

Security & Access Control

• User permissions

• Resource access lists

• Group memberships

Our Running Example: Student Enrollment System

Throughout this module, we'll use a consistent example that you can relate to:

JCU Student Course Enrollments - Trimester 1, 2026

All Students (Universe U):

U = {Alice, Bob, Charlie, Diana, Eve, Frank, Grace, Henry}

MA2011 (Discrete Maths):

CS = {Alice, Bob, Charlie, Diana}

MA1000 (Calculus):

Math = {Bob, Diana, Eve, Frank}

CP1000 (Physics):

Physics = {Charlie, Frank, Grace, Henry}

CP2001 (Data Structures):

DataSci = {Alice, Bob, Eve, Grace}

We'll use this example to understand every concept in set theory!

Module 2: What is a Set?

Definition

A set is a well-defined, unordered collection of distinct objects.

The objects in a set are called its elements or members.

Key Properties:

1. Unordered

{Alice, Bob, Charlie}

is the same as

{Charlie, Bob, Alice}

Order doesn't matter!

2. Distinct (No Duplicates)

{Alice, Bob, Bob, Alice}

is the same as

{Alice, Bob}

Duplicates are automatically removed!

Example from our enrollment system:

Students enrolled in MA2011:

CS = {Alice, Bob, Charlie, Diana}

This is a set because each student appears exactly once, and the order we list them doesn't matter.

Set Notation: Three Ways to Describe Sets

1. List Form (Roster Notation)

List all elements between curly braces:

A = {Alice, Bob, Charlie, Diana}

Best for: Small, finite sets where you know all elements

2. Predicate Form (Set-Builder Notation)

Describe the property that elements must satisfy:

A = {x | x is enrolled in MA2011}

Read as: "A is the set of all x such that x is enrolled in MA2011"

Best for: Large sets or sets defined by a rule

3. Special Symbols

Symbol Meaning Example
Natural numbers {0, 1, 2, 3, ...}
Integers {..., -2, -1, 0, 1, 2, ...}
Real numbers All numbers on number line
∅ or {} Empty set Set with no elements

Same Set, Different Notations

Let's express the same set in all three ways:

Students taking both MA2011 and MA1000:

List Form:

A = {Bob, Diana}

Predicate Form:

A = {x | x ∈ CS AND x ∈ Math}

or equivalently:

A = {x ∈ U | (x enrolled in MA2011) ∧ (x enrolled in MA1000)}

Using Set Operations (we'll learn this soon):

A = CS ∩ Math

Quick Check:

Write the set of students enrolled in Physics in both list form and predicate form.

Set Membership

Notation

x ∈ A means "x is an element of A" or "x belongs to A"

x ∉ A means "x is NOT an element of A"

Examples from our enrollment system:

Recall: CS = {Alice, Bob, Charlie, Diana}

Alice ∈ CS is TRUE

Eve ∈ CS is FALSE

Eve ∉ CS is TRUE

Bob ∈ Math is TRUE

Grace ∈ Physics is TRUE

Important Connection to Logic:

For a given element c and set A, "c ∈ A" is a proposition!

It can be either TRUE or FALSE.

If x is a variable, then "x ∈ A" is a predicate!

Cardinality: Counting Elements

Definition

The cardinality of a set A, written |A|, is the number of elements in A.

A set is finite if it has a finite number of elements.

Examples from enrollment:

|CS| = |{Alice, Bob, Charlie, Diana}| = 4

|Math| = |{Bob, Diana, Eve, Frank}| = 4

|Physics| = |{Charlie, Frank, Grace, Henry}| = 4

|DataSci| = |{Alice, Bob, Eve, Grace}| = 4

|U| = 8 (total students)

Special Cases:

Empty Set

|∅| = 0

The empty set has no elements

Singleton Set

|{Alice}| = 1

A set with exactly one element

Quick Check:

What is |{1, 1, 2, 2, 3}|? Remember: sets have no duplicates!

Module 3: Subsets

Definition

A set B is a subset of a set A, written B ⊆ A, if every element of B is also an element of A.

Formally: B ⊆ A means ∀x (x ∈ B → x ∈ A)

B A B ⊆ A (B is a subset of A)

Example from enrollment:

Let BothCourses = {Bob, Diana} (students in both CS and Math)

BothCourses ⊆ CS is TRUE

because both Bob and Diana are in CS

BothCourses ⊆ Math is also TRUE

because both Bob and Diana are in Math

More Subset Examples

True Subset Statements:

{Alice, Bob} ⊆ CS

{Bob} ⊆ CS

∅ ⊆ CS (empty set is subset of every set!)

CS ⊆ CS (every set is subset of itself!)

CS ⊆ U (every set is subset of the universe)

False Subset Statements:

{Alice, Eve} ⊆ CS

Why? Eve ∈ {Alice, Eve} but Eve ∉ CS

Math ⊆ CS

Why? Eve ∈ Math but Eve ∉ CS

Negation of Subset:

B ⊄ A means B is NOT a subset of A

Formally: ∃x (x ∈ B ∧ x ∉ A)

There exists at least one element in B that is not in A

Proper Subsets

Definition

A set B is a proper subset of a set A, written B ⊂ A, if:

  1. Every element of B is in A (B ⊆ A)
  2. There exists at least one element in A that is not in B (A ⊄ B)

In other words: B ⊂ A means B ⊆ A but B ≠ A

Proper Subsets:

{Alice, Bob} ⊂ CS

∅ ⊂ CS

CS ⊂ U

NOT Proper Subsets:

CS ⊂ CS

CS = CS, so not proper

⚠️ Warning: Notation Varies!

Some textbooks use ⊂ to mean ⊆ (subset)

Some textbooks use ⊂ to mean proper subset (like <)

Always check which convention is being used!

Think: ⊆ is like ≤, and ⊂ is like <

Set Equality

Definition

Two sets A and B are equal, written A = B, if they have exactly the same elements.

Formally: A = B if and only if A ⊆ B AND B ⊆ A

Using predicates: ∀x (x ∈ A ↔ x ∈ B)

Examples:

{Alice, Bob, Charlie} = {Charlie, Alice, Bob}

Order doesn't matter!

{Alice, Bob, Bob, Alice} = {Alice, Bob}

Duplicates don't matter!

{Alice, Bob} ≠ {Alice, Bob, Charlie}

Different elements!

How to Prove A = B:

Method 1: Show A ⊆ B and B ⊆ A

Method 2: Show every element of A is in B, and every element of B is in A

Method 3: Use set laws and algebra (we'll learn this soon!)

Important Properties of Subsets

Universal Truths About Subsets:

1. Empty Set is Subset of Everything

For any set A: ∅ ⊆ A

Why? There's no element in ∅ that fails to be in A!

Vacuous truth: "All unicorns in my room have wings" is true (there are no unicorns!)

2. Every Set is Subset of Itself

For any set A: A ⊆ A

Why? Every element of A is (obviously) in A!

3. Transitivity

If A ⊆ B and B ⊆ C, then A ⊆ C

Why? Every element of A is in B, and every element of B is in C, so every element of A is in C!

Example of Transitivity:

Let CSMajors = {Alice, Charlie}

Then: CSMajors ⊆ CS ⊆ U

Therefore: CSMajors ⊆ U

Module 4: Set Operations - Union (∪)

Definition

The union of sets A and B, written A ∪ B, is the set of all elements that are in A OR in B (or in both).

Formally:

A ∪ B = {x | x ∈ A ∨ x ∈ B}

Connection to Logic:

Union (∪) corresponds to OR (∨)

Think: "in A or in B"

A B Shaded area = A ∪ B

Example: Students in CS or Math

CS = {Alice, Bob, Charlie, Diana}

Math = {Bob, Diana, Eve, Frank}

CS ∪ Math = {Alice, Bob, Charlie, Diana, Eve, Frank}

Students taking at least one of these courses

Union: Python Implementation

# Define sets using Python's set type
CS = {'Alice', 'Bob', 'Charlie', 'Diana'}
Math = {'Bob', 'Diana', 'Eve', 'Frank'}

# Method 1: Using the | operator
union1 = CS | Math
print(union1)
# Output: {'Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank'}

# Method 2: Using the union() method
union2 = CS.union(Math)
print(union2)
# Output: {'Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank'}

# Both methods give the same result!
print(union1 == union2)  # Output: True

Properties of Union:

Commutative:

A ∪ B = B ∪ A

Associative:

(A ∪ B) ∪ C = A ∪ (B ∪ C)

Identity:

A ∪ ∅ = A

Idempotent:

A ∪ A = A

Quick Check:

What is Physics ∪ DataSci?

Physics = {Charlie, Frank, Grace, Henry}, DataSci = {Alice, Bob, Eve, Grace}

Set Operations - Intersection (∩)

Definition

The intersection of sets A and B, written A ∩ B, is the set of all elements that are in BOTH A AND B.

Formally:

A ∩ B = {x | x ∈ A ∧ x ∈ B}

Connection to Logic:

Intersection (∩) corresponds to AND (∧)

Think: "in A and in B"

A B Shaded area = A ∩ B

Example: Students in both CS and Math

CS = {Alice, Bob, Charlie, Diana}

Math = {Bob, Diana, Eve, Frank}

CS ∩ Math = {Bob, Diana}

Students taking both courses

Intersection: Python Implementation

# Define sets
CS = {'Alice', 'Bob', 'Charlie', 'Diana'}
Math = {'Bob', 'Diana', 'Eve', 'Frank'}

# Method 1: Using the & operator
intersection1 = CS & Math
print(intersection1)
# Output: {'Bob', 'Diana'}

# Method 2: Using the intersection() method
intersection2 = CS.intersection(Math)
print(intersection2)
# Output: {'Bob', 'Diana'}

# Find students in all three courses
Physics = {'Charlie', 'Frank', 'Grace', 'Henry'}
all_three = CS & Math & Physics
print(all_three)
# Output: set() (empty set - no student in all three)

Properties of Intersection:

Commutative:

A ∩ B = B ∩ A

Associative:

(A ∩ B) ∩ C = A ∩ (B ∩ C)

Identity:

A ∩ U = A

Annihilator:

A ∩ ∅ = ∅

Disjoint Sets

Definition

Two sets A and B are disjoint if they have no elements in common.

Formally: A and B are disjoint if A ∩ B = ∅

Using predicates: ¬∃x (x ∈ A ∧ x ∈ B)

A B A and B are disjoint (no overlap)

Example from enrollment:

Let CSOnly = {Alice, Charlie} (students only in CS, not in Math)

Let MathOnly = {Eve, Frank} (students only in Math, not in CS)

CSOnly ∩ MathOnly = ∅

These sets are disjoint!

# Check if sets are disjoint
CSOnly = {'Alice', 'Charlie'}
MathOnly = {'Eve', 'Frank'}

print(CSOnly.isdisjoint(MathOnly))  # Output: True
print(CS.isdisjoint(Math))          # Output: False (they share Bob and Diana)

Set Operations - Difference (\)

Definition

The difference of sets A and B, written A \ B or A - B, is the set of elements that are in A but NOT in B.

Formally:

A \ B = {x | x ∈ A ∧ x ∉ B}

⚠️ Note:

A \ B ≠ B \ A

Difference is NOT commutative!

A B Shaded area = A \ B

Example: Students in CS but not in Math

CS = {Alice, Bob, Charlie, Diana}

Math = {Bob, Diana, Eve, Frank}

CS \ Math = {Alice, Charlie}

Students taking CS but not Math

Math \ CS = {Eve, Frank}

Students taking Math but not CS

Set Difference: Python Implementation

# Define sets
CS = {'Alice', 'Bob', 'Charlie', 'Diana'}
Math = {'Bob', 'Diana', 'Eve', 'Frank'}

# Method 1: Using the - operator
cs_only = CS - Math
print(cs_only)
# Output: {'Alice', 'Charlie'}

# Method 2: Using the difference() method
math_only = Math.difference(CS)
print(math_only)
# Output: {'Eve', 'Frank'}

# Demonstrate non-commutativity
print(CS - Math)      # {'Alice', 'Charlie'}
print(Math - CS)      # {'Eve', 'Frank'}
print((CS - Math) == (Math - CS))  # False!

Practical Application: Finding Exclusive Students

# Students taking exactly one course (not both)
cs_exclusive = CS - Math        # Only CS
math_exclusive = Math - CS      # Only Math
one_course_only = cs_exclusive | math_exclusive
print(one_course_only)
# Output: {'Alice', 'Charlie', 'Eve', 'Frank'}

# This is called "symmetric difference" (we'll see this soon!)

Quick Check:

What is U \ CS (students not taking CS)?

Set Operations - Complement (')

Definition

The complement of set A, written A' or Ā or Ac, is the set of all elements in the universe U that are NOT in A.

Formally:

A' = U \ A = {x ∈ U | x ∉ A}

Connection to Logic:

Complement (') corresponds to NOT (¬)

Think: "not in A"

A U Shaded area = A'

Example: Students NOT taking CS

U = {Alice, Bob, Charlie, Diana, Eve, Frank, Grace, Henry}

CS = {Alice, Bob, Charlie, Diana}

CS' = {Eve, Frank, Grace, Henry}

Students NOT taking CS

Complement: Properties and Python

# Define universe and sets
U = {'Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace', 'Henry'}
CS = {'Alice', 'Bob', 'Charlie', 'Diana'}

# Complement: elements in U but not in CS
CS_complement = U - CS
print(CS_complement)
# Output: {'Eve', 'Frank', 'Grace', 'Henry'}

# Verify important properties
print(CS | CS_complement)  # Should equal U
# Output: {'Alice', 'Bob', ..., 'Henry'} (all 8 students)

print(CS & CS_complement)  # Should be empty
# Output: set() (empty set)

Important Properties of Complement:

Union with Complement:

A ∪ A' = U

Intersection with Complement:

A ∩ A' = ∅

Double Complement:

(A')' = A

Universe & Empty Set:

U' = ∅

∅' = U

Quick Check:

If Math = {Bob, Diana, Eve, Frank}, what is Math'?

Summary: All Set Operations

Operation Symbol Definition Logic Connection Python
Union A ∪ B Elements in A OR B ∨ (OR) A | B
Intersection A ∩ B Elements in A AND B ∧ (AND) A & B
Difference A \ B Elements in A but NOT in B ∧ ¬ A - B
Complement A' Elements NOT in A ¬ (NOT) U - A

Quick Reference: Our Enrollment Data

CS = {Alice, Bob, Charlie, Diana}

Math = {Bob, Diana, Eve, Frank}

CS ∪ Math = {Alice, Bob, Charlie, Diana, Eve, Frank}

CS ∩ Math = {Bob, Diana}

CS \ Math = {Alice, Charlie}

CS' = {Eve, Frank, Grace, Henry}

Module 5: Set Laws - Connection to Logic

Remember the laws of logic from Weeks 1-2? Set theory has parallel laws!

Law Name Logic Law Set Law
Commutative p ∨ q ≡ q ∨ p
p ∧ q ≡ q ∧ p
A ∪ B = B ∪ A
A ∩ B = B ∩ A
Associative (p ∨ q) ∨ r ≡ p ∨ (q ∨ r)
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
(A ∪ B) ∪ C = A ∪ (B ∪ C)
(A ∩ B) ∩ C = A ∩ (B ∩ C)
Distributive p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
De Morgan's ¬(p ∨ q) ≡ ¬p ∧ ¬q
¬(p ∧ q) ≡ ¬p ∨ ¬q
(A ∪ B)' = A' ∩ B'
(A ∩ B)' = A' ∪ B'

Why does this parallel exist?

Because sets are defined using predicates!

A ∪ B = {x | x ∈ A ∨ x ∈ B}

The ∨ in the predicate becomes ∪ in the set!

De Morgan's Laws for Sets

De Morgan's Laws

Law 1: (A ∪ B)' = A' ∩ B'

The complement of a union is the intersection of complements

Law 2: (A ∩ B)' = A' ∪ B'

The complement of an intersection is the union of complements

Example: Students NOT in CS or Math

CS = {Alice, Bob, Charlie, Diana}

Math = {Bob, Diana, Eve, Frank}

CS ∪ Math = {Alice, Bob, Charlie, Diana, Eve, Frank}

Using Law 1:

(CS ∪ Math)' = {Grace, Henry}

Students not taking CS or Math

CS' ∩ Math' = {Eve, Frank, Grace, Henry} ∩ {Alice, Charlie, Grace, Henry}

= {Grace, Henry}

Intuition:

"Not (in CS or Math)" = "Not in CS AND not in Math"

"Not (in CS and Math)" = "Not in CS OR not in Math"

Proving Set Equality

Three Methods to Prove A = B:

Method 1: Element-Chasing (Double Subset)

Show A ⊆ B and B ⊆ A

  1. Prove: If x ∈ A, then x ∈ B (shows A ⊆ B)
  2. Prove: If x ∈ B, then x ∈ A (shows B ⊆ A)
  3. Conclude: A = B

Method 2: Using Predicates

Show that x ∈ A ⟺ x ∈ B for all x

Use logical equivalences to transform the predicate for A into the predicate for B

Method 3: Using Set Laws

Apply known set laws to transform one side into the other

(Like algebraic manipulation, but with sets!)

Let's see an example of each method...

Proof Example: De Morgan's Law

Prove: (A ∪ B)' = A' ∩ B'

Method 2: Using Predicates

(A ∪ B)' = {x | x ∉ (A ∪ B)}

Definition of complement

= {x | ¬(x ∈ (A ∪ B))}

Rewrite ∉ as ¬∈

= {x | ¬(x ∈ A ∨ x ∈ B)}

Definition of union

= {x | ¬(x ∈ A) ∧ ¬(x ∈ B)}

De Morgan's law of logic!

= {x | x ∉ A ∧ x ∉ B}

Rewrite ¬∈ as ∉

= {x | x ∈ A' ∧ x ∈ B'}

Definition of complement

= A' ∩ B'

Definition of intersection

Therefore, (A ∪ B)' = A' ∩ B' ✓

Complete Table of Set Laws

Law Name Set Law
Identity Laws A ∪ ∅ = A
A ∩ U = A
Domination Laws A ∪ U = U
A ∩ ∅ = ∅
Idempotent Laws A ∪ A = A
A ∩ A = A
Complement Laws A ∪ A' = U
A ∩ A' = ∅
(A')' = A
Commutative Laws A ∪ B = B ∪ A
A ∩ B = B ∩ A
Associative Laws (A ∪ B) ∪ C = A ∪ (B ∪ C)
(A ∩ B) ∩ C = A ∩ (B ∩ C)
Distributive Laws A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
De Morgan's Laws (A ∪ B)' = A' ∩ B'
(A ∩ B)' = A' ∪ B'
Absorption Laws A ∪ (A ∩ B) = A
A ∩ (A ∪ B) = A

Module 6: Power Sets

Definition

The power set of a set A, written P(A) or 2A, is the set of all subsets of A.

Formally: P(A) = {B | B ⊆ A}

Example: Small Set

Let A = {1, 2}

The subsets of A are:

  • ∅ (empty set)
  • {1}
  • {2}
  • {1, 2}

P(A) = {∅, {1}, {2}, {1, 2}}

Notice: |A| = 2, but |P(A)| = 4 = 2²

⚠️ Important:

Elements of P(A) are SETS, not individual elements!

1 ∈ A but 1 ∉ P(A)

{1} ∈ P(A) but {1} ∉ A

Power Set: Cardinality

Theorem

If A is a finite set with |A| = n, then:

|P(A)| = 2n

Why 2n?

Think of building a subset: for each element, we have 2 choices:

  • Include it in the subset, or
  • Exclude it from the subset

For n elements: 2 × 2 × 2 × ... × 2 (n times) = 2n subsets

Example: Three Students

Let Small = {Alice, Bob, Charlie}

|Small| = 3, so |P(Small)| = 2³ = 8

P(Small) = {

∅,

{Alice}, {Bob}, {Charlie},

{Alice, Bob}, {Alice, Charlie}, {Bob, Charlie},

{Alice, Bob, Charlie}

}

Cartesian Products

Definition

The Cartesian product of sets A and B, written A × B, is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B.

Formally: A × B = {(a, b) | a ∈ A ∧ b ∈ B}

⚠️ Important:

Order matters! (a, b) ≠ (b, a) unless a = b

A × B ≠ B × A in general

Example: Course-Student Pairs

Let Courses = {CS, Math}

Let Students = {Alice, Bob}

Courses × Students = {

(CS, Alice), (CS, Bob),

(Math, Alice), (Math, Bob)

}

This represents all possible course-student pairings!

(Think: enrollment possibilities)

Cartesian Product: Properties and Applications

Cardinality

If |A| = m and |B| = n, then:

|A × B| = m × n

Computer Science Applications:

Database Tables

JOIN operations compute Cartesian products

Students × Courses = all possible enrollments

Coordinate Systems

ℝ² = ℝ × ℝ

All points (x, y) in the plane

# Python implementation
from itertools import product

courses = {'CS', 'Math'}
students = {'Alice', 'Bob'}

# Cartesian product
pairings = set(product(courses, students))
print(pairings)
# Output: {('CS', 'Alice'), ('CS', 'Bob'), 
#          ('Math', 'Alice'), ('Math', 'Bob')}

print(len(pairings))  # 2 × 2 = 4

Quick Check:

If |A| = 3 and |B| = 4, what is |A × B|?

Inclusion-Exclusion Principle

Theorem

For any finite sets A and B:

|A ∪ B| = |A| + |B| - |A ∩ B|

|A| only |A ∩ B| |B| only Don't count the overlap twice!

Example from Enrollment:

CS = {Alice, Bob, Charlie, Diana}, so |CS| = 4

Math = {Bob, Diana, Eve, Frank}, so |Math| = 4

CS ∩ Math = {Bob, Diana}, so |CS ∩ Math| = 2

Calculate |CS ∪ Math|:

|CS ∪ Math| = 4 + 4 - 2 = 6

Verify:

CS ∪ Math = {Alice, Bob, Charlie, Diana, Eve, Frank}

Count: 6 students ✓

Practice Problem 1: Set Operations

Given:

U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

A = {2, 4, 6, 8, 10} (even numbers)

B = {1, 2, 3, 5, 7} (primes and 1)

C = {3, 6, 9} (multiples of 3)

Find:

  1. A ∪ B
  2. A ∩ B
  3. A \ B
  4. B'
  5. (A ∪ C)'
  6. A ∩ (B ∪ C)
  7. |A × C|
  8. Verify: |A ∪ B| = |A| + |B| - |A ∩ B|

Try this yourself first, then check your answers!

Practice Problem 1: Solutions

Solutions:

1. A ∪ B = {1, 2, 3, 4, 5, 6, 7, 8, 10}

2. A ∩ B = {2}

3. A \ B = {4, 6, 8, 10}

4. B' = {4, 6, 8, 9, 10}

5. A ∪ C = {2, 3, 4, 6, 8, 9, 10}

(A ∪ C)' = {1, 5, 7}

6. B ∪ C = {1, 2, 3, 5, 6, 7, 9}

A ∩ (B ∪ C) = {2, 6}

7. |A| = 5, |C| = 3

|A × C| = 5 × 3 = 15

8. |A| = 5, |B| = 5, |A ∩ B| = 1

|A ∪ B| = 5 + 5 - 1 = 9

Count elements: 9 ✓

Practice Problem 2: Prove Set Equality

Prove: A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)

(Distributive Law for Sets)

Method 1: Double Subset Proof

Show: A ∩ (B ∪ C) ⊆ (A ∩ B) ∪ (A ∩ C) and (A ∩ B) ∪ (A ∩ C) ⊆ A ∩ (B ∪ C)

Method 2: Using Predicates

Show the predicates are logically equivalent

Try Method 2 yourself!

Hint: Start with x ∈ A ∩ (B ∪ C) and transform using definitions and logic laws

Practice Problem 2: Solution

Proof using Predicates:

x ∈ A ∩ (B ∪ C)

⟺ x ∈ A ∧ x ∈ (B ∪ C)

Definition of ∩

⟺ x ∈ A ∧ (x ∈ B ∨ x ∈ C)

Definition of ∪

⟺ (x ∈ A ∧ x ∈ B) ∨ (x ∈ A ∧ x ∈ C)

Distributive law of logic!

⟺ x ∈ (A ∩ B) ∨ x ∈ (A ∩ C)

Definition of ∩

⟺ x ∈ (A ∩ B) ∪ (A ∩ C)

Definition of ∪

Therefore, A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) ✓

Real-World Application: Database Queries

University Database: Student Records

Consider a database table with student enrollments:

Student Course
AliceMA2011
BobMA2011
BobMA1000
CharlieMA2011
DianaMA2011
DianaMA1000
-- SQL UNION: Students in MA2011 OR MA1000
SELECT Student FROM Enrollments WHERE Course = 'MA2011'
UNION
SELECT Student FROM Enrollments WHERE Course = 'MA1000';
-- Result: Alice, Bob, Charlie, Diana, Eve, Frank

-- SQL INTERSECT: Students in MA2011 AND MA1000
SELECT Student FROM Enrollments WHERE Course = 'MA2011'
INTERSECT
SELECT Student FROM Enrollments WHERE Course = 'MA1000';
-- Result: Bob, Diana

-- SQL EXCEPT: Students in MA2011 but NOT MA1000
SELECT Student FROM Enrollments WHERE Course = 'MA2011'
EXCEPT
SELECT Student FROM Enrollments WHERE Course = 'MA1000';
-- Result: Alice, Charlie

Set theory is the foundation of SQL!

Real-World Application: Access Control

User Permissions System

# Define user groups (sets)
admins = {'alice', 'bob'}
editors = {'bob', 'charlie', 'diana'}
viewers = {'diana', 'eve', 'frank'}

# Users who can edit OR view
can_access = editors | viewers
print(f"Can access: {can_access}")
# {bob, charlie, diana, eve, frank}

# Users who are both editors AND viewers
power_users = editors & viewers
print(f"Power users: {power_users}")
# {diana}

# Users who can edit but NOT admin
editors_only = editors - admins
print(f"Editors only: {editors_only}")
# {charlie, diana}

# Check specific permissions
def has_permission(user, required_groups):
    """Check if user is in any of the required groups"""
    user_groups = set()
    if user in admins: user_groups.add('admin')
    if user in editors: user_groups.add('editor')
    if user in viewers: user_groups.add('viewer')
    
    return bool(user_groups & required_groups)

print(has_permission('bob', {'admin', 'editor'}))  # True
print(has_permission('eve', {'admin', 'editor'}))  # False

Common Mistakes to Avoid

❌ Mistake 1: Confusing ∈ and ⊆

1 ∈ {1, 2, 3} ✓ (1 is an element)

1 ⊆ {1, 2, 3} ✗ (1 is not a set!)

{1} ⊆ {1, 2, 3} ✓ ({1} is a subset)

{1} ∈ {1, 2, 3} ✗ ({1} is not an element!)

❌ Mistake 2: Forgetting Order Matters in Pairs

{1, 2} = {2, 1} ✓ (sets are unordered)

(1, 2) = (2, 1) ✗ (ordered pairs are ordered!)

❌ Mistake 3: Thinking ∅ and {∅} are the Same

is the empty set (no elements)

{∅} is a set containing one element (the empty set!)

|∅| = 0 but |{∅}| = 1

❌ Mistake 4: Counting Union Wrong

If A and B overlap, you can't just add: |A ∪ B| ≠ |A| + |B|

Use inclusion-exclusion: |A ∪ B| = |A| + |B| - |A ∩ B|

Study Tips for Set Theory

1. Draw Venn Diagrams

Visual representations help understand operations and prove identities

2. Connect to Logic

Every set law has a corresponding logic law:

∪ ↔ ∨, ∩ ↔ ∧, ' ↔ ¬

3. Practice with Concrete Examples

Use small sets to verify laws before proving them generally

4. Write Proofs Carefully

Show every step, state which law or definition you're using

5. Use Python to Check Your Work

# Verify De Morgan's Law
A = {1, 2, 3}
B = {3, 4, 5}
U = {1, 2, 3, 4, 5, 6}

left = U - (A | B)
right = (U - A) & (U - B)
print(left == right)  # Should be True

6. Review Tutorial Exercises

The practice problems cover all major concepts and proof techniques

Summary: What We Learned

Foundations

  • Sets: unordered, distinct collections
  • Three ways to describe sets
  • Membership (∈) and cardinality (|A|)
  • Subsets (⊆) and equality

Operations

  • Union (∪) - OR
  • Intersection (∩) - AND
  • Difference (\) - BUT NOT
  • Complement (') - NOT

Set Laws

  • Parallel to logic laws
  • De Morgan's laws
  • Distributive laws
  • Proving set equality

Advanced Topics

  • Power sets: |P(A)| = 2|A|
  • Cartesian products: |A × B| = |A| × |B|
  • Inclusion-exclusion principle

Key Insight

Set theory is the foundation of computer science!

Databases, algorithms, data structures all use set operations

Looking Ahead: How Sets Connect to Future Topics

Functions (Week 6-7)

Functions are special types of relations (subsets of Cartesian products)

f: A → B is a subset of A × B

Relations (Week 7-8)

Binary relations are subsets of A × A

Equivalence relations partition sets into disjoint subsets

Counting & Combinatorics (Week 9-10)

Counting subsets, permutations, combinations

Inclusion-exclusion for complex counting problems

Graph Theory (Week 11-12)

Graphs are sets of vertices and edges

G = (V, E) where V is a set and E ⊆ V × V

Everything Builds on Sets!

Set theory is the language of discrete mathematics. Master it now!

Questions?

Next Steps:

  • ✓ Complete tutorial exercises
  • ✓ Practice Python set operations
  • ✓ Review proof techniques
  • ✓ Prepare for Week 6: Functions

Remember: Sets are the foundation!

Master them now, everything else builds on this.