Top Banner
Computing Fundamentals 1 Lecture 6 A Theory of Sets Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 11. A Logical approach to Discrete Math By David Gries and Fred B. Schneider
54

Computing Fundamentals 1 Lecture 6 A Theory of Sets

Feb 18, 2016

Download

Documents

deiondre

Computing Fundamentals 1 Lecture 6 A Theory of Sets. Lecturer: Patrick Browne http://www.comp.dit.ie/pbrowne/ Room K308 Based on Chapter 11. A Logical approach to Discrete Math By David Gries and Fred B. Schneider. Sets. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Computing Fundamentals 1 Lecture 6

A Theory of Sets

Lecturer: Patrick Brownehttp://www.comp.dit.ie/pbrowne/

Room K308Based on Chapter 11.

A Logical approach to Discrete Math By David Gries and Fred B. Schneider

Page 2: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Set theory can be defined as an extension of predicate calculus. A set is a collection of distinct elements (e.g. set of integers, set of students).

• The operations on sets (e.g. union) correspond in a natural way to the logical connectives of logic (e.g. or).

Sets

Page 3: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Two methods of describing sets; set enumeration and set comprehension.

• Set comprehension is defined in terms testing membership in sets.

• This membership test is the basis for the definition of equality of sets.

Sets

Page 4: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Enumerations list elements: – Constants {1,2,3}, – Variables {a,b}

• Comprehension state properties: – {x: | 0 x < 5 : 2 x}

• Represents: – {0,2,4,6,8}

• The general form of comprehension (11.1) is:– {x:t | R : E}

Sets

Page 5: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Recall from Lecture 1 a state is a list of variables with associated values.

• The evaluation of:{x:t | R:E}

• in a state yields the set of values from evaluating E[x := v] in the state for each value v in t such that R[x:=v] holds in that state. Notation similar to quantification

Sets

Page 6: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• A theory of sets concerns sets constructed from some collection of elements. There is a theory of sets of integers, a theory of sets of characters, a theory of sets of sets of integers. The collection of elements is called the domain of discourse or universe of values and is denoted by U. The DOD can be thought of as the type of every set variable in the theory (e.g. DOD is set(), then v:set()).

Universe

Page 7: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• When several set theories are being used at the same time, there is a different universe for each. The name U is then overloaded similar to 1 being considered as a real or an integer.

Universe

Page 8: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• For expression e and a set valued expression S e S is an expression whose value is the value of the

statement “e is a member of S”. We can write “e is not a member of S” as:

(e S) or (eS) • The symbol is treated as conjunctional

operator and has the same precedence as equality (=).

Set Membership & Equality

Page 9: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• (11.3) Axiom, set membership. For expression F:t and set {x|R : E:t} for type t :

provided occurs(‘x’,’F’) F {x | R : E} (x | R : F= E)Example y {x | x>1 : 3x)} (x | x>1 : y=3x)• (11.4) Axiom ,extensionality S=T (x| xS xT)• An extensional definition depends only on the content of

the set. In contrast, an intentional1 definition describes how the set was defined or constructed.

Set Membership & Equality

Recall that F and E are expressions.For example F=z+y-3 is OK but F=x+y+3 is not. In the second case the x in F clashes with the quantified x.

Page 10: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• (11.7) Theorem: x {x| R } R For any expression y y {x | R} R[x:=y]• Theorem (11.7) formalizes the connection

between sets and predicates; a predicate is a representation for the set of argument-values for which the predicate is true.

• 2 {x | x>1} 2>1

Sets versus Predicates

Substitution

Range

Free x Bound x Free x

Substitution x:=2

Page 11: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• (11.8) The principle of comprehension:• To each predicate R there corresponds a

set comprehension {x|R} , which contains the objects t that satisfy R; R is called the characteristic predicate of the set.

Sets versus Predicates

Page 12: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• (11.8) means we can define a set using comprehension and by its characteristic predicate.

• For example the set comprehension:• S = { x | x=3 x=5}• And the characteristic predicate:• x S x=3 x=5 (for all x)• Are equivalent.

Sets versus Predicates

