SP20:Lecture 2 Set definitions

From CS2800 wiki

We will discuss sets and the basic definitions: union, intersection, set difference subset, etc.

Sets

Definition: Set
A set is a collection of things. If [math]A [/math] is a set and [math]x [/math] is a thing, then [math]x [/math] is either in [math]A [/math] (written [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} A [/math]) or not in [math]A [/math] (written [math]x \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} A [/math]).

If [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} A [/math] we say that [math]x [/math] is an element of [math]A [/math].

Two sets are equal if they contain the same set of things (see the definition of set equality for more details).

examples

Here are some useful sets:

  • The set [math]\href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} \href{/cs2800/wiki/index.php/Definition}{:=} \href{/cs2800/wiki/index.php/Enumerated_set}{\{0,1,2,\dots\}} [/math] of natural numbers.
  • The set [math]\href{/cs2800/wiki/index.php/%E2%84%A4}{ℤ} \href{/cs2800/wiki/index.php/Definition}{:=} \href{/cs2800/wiki/index.php/Enumerated_set}{\{\dots,-2,-1,0,1,2,\dots\}} [/math] of integers.


Sets can contain things other than numbers:

  • Let [math]A [/math] be the set of people in the room


The defining feature of a set [math]A [/math] is that every object is unambiguously either in [math]A [/math] or not in [math]A [/math]. You don't need an algorithm for determining which is true. For example:

  • Let [math]B [/math] be the set of Java programs that never crash


This is a perfectly good set (assuming you define "Java program" and "crash"), even though there is no algorithm to determine whether a given program crashes or not. It either does or it doesn't, we don't have to know which.

  • The empty set (written [math]\href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math] or [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{\}} [/math]) is a set; [math]x \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} \href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math] for all [math]x [/math].


This is an example of a degenerate object. An informal definition of a set would be something that has things in it; the empty set has no things in it, so perhaps we should rule it out. But most proofs work just as well with special cases as they do for the general case, so by default we include the special cases. We do the same thing when we define subset below.


We can list (or enumerate) the elements of a set:

You can think of this as shorthand for the set comprehension [math]\{n \href{/cs2800/wiki/index.php/%5Cmid}{\mid} n = 1\href{/cs2800/wiki/index.php/Or}{\text{ or }n} = 2\href{/cs2800/wiki/index.php/Or}{\text{ or }n}=3\} [/math].

Sometimes we include a $\dots$ in an enumerated set if its meaning is clear (such as in the definition of [math]\href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} [/math]). This can be formalized more carefully as an inductively defined set.

Sets can contain other sets:

  • [math]\{\{1,2\}, \{3,4\}\} [/math] is a set containing two elements: the first is the set [math]\{1,2\} [/math]; the second is the set containing [math]\{3,4\} [/math].
  • Note that [math]\{\href{/cs2800/wiki/index.php/%E2%88%85}{∅}\} \href{/cs2800/wiki/index.php?title=Set_equality&action=edit&redlink=1}{\neq} ∅ [/math]; the former contains one thing (the empty set), while the latter contains no things. This is analogous to the difference in python between [] and [[]]:
>>> len([])
0
>>> len([[]])
1

One easy way to construct a set is to draw a picture of it. A common way of doing so is a Venn diagram such as this one:

Venn-diag.svg

This diagram indicates that the set [math]A [/math] consists of all of the points in the left-hand circle, while set [math]B [/math] consists of the points in the right hand circle.

Be careful: although Venn diagrams are a great way to create examples, they do not provide proofs that work for arbitrary sets. For example, an argument made using the diagram above does not describe the cases where [math]A \href{/cs2800/wiki/index.php/%5Csubseteq}{\subseteq} B [/math] or when [math]A \href{/cs2800/wiki/index.php/%5Ccap}{\cap} B \href{/cs2800/wiki/index.php/Equality_(sets)}{=} \href{/cs2800/wiki/index.php?title=%5Cemptyset&action=edit&redlink=1}{\emptyset} [/math]. Moreover, it doesn't consider finite sets or sets that are larger than any set of points in the plane. Venn diagrams give intuition (and examples) but not proofs.

Set comprehensions

The notation [math]\{x \mid \text{property of } x\} [/math] denotes the set of all [math]x [/math] that satisfy the property. You should read [math]\href{/cs2800/wiki/index.php/%5Cmid}{\mid} [/math] as "such that". For example,

[math]A \href{/cs2800/wiki/index.php/Definition}{:=} \{x \mid x\href{/cs2800/wiki/index.php/Even}{\text{ is even}}\} [/math]

indicates the set of all even numbers. [math]2 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} A [/math] because [math]2 [/math] is even, while [math]1 \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} A [/math] because [math]1 [/math] is not even.

