1 / 54

Computing Fundamentals 1 Lecture 6 A Theory of Sets

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.

deiondre
Télécharger la présentation

Computing Fundamentals 1 Lecture 6 A Theory of Sets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computing Fundamentals 1Lecture 6A 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. 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).

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

  4. 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}

  5. 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 evaluatingE[x := v] in the state for each value v in t such that R[x:=v] holds in that state. Notation similar to quantification

  6. Universe • 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()).

  7. Universe • 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.

  8. Set Membership & Equality • 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 (=).

  9. Set Membership & Equality • (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 intentional1 definition describes how the set was defined or constructed. 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. Sets versus Predicates Free x Bound x Free x Range • (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 Substitution Substitution x:=2

  11. Sets versus Predicates • (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.

  12. Sets versus Predicates • (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.

  13. Sets versus Predicates • Theorem (11.10) • {x|Q}={x|R}is valid iff Q  Ris 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.

  14. Sets examples

  15. Operations on Sets

  16. Operations on 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)

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

  18. Operations on Sets

  19. Operations on Sets

  20. Operations on Sets

  21. The cardinality of Sets denoted by n or #

  22. The cardinality of Sets (n,#)

  23. The general 3 set problem

  24. Draw a Venn Diagram for the following:

  25. Operations on Sets

  26. 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}

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

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

  29. Subset & Superset • 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

  30. Subset & Superset • (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.

  31. 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}

  32. 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}

  33. 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: S:PX x:X xeS .x S X

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

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

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

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

  38. 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)

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

  40. Complement • 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Sc vU  vS S U

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

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

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

  44. 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. [X] S:PX R:PX T:PX {R,S,T} R S T X • {{2,4},{3,1,2},{2,3,4}} = {1,2,3,4}

  45. 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. [X] S:PX R:PX T:PX {R,S,T} R T S X

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

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

  48. 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>partitionT • For example: • <Temporary, Part-time, Permanent> may partition Employee.

More Related