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

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

Embed Size (px)

Citation preview

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

Intro to Maths for CS:2012/13

Sets (week 1 part)

John BarndenProfessor of Artificial Intelligence

School of Computer ScienceUniversity of Birmingham, UK

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

Mathematical “sets”: Basics A “set” is an unordered collection of items of any sorts (people,

numbers, numerals, shoes, atoms, strings of characters, databases, sets, blades of grass, …) without any duplication of items.

The items are called “elements” or “members”.

S = {34, JAB, 59, UoB}, where “JAB” is a name for me and “UoB” is a name for this university,

means that

S is the set consisting of (exactly) the following four items:

the abstract number 34, me, the abstract number 59, this university.

Page 3: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Basics, contd {34, JAB, 59, UoB} = {UoB, 59, 34, JAB, JAB, 34}

Order of writing the members doesn’t matter; duplication in the writing doesn’t duplicate the member.

A set can be infinite (e.g., the set of all whole numbers).

A set can contain just one member (e.g. the set whose only element is your favourite pencil). Singleton set.

It’s different from the member itself..

There’s a set with no members at all: the “empty set”, usually notated as , but can also be written { }.

Somewhat analogous to zero, or a new committee which has no members yet.

There is only one empty set (rather than an empty set of numbers, an empty set of pencils, etc.)

Page 4: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Another Notation

{n || n is an integer, n >> 301} = “The set of n such that n is an integer and n > 301.” (Actually, this notation is a slight simplification.)

The set is the same as that denoted by, for instance, {n | n is an integer, n 302}.

Page 5: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Some More Examples

{JAB, “JAB”} has 2 members: me, and a 3-char string.

{3, {4,5}, 4, 6}has 4 members, one of which is a set.

{3, {5,4}, 4, 6} is that same set.

{ {4,5} } has 1 member, which is a set.

{4,5} has 2 members, both numbers.

{} has 1 member, which is the empty set.

{{}} is a different singleton set.

Page 6: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Membership Relationship

a A means that a is a member of A. 5 {4,5}

{5,4} {3, {4,5}, 4, 6}

a A means that a is not a member of A. 5 {3, {4,5}, 4, 6}

{5} {3, {4,5}, 4, 6}

{4,6} {3, {4,5}, 4, 6}

{3,4,5} {3, {4,5}, 4, 6}

Page 7: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Subsets and Supersets A B means that A is a “subset” of B (and that B is a

“superset” of A). I.e., every member of A is also a member of B.

Carefully distinguish between subset-of and member-of !!!

The symbol means the same as does NOT mean that there cannot be equality.

Examples: {4,5}

{5} {4,5,6}, {6,4} {4,5,6,7}, {6,4,7,5} {4,5,6,7}

{n | n is an EVEN whole number} {n | n is a whole number}

Page 8: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Subsets and Supersets

A for any set A.

A A for any set A. (Reflexivity)

If A B and B A then A = B. (Antisymmetry)

If A B and B C then A C. (Transitivity)

Page 9: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

Some Operations on Sets

Union of sets A and B:

A B = the set of things that are in A or B (or both).

NB: no repetitions created.

Intersection of sets A and B:

A B = the set of things that are in both A and B.

Difference of sets A and B:

A B = the set of things that are in A but not B.

Note: also notated by a backslash instead of a minus sign.

Page 10: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

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

Page 11: Intro to Maths for CS: 2012/13 Sets (week 1 part) John Barnden Professor of Artificial Intelligence School of Computer Science University of Birmingham,

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)