------------------------------------------------------------ a | set | is a collection or group of | elements | which can be any objects ------------------------------------------------------------ should have specification of | universe | #U# ------------------------------------------------------------ with braces | { | | } | ------------------------------------------------------------ same as | {1, 2, 3, 4} | ------------------------------------------------------------ #:= { | 6, 8, 10, 12, 14, ... | }# ------------------------------------------------------------ | Goldbach's conjecture | ------------------------------------------------------------ {Spam} {Spam,Spam,Spam,Spam,Spam,Spam,Spam,Spam,Spam,Spam,Spam} ------------------------------------------------------------ votes: yes: | 9 | ------------------------------------------------------------ no: | 0 | ------------------------------------------------------------ abstentions: | 2 | ------------------------------------------------------------ though it is true that #green isin {red,green} ~ isin { N, -2, R, yellow, {red,green} }# don't say ~ #green isin { N, -2, R, yellow, {red,green} }# because "isin" does not search deeply/recursively consider this situation in Java: int[] N = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; double[] R = {0, 0.1, -0.1, 0.2, -0.2, Math.PI, Math.sqrt(5)}; Color[] C = {Color.RED, Color.GREEN}; Object[] A = { N, new Integer(-2), R, Color.YELLOW, C }; for ( Object A_element : A ) if ( A_element.equals(Color.GREEN) ) System.out.println("Color.GREEN is in A[]"); will or won't that code output "Color.GREEN is in A[]"? won't ------------------------------------------------------------ it's common to use the term | collection | for a set whose elements are sets ------------------------------------------------------------ then the collection #{"helo", "world", ""}# contains how many #String#s? | 3 | ------------------------------------------------------------ whereas by contrast the collection #{"helo", "world"}# contains | 2 | ------------------------------------------------------------ e.g. #|{red,green,blue}|# is | 3 | ------------------------------------------------------------ e.g. #|∅|# is | 0 | ------------------------------------------------------------ e.g. #|{N}|# is | 1 | ------------------------------------------------------------ outer set has | 1 set | inside ------------------------------------------------------------ e.g. #|{∅}|# is | 1 | ------------------------------------------------------------ outer set has | 1 set | inside ------------------------------------------------------------ no consider: Object[] C = {Color.RED, Color.GREEN}, A_1 = {a0, Color.YELLOW}, A_2 = {Color.RED, Color.GREEN, Color.YELLOW}; ------------------------------------------------------------ e.g.? #{green} ?⊂? {red,green,blue}# ? | yes | ------------------------------------------------------------ | no: can't say yes because object on left isn't a set | ------------------------------------------------------------ e.g.? #{red} ?⊂? [red,{green,yellow}]# ? | yes | ------------------------------------------------------------ e.g.? #{green,yellow} ?⊂? [red,{green,yellow}]# ? | no | ------------------------------------------------------------ e.g.:? #{red,green,blue} ?⊂? {red,green,blue}# ? | ??? | ------------------------------------------------------------ why wouldn't the set on the left be a subset of the set on the right? aren't all the elements of the set on the left also contained in the set on the right? ------------------------------------------------------------ e.g.:? #{red,green,blue} ?⊆? {red,green,blue}# ? | yes | ------------------------------------------------------------ e.g.:? #{red,green,blue} ?⊂? {red,green,blue}# ? | no | ------------------------------------------------------------ e.g.:? #{green,blue} ?⊆? {red,green,blue}# ? | yes | ------------------------------------------------------------ e.g.? #∅ ⊆ ∅# ? | yes | ------------------------------------------------------------ e.g.? #∅ ⊂ ∅# ? | no | ------------------------------------------------------------ | #∅#, #{a}#, #{b}#, #{a,b}# | ------------------------------------------------------------ | power set | of a set S is the collection of all the subsets of S ------------------------------------------------------------ e.g. #P({a,b}) = | { ∅, {a}, {b}, {a,b} } | # ------------------------------------------------------------ e.g. #P({a}) = | { ∅, {a} } | # ------------------------------------------------------------ e.g. #P(∅) = | { ∅ } | # ------------------------------------------------------------ e.g. #P({a,b,c}) = | { ∅, {a}, {b}, {a,b}, {a,c}, {b,c}, {a,c,b}, {c} } | # ------------------------------------------------------------ ∅, {a}, {b}, {a,b}, {a,c}, {b,c}, {a,c,b}, {c}, {d}, {a,d}, {b,d}, {a,b,d}, {a,c,d}, {b,c,d}, {a,c,b,d}, {c,d} ------------------------------------------------------------ 0 | 1 | ------------------------------------------------------------ 1 | 2 | ------------------------------------------------------------ 2 | 4 | ------------------------------------------------------------ 3 | 8 | ------------------------------------------------------------ 4 | 16 | ------------------------------------------------------------ n | 2`n | ------------------------------------------------------------ again, may use | Venn | diagram ------------------------------------------------------------ the | union | of sets #S1# and #S2#, denoted "#S1 + S2#", ------------------------------------------------------------ e.g.: #B + V := | {a,b,c,d,e,a,e,i,o,u} := {a,b,c,d,e,i,o,u} | # ------------------------------------------------------------ | programmers | , implemented operators for adding individual elts. to sets: ------------------------------------------------------------ e.g.: #{a,b,c} + ∅# i.e. #{a,b,c} + { } := | {a,b,c } | # ------------------------------------------------------------ Definition: The | intersection | of sets S1 and S2, denoted "S1 * S2", ------------------------------------------------------------ e.g.: #B * V# is | {a,e} | ------------------------------------------------------------ another e.g.: #V * E := | { } i.e. ∅ | # ------------------------------------------------------------ another e.g.: #B * ∅# i.e. #B * { } := | { } i.e. ∅ | # ------------------------------------------------------------ and #V * ∅ := | ∅ | # ------------------------------------------------------------ for the following example(s), let #W := V ∪ {y} := | {a,e,i,o,u,y} | # ------------------------------------------------------------ #W * | {a,b,c,d,e,x,y,z} | =?= | {a,e} | + | {y} | ?# ------------------------------------------------------------ # | {a,e,y} | =?= | {a,e,y} | ?# | yes | ------------------------------------------------------------ #B + | {y} | =?= | {a,b,c,d,e,i,o,u,y} | * | {a,b,c,d,e,x,y,z} | ?# ------------------------------------------------------------ # | {a,b,c,d,e} | =?= | {a,b,c,d,e,y} | ?# | yes | ------------------------------------------------------------ U Si := | {a,b,c,d,e,f} | ------------------------------------------------------------ I Si := | {c,d} | ------------------------------------------------------------ USi := | {1,2,3,...} | ------------------------------------------------------------ ISi := | {1} | ------------------------------------------------------------ | set-difference | , denoted "#S1 - S2#" or maybe "#S1 ∖ S2#" ("#S1 ∖ S2#") ------------------------------------------------------------ e.g. #B - V := | {b,c,d} | # ------------------------------------------------------------ then #T - V := | { } i.e. ∅ | # ------------------------------------------------------------ A set #@S@#'s | complement | , denoted "#@S@#" or "# @S@#" ------------------------------------------------------------ e.g. #V# a.k.a. # V# is | {b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} | ------------------------------------------------------------ another e.g. #B# a.k.a. # B := | {f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z} | # ------------------------------------------------------------ # B * V := | {f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} | # ------------------------------------------------------------ and from above #B + V := | {a,b,c,d,e,i,o,u} | # so 'coincidentally' ------------------------------------------------------------ # (B + V) := | {f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} | # ------------------------------------------------------------ set-properties such as that listed page | 124 | of our textbook ------------------------------------------------------------ so # ( V)# is everything not a consonant i.e. all the vowels again, | V | ------------------------------------------------------------ a pair of sets is called | disjoint | if their intersection is empty. ------------------------------------------------------------ a collection of sets {S_1,S_2,...,S_n} is called | pairwise disjoint | ------------------------------------------------------------ e.g.? #{B, V, E}# ? | no | ------------------------------------------------------------ e.g.? #{{r,g,b}, V, E}# ? | yes | ------------------------------------------------------------ e.g.? #{ {1}, {1,2}, {1,3}, {1,2,4}, {1,5}, {1,2,3,6}, ... }# ? | no | ------------------------------------------------------------ to | partition | a set means to separate it into a collection of its subsets ------------------------------------------------------------ which are supposed to be | pairwise disjoint | ------------------------------------------------------------ if M is | {f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w} | ------------------------------------------------------------ | {b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z} | ------------------------------------------------------------ e.g.: #(20,50) ?==? (50,20)# ? | no | ------------------------------------------------------------ e.g.: #(20,20) ?==? (20)# ? | no | ------------------------------------------------------------ a | tuple | (as in "quadruplet", "quintuplet", …) is a list of elements ------------------------------------------------------------ e.g. | pair | , | triple | , ... ------------------------------------------------------------ If S_1, S_2, S_3, ..., S_n are sets, then their | Cartesian product | , ------------------------------------------------------------ { (163,Dulimarta,easy), (163,Ferguson,easy), (163,Dulimarta,moderate), (163,Ferguson,moderate), (163,Dulimarta,hard), (163,Ferguson,hard) } ------------------------------------------------------------ e.g. #{t,f} x {t,f} := | { (t,t), (t,f), (f,t), (f,f) } | # ------------------------------------------------------------ | { (t,r), (t,g), (t,b), (f,r), (f,g), (f,b) } | ------------------------------------------------------------ | { (t,r), (t,g), (f,r), (f,g) } | ------------------------------------------------------------ | { (t,r), (f,r) } | ------------------------------------------------------------ | { } | ------------------------------------------------------------ | ∅ | ------------------------------------------------------------ ====================================================================