Intro to Maths for CS: 2012/13 Sets (contd, week 2)

Slides:



Advertisements
Similar presentations
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
Advertisements

Set theory Sets: Powerful tool in computer science to solve real world problems. A set is a collection of distinct objects called elements. Traditionally,
Intro to Maths for CS: 2013/14 Sets (2) – OPTIONAL MATERIAL John Barnden Professor of Artificial Intelligence School of Computer Science University of.
CS355 - Theory of Computation Lecture 2: Mathematical Preliminaries.
Relation, function 1 Mathematical logic Lesson 5 Relations, mappings, countable and uncountable sets.
Fundamentals/ICY: Databases 2010/11 WEEK 11 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK.
Math 002 College Algebra Final Exam Review.
Fundamentals/ICY: Databases 2012/13 WEEK 7 John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK.
Homework: p odd, odd, odd, odd, and odd.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
R. Johnsonbaugh, Discrete Mathematics 5 th edition, 2001 Chapter 2 The Language of Mathematics.
Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,
Fundamentals/ICY: Databases 2012/13 WEEK 10 (maths, normalization) John Barnden Professor of Artificial Intelligence School of Computer Science University.
Basic Structures: Sets, Functions, Sequences, and Sums CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Sets Define sets in 2 ways  Enumeration  Set comprehension (predicate on membership), e.g., {n | n  N   k  k  N  n = 10  k  0  n  50} the set.
Mathematical Induction
Copyright © 2014 Curt Hill Cardinality of Infinite Sets There be monsters here! At least serious weirdness!
Fundamentals/ICY: Databases 2013/14 WEEK 9 –Monday John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,
Discrete Mathematics R. Johnsonbaugh
Discrete Mathematics Relation.
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
COMPSCI 102 Introduction to Discrete Mathematics.
Fundamentals/ICY: Databases 2013/14 WEEK 9 –Friday John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,
Great Theoretical Ideas in Computer Science.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
Intro to Maths for CS: 2012/13 Sets (end, week 3) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,
Section 3.2: Sequences and Summations. Def: A sequence is a function from a subset of the set of integers (usually the set of natural numbers) to a set.
Fundamentals/ICY: Databases 2013/14 Week 11 – Monday – relations, ended. John Barnden Professor of Artificial Intelligence School of Computer Science University.
Chapter 2 1. Chapter Summary Sets (This Slide) The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions.
Set Builder Notation. If you recall, a set is a collection of objects which we write using brackets and name using a capital letter. Remember also that:
CPCS 222 Discrete Structures I
Sets, Permutations, and Combinations. Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of.
Sets CS 202, Spring 2007 Epp, chapter 5.
Dr. Ameria Eldosoky Discrete mathematics
Welcome to MATH225 Applications of Discrete Mathematics and Statistics.
Chapter 2 Sets and Functions.
CHAPTER 2 Set Theory A B C.
Set Definition: A set is unordered collection of objects.
The Acceptance Problem for TMs
Discrete Mathematics CS 2610
A Universal Turing Machine
CHAPTER 3 SETS, BOOLEAN ALGEBRA & LOGIC CIRCUITS
Fundamentals/ICY: Databases 2013/14 WEEK 8 –Monday
1.1: Objectives Properties of Real Numbers
Set, Combinatorics, Probability & Number Theory
CS 2210:0001 Discrete Structures Sets and Functions
Chapter 1 Logic and Proofs Homework 2 Given the statement “A valid password is necessary for you to log on to the campus server.” Express the statement.
MATH 224 – Discrete Mathematics
Fundamentals/ICY: Databases 2010/11 WEEK 6
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 2 Sets Slides are adopted from “Discrete.
CS100: Discrete structures
Precalculus Mathematics for Calculus Fifth Edition
Lesson 5 Relations, mappings, countable and uncountable sets
1.1 Real Numbers.
Copyright © Cengage Learning. All rights reserved.
Lesson 5 Relations, mappings, countable and uncountable sets
Mathematical Background 1
Mathematical Background 1
The aim of education is to teach students how to think rather than what to think. Sets The set is the fundamental discrete structure on which all other.
Introduction to Relations and Functions
MCS680: Foundations Of Computer Science
Real Numbers and Their Properties Section 1.1 – The Real Numbers
Mathematical Background
Relations And Functions.
Sets & Set Operations.
John Barnden Professor of Artificial Intelligence
Everything is an Integer Countable and Uncountable Sets
Set – collection of objects
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
ordered pairs mapping diagram (-2, -8) (-1, -4) (1, 4) (2, 8) x y table of values x y We can represent.
Presentation transcript:

