Sets
Goals: Use our logic basis to define Sets, Power Sets, and Recursively
Defined Sets
First, we've talked about sets. We used them to define the meaning of
quantifiers. But let's, for a moment, be a little bit more formal.
A set is a collection of elements.
A set does not contain more than one of an element, because a set just
says "which things are and aren't in the set". That is, the
following two lists define the same set:
S = {2 3 5 9 121}, and S = {2, 2, 2, 9, 5, 121, 3}
says that the set S contains 2,3,5,9,121. Putting another "2" in the
list to make {2 2 3 5 9 121} still lists the same elements and doesn't
change the definition of the set. (a "multi-set" is the name for a
representation of a collection of items which say how many of a
particular element there are. We won't have any problems in the next
several lectures that concern multi-sets.
Ways of defining a set
- Listing the elements. This is done using curly braces.
- For example S = {2,3,5,10}
- Providing a predicate that is true if an object is in the set.
The format for this is to say {x | P(x)}, which is read "the set of
elements x that make P(x) true." This predicate P is called the
characteristic function (or, sometimes, indicator function) of
the set.
- For example S = {x | x is an integer and x > 6}
- A set can also be constructed from other sets. If A is a set and
B is a set, then so are:
- A U B, A union B
- A n B, A intersection B
- A - B, A minus B
We can use logical operators to define the predicate which defines
these constructed sets. Suppose we have sets A and B, where:
A = {x | AA(x)}, and
B = {x | BB(x)},
then
A union B = {x | AA(x) v BB(x)}
A intersect B = {x | AA(x) ^ BB(x)}
A minus B = {x | AA(x) ^ ~BB(x)}
This means that we can prove the truth or falsehood of set formulas by
proving the truth or falsehood of logical formulas.
The set defined by {x | ~AA(x)} requires that we somehow restrict what
"x" values we might put in. This is done with a "Universal set" U
that defines something relevant to the problem domain you're talking about.
Powersets
Ha, I'm going to use the discusion of powersets to remind you what a
subset is. A set S is a subset of a set T if and only if every
element that is in S is also in T. The notation is:
S c T = {x | S(x) --> T(x)} (Cool!... check out the "implies")
Now. The Powerset of a set S is written as PS, and
is the set of all subset of S.
For example, if S = {1,2,B}, then
PS = { {}, {1}, {2}, {B}, {1,2}, {1,B}, {2,B}, {1,2,B} }
The first item {}, is the empty set... the set containing no elements.
The empty set is a subset of every set (can you give a cute logic
proof of this?!?). Also, it is an element of every powerset.
Recurively Defined Sets
Recursion is the basis of many ideas of computer science. Long before
computers, however, it has been used to formally define sets. Things
as basic as "natural numbers" can be defined using recursively defined
sets. This starts with a recursive definition:
We can define the set N as:
0 is an element of N
for any element x in N, S(x) is also in N.
we can even define addition in this ridiculous formulation:
add(a,S(b)) = add(S(a),b)
add(a, 0 ) = a
(try this out with: "add(S(S(S(0))), S(S(0)))"
= "add(S(S(S(S(0)))), S(0))"
= "add(S(S(S(S(S(0))))), 0)"
= " S(S(S(S(S(0)))))
In the next class, we're going to talk about mappings between sets.