Page 13: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Theorem (11.10) • {x|Q}={x|R} is valid iff Q R is valid.• The above says that if we show that the

characteristic predicates of two sets are equivalent can say that the sets are equal.

• DeMorgan’s Laws for logic can be applied to sets.

Sets versus Predicates

Page 14: Computing Fundamentals 1 Lecture 6 A Theory of Sets
Page 15: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Sets examples

Page 16: Computing Fundamentals 1 Lecture 6 A Theory of Sets
Page 17: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Operations on Sets

Page 18: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Three methods for proving set equality:• (a) Use Leibniz directly (substitution of

equals)• (b) Use axiom of Extensionality (11.4) and

prove v S v T for an arbitrary value of v. (using element by element)

• (c) Prove Q R and conclude {x|Q}={x|R} (using characteristic predicates)

Operations on Sets

Page 19: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• Let S,T,U,V have type set(t) for some type t. This convention allows us to shorten a definition

• For example, set cardinality (S:set(t) | #S =(x| xS:1)) If we remove quantifier we lose the type: #S =(x| xS : 1)

Operations on Sets

Page 20: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Operations on Sets

Page 21: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Operations on Sets

Page 22: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Operations on Sets

Page 23: Computing Fundamentals 1 Lecture 6 A Theory of Sets

The cardinality of Sets denoted by n or #

Page 24: Computing Fundamentals 1 Lecture 6 A Theory of Sets

The cardinality of Sets (n,#)

Page 25: Computing Fundamentals 1 Lecture 6 A Theory of Sets

The general 3 set problem

Page 26: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Draw a Venn Diagram for the following:

Page 27: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Operations on Sets

Page 28: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Example: EU set• The remaining slides contain mainly examples;• Let the set EU be the set of all countries in the

European Union (old). • EU = the set of all countries in the European Union.

• It could be declared as an enumeration:• EU={A,B,DK,F,SF,D,GB,GR,IRL,I,L,NL,P,E,S}

• The variable homeland can refer to one element in the set EU

• homeland EU• benelux={B,NL,L}

Page 29: Computing Fundamentals 1 Lecture 6 A Theory of Sets

The Empty Set and Singleton

• It is possible to have a set with no values, it is called the empty set and denoted as:

or • A set that contains only one element is

called a singleton set. For example: {IRL}• Note the difference between the set {IRL}

and element IRL.• Sets are not ordered. There are no

duplicates, each element is unique.

Page 30: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Subset or Set inclusion

S

X

X (universal set)

S:X ( is power set)

T:X

S T

T

The following statements are true:

B,NL} {B,NL,L}

{B,NL,L}

{B,NL,L} {B,NL,L}

Page 31: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• S is a subset of T if every element if of S is an element of T.

• (11.13) axiom, subset: S T (x | x S : x T) • (11.14) axiom, proper subset: S T ST ST

Subset & Superset

Page 32: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• (11.15) axiom, superset: T S S T • (11.16) axiom, proper superset: T S S T• The axioms and theorems for set

operations are given in the course text and the course web site, only a few are covered in these slides.

Subset & Superset

Page 33: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators

• Set Equivalence• Two values of the same type can be

tested to see if they are the same by using the equals sign, as in:

• x = y• Two sets are equal if they contain

exactly the same elements. For example the two sets below are equal:

• {B,NL,L} = {NL, B, L}

Page 34: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators

• Set Non-Equivalence• Two values of the same type can be

tested to see if they are not the same by using the not-equals sign . Two sets are not equal if they do not contain exactly the same elements

{B,NL} {B,NL,L}

Page 35: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators• The membership operator is written: • NL {B, NL, L}it is true; the Netherlands is a Benelux country

• General case below:

X

S

.x S:X

x:X

xS

Page 36: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators

• The non-membership operator is written: IRL{B, NL, L}; Ireland is not a Benelux

country

X

S

.x

S:X

x:X

x S

General case

Page 37: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators

• The validity of membership test.• The value to be tested for membership

must be an element of the underlying type of the set. For example:

• USA {B, NL, L}• USA {B, NL, L}• is illegal in this context, since USA is

not an element of the type EU.

Page 38: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators

• Size Cardinality: The number of values in a set is called its size, or cardinality, and is signified with the has sign:

• #{B,NL,L} = 3• #{IRL} = 1• #IRL illegal, IRL is not a set• # = 0

Page 39: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators• Powersets: The powerset of a set is

writtenS• It is the set of all subsets of S. For

example the powerset of the Benelux countries is:P{B,NL,L} ={ , {B},{NL},{L}, {B,NL},{B,L},{NL,L}, {B,NL,L}}

Page 40: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators:Powersets

• When a variable is to be declared to have a type that is a set of elements, the type is the powerset of the type of the elements:

• benelux: EU• This can be read as ‘the variable benelux

is a subset of the set of countries EU’ or ‘the variable benelux is a set of EU countries’ (not the set)

Page 41: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators:Powersets

• The size of the powerset of a set is equal to two raised to the power of the size of the set.

• #(S) = 2#s

• #{B,NL,L} = 3• #({B,NL,L}) = 8

Page 42: Computing Fundamentals 1 Lecture 6 A Theory of Sets

• The complement of S (S) is the set of elements that are not in S but are in the universe.

• (11.17) axiom, complement: vSc vU vS

Complement

SU

Page 43: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators: Union• The union of two sets is the set containing all

the elements that are in either the first set or the second set or both.

ST

X

U = [X]

S:X

T:X

T S

T S = S T

S = S

Page 44: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators: Intersection• The intersection of two sets is the set

containing all the elements that are in the first set and in the second set.

ST

X

U =[X]

S:X

T:X

T S

T S = S T

S =

Page 45: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators: Difference• The difference of two sets is the set

containing all the elements that are in the first set and are not in the second set. The shaded area is the difference of S and T.

S

X

[X]

S:X

T:X

S T S T T SS = SS =

T

Page 46: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators: Distributed Union• The distributed union of a set of sets is

the set containing just those elements that occur in at least one of the component sets.

S

X

[X]

S:X

R:X

T:X

R,S,T}T