Intro to Maths for CS: 2012/13 Sets (contd, week 2) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham, UK

((Aside: “Bags” in Maths)) A variant of sets called “bags” (or “multisets”) is used in maths (and CS) and allows repeated members. There are union, etc. operations that respect the repetitions. So bags and their operations are a better fit to DB tables and notably their repetition-respecting operations (e.g. UNION ALL) than sets and their operations are. But bags are non-standard and they’re not normally covered at an introductory level. See Garcia-Molina et al 2009 for bags and their use in the DB area.

Reminder of Week 1

Some Properties of those Operations Union and intersection are commutative (“can switch”): A  B = B  A A  B = B  A Union and intersection are associative (“can group differently”): A  (B  C) = (A  B)  C A  (B  C) = (A  B)  C Because of associativity, we can omit parentheses: A  B  C  D A  B  C  D

Two Other Properties Union distributes over intersection: A  (B  C) = (A  B)  (A  C) Intersection distributes over union: A  (B  C) = (A  B)  (A  C)

New for Week 2

Same Difference? Exercises for bath-time: Is the difference operation commutative or associative? And does it take part in any distributivity with the other operations?

Size (Cardinality) of a Set When set A is finite, the size or cardinality of A (its number of members) is denoted |A|. Some obvious points (where A, B are finite) … || = 0 |{}| = 1 If A  B but A  B, then |A| < |B| |A|, |B|  |A  B|  |A| + |B| | A  B |  |A|, |B|

Powersets (reminder from last term) The set of all the subsets of a set A is called the powerset of A, denoted ℙ(A) or sometimes 2A ℙ( {1,2,3} ) = { , {1}, {2}, {3}, {1,2}, {2,3}, {3,1}, A} ℙ( {1} ) = { , {1} } ℙ(  ) = {  } When A is finite, |ℙ(A) | = 2|A| (remember why?) So when |A| = 12, |ℙ(A) | = 212 = 4096

“Tuples” A “tuple” is an ordered sequence of items of any sort. We will only deal with finite tuples. Items CAN be duplicated. Can also be called a “vector.” Notation: 6, JAB, 5, “JAB”, 5, , 9> Or: (6, JAB, 5, “JAB”, 5, , 9) Singleton and empty tuples: <6>, <> <6, 6, 3>, <6,3> , <6,6,3,6> and <6,3,6> are all different.

Ordered Pairs  6, JAB >  “JAB”,  >  -6, -6 >  5, -6 > Bernd Bohnet in Term 1mentioned ordered pairs of numbers, when discussing graphs (textbook p.152). An ordered pair is simply a tuple of length two:  6, JAB >  “JAB”,  >  -6, -6 >  5, -6 >  ,  >

“Cartesian Products” and “Relations” The set of all possible tuples formed from some sets is called the Cartesian product of the sets. Notation, e.g.: D  E  F  G  H if D, E, F, G, H are the sets—not necessarily different. Each tuple is of form <d,e,f,g,h> where d D, e  E, etc. Any subset at all of that Cartesian product is called a relation on the sets in question (D, E, …) even the whole of the product (even if infinite) and even the empty set. I.e., a relation on D, E, …, H is just some set of tuples that are each of form <d,e, …, h> where d  D, e  E, …, h  H.

