1 / 20

Sets

Sets. Sets. A set is a well-defined collection of values of the same kind (objects) Objects can be numbers, people, letters, days, may be sets themselves Examples. Sets. Small sets may be introduced by listing their elements

hewitt
Download Presentation

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

  2. Sets • A set is a well-defined collection of values of the same kind (objects) • Objects can be numbers, people, letters, days, may be sets themselves • Examples

  3. Sets • Small sets may be introduced by listing their elements • Other sets may be constructed using set comprehension, the power set operator, and the cartesian product • Use extension for listing elements • Examples

  4. Membership of a set • We write x  s to indicate that x is an element of set s • We write (x  s ) as x  s • Examples 3  Primes 6  Primes

  5. Equality of sets & Null set • Two sets of values of the same kind are equal if and only if they have the same members • Examples s == {2,2,5,5,3} t == {2,3,5} s = t • A null set is set with no members • Denoted as  or {}

  6. Subsets • One set is said to be a subset of another if all the members of the one are also the members of the other • Example A is a set of all primes and B == {2,3,5} then B is a subset of A denoted by B  A

  7. Union of sets • Two sets of the same kind, A and B, whose members are the members of A and B together • Denoted by A  B • Example: A == {1,2,3,4,5} B == {2,4,5,6,7} A  B == {1,2,3,4,5,6,7}

  8. Intersection • Two sets of the same kind, A and B, whose members are the members that A and B have in common • Denoted by A  B • Example A == {1,2,3,4,5} B == {2,4,6,7} A  B == {2,4} • Two sets are disjoint if they have no member in common C == {6,7,8} A  C = 

  9. Set Difference • Two sets A, B of the same kind, whose members are the members of A but not of B • Denoted by A\B • Example A == {1,2,3,4,5} B == {2,4} A\B == {1,3,5}

  10. Set Comprehension • Defining a set by stating a property that distinguishes its member from other values of the same kind • Suppose D denotes some declarations, P denotes a predicate constraining the value, and E denotes an expression denoting a term, then {D|P•E} is called set comprehension term • Denotes a set of values consisting of all values of the term E for everything declared in D satisfying the constraint P

  11. Set Comprehension • Example {x :  | x  5 • x2} denotes the same set as {0,1,4,9,16,25} • We can omit heavy dot {x :  | x  5} • We can omit constraint and constraint bar {x :  • x2}

  12. Defining sets using predicates • BigCountries == {c : country | c has more than 40 million inhabitants} • MultipleOfSixes == {n : |  m :   n = m  6} • BiggestCities == {macropolis : city | co : country  macropolis is in co  ci : city  ci is in co   ci is macropolis  macropolis is bigger than ci}

  13. Power Sets • The power set of a set A is the set of all its subsets. • Denoted by pA --- power set of A • Example A == {x,y} pA == {, {x}, {y}, {x,y}} • A  B has the same meaning as A  pB • Example • X == {1}, pX == {, {1}}, ppX == {, {}, {{1}}, {, {1}}} • Exercise : list the power set for {1,2,3}

  14. Cartesian Product • Countries == {UK, USA, Malaysia, Iran …} • Capitals == {London, Washington, KL, Tehran, …} • CountriesAndCapitals == {(UK,London), (USA,Washington), (Malaysia,KL), (Iran,Tehran),…} • CountriesAndCapitals == {co : country; ca : city | ca is the capital of co}

  15. Tuple membership • If a1…an are sets and then • Example

  16. Tuple equality • if x1 = y1 and x2 = y2 … xn = yn then (x1,x2,..,xn) = (y1,y2,…,yn)

  17. Component selection

  18. Types

  19. Sets of numbers • Integers, denoted by , is the set of positive and negative whole numbers including zero. Its type is p • Natural numbers, denoted by , is the set of whole numbers from zero onwards. The natural numbers are a subset of the integers. Its type is p • Restricted set of numbers, whose numbers lying in a certain range is called a subrange, eg. 1..4 denotes {1,2,3,4} • Finite set : 1..4 • Infinite set : , ‘the set of natural numbers that are prime’ • If X denotes some finite set, then the number of elements in the set is called its cardinality or size, and denoted by #X

  20. Other forms of type • Types of ordered pair (cartesian product) involving integer  • In general if a specification has the basic types X and Y, we can have a list of other types: pX, pY, ppX, ppY, …. XX, XY, YX, YY (pX)  (pX), p(XX), (pX)  Y ….

More Related