R

{{2,4},{3,1,2},{2,3,4}} = {1,2,3,4}

Page 47: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Operators: Distributed Intersection

• The distributed intersection of a set of sets is the set containing just those elements that occur in all of the component sets.

S

X

[X]

S:X

R:X

T:X

R,S,T}T

R

Page 48: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Disjoint Sets

• Sets that are disjoint have no elements in common; their intersection is the empty set.

• For disjoint sets T and S the following expression is true:

• T S = .

Page 49: Computing Fundamentals 1 Lecture 6 A Theory of Sets

More than 2 Disjoint Sets

• For more that two sets the notation become clumsy, since every pair must have an empty intersection. For example for sets A, B and C to be disjoint the following must be true:

• A B = and

• B C = and

• C A =

Page 50: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Partition• A sequence of sets is said to partition

another larger set if the sets are disjoint and their distributed union is the entire larger set if the sets are disjoint. For example:

• if disjoint<A,B,C> ({A,B,C} = T)• then <A,B,C> partition T• For example:• <Temporary, Part-time, Permanent> may

partition Employee.

Page 51: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Relating sets and Boolean Expressions

• The definition of the set operations reveals a connection between the set operators and the propositional operators. For example, in the definition of , as the phrase “x” of the LHS is distributed inward to the operands S and T of the RHS, becomes .

x (S T) x S x T

Page 52: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Relating sets and Boolean Expressions

• The properties of propositional operators are reflected as similar properties of set operators, e.g. absorption laws:

S (S T) S (type S,T:Boolean)S (S T) = S (type S,T:set(t))• The zero laws for props. & sets.S false false (type S:Boolean)S (type S:set(t))

Page 53: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set expression Es

Propositional expression Ep In Es replace symbols with the symbols giving Ep

false

Sc

U true

Page 54: Computing Fundamentals 1 Lecture 6 A Theory of Sets

Set Comprehension Example

• Express: The set of positive integers that are less than 5

• Solution• {x: | 0 x 4:x} or {x: | 0 x <5:x} • Or• {0,1,2,3,4}