Examples Let A = {3, 8, 2} and B = {‘jjj’, ‘bb’}. Then A  B = { <3, ‘jjj’>, <3, ‘bb’>, <8, ‘jjj’>, <8, ‘bb’>, <2, ‘jjj’>, <2, ‘bb’> }. B  B = { <‘jjj’, ‘jjj’>, <‘jjj’, ‘bb’>, <‘bb’, ‘jjj’>, <‘bb’, ‘bb’>}. A   =  =   A A  {JAB} = { <3, JAB>, <8, JAB>, <2, JAB> } Some relations on A and B: { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>} { <2, ‘bb’> } A  B 

Some “Relational Operations”: Set Operations Applied to Relations Union of relations R and S: R  S = the set of tuples that are in R or S (or both). Intersection of relations R and S: R  S = the set of tuples that are in both R and S. Difference of relations R and S: R  S = the set of tuples that are in R but not S.

((“Relations don’t remember where they came from”)) Consider a relation R on A, B, C, D, E, … i.e., R  A  B  C  D  E  …. Suppose A  AA, B  BB, C  CC, etc. Then: a tuple formed from sets A, B, … is also automatically a tuple formed from AA, BB, … That is, R  AA  BB  CC  DD  EE  …. So R is also a relation on AA, BB, CC, DD, EE, …. So a relation has no very close connection to the original sets it might have been defined from, unlike the case of tables, where the attribute domains are part of the nature of the table.

“Arity” of Relations A relation on two sets is binary, on three sets is ternary, … … even when not all the sets are different. So a relation on A and A is still binary and NOT “unary.” The members of the relation are two-element tuples. A relation on, say, A, B and A is ternary and not binary. The members of the relation are three-element tuples.

“Arity” of Relations, contd. A “unary relation” on A is a set of singleton tuples formed from A elements. Unusual (though not inconceivable) to want a single-attribute table in a finalized ER model. But one-attribute tables often arise dynamically from table operations, as you know.

Relations from Somewhere to Somewhere A relation R “from” set A “to” set B is the same thing as a relation “on” A “and” B — just different terminology. Similarly, a relation from A, B, C to D, E is the same thing as a relation on A, B, C, D, E.

Changing the Sets in a Relation Around A relation R on A, B, C, D, E, say, obviously “induces” (i.e., gives rise to, in a natural way) a relation on any reordering of the sets, such as D, A, B, E, C, just by reordering each tuple in the same way. Thus, R induces a relation from, say, D, A to B, E, C. When there are just two sets A and B, the (only possible) reordering of the sets gives the inverse of R.

Inverse Example Suppose R = { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>} Then the inverse of R, notated R-1 is the relation { <‘jjj’, 3>, <‘bb’, 3>, <‘jjj’, 2>}

Removing some of the Sets in a Relation (Projection) And we can remove some of the sets and the corresponding items from each tuple. Given the relation on D,A,B,E,C, we can get a relation on, say, D,B,C, just by removing the second and fourth item from each tuple. This is the mathematical operation underlying the PROJECT relational operator on tables (what I would prefer call Select-Columns or Select-Attributes).

Restriction of a Relation Consider a relation R from A to B, and a subset AA of A. Then the restriction of R to AA is the relation derived from R by restricting attention to AA, i.e., including only tuples whose first element is in AA. The new relation is notated R|AA

Restriction Example A = {3, 8, 2}, B = {‘jjj’, ‘bb’, ‘c’}. R = { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>, <8, ‘c’>, <2, ‘c’> } AA = {3, 8}. Then R|AA = { <3, ‘jjj’>, <3, ‘bb’>, <8, ‘c’>}

((Restriction More Generally)) Consider a relation R from A, B, …C to D, E, …, F and subsets AA of A, BB of B, …, CC of C. Then the restriction of R to AA, BB, …, CC is the relation derived from R by restricting attention to AA, BB, …, CC i.e., including only tuples whose first few elements are in AA, BB, …, CC respectively. The new relation is notated R|AA, BB, …, CC

