DM 04 Sets

Previous: DM 03 Proof Techniques | DM 00 Course Map | Next: DM 05 Functions and Relations

One sentence

A set is an unordered collection of distinct objects, and the operations on sets mirror the connectives of logic exactly.

What a set is

A set is a collection of objects, called its elements. Write for ” is an element of ” and otherwise.

Two things do not matter: order and repetition.

A set is completely determined by which objects are in it. In Python this is set, as opposed to list.

Describing sets

Roster: list the elements. .

Set-builder: state a property.

Read: “the set of integers such that is even and between 0 and 10”. In Python: {x for x in range(1, 10) if x % 2 == 0}.

Standard sets:

SymbolSet
natural numbers (some books start at 1)
integers
rational numbers
real numbers
the empty set, with no elements

The cardinality is the number of elements. and .

Subsets

(” is a subset of ”) means every element of is also in :

Facts:

  • for every set . (Vacuously true: there is no element of to fail the test.)
  • .
  • exactly when and . This is how you prove two sets are equal: show each is contained in the other.
versus

relates an element to a set; relates a set to a set. With : , , , but . Also : an empty box is not the same as a box containing an empty box.

Operations

Let be the universe of discourse.

OperationNotationDefinitionLogic
unionin or in
intersectionin and in
differencein and not in
complementnot in (within )
symmetric differencein exactly one

Example. , , .

and are disjoint when .

Venn diagrams (overlapping circles) are the right picture for two or three sets. Draw one whenever a set identity looks doubtful.

Laws

Because set operations are defined by logical connectives, every logical law has a set version:

LawStatement
De Morgan
De Morgan
distributive
distributive
absorption
difference

Worked proof of the first De Morgan law, by showing both inclusions through a chain of equivalences:

The middle step is De Morgan’s law for propositions (DM 01 Logic and Propositions). Since each step is an “if and only if”, both inclusions are proved at once.

Counting elements: inclusion-exclusion

Adding the sizes counts the overlap twice. For three sets:

Example. How many integers from 1 to 100 are divisible by 2 or by 5? , where 10 counts the multiples of 10.

The identical formula holds for probabilities (PS 01 Sample Spaces Events and Axioms).

Power set

The power set is the set of all subsets of .

If then . Reason: to build a subset, make a yes/no decision for each of the elements. outcomes. This is the same as the rows of a truth table, and the bit strings of length .

Cartesian product

The Cartesian product is the set of all ordered pairs:

Unlike sets, pairs are ordered: .

Example. has pairs. is the plane, and is the space of vectors from LA 01 Vectors and Linear Combinations. A database table is a subset of a Cartesian product of its column domains.

Partitions

A partition of is a collection of non-empty subsets that are pairwise disjoint and whose union is . Every element lands in exactly one block.

Example: the integers split into evens and odds. Partitions are how “proof by cases” and the law of total probability organize their cases, and they correspond exactly to equivalence relations (DM 05 Functions and Relations).

Infinite sets: a glimpse

Two sets have the same cardinality when their elements can be paired off one-to-one. By this measure the even numbers are as numerous as all natural numbers (pair with ), and so are the rationals. Such sets are countable. The real numbers are not: Cantor’s diagonal argument shows no list can contain them all. So there are different sizes of infinity, and consequently there are more functions than there are programs to compute them.

A warning: Russell’s paradox

Let , the set of all sets that are not members of themselves. Is ? If yes, then by definition . If no, then . Contradiction either way. The lesson: “the set of all things with property ” is not always a legitimate set. Building sets as subsets of an existing set, as in , is safe.

Learn by doing

  1. With , , : find , and .
  2. List . How many elements?
  3. In a class of 40, 25 take maths, 20 take physics and 8 take neither. How many take both?
  4. True or false: ; ; .

Where this shows up

Events are sets (PS 01 Sample Spaces Events and Axioms). State spaces and action spaces in reinforcement learning are sets, and a policy is a function between them. SQL’s UNION, INTERSECT and EXCEPT are the set operations above.