sets. definitions (i) collection of elements such that: there are no duplicates there is no order...
TRANSCRIPT
Sets
Definitions (I)
Collection of elements such that:There are no duplicatesThere is no order
Special setsUniverse (U or E): all elements under considerationEmpty set ({ } or ): set with no elements Others: N, Z, R, etc.
Notation { }Enumeration: {1, 2, 3}, {1, 2, …}, {1, 2, … , 100}, etc.Set building: { x | P(x) } all elements in E that satisfy
property P (e.g., { x in N | x>5 x<10 } = {6, 7, 8, 9}
Definitions (II)
Element of:x A
Cardinality:|A| = size or number of elements in A
Set EqualityA = B iff A and B have the same elements
A = B xA xB
Subset/SupersetA B xA xB (subset or equal)
A B A B x(xB xA) (proper subset)
Set Operations: Intersection
A B {x | xA xB}
Example: {1, 2, 3} {2, 3, 4} = {2, 3}
Prove: A B ABy definition, A B A xAB xA
1. xA negate conclusion2. xAB premise3. xA xB def of 4. xA 3, simplification5. xA xA 1&4, conjunction6. F 5, contradiction
Proof by contradiction
A B
Set Operations: Union
A B {x | xA xB}
Example: {1, 2, 3} {2, 3, 4} = {1, 2, 3, 4}No duplicates!
Prove: A A BBy definition, A AB xA xA xB
1. xA premise2. xA xB 1, law of addition
A B
Set Operations: Difference
A – B {x | xA xB}
Example: {1, 2, 3} – {2, 3, 4} = {1}Remove elements of B from A
Prove: A – B ABy definition, A – B A xA–B xA
1. x A – B premise2. x A x B definition3. x A simplification
A B
Set Operations: Complement
~ A E – A {x | xE xA}
Example: ~{1, 2, 3} = {4} if E = {1, 2, 3, 4}
Prove: A ~A = A ~A =
A ~A A ~A set equality A ~A T is subset
of every set A ~A identity x A x ~A x def of and x A x E x A x def of ~ F x comm.,
contradict., dominat. T
A
Basic Set LawsSet Algebra Name
A ~A = EA ~A =
Complementation lawExclusion law
A E = AA = A
Identity laws
A E = EA =
Domination laws
A A = AA A = A
Idempotent laws
Duals: and E
Basic Set Identities (continued…)Set Algebra Name
~(~A) = A Double Compl.
A B = B A A B = B A
Commutative laws
(A B) C = A (B C) (A B) C = A (B C)
Associative laws
A (B C) = (A B) (A C) A (B C) = (A B) (A C)
Distributive laws
~ (A B) = ~A ~B~ (A B) = ~A ~B
De Morgan’s laws
Example: Set LawsAbsorption
A (A B) = AA (A B) = A
Venn Diagram “Proof”Direct Proof
A (A B)= (A ) (A B) ident.= A ( B) distrib.= A
dominat.= A
ident.
A B
Practice ExercisesPE1
Prove that if R is a subset of S and S is a subset of T, then R is a subset of T.
------------------
PE2
Prove De Morgan's law for sets (do not use a Venn diagram): ~ (A B) = ~A ~B
Tuples
Collection of elements, such that:All elements are ordered
Notation: ( )(x1, x2, …, xn)
Tuples of 2 elements are known as pairsTypically, elements are taken from known sets
x females, y males(Mary, Jim) – might mean: Mary and Jim are a married couple
x people, y cars(Mary, red sports car17) – might mean: Mary owns red sports car17
x, y, z integers(3, 4, 7) – might mean: 3 + 4 = 7
Cartesian/Cross Product
A1 … An = {(x1, …, xn) | xA1 … xnAn}
Example: A = {1, 2}, B = {a, b, c}A B = {(1, a), (1, b), (1, c), (2, a), (2, b),
(2, c)}
A = {1, 2}, B = {a, b, c}, C = {, }A B C = {(1,a,), (1,a,), (1,b,), (1,b,),
(1,c,), (1,c,), (2,a,), (2,a,), (2,b,), (2,b,), (2,c,), (2,c,)} |A1 … An| = |A1| … |An|
Can get large:A = set of students at BYU (30,000)B = set of BYU student addresses (10,000)C = set of BYU student phone#’s (60,000)|A| |B| |C| = 1.8 1013
RelationsRelation
Subset of the cross product
Examples:A = {1, 2} & B = {a, b, c}
R = {(1, a), (2, b), (2, c)}A = {1, 2} & B = {a, b, c} & C = {, }
R = {(1, a, ), (2, c, )}Marriage: subset of the cross product of
males and females
If 2 sets, the relation is binary
Functions
A function is a special kind of binary relation
A binary relation f A B is a function if for each a A there is a unique b B
Function Definition
1
2
3
α
β
γ
x
y
NOT Functions
1
2
3
α
β
γ
f = {(1, α), (2, β)} “For each” violated
Some x’s do not have corresponding y’s
x
y
NOT Functions
Uniqueness violated for some x’s
x
y
1
2
3
α
β
γ
f = {(1, α), (2, β), (3, β), (3, γ)} uniqueness violated for 3 appears twice
Functionswith N-Dimensional
Domains An (n+1)-ary relation f A1 A2 …
An B is a function if for each < a1, a2, …, an> A1 A2 … An there is a unique b B.
α
β
γ
<1,1>
<1,2>
<1,3>
We can use various notation for functions: for f = {(1, α),(2, β),(3, β)}
Notation for Functions
Notation (x, y) f f : x→y y = f(x)
Example (2, β) f f : 2→β β = f(2)
• In the notation, x is the argument or preimage and y is the image.
• For functions with n-ary domains, use <x0, x1, …, xn> in place of x.
Function Domain and Range
f : A → BA is the domain space
same as the domain (since all elements participate)dom f, dom(f), or domain(f)
B is the range spacemay or may not be the same as the range, which is:
{y | x(y=f(x))}All rhs values in pairs (all that get “hit”)
Bf
ran f, ran(f), range(f)
f : D1 D2 … Dn → Z
f : Dn → Z (when all domains are the same)
Remove the requirement that each a A must participate. Retain the uniqueness requirement.
Partial Functions
Partial Function:
α
β
γ
f = {(<1,2>, β),(<1,3>, β),(<1,3>, γ)} <1,3> not unique
<1,1>
<1,2>
<1,3>
α
β
γ
<1,1>
<1,2>
<1,3>
NOT a Partial Function:
α
β
γ
<1,1>
<1,2>
<1,3>
Partial Function: (A Total Function is also a Partial Function.)
Identity FunctionIA : A → A
IA = {(x, x) | x A}
Constant FunctionC : A → BC = {(x, c) | x A c B }Often A and B are the same
C : A → AC= {(x, c) | x A c A}
Special Functions
Composition of Functions
Composition is written “°”
Range space of f = domain space of g
a
c
1
2
4
fg
b
α
β3
f(a) = 2 g(2) = α g(f(a)) = α
g°f(a) = α
f(b) = 2 g(2) = α g(f(b)) = α
g°f(b) = α
f(c) = 4 g(4) = β g(f(c)) = β
g°f(c) = β
Injection: “one-to-one” or “1-1”xy(f(x) = f(y) x = y)For f : A → B, the elements in B are “hit” at most once
Injection
a
b
d
1
2
3
c
Injective
a
b
d
1
2
3
c
NOT Injective
x
y
x
y
Surjection: “onto”yx(y = f(x))For f : A → B, the elements in B are all “hit” at least once
Surjection
1
2
4
a
b
c3
Surjective NOT Surjective
x
y
x
y
1
2
4
a
b
c3
{ not “hit”
Bijection: “one-to-one and onto” or “1-1 correspondence”xy(f(x) = f(y) x = y) yx(y = f(x))For f : A → B, every B element is “hit” once and only once
Bijection
1
2
a
b
c3
Bijective NOT Bijective
x
y
x
y
1
2
4
a
b
c3
NOT Surjective
NOT injective
Notes on Bijection
1. |A| = |B|An “extra” B cannot be “hit” (not a surjection)
An “extra” A requires that at least one B must be “hit” twice (not an injection)
2. If f is a bijection, swapping the elements of the ordered pairs is a function
Called the inverse
Denoted f-1
Is also a bijection
f-1(f(x)) is the identity function, i.e. f-1(f(x)) = x.
Practice ExercisesPE1
If A={a,b,c,d}, are the following functions from A to A injective, surjective or bijective?
{(d, a), (d, c), (b, b), (b, d)}
{(a, b), (b, b), (c, d), (d, d)}
------------------
PE2
If f(x)=2x+3 and g(x)=x-3, what is g°f?
------------------
PE3
Which is the larger set?
E (even numbers) vs. O (odd numbers)
N (natural numbers) vs. Z (integers)
N (natural numbers) vs. [0,1] (real numbers between 0 and 1)
Which is bigger? N or Z?
f(x) =x odd: (x+1)/−2
x even: x/2
y negative: −2x−1
y positive: 2xg(y) =
{{
x y 0 0 1 −1 2 1 3 −2 4 2
Since g = f−1, there is a bijection from N to Z and thus |N| = |Z|
Which is bigger? N or [0,1]?
Assume |N| = |[0,1]|, then there exists a bijection, e.g.,
1 0.34234…2 0.34987… diagonalization3 0.00040…
But now, there exists a number in [0,1] such that d1 = not 3, d2 = not 4, d3 = not 0, etc. Hence, not surjective and thus not bijective
ALL THAT THE FATHER HATH
A Functional “Proof”
Language
Power Set
Set of all subsets of a set AA = {1,2}P(A) = 2A = { {}, {1}, {2}, {1,2} }
Each element of A is either present (1) or not present (0)Treat the elements of A as a sequence (e.g., A={a,b,c,d})
Use bit-string representation to say which elements are present (e.g., 0110 means {b,c})
Can represent all subsets of A, from = 0000 to A = 1111
Number of subsets in power set|2A| = 2 · 2 · … · 2 (|A| times) = 2|A|
Motivates the notation 2A for the power set
Bit-String Operations
With bit string representationsSet intersection: = pairwise Set union: = pairwise Set complement: ~ = bit complementSet minus: – = mask out using 1’s = complement 2nd operand
and do pairwise
E.g. using {a,b,c,d}1011 1101 = 1001 i.e. {a,c,d} {a,b,d} = {a,d}1011 1101 = 1111 i.e. {a,c,d} {a,b,d} = {a,b,c,d}~1011 = 0100 i.e. ~{a,c,d} = {b}1010 – 1100 = 0010 i.e. {a,c} – {a,b} = {c}
Practice ExercisesPE1
What is the power set of {a, 1, x, 2}?
------------------
PE2
What is the power set of (i.e., the empty set)?
------------------
PE3
What is the power set of { } (i.e., the set containing the empty set)?
------------------
PE4
What is the power set of { a, { } }?
Language
Let V be a set of symbols, known as an alphabet or a vocabulary
A string is any finite sequence of symbols from V
Strings have length
Vn denotes the set of all strings of length n
V* denotes the set of all strings, or sentences, over V
A language L is a subset of V*, i.e., L V*
Programming languageSet of all possible programs (valid, very long string)
Language Representation
• Finite– Enumerate all sentences
• Infinite language– Cannot be specified by enumeration– Use a generative device, i.e., a grammar
• Specifies the set of all legal sentences• Defined recursively (or inductively)