Functional Relations (Partial Functions) A relation R from A to B is functional if, for any a in A, there is AT MOST one (but perhaps no) b in B such that a, b> is in R. So several things in A can be related to the same thing in B. But you can’t have several things in B related to the same thing in A. A functional relation from A to B is also called a partial function from A to B.

Examples A = {3, 8, 2, 100}, B = {‘jjj’, ‘bb’, ‘c’, ‘x’, ‘y’}. R = { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>, <8, ‘c’>, <2, ‘c’> } NOT functional, because 3 maps to both ‘jjj’ and ‘bb’, and … R = { <3, ‘jjj’>, <2, ‘jjj’>, <100, ‘x’>} IS functional (NB: 8 doesn’t map to anything, and both 3 and 2 map to ‘jjj’)

Functional Relations, contd. Can generalize: a relation R from A1, A2, A3 … to B1, B2, B3, …is functional if, for each combination of things a1, a2, a3, … in A1, A2, A3, … respectively, there is at most one b1, b2, b3, … in B1, B2, B3, … respectively such that a1, a2, a3, …, b1, b2, b3, …> is in R.

Totality of Relations A relation R from A to B is total (on A) if it relates everything in A to AT LEAST one thing in B. I.e., for every member a of A, there is at least one b in B such that  a, b > is in R. A relation may be merely partial (on A above) in not being total. However, technically all relations are “partial”, with total being a special case.

Examples A = {3, 8, 2, 100}, B = {‘jjj’, ‘bb’, ‘c’, ‘x’, ‘y’}. R = { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>, <8, ‘c’>, <100, ‘y’>} IS total (NB: 3 maps to more than one thing) R = { <3, ‘jjj’>, <2, ‘jjj’>, <100, ‘x’>} NOT total, because 8 fails to map to anything.

((Totality, contd.)) Can generalize: A relation R from A, B, C, … to D, E, … is total (on A, B, C, …) if for every member a of A, b of B, c of C, etc. there is at least one d in D, e in E, etc. such that  a, b, c, …, d, e, … > is in R.

Functions A total functional relation from A to B is called a function from A to B. Each thing in A is related to exactly one thing in B. (But two different things in A can be related to the same thing in B, and not everything in B needs to be related to anything in A. So the inverse relation is not necessarily either functional or total.) Caution: every function is also a partial function.

Examples A = {3, 8, 2, 100}, B = {‘jjj’, ‘bb’, ‘c’, ‘x’, ‘y’}. R = { <3, ‘jjj’>, <3, ‘bb’>, <2, ‘jjj’>, <8, ‘c’>, <100, ‘y’>} NOT a function, because 3 maps to more than one thing R = { <3, ‘jjj’>, <2, ‘jjj’>, <100, ‘x’>} NOT a function, because 8 fails to map to anything. R = { <3, ‘jjj’>, <2, ‘jjj’>, <100, ‘x’>, <8, ‘x’>} IS a function.

From Partiality to Totality by Restriction We can always turn a merely-partial R from A to B into a total one by slimming A down enough! Just remove the members of A that aren’t related to anything by R, to get a new set AA. We don’t remove any tuples from R. R (as a relation from AA to B) is total on AA. And note that R|AA = R. AA is called the domain of R, notated dom(R).

Totality contd. and “Onto” A relation R from A to B is onto if for everything in B there is at least one thing in A that is related by R to it. I.e.: For every member b of B, there is at least one a in A such that a, b> is in R. Onto-ness is just totality in the other direction. You can also say that R is total on B, or that the inverse of R is total.

Other Categories of Relation A relation R from A to B is one-to-one (1-1) if, for any a in A, there is at most one b in B such that a, b> is in R, AND for any b in B, there is at most one a in A such that a, b> is in R. That is, both the relation and its inverse from B to A are functional. (But they don’t need to be total.) To put it another way: it is functional and different members of A map to (= are related to) different members of B. Or again: Different members of A map to different members of B and different members of B map to different members of A.

