michaelmas term 2004 discrete mathematics csc 141 discrete mathematics dr. corina sas and ms. nelly...

24
CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo [email protected] ; [email protected] Computing Department

Upload: maude-harrell

Post on 31-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

CSC 141

Discrete Mathematics

Dr. Corina Sas and Ms. Nelly [email protected]; [email protected]

Computing Department

Page 2: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Course details

• weeks 1-10– 10 x 50 min lectures

• Material– http://info.comp.lancs.ac.uk/year1/notes/csc141

• coursework– written work (relevant to exam)

• recommended resource– http://www.cs.odu.edu/~toida/nerzic/content/web_cou

rse.html

Page 3: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Syllabus

• Sets

• Relations

• Functions

• Recursion

• Logic– Boolean– propositional– predicate logic

Page 4: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Overview

• Discrete Maths

• Sets– Defining sets– Set operations– Subsets– Universal and power set

Page 5: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Objectives

• Understanding the relevance of discrete maths for computer science

• Understanding the basic ideas about sets

• Facility with basic ideas about sets

Page 6: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Discrete maths

• What– discrete objects

• Why – formal specification– infinity or indefiniteness– reusability

Page 7: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Sets and membership

• Set = collection of objects– in a set there are no duplicates– a set is Unordered– example set: A = {1, 2, 3, 4, 5, 6, 7}

• 1 in set A:– 1 belongs to the set A– 1 is an element/object/member of the set A

• Write this:– 1 A– 8 A

Page 8: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Defining sets

• Listing all its members – writing down all the elements– small, finite sets– A = {a, b, {a, b}, c}

• Listing a property that its members must satisfy– {x | 0 < x < 8} – every integer that is greater than 0 and less than 8– expression on the left does not have to be a variable:

• {x-2 | 2 < x < 10}

– infinite sets• {x | x > 0}

Page 9: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Defining sets

• Procedure (program) to generate the members of a set.– a procedure to generate an infinite set is a

never ending procedure– EXERCISES. Formally specify the following

sets: • all (+ve) even numbers • all (+ve) odd numbers • all (+ve) numbers exactly divisible by 3

• all (+ve) numbers that do not divide exactly by 8

Page 10: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Exercise

Exercises – answers

{2x | x > 0}

{2x + 1 | x ≥ 0}

{3x | x > 0}

{8x + y | x ≥ 0, 1 ≤ y ≤ 7}

Procedure:Set = i = 1while i >0 do

put i*3 into Set

i = i+1endwhile

Write similar procedure to generate the other sets

Page 11: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Answers• (all +ve even numbers)

Set = i = 1

while i ≥ 1 do

put i * 2 into Set

i := i + 1

endwhile

• (all +ve odd numbers)

Set = i = 0

while i ≥ 0 do

put 2 * i + 1 into Set

i := i + 1

endwhile

• (all +ve numbers not exactly divisible by 8) Set = i = 0 while i ≥ 0 do

for j = 1 to 7 do put i

+ j into Set endfor i = i + 8

endwhile

Page 12: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Set Operations• UNION (written )

– takes all of the elements from two sets, and makes a new set containing those elements (with no duplicate elements)

–  A B = { x | x A x B } – Example: If A = {1, 2, 3} and B = {4, 5} ,  then A B = {1, 2, 3, 4, 5} . – Example: If A = {1, 2, 3} and B = {1, 2, 4, 5} ,  then AB = {1, 2, 3, 4, 5}

.

• INTERSECTION (written ) – forms a new set from two sets, consisting of all elements that are in

BOTH of the original sets – A B = { x | x A x B }– Example: If A = {1, 2, 3} and B = {1, 2, 4, 5} ,  then A B = {1, 2} . – Example: If A = {1, 2, 3} and B = {4, 5} ,  then A B =

Page 13: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Set Operations

• DIFFERENCE (written – or /) – forms a new set from two sets, consisting of all elements from

the first set that are not in the second– A - B = { x | x A x B } – Example: If A = {1, 2, 3} and B = {1, 2, 4, 5} ,  then A - B = {3}.– Example: If A = {1, 2, 3} and B = {4, 5} ,  then A - B = {1, 2, 3} .

• Each of the basic set operations: – is infix operator

• i.e. it is written in between its arguments, as is, for example “+” in arithmetic

– takes two sets as its arguments

Page 14: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Union

• Examples: – {a, b, c} {b, c, d} = {a, b, c, d} – {a, b, c} = {a, b, c} {a, b, c} = {a, b, c} – {2x | x > 0} {2x + 1 | x ≥ 0} = {x | x > 0}

