week 7 - monday. what did we talk about last time? sets

58
CS322 Week 7 - Monday

Upload: lydia-norton

Post on 05-Jan-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Week 7 - Monday.  What did we talk about last time?  Sets

CS322Week 7 - Monday

Page 2: Week 7 - Monday.  What did we talk about last time?  Sets

Last time

What did we talk about last time? Sets

Page 3: Week 7 - Monday.  What did we talk about last time?  Sets

Questions?

Page 4: Week 7 - Monday.  What did we talk about last time?  Sets

Logical warmup

A man offers you a bet He shows you three cards

One is red on both sides One is green on both sides One is red on one side and green on the other

He will put one of the cards, at random, on the table If you can guess the color on the other side, you win If you bet $100

You gain $125 on a win You lose your $100 on a loss

Should you take the bet? Why or why not?

Page 5: Week 7 - Monday.  What did we talk about last time?  Sets

Set Theory

Page 6: Week 7 - Monday.  What did we talk about last time?  Sets

Set operations

We usually discuss sets within some superset U called the universe of discourse

Assume that A and B are subsets of U

The union of A and B, written A B is the set of all elements of U that are in either A or B

The intersection of A and B, written A B is the set of all elements of U that are in A and B

The difference of B minus A, written B – A, is the set of all elements of U that are in B and not in A

The complement of A, written Ac is the set of all elements of U that are not in A

Page 7: Week 7 - Monday.  What did we talk about last time?  Sets

Examples

Let U = {a, b, c, d, e, f, g} Let A = {a, c, e, g} Let B = {d, e, f, g} What are:

A B A B B – A Ac

Page 8: Week 7 - Monday.  What did we talk about last time?  Sets

The empty set

There is a set with no elements in it called the empty set

We can write the empty set { } or It comes up very often For example, {1, 3, 5} {2, 4, 6} = The empty set is a subset of every

other set (including the empty set)

Page 9: Week 7 - Monday.  What did we talk about last time?  Sets

Disjoint sets and partitions

Two sets A and B are considered disjoint if A B =

Sets A1, A2, … An are mutually disjoint (or nonoverlapping) if Ai Aj = for all i j

A collection of nonempty sets {A1, A2, … An} is a partition of set A iff:1. A = A1 A2 … An

2. A1, A2, … An are mutually disjoint

Page 10: Week 7 - Monday.  What did we talk about last time?  Sets

Power set

Given a set A, the power set of A, written P(A) or 2A is the set of all subsets of A

Example: B = {1, 3, 6}P(B) = {, {1}, {3}, {6}, {1,3},

{1,6}, {3,6}, {1,3,6}} Let n be the number of elements in

A, called the cardinality of A Then, the cardinality of P(A) is 2n

Page 11: Week 7 - Monday.  What did we talk about last time?  Sets

Cartesian product

An ordered n-tuple (x1, x2, … xn) is an ordered sequence of n elements, not necessarily from the same set

The Cartesian product of sets A and B, written A x B is the set of all ordered 2-tuples of the form (a, b), a A, b B

Thus, (x, y) points are elements of the Cartesian product R x R (sometimes written R2)

Page 12: Week 7 - Monday.  What did we talk about last time?  Sets

Subset Relations

Page 13: Week 7 - Monday.  What did we talk about last time?  Sets

Basic subset relations

Inclusion of Intersection: For all sets A and B A B A A B B

Inclusion in Union: For all sets A and B A A B B A B

Transitive Property of Subsets: If A B and B C, then A C

Page 14: Week 7 - Monday.  What did we talk about last time?  Sets

Element argument

The basic way to prove that X is a subset of Y1. Suppose that x is a particular but

arbitrarily chosen element of X2. Show that x is an element of Y

If every element in X must be in Y, by definition, X is a subset of Y

Page 15: Week 7 - Monday.  What did we talk about last time?  Sets

Procedural versions

We want to leverage the techniques we've already used in logic and proofs

The following definitions help with this goal:1. x X Y x X x Y2. x X Y x X x Y3. x X – Y x X x Y4. x Xc x X5. (x, y) X Y x X y Y

Page 16: Week 7 - Monday.  What did we talk about last time?  Sets

Example proof

Theorem: For all sets A and B, A B A

Proof: Let x be some

