Professional Documents
Culture Documents
Advincula, MAT
SETS
Intuitively, a set is simply a collection of objects. More formally, we have the
following definition and notation:
Notation:
sets uppercase letters A, B, C, . . ., X, Y, Z
elements lowercase letters a, b, c, . . . , x, y, z
set groupings braces { …}
Based on our definition of a set, note that the order in which we present the
elements of a set is not important. Thus, the set A = {a, e, i, o, u} and the set B =
{u, i, o, a, e} actually describe the same set. Secondly, duplication of elements is
not allowed. For example, the set {1,3,4,4,7} can be rewritten as {1,3,4,7}.
1
Instructor: Mr. Advincula, MAT
The elements of the universal set will differ from application to application.
So if we speak of a set A = {a, e, i, o, u} then we may define U to be the set of all
letters of the English Alphabet. If we define A instead to be the set of students
enrolled in CS33 (Automata & Language Theory), the universal set with respect to
this set may be the entire set of students in the BS Computer Science curriculum in
CKC or it could be also be the set of students in CKC.
Example: Let
S = {set of students enrolled in CS 33}
B = {0,1,3,5,8}
Z = {x | x is an integer}
A = {a}
2
Instructor: Mr. Advincula, MAT
Sets B and C are equal in particular since the order in which the elements are
written does not matter. The set A is equal to both B and C since they have exactly
the same elements even if they described differently.
(A B) ↔ (x)(x A→ x B)
(A B) ↔ (A B) (A B)
Example: Let A = {A x Z and x 10)
B = {x x Z and x 10)
C = {1,2,3,4,5,6,7,8,9,10}
Note that
a) B A, C A, B C and C B.
b) A A, B B, and C C
c) B A, and C A
3
Instructor: Mr. Advincula, MAT
Remark: We can also define equality of two sets based on the concept of subsets:
(A = B) ↔ (A B) (B ) A)
===================================================
Exercise:
Prove the following theorem:
We can easily see that A B and that B C and therefore A C. Note that
actually A B (although B C) which still implies that A C.
Definition. A null or empty set, denoted by or {}, is the unique set that
does not contain any element.
Note that = 0 and that {}. In the latter, {} actually describes a
set that contains the empty set. Thus {} is not empty.
Example. The set A = {x x2-6x+9 = 0 and x < 0) is an empty set.
Definition. The power set of a set A, denoted by P(A), is the set of all
subsets of A or P(A) = {x x is a set and x A}.
Examples:
P(1,2,3) = {, {1}, {2}, {3}, {1,2}, {1,3},{2,3},{1,2,3}}
P() = {}
4
Instructor: Mr. Advincula, MAT
OPERATIONS ON SETS
Definition. The union of two sets A and B, denoted by A B, is made up of
those elements that belong to both A and B.
A B = {x (x A) (x B)}
A B = {x (x A) (x B)}
A B = {x (x A) (x B) (x (A B))}
A - B = {x (x A) (x B)}
A’ = U - A = {x (x U) (x A)}
5
Instructor: Mr. Advincula, MAT
Exercise:
Using the example above, what is the set define by:
1. A’ B
2. A’ B
3. (A B)’
In other words, two sets are disjoint if they do not have any element in
common. An example of this would be the sets A = {set of negative integers} and
B = {set of positive integers}. Likewise if we consider another set C = {0}, this is
also disjoint with respect to both sets A and B.
4. A (B C) = (A B) C Associative Laws
A (B C) = (A B) C
5. A (B C) = (A B) (A C) Distributive Laws
A (B C) = (A B) (A C)
6. A A = A Idempotency Laws
AA=A
7. A = A Identity Laws
AU=A
6
Instructor: Mr. Advincula, MAT
Let A, B U
Theorem: A - B = A B’
Theorem: A B = (A B) – (A B)
Theorem: A B = A B’
Theorem: (A – B) A (A B)
===================================================
Exercise:
Prove the following theorem:
RELATIONS
Before we formally define what a relation is, the following definition will be
necessary:
7
Instructor: Mr. Advincula, MAT
8
Instructor: Mr. Advincula, MAT
Exercise:
Let A = {0,1,2,3} and B = {2,3,4,5). What are sets described by the following:
1. R1 = {(x, y) x > y }
2. R2 = {(x, y) x + y = 3}
3. R3 = {(x, y) x + y 6}
4. R4 = {(x, y) x – y = -4 }
5. R5 = {(x, y) x = y }
PROPERTIES OF RELATIONS
9
Instructor: Mr. Advincula, MAT
Example: For this example and for the rest regarding properties of relations,
define F(R) = {a,b,c}.
Example:
R4 = {(a,b), (b,c), (b,b), (b,a), (c,b)} is symmetric.
R5 = {(a,a), (c,c))} is also symmetric.
But R6 = {(a,b), (b,c), (c,b)} is not symmetric.
Example:
R7 = {(a,b), (b,c)} is asymmetric.
R8 = {(a,b), (b,b)} is not asymmetric (nor symmetric).
10
Instructor: Mr. Advincula, MAT
Example:
R9 = {(a,a), (b,c)} is antisymmetric but not symmetric nor asymmetric.
R10 = {(a,b), (b,b), (b,a)} is not antisymmetric but is symmetric.
R11 = {(a,b), (a,c)} is not antisymmetric but is asymmetric.
Example:
R12 = {(a,a), (a,b), (b,c), (a,c)} is transitive.
R13 = {(a,b), (b,c), (b,b)} is not transitive since it does not contain the
ordered pair (a,c) .
R14 = {(a,b), (a,c)} is transitive.
R15 = {(a,a), (c,c)} is also transitive.
Example:
R16 = {(a,b), (b,c), (c,a)} is intransitive.
R17 = {(a,b), (b,c), (b,b)} is not intransitive nor transitive. Note that R17
becomes intransitive if remove the pair (b,b).
11
Instructor: Mr. Advincula, MAT
Solutions:
1. Reflexive, symmetric and not transitive.
R1 = {(1,1), (2,2), (3,3), (4,4), (1,2), (2,1), (2,3), (3,2), (3,4)}
===================================================
Exercises:
Given F(R) = {a, b, c}. Give examples of relations R having the following
properties:
1. Reflexive, symmetric and not transitive.
2. Reflexive, not symmetric and not transitive.
3. Reflexive, antisymmetric and not transitive.
4. Not reflexive, not antisymmetric but transitive and symmetric.
5. Not reflexive, not symmetric but transitive.
12
Instructor: Mr. Advincula, MAT
FUNCTIONS
Definition: Let A and B be non-empty sets. A function or mapping f from A
to B, is a relation from A to B in which every element of A appears exactly once as
the first coordinate of an ordered pair in the relation. If f is a function from set A to
set B, then we write f: A → B.
Note that from the definition, it can be understood that for a relation to be a
function, all the elements in the set A must appear as first coordinates in the
ordered pairs in the relation. In addition to this, each element in A must appear no
more than once as a first coordinate.
Example. We may visualize the relation {(1,c), (2,a), (3,a)} in Figure 1.1.
a
1
b
2 c
d
3
e
A B
Figure 1.1. The relation {(1,c), (2,a), (3,a)}.
13
Instructor: Mr. Advincula, MAT
Exercises:
Let A = {1,2,3,4,5} and B = {a,b,c,d,e}. Give two examples of:
Example. In the example given earlier, i.e., f = {(1,5), (3,4), (2,6), (4,5)},
the image of the element 1 (of the set A) under the function f is 5. conversely, the
element 1 is the pre-image of 5.
14
Instructor: Mr. Advincula, MAT
A B
Figure 1.2. 1-1 function
Note that if sets A and B are finite sets, A B must hold in order for
some function f: A → B to be a 1-1 function.
15
Instructor: Mr. Advincula, MAT
3) h = {(1,6), (1,5), (3,5)} is not a 1-1 function since the element 5 in the
set B appears twice as a second coordinate.
===================================================
Exercises:
Let A = {1,2,3} and B = {a,b,c,d}. Give two examples of:
1) 1-1 functions
2) Not 1-1 functions
A B
Figure 1.3 An onto function.
Note that if the sets A and B are finite sets, A B must hold in order for
some function f: A → B to be an onto function.
Examples. Let A = {1,2,3,4} and B = {5,6,7}
===============================================
Exercises:
Let A = {1,2,3} and B = {a,b,c,d}. Give two examples of:
1) onto functions
16
Instructor: Mr. Advincula, MAT
A B
Figure 1.4 A one-to-one correspondence.
Note that if the sets A and B are finite sets, A = B must hold in order for
some function f: A → B to be a one-to-one correspondence.
17
Instructor: Mr. Advincula, MAT
w3 = aaa if w = a
w3 = ababab if w = ab
hence, the string anbn denotes the string with n a’s followed by n b’s.
Definition. The set of all string, including the empty string, over the
alphabet is denoted by *.
18
Instructor: Mr. Advincula, MAT
Two strings over the same alphabet can be combined to form a third string
using the operation concatenation. The concatenation of the string x and y,
written as xy, is the string x followed by the string y. concatenation is obviously
associative, i.e., (wx)y = w(xy) for nay string w, x, and y.
A string v is a substring of string w if and only if there are strings (possibly
empty) x and y such that w = xvy. Clearly, x and y could both є, os every string is
a substring of itself. Taking x = w and v = y = є, we conclude that є is a substring
of every string.
The collection of symbols forms a string, while the collection of strings forms
a language. A language my be finite or infinite
Formal Grammars
Definition. A formal grammar is a four-tuple G = (V, T, P, S) where V is the
finite set of nonterminals, T is the set of termin0als, P is the set productions and S
is the start symbol (S V). Each production in P is of the form УAΨ → УwΨ in which
У, Ψ and w are possibly empty strings in (V T)* and A is a nonterminal.
19
Instructor: Mr. Advincula, MAT
The sequence w1, w2, …,wn is called the derivation of wn from w1 according to
G.
S Start Symbol
A S→A
aABC A → aABC
aabCBC A → abC
aabBCC CB → BC
aabbCC bB → bb
aabbcC bC → bc
aabbcc cC → cc
Note that the same language can be generated another grammar G = (V, T, P, S),
where V = {S, B}, T = {a, b, c} and the set of productions
{S → aBSc,
20
Instructor: Mr. Advincula, MAT
S → abc,
Ba → aB,
Bb → bb}.
S Start Symbol
aBSc S → aBSc
aBabcc S → abc
aaBbcc Ba → aB
aabbcc Bb → bb
Classes of Grammars
There are four types of grammars. These are:
1. Unrestricted Grammar (Type 0) – the definition of unrestricted grammar is
exactly similar to the definition of forma grammars.
A contracting rule is one that produces a new sentential form wi+1 shorter in
length that w1. For example the rule bC → b is a contracting rule. A grammar
containing at least one contracting rule is a contracting grammar.
21
Instructor: Mr. Advincula, MAT
22
Instructor: Mr. Advincula, MAT
Regular Expression
Let be an alphabet. The regular expression over and the sets that they
denote are defined recursively as follows:
1. ф is a regular expression and denotes the empty set;
2. is a regular expression and denotes the set of {};
3. for each a in , a is a regular expression and denotes the set {a};
4. If r and s are regular expressions denoting the language R and S,
respectively, then (r+s), rs, r* are regular expressions denoting the sets R
S, RS and R*, respectively.
23
Instructor: Mr. Advincula, MAT
The set of all strings of 0’1 and 1’s (denoted by (0+1)*) is a regular expression
because
0 is a regular expression
1 is a regular expression
0+1 is a regular expression
(0+1)* is a regular expression
The same arguments can be used for the other examples above.
Note that {0}*{0}{1} is a set of strings that ends with a 1 but with one or more
0’s before it. On the other hand, {1} is a string with only 1 (but also with no 0‘s
before it). Hence, if we the two sets, we end up with the set of strings that ends
in 1 but with zero or more 0’s before. That is,
24
Instructor: Mr. Advincula, MAT
Clearly, the string described by (0+1)* is the set of strings composed of any
number of 0’s and 1’s. then, the regular expression ends with a 1. This means that
the language represented by the regular expression is:
a*a describes the language composed of strings of a’s with at least one a. a*
ab is the set of strings composed at least one a ended by ab. a*ab is the set of
string composed any number of a’s followed by ab. Formally,
Note that a* is a subset of set (a+b). The same is true with b*. Hence, a* +
b* + (a+b)* = (a+b)*
(aa)*a – contains odd number of a’s with the shortest containing one a.
(aa)* – contains even number of a’s with the shortest containing no a.
25
Instructor: Mr. Advincula, MAT
Solution: (110 + 0)
Finite Automata
A finite automaton (figure below) is a restricted model of an actual computer.
It has a processor, but has no memory. Its input is in the form of a string that is
delivered to it on an input tape. It delivers no output except an indication of
whether the input is accepted or not. Hence, a finite automaton is basically a
language recognizer.
Input Tape
a b a b b b a a a b b
q0 q1
q5 q2
q4 q3
Finite Control
Finite Automaton
26
Instructor: Mr. Advincula, MAT
Before one can say that w is accepted or not, however, the string w need to
be read one symbol at a time and every time a symbol is read M changes state. The
intermediate states of M are what we call the sequence of configuration that
represents the status of the finite control (processor state), reading head and input
tape at successive moments. We represents a configuration by the pair (q,w) where
q is the current state of the DFA, w is the remaining string and the first symbol of w
is where the reading head is pointing.
The binary operation - will be defined to show the transition from one
configuration to another. Trhus if (q,w) and (q’,w’) are two configurations of M,
then (q,w) -(q’,w’) if and only if w = σ w’ for some σ and δ(q, σ) = q’.
Example. Consider the DFA M = (Q, , δ, q0, F) where Q = {q1, q2, q3},
= {0,1}, F = {q0}. The transition function δ may be presented in tabular form
(transition table),
inputs
states 0 1
q0 q2 q1
q1 q3 q0
q2 q0 q3
q3 q1 q2
27
Instructor: Mr. Advincula, MAT
q1
1 0
1 0
q0 q2
0 1
0 1
q3
Note that with the transition diagram, the five components of M may be
deduced. For example, given the transition diagram above, one can figure out that
Q = {q0, q1, q2, q3} and = {0,1}. The final states are represented by states in
two consecutive circles and the initial states is always q0. From now, we shall use
the transition diagram to represent finite automaton.
Suppose M is given the input w = 110101. Does M accept w or not? This can
be answered using the notations for configuration of FA’s.
(q0, 110101
- (q1, 10101)
- (q0, 0101)
- (q2, 101)
- (q3, 01)
- (q1, 1)
- (q0, )
b
Figure 2.3
28
Instructor: Mr. Advincula, MAT
Note that starting from q0, it can stop and accept immediately. Hence, the
empty string is part of the language. If the language is not empty, then it must
take an a and for it to be accepted by the DFA, it should take a b after a. Therefore,
every time an a is recognized it should be followed by a b to be accepted. Hence,
ab is in the language. Note that after ab it could be followed by another ab and
another and so on. Therefore, the language accepted by the DFA is
L = (ab)*
that is any number greater than or equal to 0 of ab’s.
a
q0 q1
d c
q2
Figure 2.4
Note that the difference from the previous example is the addition of another
state q2 that is connected to q0. Hence, the original language (ab)* is still being
recognized by this DFA. Similarly, the language (cd)* is also recognized by the DFA.
This time, however, the DFA can either go to q1 or q2 and repeat this as many as it
likes. Therefore, the language recognized by the DFA is
L = ((ab)* + (cd)*)*
29
Instructor: Mr. Advincula, MAT
Example. Describe the language recognized by the DFA whose transition diagram is
given in Figure 2.5.
a c
q0 q1 q2
b d
Figure 2.5
This time we extended the transition diagram from a non-final state. Again,
DFA recognized the language (ab)*. Note that after a it could go to c and d and
repeat this as many times as it likes. Therefore, the language recognized is
L = (a(ad)*b)*
1 1
0
q0 q1
30
Instructor: Mr. Advincula, MAT
(q0, 111011
- (q0, 11011)
- (q0, 1011)
- (q0, 011)
- (q1, 11)
- (q1, 1)
- (q1, )
Note that whatever the state goes to q1 for the string to be accepted it
should go back to q0. Hence, the set of strings described by the DFA above is
Exercise:
Construct a DFA for each of the following Languages
1. 0*(1+0*)*
2. (0+)(1+)
3. 01*0
4. (00+1)*
31
Instructor: Mr. Advincula, MAT
↔→γγΨΨУąαβ≠ßδβQσ
^
q0
New # 09269689542
32
Instructor: Mr. Advincula, MAT
33