Title: Sets
1Sets
2(No Transcript)
3(No Transcript)
4(No Transcript)
5(No Transcript)
6Set builder notation
- N 0,1,2,3, the natural numbers
- R reals
- Z -3,-2,-1,0,1,2,3,
- Z 1,2,3,4,5,
- Q the set of rational numbers
7Set builder notation
S contains all elements from U (universal
set) That make predicate P true
Brace notation with ellipses (wee dots)
8Set Membership
x is in the set S (x is a member of S)
y is not in the set S (not a member)
9Am I making this up?
10(No Transcript)
11(No Transcript)
12(No Transcript)
13Set operators
14Set empty
The empty set
15The universal set
U
16Venn Diagram
U
B
A
U is the universal set A is a subset of B
17Venn Diagram
U
B
A
U is the universal set A united with B
18Venn Diagram
U
B
A
U is the universal set A intersection B
19Cardinality of a set
The number of elements in a set (the size of the
set)
20Power Set
The set of all possible sets
21Power Set
The set of all possible sets
22Power Set
The set of all possible sets
We could represent a set with a bit string
0th element
23Is this true for a set S?
24Cartesian Product
A set of ordered tuples
25(improper) Subset
- is empty a subset of anything?
- Is anything a subset of ?
- We have an implication, what is its truth table?
- Note improper subset!!
26(proper) Subset
Consequently A is strictly smaller than B A lt
B
27Equal sets?
Two show that 2 sets A and B are equal we need to
show that
And we know that
28Try This
- Using set builder notation describe the following
sets - odd integers in the range 1 to 9
- the integers 1,4,9,16,25
- even numbers in the range -8 to 8
29Answers
- Using set builder notation describe the following
sets - odd integers in the range 1 to 9
- the integers 1,4,9,16,25
- even numbers in the range -8 to 8
30Go do this in claire
- build the sets we just mentioned
- test if is a subset of itself
- Using set builder notation describe the following
sets - odd integers in the range 1 to 9
- the integers 1,4,9,16,25
- even numbers in the range -8 to 8
31How might a computer represent a set?
Remember those bit operations?
32Computer Representation (possible
- How do we compute the following?
- membership of an element in a set
- union of 2 sets
- intersection of 2 sets
- compliment of a set
- set difference (tricky?)
33Power set
Try this
- Compute the power set of
- 1,2
- 1,2,3
- 1,2
-
34Power set
- Compute the power set of
- 1,2
- 1,2,3
- 1,2
-
Do it in claire
Think again how might we represent sets?
35Cartesian Product
- A set of ordered tuples
- note AxB is not equal to BxA
Just reminding you (and me)
36Try This
- Let A1,2,3 and Bx,y, find
- AxB
- BxA
- if An and Bm what is AxB
37My answer
Do it in claire
- Let A1,2,3 and Bx,y, find
- AxB
- BxA
- if An and Bm what is AxB
38For the brave the claire code
39member(eany,Aset) boolean -gt exists(x in A
x e) // // There exists some element x in A
such that // x e // subset(Aset,Bset)
boolean -gt forall(x in A member(x,B)) // //
All elements of A are in B. Sometimes called
"improper" subset // What does it do when A ?
Hint P -gt Q and P is false! //
40PS(Aset) set -gt PS(A,) PS(A,Bset)
set -gt set(B) PS(Aset,Bset) void -gt let
x A1 in PS(delete(copy(A),x),add(copy(B),
x)) U PS(delete(copy(A),x),B) // // The
power set of A // NOTE U is the (claire) union
operator //
41CP(Aset,Bset) set -gt let pairs
in (for x in A (for y in B pairs
add(pairs,list(x,y))), pairs) // // The
cartesian product of 2 sets A and B // Produce a
set of tuples (as a list) // // Demo
CP(1,2,3,1,5) // CP(1,2,3,"A","B") /
/