element in A B x A x B x A Thus, all elements in

A B are in A A B AQED

Premise

Definition of intersection

Specialization By generalization

Definition of subset

Page 17: Week 7 - Monday.  What did we talk about last time?  Sets

Laying down the law (again)

Name Law Dual

Commutative A B = B A A B = B A

Associative (A B) C = A (B C) (A B) C = A (B C)

Distributive A (B C) = (A B) (A C) A (B C) = (A B) (A C)

Identity A = A A U = A

Complement A Ac = U A Ac =

Double Complement (Ac)c = A

Idempotent A A = A A A = A

Universal Bound A U = U A =

De Morgan’s (A B)c = Ac Bc (A B)c = Ac Bc

Absorption A (A B) = A A (A B) = A

Complements of U and

Uc = c = U

Set Difference A – B = A Bc

Page 18: Week 7 - Monday.  What did we talk about last time?  Sets

Proving set equivalence

To prove that X = Y Prove that X Y and Prove that Y X

Page 19: Week 7 - Monday.  What did we talk about last time?  Sets

Example proof of equivalenceTheorem: For all sets A,B, and C, A (B C) = (A B) (A C)Proof: Let x be some element in A (B C) x A x (B C) Case 1: Let x A

x A x B x A B x A x C x A C x A B x A C x (A B) (A C)

Case 2: Let x B C x B x C x B x A x B x A B x C x A x C x A C x A B x A C x (A B) (A C)

In all possible cases, x (A B) (A C), thus A (B C) (A B) (A C)

Page 20: Week 7 - Monday.  What did we talk about last time?  Sets

Proof of equivalence continued Let x be some element in (A B) (A C) x (A B) x (A C) Case 1: Let x A

x A x B C x A (B C)

Case 2: Let x A x A B x A x B x B x A C x A x C x C x B x C x B C x A x B C x A (B C)

In all possible cases, x A (B C), thus (A B) (A C) A (B C) Since both A (B C) (A B) (A C) and (A B) (A C) A (B C), A (B

C) = (A B) (A C)QED

Page 21: Week 7 - Monday.  What did we talk about last time?  Sets

Proof example

Prove that, for any set A, A = Hint: Use a proof by contradiction

Page 22: Week 7 - Monday.  What did we talk about last time?  Sets

Disproofs and Algebraic Proofs

Page 23: Week 7 - Monday.  What did we talk about last time?  Sets

Disproving a set property

Like any disproof for a universal statement, you must find a counterexample to disprove a set property

For set properties, the counterexample must be a specific examples of sets for each set in the claim

Page 24: Week 7 - Monday.  What did we talk about last time?  Sets

Counterexample example

Claim: For all sets A, B, and C, (A – B) (B – C) = A – C

Find a counterexample

Page 25: Week 7 - Monday.  What did we talk about last time?  Sets

Algebraic set identities

We can use the laws of set identities given before to prove a statement of set theory

Be extremely careful (even more careful than with propositional logic) to use the law exactly as stated

Page 26: Week 7 - Monday.  What did we talk about last time?  Sets

Algebraic set identity example

Theorem: A – (A B) = A – BProof:A – (A B) = A (A B) c = A (Ac B c) = (A Ac) (A B c) = (A B c) = A B c

= A – BQED

Page 27: Week 7 - Monday.  What did we talk about last time?  Sets

Prove or disprove

For all sets A, B, and C, if A B and B C, then A C

Page 28: Week 7 - Monday.  What did we talk about last time?  Sets

Prove or disprove

For all sets A and B, ((Ac Bc) – A)c = A

Page 29: Week 7 - Monday.  What did we talk about last time?  Sets

Russell's Paradox

Page 30: Week 7 - Monday.  What did we talk about last time?  Sets

Naïve set theory

Set theory is a slippery slope We are able to talk about very abstract

concepts { x Z | x is prime }

This is a well-defined set, even though there are an infinite number of primes and we don't know how to find the nth prime number

Without some careful rules, we can begin to define sets that are not well-defined

Page 31: Week 7 - Monday.  What did we talk about last time?  Sets

Barber Paradox

Let a barber be the man in Elizabethtown who shaves the men in Elizabethtown if and only if they don't shave themselves. Let T be the set of all men in

