Title: Computing Fundamentals 1 Lecture 6 A Theory of Sets
1Computing Fundamentals 1 Lecture 6A Theory of
Sets
- Lecturer Patrick Browne
- http//www.comp.dit.ie/pbrowne/
- Room K308
- Based on Chapter 11.
- A Logical approach to Discrete Math
- By David Gries and Fred B. Schneider
2Sets
- Set theory can be defined as an extension of
predicate calculus. A set is a collection of
distinct elements (e.g. set of integers, set of
students). - The operations on sets (e.g. union) correspond in
a natural way to the logical connectives of logic
(e.g. or). Later we will show how DeMorgans Laws
for logic can be applied to sets.
3Sets
- Two methods of describing sets set enumeration
and set comprehension. - Set comprehension is defined in terms testing
membership in sets. - This membership test is the basis for the
definition of equality of sets.
4Sets
- Enumerations list elements
- Constants 1,2,3,
- Variables a,b
- Comprehension state properties
- x? 0 ? x lt 5 2 ? x
- Represents
- 0,2,4,6,8
- The general form of comprehension (11.1) is
- xt R E
5Sets
- Recall from Lecture 1 a state is a list of
variables with associated values. - The evaluation of
- xt RE
- in a state yields the set of values from
evaluating Ex v in the state for each value
v in t such that Rxv holds in that state.
Notation similar to quantification -
6Universe
- A theory of sets concerns sets constructed from
some collection of elements. There is a theory of
sets of integers, a theory of sets of characters,
a theory of sets of sets of integers. The
collection of elements is called the domain of
discourse or universe of values and is denoted by
U. The DOD can be thought of as the type of every
set variable in the theory (e.g. DOD is set(?),
then vset(?)).
7Universe
- When several set theories are being used at the
same time, there is a different universe for
each. The name U is then overloaded similar to 1
being considered as a real or an integer.
8Set Membership Equality
- For expression e and a set valued expression S
- e ? S
- is an expression whose value is the value of
the statement e is a member of S. We can write
e is not a member of S as - ?(e ? S) or (e?S)
- The symbol ? is treated as conjunctional operator
and has the same precedence as equality ().
9Set Membership Equality
- (11.3) Axiom, set membership. For expression Ft
and set xR Et for type t - provided ? occurs(x,F)
- F ? xR E ? (?x RFE)
- Example
- y ? x xgt1 3x) ? (?x xgt1y3x)
- (11.4) Axiom ,extensionality
- ST ? (?x x?S ? x?T)
- An extensional definition depends only on the
content of the set. In contrast, an intentional1
definition describes how the set was defined or
constructed.
10Sets versus Predicates
- (11.7) Theorem
- x ? xRx ? R
- y ? xR ? Rxy
- Theorem (11.7) formalizes the connection between
sets and predicates a predicate is a
representation for the set of argument-values for
which the predicate is true. - 2 ? xxgt1 ? 2gt1
11Sets versus Predicates
- (11.8) The principle of comprehension
- To each predicate R there corresponds a set
comprehension xR , which contains the objects
t that satisfy R R is called the characteristic
predicate of the set.
12Sets versus Predicates
- (11.8) means we can define a set using
comprehension and by its characteristic
predicate. - For example the set comprehension
- S x x3 ? x5
- And the characteristic predicate
- x ? S ? x3 ? x5 (for all x)
- Are equivalent.
13Sets versus Predicates
- Theorem (11.10)
- xQxR is valid iff Q ? R is valid.
14Operations on Sets
15Operations on Sets
- Three methods for proving set equality
- (a) Use Leibniz directly
- (b) Use axiom of Extensionality (11.4) and prove
v ? S ? v ? T for an arbitrary value of v. - (c) Prove Q ? R and conclude xQxR
16Operations on Sets
- Let S,T,U,V have type set(t) for some type t.
This convention allows us to shorten a definition
- For example, set cardinality
- (?Sset(t) S (?x x?S1))
- can be defined as
- S (?x x?S1)
17Operations on Sets
18Operations on Sets
19Operations on Sets
20Operations on Sets
21EU set
- Let the set EU be the set of all countries in the
European Union (old). - EU the set of all countries in the European
Union. - It could be declared as an enumeration
- EUA,B,DK,F,SF,D,GB,GR,IRL,I,L,NL,P,E,S
- The variable homeland can refer to one element in
the set EU - homeland ? EU
- beneluxB,NL,L
22The Empty Set and Singleton
- It is possible to have a set with no values, it
is called the empty set and denoted as - 0 or
- A set that contains only one element is called a
singleton set. For example IRL - Note the difference between the set IRL and
element IRL. - Sets are not ordered. There are no duplicates,
each element is unique.
23Subset or Set inclusion
The following statements are true B,NL z
B,NL,L 0 zB,NL,L B,NL,L z B,NL,L
X (universal set) SPX (? is power set) TPX S z
T
T
S
X
24Subset Superset
- S is a subset of T if every element if every
element of S is an element of T. - (11.13) axiom, subset
- S ? T ? (?x x ? S x ? T)
- (11.14) axiom, proper subset
- S ? T ? S?T ? S?T
25Subset Superset
- (11.15) axiom, superset
- T ? S ? S?T
- (11.16) axiom, proper superset
- T ? S ? S ? T
- The axioms and theorems for set operations are
given in the course text and the course web site,
only a few are covered in the slides.
26Set Operators
- Set Equivalence
- Two values of the same type can be tested to see
if they are the same by using the equals sign, as
in - x y
- Two sets are equal if they contain exactly the
same elements. For example the two sets below are
equal - B,NL,L NL, B, L
27Set Operators
- Set Non-Equivalence
- Two values of the same type can be tested to see
if they are not the same by using the not-equals
sign ?. Two sets are not equal if they do not
contain exactly the same elements - B,NL ? B,NL,L
28Set Operators
- The membership operator is written e
- NL e B, NL, Lit is true the Netherlands is a
Benelux country - General case below
SPX xX xeS
.x
S
X
29Set Operators
- The non-membership operator is written
- IRL?B, NL, L Ireland is not a Benelux country
SPX xX x ? S
General case
S
.x
X
30Set Operators
- The validity of membership test.
- The value to be tested for membership must be an
element of the underlying type of the set. For
example - USA e B, NL, L
- is illegal, since USA is not an element of the
type EU.
31Set Operators
- Size Cardinality The number of values in a set
is called its size, or cardinality, and is
signified with the has sign - B,NL,L 3
- IRL 1
- IRL illegal, IRL is not a set
- ? 0
32Set Operators
- Powersets The powerset of a set is written
- PS
- It is the set of all subsets of S. For example
the powerset of the Benelux countries is - PB,NL,L ?,
- B,NL,L,
- B,NL,B,L,NL,L,
- B,NL,L
33Set OperatorsPowersets
- When a variable is to be declared to have a type
that is a set of elements, the type is the
powerset of the type of the elements - benelux PEU
- This can be read as the variable benelux is a
subset of the set of countries EU or the
variable benelux is a set of EU countries
34Set OperatorsPowersets
- The size of the powerset of a set is equal to two
raised to the power of the size of the set. - (PS) 2s
- B,NL,L 3
- (PB,NL,L) 8
35Complement
- The complement of S (S) is the set of elements
that are not in S but are in the universe. - (11.17) axiom, complement
- v?Sc ? v?U ? v?S
-
S
U
36Set Operators Union
- The union of two sets is the set containing all
the elements that are in either the first set or
the second set or both.
X SPX TPX T U S T U S T U S S U 0 S
S
T
X
37Set Operators Intersection
- The intersection of two sets is the set
containing all the elements that are in the first
set and in the second set.
X SPX TPX T I S T I S S I T S I 0 0
S
T
X
38Set Operators Difference
- The difference of two sets is the set containing
all the elements that are in the first set and
are not in the second set. The shaded area is the
difference of S and T.
X SPX TPX S \ T S \ T T \ S S \ 0 S 0
\ S 0
S
T
X
39Set Operators Distributed Union
- The distributed union of a set of sets is the set
containing just those elements that occur in at
least one of the component sets.
X SPX RPX TPX R,S,T
R
S
T
X
40Set Operators Distributed Intersection
- The distributed intersection of a set of sets is
the set containing just those elements that occur
in all of the component sets.
X SPX RPX TPX R,S,T
R
T
S
X
41Disjoint Sets
- Sets that are disjoint have no elements in
common their intersection is the empty set. - For disjoint sets T and S the following
expression is true - T I S 0.
42More than 2 Disjoint Sets
- For more that two sets it becomes longer, since
every pair must have an empty intersection. For
example for sets A, B and C to be disjoint the
following must be true - A I B 0 and
- B I C 0 and
- C I A 0
43Partition
- A sequence of sets is said to partition another
larger set if the sets are disjoint and their
distributed union is the entire larger set if the
sets are disjoint. For example - if
- disjointltA,B,Cgt ? (?A,B,C T)
- then ltA,B,Cgt partition T
- For example
- ltTemporary, Part-time, Permanentgt may partition
Employee.
44Relating sets and Boolean Expressions
- The definition of the set operations reveals a
connection between the set operators and the
propositional operators. For example, in the
definition of ? , as the phrase x? of the LHS
is distributed inward to the operands S and T of
the RHS, ? becomes ?. - x ? S ? T ? x ? S ? x ? T
45Relating sets and Boolean Expressions
- The properties of propositional operators are
reflected as similar properties of set operators,
e.g. absorption laws - S ? (S ? T) ? S (type S,TBoolean)
- S ? (S ? T) S (type S,Tset(t))
- The zero laws for props. sets.
- S ? false ? false (type SBoolean)
- S ? 0 0 (type Sset(t))
46Set expression Es Propositional expression Ep
47Numerical Problem for 3 sets (see lab 4)
- Out of group of 42 students
- 3 studied French, Business and Music.
- 10 studied French and Business.
- 6 studied French and Music.
- 5 studied Business and Music.
- 18 studied French.
- 20 studied Business.
- 17 studied Music.
48Another Set Problem
- A group of 41 students study Finance, Business
and Mathematics as follows - 2 studied Finance, Business and Mathematics.
- 9 studied Finance and Business.
- 4 studied Finance and Mathematics.
- 5 studied Business and Mathematics.
- 17 studied Finance.
- 20 studied Business.
- 16 studied Mathematics.
49 Another Set Problem
50Another Numerical Set Problem
- How many studied Finance and Mathematics but not
Business? - (Finance Mathematics) All Three
- 4 - 2 2.
51Another Set Problem
- How many studied Business and neither Finance nor
Mathematics? - Business - FinanceBusiness -
MathematicsBusiness All three - 20 5 9 2 8
The overlap (intersection) between these two
pairs was removed twice so it needs to be added
back
52Another Set Problem
- How many are taking none of the subjects?
- 17201653 subjects with intersections
- (945 ) pair wise intersections
- 53 - (9 4 5 ) 2 37 remove intersections
and double counting - 41 37 4 not taking a subject.
53A Set Proof
- We will prove the distribution of set union over
set intersection - A ? (B ? C) (A?B) ? (A?C)
- We will use the following theorem and axiom
- (1) p ?(q?r) ? (p?q)?(p?r)
- (2) S T ? (?v v ? S ? v ? T)
- And the definitions of union and intersection
- (3) v ? B ? C ? v ? B ? v ? C
- (4) v ? B ? C ? v ? B ? v ? C
54A Set Proof
- Axiom are numbered as in the previous slide. We
prove distribution by using Extensionality (3) to
show that an arbitrary element v is in LHS
exactly when it is in the RHS. - v ? A ? (B ? C)
- lt definition of ? (3) gt
- v ? A ? v ? (B ? C)
- lt definition of ? (4) gt
- v ? A ? (v ? B ? v ? C)
- lt Distribution of ? over ? (1) gt
- (v ? A ? v ? B) ? (v ? A ? v ? C)
- lt definition of ? (3) twicegt
- (v ? A ? B) ? (v ? A ? C)
- lt definition of ? (4) gt
- v ? (A ? B) ? (A ? C)
-
55DeMorgans First Law for sets not(A ? B)
not(A) ? not(B)
A ? B
not(A ? B)
A
A
B
B
not(A)
not(B)
A
A
B
B
56DeMorgans First Law for sets not(A ? B)
not(A) ? not(B)
not(B)
not(A)
A
A
B
B
not(A) ? not(B)
A
B
57Example Proof
- Prove (S - T) ? S ? T
- x ? (S T)
- lt Set difference 11.22 gt
- x ? S ? x ? T
- lt using x ? (S) ? x ? S gt
- x ? S ? x ? T
- lt Set Intersection 11.21gt
- x ? (S ? T)
58Set Comprehension Example
- The set of positive integers that are less than 5
- Solution
- x? 0 ? x ? 4x or x? 0 ? x lt5x
- Or
- 0,1,2,3,4
59Set Comprehension Example
- The set of positive integers which are divisible
by 3 and less than 7. - Solution
- x? 0ltxlt7 ? x/3x?3
- where / is ordinary division, ? is integer
division - All powers of 2.
- Solution i? 0?i2i