Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computing Fundamentals 1 Lecture 6 A Theory of Sets Lecturer: Patrick Browne Room K308 Based on Chapter 11. A Logical approach.

Similar presentations


Presentation on theme: "Computing Fundamentals 1 Lecture 6 A Theory of Sets Lecturer: Patrick Browne Room K308 Based on Chapter 11. A Logical approach."— Presentation transcript:

1 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

2 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

3 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

4 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

5 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

6 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

7 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

8 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 (e  S) The symbol  is treated as conjunctional operator and has the same precedence as equality (=). Set Membership & Equality

9 (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| x  S  x  T) An extensional definition depends only on the content of the set. In contrast, an intentional 1 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.

10 (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

11 (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

12 (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

13 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

14

15 Sets examples

16

17 Operations on Sets

18 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

19 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| x  S:1)) If we remove quantifier we lose the type: #S =(  x| x  S : 1) Operations on Sets

20

21

22

23 The cardinality of Sets denoted by n or #

24 The cardinality of Sets ( n, # )

25 The general 3 set problem

26 Draw a Venn Diagram for the following:

27 Operations on Sets

28 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}

29 The Empty Set and Singleton It is possible to have a set with no values, it is called the empty set and denoted as: 0 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.

30 Subset or Set inclusion S X X (universal set) S: P X (  is power set) T: P X S z T T The following statements are true: { B,NL} z {B,NL,L} 0 z {B,NL,L} {B,NL,L} z {B,NL,L}

31 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  S  T  S  T Subset & Superset

32 (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

33 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}

34 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}

35 Set Operators The membership operator is written: e NL e {B, NL, L} it is true; the Netherlands is a Benelux country General case below: X S.x.x S: P X x:X x e S

36 Set Operators The non-membership operator is written: IRL  {B, NL, L}; Ireland is not a Benelux country X S.x.x S: P X x:X x  S General case

37 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.

38 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

39 Set Operators Powersets: The powerset of a set is written PS 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}}

40 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: PEU 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)

41 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. #(PS) = 2 #s #{B,NL,L} = 3 #(P{B,NL,L}) = 8

42 The complement of S (S) is the set of elements that are not in S but are in the universe. (11.17) axiom, complement: v  S c  v  U  v  S Complement S U

43 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. S T X U = [X] S: P X T: P X T U S T U S = S U T S U 0 = S

44 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. S T X U = [X] S: P X T: P X T I S T I S = S I T S I 0 = 0

45 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: P X T: P X S \ T S \ T T \ S S \ 0 = S 0 \ S = 0 T

46 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: P X R: P X T: P X { R,S,T} T R {{2,4},{3,1,2},{2,3,4}} = {1,2,3,4}

47 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: P X R: P X T: P X { R,S,T} T R

48 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 I S = 0.

49 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 I B = 0 and B I C = 0 and C I A = 0

50 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} = T) then partition T For example: may partition Employee.

51 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

52 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  0 = 0 (type S:set(t))

53 Set expression E s Propositional expression E p In E s replace symbolswith the symbols giving E p 0false   ScSc  U true

54 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}


Download ppt "Computing Fundamentals 1 Lecture 6 A Theory of Sets Lecturer: Patrick Browne Room K308 Based on Chapter 11. A Logical approach."

Similar presentations


Ads by Google