Elizabethtown Let B(x) be "x is a barber" Let S(x,y) be "x shaves y" b T m T (B(b) (S(b,m) ~S(m,m)))

But, who shaves the barber?

Page 32: Week 7 - Monday.  What did we talk about last time?  Sets

Russell's Paradox

Bertrand Russell invented the Barber Paradox to explain to normal people a problem he had found in set theory

Most sets are not elements of themselves

So, it seems reasonable to create a set S that is the set of all sets that are not elements of themselves

More formally, S = { A | A is a set and A A }

But, is S an element of itself?

Page 33: Week 7 - Monday.  What did we talk about last time?  Sets

Escaping the paradox

How do we make sure that this paradox cannot happen in set theory?

We can make rules about what sets we allow in or not

The rule that we use in class is that all sets must be subsets of a defined universe U

Higher level set theory has a number of different frameworks for defining a useful universe

Page 34: Week 7 - Monday.  What did we talk about last time?  Sets

Halting Problem

Page 35: Week 7 - Monday.  What did we talk about last time?  Sets

Applying the idea again

It turns out that the idea behind Russell's Paradox actually has practical implications

It wasn't new, either Cantor had previously used a

diagonal argument to show that there are more real numbers than rational numbers

But, unexpectedly, Turing found an application of this idea for computing

Page 36: Week 7 - Monday.  What did we talk about last time?  Sets

Turing machine

A Turing machine is a mathematical model for computation

It consists of a head, an infinitely long tape, a set of possible states, and an alphabet of characters that can be written on the tape

A list of rules saying what it should write and should it move left or right given the current symbol and state

1 0 1 1 1 1 0 0 0 0

A

Page 37: Week 7 - Monday.  What did we talk about last time?  Sets

Church-Turing thesis

If an algorithm exists, a Turing machine can perform that algorithm

In essence, a Turing machine is the most powerful model we have of computation

Power, in this sense, means the ability to compute some function, not the speed associated with its computation

Page 38: Week 7 - Monday.  What did we talk about last time?  Sets

Halting problem

Given a Turing machine and input x, does it reach the halt state?

First, recognize that we can encode a Turing machine as input for another Turing machine We just have to design a system to

describe the rules, the states, etc. We want to design a Turing machine

that can read another

Page 39: Week 7 - Monday.  What did we talk about last time?  Sets

Halting problem problems Imagine we have a Turing machine H(m,x)

that takes the description of another Turing machine m and its input x and returns 1 if m halts on input x and 0 otherwise

Now, construct a machine H’(m,x) that runs H(m,x), but, if H(m,x) gives 1, then H’(m,x) infinitely loops, and, if H(m,x) gives 0, then then H’(m,x) returns 1

Let’s say that d is the description of H’(m,x)

What happens when you run H’(d,d)?

Page 40: Week 7 - Monday.  What did we talk about last time?  Sets

Halting problem conclusion Clearly, a Turing machine that solves the

halting problem doesn’t exist Essentially, the problem of deciding if a

problem is computable is itself uncomputable Therefore, there are some problems (called

undecidable) for which there is no algorithm Not an algorithm that will take a long time,

but no algorithm If we find such a problem, we are stuck …unless someone can invent a more

powerful model of computation

Page 41: Week 7 - Monday.  What did we talk about last time?  Sets

And it gets worse!

Gödel used diagonalization again to prove that it is impossible to create a consistent set of axioms that can prove everything about the set of natural numbers

As a consequence, you can create a system that is complete but not consistent

Or, you can create a system that is consistent but not complete

Either way, there are principles in math in general that are true but impossible to prove, at least with any given system

You might as well give up on math now

Page 42: Week 7 - Monday.  What did we talk about last time?  Sets

Functions

Page 43: Week 7 - Monday.  What did we talk about last time?  Sets

Definitions

A function f from set X to set Y is a relation between elements of X (inputs) and elements of Y (outputs) such that each input is related to exactly one output

We write f: X Y to indicate this X is called the domain of f Y is called the co-domain of f The range of f is { y Y | y = f(x), for

some x X} The inverse image of y is { x X | f(x) = y

}

Page 44: Week 7 - Monday.  What did we talk about last time?  Sets

Examples

Using standard assumptions, consider f(x) = x2

