Review of Set Theory

COMP 2600: Formal Methods for Software
Engineeing
(Review of Set Theory)
Dirk Pattinson
Semester 2, 2013
Why should we study set theory?
Set Theory as Foundation
All aspects of mathematics can ultimately be ‘compiled’ down to set theory.
Programming
Programs as functions that map structured sets of inputs to (structured)
sets of outputs. Types are sets (of values).
Set Theory as a Discipline
• much foundational work on ‘Sets as Foundation’
• here: just need the basics
Set Theory Basics
Basic Constructs
• set membership: x ∈ A
• set equality: A = B
linked by extensionality: A = B ↔ ∀x.(x ∈ A ↔ x ∈ B)
Derived Concept: Subsets
A ⊆ B ≡ ∀x.(x ∈ A → x ∈ B)
Notation
• explicit enumeration: A = {1, 2, 12, 17, ’polar bear’}
• comprehension: A = {x ∈ N ∣ x even}
1
Simplest Consequence
• order doesn’t matter: {1, 2, 12} = {12, 1, 2}
• multiplicity doesn’t matter: {1, 1, 2} = {1, 2}
Some Sets that We All Know and Love
Numbers
N is the set of natural numbers; Z is the set of integers; Q is the set of
rational numbers; R is the set of real numbers.
(constructed using the axiom of infinity)
Booleans and Characters
Bool = {⊺, –} is the set of truth values, Char is the set of (ASCII) characters.
The empty set
• can be defined: ∅ = {x ∈ N ∣ x ≠ x}
• is a subset of every set: ∅ ⊆ A
• should not be confused with {∅}.
Interlude: Set Theory as Assembly Language
Compiling ∅ ⊆ A: The Ingredients
• ∅ ≡ {x ∈ N ∣ x ≠ x}
• A ⊆ B ≡ ∀x(x ∈ A → x ∈ B)
Assember Proof of ∅ ⊆ A
∀x(x ∈ {x ∈ N ∣ x ≠ x} → x ∈ A
≡∀x(x ∈ N ∧ x ≠ x → x ∈ A)
≡∀x(x ∈ N ∧ – → x ∈ A)
≡∀x.⊺ ≡ ⊺
(But we’re not going to do any more gymnastics at this low level.)
2
Caveat on Notation
Dots . . .
• O = {1, 3, 5, 7, . . . } is the set of odd numbers. Or is it?
• Maybe {1, 3, 5, 7, . . . } is the set of numbers not divisible by 2 or 13?
Comprehension to the Rescue
O = {x ∈ N ∣ x odd}
(of course dots are OK if we really agree on what we mean . . . )
Russel’s Paradox
• Comprehension: {x ∈ A ∣ φ(x)} is a set whenver φ(x) is a formula.
• for otherwise, R = {x ∣ x ∉ x} would also be a set
• and R ∈ R ∨ R ∉ R → – would follow, a contradiction!
New Sets from Old
Power Sets, Products, Union and Intersection
• can all be ‘compiled’ into primitive constructions just using ∈, =
• we don’t do this here – too bureaucratic.
Products and Powersets and Unions
P(A) = {B ∣ B ⊆ A}
the powerset of A
A × B = {(a, b) ∣ a ∈ A and b ∈ B}
the cartesisian product of A and B
A ∪ B = {x ∣ x ∈ A or x ∈ B}
the union of A and B
Illegal? Unrestricted Comprehension? – No, justified by specific axioms.
Intersection is Definable
A ∩ B = {x ∈ A ∣ x ∈ B}
the intersection of A and B
(if you like assembler, try to show that A ∩ B = B ∩ A ;-) )
3
Reflexivity: Self Loops
Transitivity: Two Hops in One Go
Union and Intersection of Families
Union and Intersection of Families
Suppose that Di is a set for all i ∈ I (and I is a set).
⋃ Di = {x ∣ ∃i ∈ I.(x ∈ Di )} and ⋂ Di = {x ∣ ∀i ∈ I.(x ∈ Di )}
i∈I
i∈I
is the union and intersection of all Di (again, ⋃ is definable and ⋃ needs an
axiom)
Example 1. Let I = {0, 1, . . . , 26} and Di contain the first i letters of the
alphabet.
⋃ Di = {a, b, . . . , z} and ⋂ Di = ∅
i∈I
i∈I
and, if J = {2, 4, 7}
⋃ Di = {a, b, c, d, e, f, g} and ⋂ Di = {a, b}
i∈J
i∈J
Relations and Functions
Definition 2. If A and B are sets then a subset R ⊆ A × B is a relation
between A and B. People often write xRy to mean (x, y) ∈ R.
Flavours of Relations
A relation R between A and itself is
• reflexive, if ∀x ∈ A.(x, x) ∈ R (can always go from x to itself)
• transitive, if ∀x, y, z.(x, y) ∈ R ∧ (y, z) ∈ R → (x, z) ∈ R
Functions
Definition 3. A relation R between A and B is functional if both
• ∀x ∈ A.∃y ∈ B.(x, y) ∈ R (left-totality, every x maps somewhere)
• ∀x, y, z.(x, y) ∈ R ∧ (x, z) ∈ R → y = z (right-uniqueness, only one
function value)
If f is a functional relation between A and B, we call f a function and write
f ∶ A → B.
4
A functional relation
References
Chapter 5 of Grassman and Tremblay is called Sets and Relations.
5.1 Sets and Set Operations. You must know this.
5.2 Tuples, Sequences and Power-sets.
5.2.1 Introduction: should know.
5.2.2 Tuples and Cartesian Products: must know.
5.2.3 Sequences and Strings: We’ll get to this.
5.2.4 Power-sets: should know.
5.2.5 Types and Signatures: We’ll cover this.
5.3 Relations: We’ll be talking about this.
5.4 Properties of Relations: We’ll be talking about this.
5