Chapter 1
Chapter 1
highly flexible
quite powerful
Disadvantages
vague
imprecise
ambiguous
Formal Languages
developed with strict rules
predefined syntax and semantics
precise
unambiguous
Derivation tree for the simple sentence: A person entered the room.
Operation on sets
Let A and B be two sets and U the universal set
Subset: A C B
Proper subset: A c B
Equality: A = B
Union: A U B
Intersection: A ∩ B
Set difference: A \ B or A – B
Complement: A’ or A bar
Properties
Let A, B, C be sets and U the universal set
Associative property: A U (B U C) = ( A U B) U C
Commutative property: A U B = B U A
Definitions:
Let A be a set. The cardinality of a set A is a measure
of the "number of elements of the set" and denoted by
|A| or #(A).
The set of all subsets of a set A is called the power set
of A, denoted by 2A.
October 14, 2024 Formal Language Theory 10
Set theory and relations: cont’d
Definition:
Let S be a set. A collection {A1, A2, …, An} of subsets of S is called a partition
if Ai ∩ Aj = Ø, i≠j and S = A1 U A2 U … U An.
Ex. S = {1, 2, …, 10}
Let A1 ={1, 3, 5, 7, 9} and A2 ={2, 4, 6, 8, 10}, then {A1 , A2} = {{1, 3, 5, 7, 9},{2, 4,
6, 8, 10}} is a partition of S.
Q. Find other partitions of S
Countability
A finite set is countable
If the elements of set A can be associated with 1st,2nd, …, ith, … elements of
the set of Natural Numbers, then A is countable.
Note: that in this case A may not be finite.
Ex.
1. N = {1, 2, …, ith, …} is countable
2. Z = {…, -3, -2, -1, 0, 1, 2, 3, …} = {0, 1, -1, 2, -2, 3, -3, …} is countable
3. [0, 3] is uncountable (not countable)
Relations
Definition: A relation R is a set of ordered pairs of elements
in S. (i.e is a subset of S X S)
Notation: (x, y) Є R or x R y
Properties of relations
Let R be a relation on a set A, then
a. R is reflexive if for all a Є A, a R a or (a, a) Є R
b. R is symmetric if a R b => b R a
c. R is transitive if a R b and b R c => a R c, for all a, b, c Є R
d. R is an equivalence relation if (a), (b) and (c) above hold.
Let R be an equivalence relation on set A and let a Є A, then
the equivalence class of a, denoted by [a], is defined as:
[a] = {b ЄA | a R b}
Examples:
Check whether the following relations are
reflexive, symmetric, and transitive
Functions
Definition: A function f from a set X to a set Y is a rule that
associates to every element x in X a unique element in Y,
which is denoted by f(x).
The element f(x) is called the image of x under f.
The function is denoted by f: X Y
Functions can be defined in the following two ways:
1. By giving the images of all elements of X
Ex. f:{1, 2, 3, 4} {2, 4, 6} can be defined by
f(1) = 2, f(2) = 4, f(3) = 6, f(4) = 6
2. By a computational rule which computes f(x) once x is given
Ex. f:R R can be defined by f(x) = x2 + 2x + 1, x Є R (R =
the set of all real numbers)
Let f: A B be a function
1. f is an into function if Rf C B
2. f is an onto function if Rf = B
3. f is a one-to-one function
if for x1 & x2 Є A, x1 ≠ x2 => f(x1) ≠ f(x2)
4. f is bijective (one-to-one correspondence) if it satisfies (2)
and (3) above.
Ex. f:Z Z is given by f(x) = 2x
Show that f is one-to-one but not onto.
Graphs
Definition: A graph (undirected graph) consists
of:
a. A non-empty set v called the set of vertices,
b. A set E called the set of edges, and
c. A map Φ (phi) which assigns to every edge a unique
unordered pair of vertices
e1 e6
v2 e1 = {v1, v2}
v1 e2 = {v1, v3}
e2 e3 e5 …
v3 v4 e6 = {v2, v2} (a self loop)
e4
e1
v2 e1 = (v1, v2)
v1 v1 : a predecessor of v2
e2 e3 e5 v2 : a successor of v1
v3 e4 v4
Trees
Definition: A graph (directed or undirected) is
called a tree if it is connected and has no circuits.
Q. Are the previous two graphs trees?
Properties of trees:
In a tree there is one and only one path between every
pair of vertices (nodes)
A tree with n vertices has n-1 edges
A leaf in a tree can be defined as a vertex of degree one
Vertices other than leaves are called internal vertices
Ex. ∑ = {0, 1} => ∑* = {λ, 0, 1, 01, 00, 11, 111, 0101, 0000, …}
∑i is a set of strings of length i, i = 0, 1, 2, …
*
Let x Є ∑ and /x/ = n, then x = a1a2…an, ai Є ∑
Operations on strings
Concatenation operation
Let x, y Є ∑* and /x/ = n and /y/ = m. Then xy,
concatenation of x and y, = a1a2…anb1b2…bm, ai, bi Є ∑
The set ∑* has an identity element λ with respect to the
binary operation of concatenation.
Ex. x Є ∑* , xλ = λx = x
∑* has left and right cancellation
For x, y, z Є ∑*,
zx = zy => x = y (left cancellation)
xz = yz => x = y (right cancellation)
For x, y Є ∑* , we have /xy/ = /x/ + /y/
Transpose operation
For any x in ∑* and a in ∑, (xa)T = a(x)T
Ex. (aaabab)T = babaaa
A palindrome of even length can be obtained by the
concatenation of a string and its transpose.
A prefix of a string is a substring of leading symbols of that
string.
w is a prefix of y if there exists y’ in ∑* such that y=wy’
Ex. y = 123, list all prefixes of y.
A suffix of a string is a substring of trailing symbols of that
string.
w is a prefix of y if there exists y’ in ∑* such that y=y’w
Ex. y = 123, list all suffixes of y.