Example A = {3, 8, 2, 100}, B = {‘jjj’, ‘bb’, ‘c’, ‘x’, ‘y’}. R = { <3, ‘jjj’>, <8, ‘c’>, <100, ‘y’>} IS 1-1

((Other Categories of Relation, contd.)) A relation R from A to B is many-to-one if it is functional but not one-to-one: i.e., there are different members of A that map to the same member of B, in at least one case. A relation R from A to B is one-to-many if it is not functional but its inverse from B to A is functional. That is, there’s a member of A that maps to more than one member of B; but each member of B maps to at most one member of A. A relation R from A to B is many-to-many if neither it nor its inverse is functional: i.e., there’s a case of a member of A mapping to more than one member of B, and a case of a member of B mapping to more than one member of A.

Other categories, contd. A one-to-one correspondence between a set A and B is a SPECIAL one-to-one relation from A to B (or B to A): it is not only one-to-one but also TOTAL (on A) and ONTO (B). (Or we can say: total on both A and B.)

Example A = {3, 8, 2, 100}, B = {‘jjj’, ‘bb’, ‘c’, ‘y’}. R = { <3, ‘jjj’>, <8, ‘c’>, <100, ‘y’>} NOT a 1-1 correspondence between A and B, even though it is 1-1, as 2 is left out from A, and ‘bb’ is left out from B. R = { <3, ‘jjj’>, <2, ‘bb’>, <8, ‘c’>, <100, ‘y’>} IS a 1-1 correspondence between A and B

Other categories, contd. But any 1-1 relation from A to B is a 1-1 correspondence between the subsets of A, B consisting of those members that do happen to feature in the relation!

Countable and Uncountable Sets [Brief Intro] A set X is countable if it can be placed in a one-to-one correspondence with some subset of N, the set of natural numbers from 1. Trivial case: X = N Let R be the relation {<x,x> | x  X}. This is the identity relation on X. Then R is a 1-1 correspondence between X and X.

Countable Sets, contd 1 Similarly for any proper subset X of N: just use the identity relation on X again. More interesting case: X = the set of all whole numbers (negative, positive and zero). Let R be the relation {<x, 2x> | x  X, x  0}  {<x, -1-2x> | x  X, x < 0 } So R = {(0,0), (-1,1), (1,2), (-2,3), (2,4), (-3,5), (3,6), …} Then R is a 1-1 correspondence between X and N.

Countable Sets, contd 2 Yet more interesting case: X = the set of positive rational numbers. Can get our relation R by putting the possible fractions (with positive whole number parts) in a square infinite table with numerators increasing horizontally and denominators increasing vertically: 1/1 2/1 3/1 4/1 5/1 6/1 … 1/2 2/2 3/2 4/2 5/2 6/2 … 1/3 2/3 3/3 4/3 5/3 6/3 … 1/4 2/4 2/5 2/6 : : … : : : : : : … Then traverse through the numbers in sequence by going up and down diagonals, with steps on edges as necessary, and missing out fractions that are not in simplest form (missed out ones are shown in brackets): 1/1, 2/1, 1/2, 1/3, (2/2), 3/1, 4/1, 3/2, 2/3, 1/4, 1/5, (2,4), (3,3), (4,2), 5/1, … Count as: 1 2 3 4 5 6 7 8 9 10 11

Uncountable Sets All finite sets are countable. And they needn’t be sets of numbers! The set of socks in this class is countable. We have seen that some infinite ones are countable … Even if the set X contains the natural numbers as a tiny proper subset!! E.g., X = the set of rational numbers. But some infinite sets are not countable: notably the set of real numbers (rational and irrational numbers together), or even the set of real numbers between 0 and 1. Can be shown by a “diagonalization” argument based on the decimal representations of the numbers.