We may want to specify that we're only interested in natural numbers; we often use notation like [math]\{x \href{/cs2800/wiki/index.php/%E2%88%88}{∈} \href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} \mid x\href{/cs2800/wiki/index.php/Even}{\text{ is even}}\} [/math]. This should be read as "the set of natural numbers which are even".

We can also have more complicated expressions to the left of the vertical bar, for example [math]B \href{/cs2800/wiki/index.php/Definition}{:=} \{2y \mid y \in \href{/cs2800/wiki/index.php/%E2%84%95}{ℕ}\} [/math] also denotes the set of even natural numbers: [math]8 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} B [/math] because [math]8 = 2\href{/cs2800/wiki/index.php?title=%5Ccdot&action=edit&redlink=1}{\cdot}4 [/math] and [math]4 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} \href{/cs2800/wiki/index.php/%E2%84%95}{ℕ} [/math], while [math]7 \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} B [/math] because there is no natural number that when multiplied by 2 gives 7.

Set comprehension example

Note that set comprehension notation can sometimes be tricky. Just because [math]x ∈ \href{/cs2800/wiki/index.php/Set_comprehension}{\{x \mid P(x)\}} [/math], doesn't necessarily mean [math]x [/math] satisfies [math]P(x) [/math].

For example, we know that [math]-3 + 4 \href{/cs2800/wiki/index.php/%5Cin}{\in} \{x + y \mid x \gt 0\} [/math], because [math]-3 + 4 = 1 = 4 + -3 [/math], but that doesn't mean that [math]-3 \gt 0 [/math].

Set equality

The defining feature of a set is the collections of elements that are in or not in it. This suggests that we should consider two sets to be the same if they contain the same elements. This motivates the definition of equality:

Definition: Equality (sets)
Two sets $A$ and $B$ are equal if [math]A \href{/cs2800/wiki/index.php/%5Csubseteq}{\subseteq} B [/math] and [math]B \href{/cs2800/wiki/index.php/%5Csubseteq}{\subseteq} A [/math].

This is equivalent to the following definition:

Definition: Equality (sets)
Two sets $A$ and $B$ are equal if, for all [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} A [/math], [math]x [/math] is also in [math]B [/math] and if for all [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} B [/math], [math]x [/math] is also in [math]A [/math].

Here is a third variant:

Definition: Equality (sets)
Two sets [math]A [/math] and [math]B [/math] are equal if, for all [math]x [/math], [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} A [/math] if and only if [math]x \href{/cs2800/wiki/index.php/%5Cin}{\in} B [/math].

These three definitions are equivalent (proof left as an exercise), so you can use them interchangeably.

This definition tells us that sets "ignore" duplicates and order. For example, [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{1,1,2,3\}} \href{/cs2800/wiki/index.php/Equality_(sets)}{=} \href{/cs2800/wiki/index.php/Enumerated_set}{\{1,2,3\}} [/math]; we can prove this using the definition. First, we check every [math]x [/math] in the left hand side (LHS) is in the right hand side (RHS); by inspection, we see that [math]1 \in \href{/cs2800/wiki/index.php/RHS}{RHS}, 1 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} \href{/cs2800/wiki/index.php/RHS}{RHS}, 2 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} \href{/cs2800/wiki/index.php/RHS}{RHS} [/math], and [math]3 \href{/cs2800/wiki/index.php/%E2%88%88}{∈} \href{/cs2800/wiki/index.php/RHS}{RHS} [/math]. Then, we check that every [math]x [/math] in the RHS is in the LHS; which they are, again by inspection.

Empty set

The empty set (written [math]\href{/cs2800/wiki/index.php/%E2%88%85}{∅}
[/math] or [math]\href{/cs2800/wiki/index.php/Enumerated_set}{\{\}}
[/math]) is a set; [math]x \href{/cs2800/wiki/index.php/%5Cnotin}{\notin} \href{/cs2800/wiki/index.php/%E2%88%85}{∅}
[/math] for all [math]x
[/math].

The following claim follows immediately from the definition of :

Proof: ∅ ∉ ∅
By definition of the empty set, for all [math]x [/math], [math]x \href{/cs2800/wiki/index.php/%E2%88%89}{∉} \href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math]. In particular, if [math]x = \href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math], then [math]x \href{/cs2800/wiki/index.php/%E2%88%89}{∉} \href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math], so [math]\href{/cs2800/wiki/index.php/%E2%88%85}{∅} \href{/cs2800/wiki/index.php/%E2%88%89}{∉} \href{/cs2800/wiki/index.php/%E2%88%85}{∅} [/math], as required.