• NOTE that for all sets A, B, C: – A B = B A (commutative law)– A = A (identity law)– A A = A (idempotent law)– (A B) C = A (B C) (associative law)

• Checkpoint: “prove” the above to yourself

Page 15: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Intersection

• Examples– {a, b, c} {b, c, d} = {b, c} – {a, b, c} = {a, b, c} = – {2x | x > 0} {3x | x > 0} = {6x | x > 0} – {2x | x > 0} {2x + 1 | x ≥ 0 } =

• NOTE that for all sets A, B, C: – A B = B A (commutative law)– A = (domination law)– A A = A (idempotent law)– (A B) C = A (B C) (associative law)

Page 16: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Set difference

• Examples: – {a, b, c} - {b, c, d} = {a} – {b, c, d} – {a, b, c} = {d} – {a, b, c} – {} = {a, b, c} – {a, b, c} – {d, e, f} = {a, b, c} – {x | x > 0} – {2x + 1 | x ≥ 0} = {2x | x > 0}

• NOTE: for all sets, A – A – = A – A = – A – A =

Page 17: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Cartesian product• An ordered pair is a pair of objects with an order associated with

them. If objects are represented by x and y, then we write the ordered pair as <x, y>.

• Two ordered pairs <a, b> and <c, d> are equal if and only if a = c and b = d. For example the ordered pair <1, 2> is not equal to the ordered pair <2, 1>.

• The set of all ordered pairs <a, b>, where a is an element of A and b is an element of B, is called the Cartesian product of A and B and is denoted by A x B.

• Example 1: Let A = {1, 2, 3} and B = {a, b}. Then A x B = {<1, a>, <1, b>, <2, a>, <2, b>, <3, a>, <3, b>} .

• Example 2: For the same A and B as in Example 1, B x A = {<a, 1>, <a, 2>, <a, 3>, <b, 1>, <b, 2>, <b, 3>} .

In general, A x B ≠B x A unless A = , B = or A = B. Note that A x = x A = because there is no element in to form ordered pairs with elements of A.

Page 18: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Set operations - Exercises

• if A = {a, b, c, y}, B = {a, b, c , d, e} and C = {x, y} evaluate:

1. A (B C) 2. (A B) C 3. C – A 4. (A – B) – C 5. A – (B – C) 6. (A C) B 7. A (C B)

Page 19: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Answers

1. A

2. {y}

3. {x}

4.

5. {y}

6. {a, b, c , d, e, y}

7. A

Page 20: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Subsets• A is a subset of another set, B, means that all

members of the set A are also members of the set B. Notation: A B

• we say “A is a subset of B”, or “B is a superset of A” or “A is contained in B” or “B contains A”

• Examples: – {a, b, c} {a, b, c, d, e} – {2x | x > 1} {x | x > 0}

• If A B, and the set B also contains elements that the set A does not, we say A is a proper subset of B, and we write: A B

• Checkpoint: can we correctly use instead of in the two examples above?

Page 21: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Subset Exercises

• if A = {a, b, c, d, e, f}, B = {a, b, e}, C = {c, d}, and D = {d, f, g} say which of the following are true statements:

1. B B 2. B B 3. B A 4. C A 5. (B C) A 6. D A 7. (D C) A 8. (D C) A

Page 22: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Answers

1. true (of any set) 2. false (of any set) 3. true 4. true 5. true 6. false 7. true 8. false

Page 23: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Universal sets

• we often consider sets in terms of them all being subsets of a so called universal set or universe – for example, all the sets of numbers we have

considered so far have been subsets of the set of all positive integers

– the so-called natural numbers, sometimes written N• this leads to the notion of the complement of a set

– the complement is the difference between the universe and a given set

– e.g. with a universe of N, the complement of {2x | x > 1} is {2x + 1 | x > 0}

– the complement of a set A is usually written Ā • we’ll write comp(A)

Page 24: Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo c.sas@lancaster.ac.ukc.sas@lancaster.ac.uk;

Power sets

• Universal sets - examples• suppose the universe, U = {a, b, c, d, e, f, g}, A = {a, b, c}

and B = {b, c, d, e} – comp(A) = {d, e, f, g} – comp(B) = {a, f, g} – comp (A) comp(B) = {a, d, e, f, g} – comp(A B) = comp({b, c}) = {a, d, e, f, g} – comp(A) comp(B) = {f, g} – comp (A B) = comp({a, b, c, d, e}) = {f, g}

• Power Sets - the set of all subsets of a set A is called the power set of A and denoted by   2A  or   (A) .– For example for A = {1, 2},   (A) = {, {1}, {2}, {1, 2} }