What is the domain? What is the co-domain? What is the range? What is f(3.2)? What is the inverse image of 4?

Assume that the set of positive integers is the domain and co-domain What is the range? What is f(3.2)? What is the inverse image of 4?

Page 45: Week 7 - Monday.  What did we talk about last time?  Sets

Arrow diagrams

With finite domains and co-domains, we can define a function using an arrow diagram

What is the domain? What is the co-domain? What are f(a), f(b), and f(c)? What is the range? What are the inverse images of 1, 2, 3, and 4? Represent f as a set of ordered pairs

a

b

c

1

2

3

4

X Yf

Page 46: Week 7 - Monday.  What did we talk about last time?  Sets

Functions?

Which of the following are functions from X to Y?

a

b

c

1234

X Yf

a

b

c

1234

X Yg

a

b

c

1234

X Yh

Page 47: Week 7 - Monday.  What did we talk about last time?  Sets

Function equality

Given two functions f and g from X to Y,

f equals g, written f = g, iff: f(x) = g(x) for all x X

Let f(x) = |x| and g(x) = Does f = g?

Let f(x) = x and g(x) = 1/(1/x) Does f = g?

2x

Page 48: Week 7 - Monday.  What did we talk about last time?  Sets

Applicability of functions

Functions can be defined from any well-defined set to any other

There is an identity function from any set to itself

We can represent a sequence as a function from a range of integers to the values of the sequence

We can create a function mapping from sets to integers, for example, giving the cardinality of certain sets

Page 49: Week 7 - Monday.  What did we talk about last time?  Sets

Logarithms

You should know this already But, this is the official place where it

should be covered formally There is a function called the

logarithm with base b of x defined from R+ to R as follows: logb x = y by = x

Page 50: Week 7 - Monday.  What did we talk about last time?  Sets

Functions defined on Cartesian products

For a function of multiple values, we can define its domain to be the Cartesian product of sets

Let Sn be strings of 1's and 0's of length n An important CS concept is Hamming

distance Hamming distance takes two binary strings of

length n and gives the number of places where they differ

Let Hamming distance be H: Sn x Sn Znonneg

What is H(00101, 01110)? What is H(10001, 01111)?

Page 51: Week 7 - Monday.  What did we talk about last time?  Sets

Well-defined functions

There are two ways in which a function can be poorly defined

It does not provide a mapping for every value in the domain

Example: f: R R such that f(x) = 1/x It provides more than one mapping for

some value in the domain Example: f: Q Z such that f(m/n) = m,

where m and n are the integers representing the rational number

Page 52: Week 7 - Monday.  What did we talk about last time?  Sets

One-to-one functions

Let F be a function from X to YF is one-to-one (or injective) if and

only if: If F(x1) = F(x2) then x1 = x2

Is f(x) = x2 from Z to Z one-to-one? Is f(x) = x2 from Z+ to Z one-to-one? Is h(x) one-to-one?

a

b

c

1234

X Yh

Page 53: Week 7 - Monday.  What did we talk about last time?  Sets

Proving one-to-one

To prove that f from X to Y is one-to-one, prove that x1, x2 X, f(x1) = f(x2) x1 = x2

To disprove, just find a counter example

Prove that f: R R defined by f(x) = 4x – 1 is one-to-one

Prove that g: Z Z defined by g(n) = n2 is not one-to-one

Page 54: Week 7 - Monday.  What did we talk about last time?  Sets

Onto functions

Let F be a function from X to YF is onto (or surjective) if and only

if: y Y, x X such that F(x) = y

Is f(x) = x2 from Z to Z onto? Is f(x) = x2 from R+ to R+ onto? Is h(x) onto?

a

b

c

123

X Yh

Page 55: Week 7 - Monday.  What did we talk about last time?  Sets

Inverse functions

If a function F: X Y is both one-to-one and onto (bijective), then there is an inverse function F-1: Y X such that: F-1(y) = x F(x) = y, for all x X and y

Y

Page 56: Week 7 - Monday.  What did we talk about last time?  Sets

Upcoming

Page 57: Week 7 - Monday.  What did we talk about last time?  Sets

Next time…

More on functions Composition of functions Cardinality

Page 58: Week 7 - Monday.  What did we talk about last time?  Sets

Reminders

Homework 4 is due tonight! Read Chapter 7