You are on page 1of 21

Sets, Relations, and

Languages
Prepared by: Prof.

Manuel C. Cabido
SET
► SYMBOL SYMBOL NAME
MEANING / DEFINITION a collection of EXAMPLE
► {} set
elements so that A = {3,7,9,14}, B =
► | such that
objects that belong to set A and set B A = { x | x e , x <0}
► APB intersection
objects that belong to set A or set B A PI B = {9,14}
► AUB union
A U B = {3,7,9,14,28}
► AQB subset
A is a subset of B. set A is included in set B. {9,14,28} Q {9,14,28}
► AcB proper subset / ,28}
strict subset A is a subset of B, but A is not equal to B. {9,14}
► A£B not subset
set A is not a subset of set B {9,66} £ {9,14,28}
► A^B superset
A is a superset of B. set A includes set B {9,14,28} ^ {9,
► A=>B proper superset
/ strict superset A is a superset of B, but B is not equal to A.
{9,14,28 = {9,14}
► }
set A is not a superset of set B {9,14,28} 2 {9,66}
► A2B not superset
SET
SYMBOL
SYMBOL NAME MEANING / DEFINITION EXAMPLE
► 2A
power set all subsets of A
► P(A)
power set all subsets of A
► P(A)
power set all subsets of A
► A=B B={3,9,14},
equality both sets have the
► Ac
same members A={3,9,14},
► A’
complement all the objects
► A-B
that do not belong to set A

complement all the objects

that do not belong to set A

Set difference {x | x e A; x £

B}
Relations and Functions

► Let A = {a,b} and B = {1,2,3}

► Ordered Pair

► The ordered pair of of a and 1 is (a,1) € A x B with components a e A and 1 e B

► (a,1) * {a,1}
Cartesian Product

A x B = {(a,b) | a e A and b e B}
= {(a,1), (a,2), (a,3), (b,1), (b,2), (b,3)}

A binary Relation on two sets A and B is a subset of



AxB R = {(a,1),(b,2), (a,2)} c AxB S = { (a,2),(b,2)} c

AxB

Functions and Relations

► Let A = {a,b} and B = {1,2}

► The cartesian product AxB = {(a,1),(a,2),(b,1),(b,2)}

► = {(x,y) | xsA and ysB}

► Relation is a subset of the cartesian product of sets.

► Ex: R = {(a,1),(b,2)} c AxB


Function is a binary relation on AxB such that for every element asA, there is
► exactly one ordered pair in R with first component a.

► Ex:

► R = {(a,1),(a,2),(b,2)} ; (a,1) and (a,2) have the same first component a F =

► {(a,1),(b,2)}
Graphs of Relations
► Given a set A = {a,b} , the cartesian product AxA = {(a,a),(a,b),(b,a),(b,b)}
► Let R = {(a,a),(a,b),(b,b)} be a relation in AxA

► R can be represented by a directed graph with each element in A represented by a


small circle which is called a node in the graph.
► The ordered pair (a,b) £ AxA is represented by an arrow from node a to node b.
The arrows are the edges of the directed graph.

► Let R = {(a,a),(a,b),(b,b)} and S = {(a,a),(a,b),(b,a),(b,b)}


► The graph of R and S are shown below:

1 R S
Equivalence Relation
► Let A be a set.

► Def. A relation R Q AxA is reflexive if (a,a) £ R for each a £ A.

► Def. A relation R Q AxA is symmetric if (b,a) £ R whenever (a,b) £ R.


► Def. A relation R Q AxA is anti-symmetric if whenever (a,b) £ R and a and b are
distinct, then (b,a) £ R.
► Def. A relation R Q AxA is transitive if whenever (a,b) £ R and (b,c) £ R, then
(a,c) £ R.

► Def. A relation R Q AxA is an equivalence relation if it is reflexive, symmetric and

1
transitive.
► Def. Let R be an equivalence relation on a set A. The equivalence class of

a £ A is the set of all elements in A that are related to a £ A and is denoted by ►

[a] = { b| (a,b) £ R }
Graphs of Reflexive, Symmetric and
Transitive Relations

R is not an equivalence relation S is an

equivalence relation

► S is reflexive; V a £ A, (a,a) £ S

► S is symmetric; V (a,b) £ S, (b,a) £ S

► S is transitive; (a,b) and (b,a) £ S then (a,a) £ S

R
Closures
► Let A = {a,b,c,d}. Consider two directed graphs R and R* shown below. R*
contains R; also , R* is reflexive and transitive. Thus, R* is the reflexive
transitive closure of R.

► Def. Let R Q AxA be the directed graph defined on set A. The reflexive
transitive closure of R is the relation

► R* = {(a,b)| a,b £ A and there is a path from a to b in R}


Closure Properties and Closure
► Def. Let D be a set, let n>0, and let RcD n+1 be a (n+1)-nary relation on D. Then a
subset B of D is said to be closed under R if bn+1 £ B whenever b1;b2,...,bn £ B and
(b1;b2,...,bn) £ R. Any property of the form “the set B is closed under relations R 1,
R1, R2,..., Rm” is called the closure property of B.
► Example:

► Let N+ be the set of all positive integers. Let plus ={(a,b)| a,b £ N+} Q N+xN+ be
a binary relation on set N+. The subset M of N+ is said to be closed under plus if
a+b £ M whenever a,b £ M and (a,b) £ plus.
► Thus, the set of all positive integers N+ is closed under the relation + because for
any number a,b £ N+ , a+b £ N+ .
Alphabets and Languages

► i is an alphabet comprising a finite set of symbol

► Ex. I = {a,b,...,z}

► I = {0,1}

► A string over an alphabet I is a finite sequence of symbols from I.

► Ex. aabca, 0001011

► w=aabcde

► The empty string is denoted by the symbol £.

► I* is the set of all strings, including the empty string over the alphabet I.

► The length of a string is its length as a sequence (number of symbols)

► Ex. |£| = 0; |0001011| = 7 ; |abbcddde| = 8


Alphabets and Languages
► Concatenation.
► Let x and y be strings over the alphabet I. The concatenation of string x and y is the string
xy; string x is followed by string y; formally w = xy.
► Concatenation is associative. For strings w, x, and y : w(xy) = (wx)y

► Substring.
► A string v is a substring of string w if and only if there are strings x and y such that
w=xvy. For the empty sting €, €v = v€ for some string v.

► If w=xv for some string x, then v is a suffix of w.

i
► If w=vx for some string x, then v is a prefix of w.

► For each string w and each natural number I, the string w1' is defined as

► w0 = e

► W1^1 = w’w for each i>0


Alphabets and Languages

► Reverse of a string
► The reversal of a string w, denoted by wR , is the string “spelled backward”

► Ex. reverseR = esrever

► Formal Definition
► 1. If w is a string of length 0, then wR = w = €

► 2. If w is a string of length n+1>0, then w = ua for some a £ I, and wR = auR-

► Language
► Any set of string over an alphabet I is called a language.

► Any subset of L of I* is a language. L ^ I*

► Formal Definition of a language L ^ I*

► L = {w £ I* : w has property P }
Languages
► Since languages are sets, they can be combined by the set operations:
► 1. Union L 1 U L2

► 2. Intersection L 1 H L2

► 3. Set Difference L1 - L2

► 4. Concatenation L 1 L2

► If L1 and L2 are languages over I, their concatenation is L= L 1L2 where

► L = {w £ I* : w = xy for some x £ L 1 and y £ L2}


► Ex. Let L1 = {0,1,01,10,00,11,0011,1100,...} and L 2 = {a,b,aa,bb,aaa,bbb,...}
► w = 10aaa £ L1L2
Kleene Star
► Let L be a language. The Kleene Star of L is denoted by L*.

► L* is the set of all strings obtained by concatenating zero or more strings from L.

► Formally
► L* = { w £ I* : w = w-,w2...wk for some k > 0 and some w-,,w2,...,wk £ L }

Ex.

Let L = {01,1,100} then

10010111 £ L* since 100,1,01,1,1 £ L

Let I = {a}

L0 = {£}

L1 = {a}

L2 = {aa}

► L = {aa...a} n number of a.
n
The Language L+

► Let L Q I* be a language on alphabet I.


L+ is the language

L+ = {w £ I* : w = w,w2...wk for some k > 1 and some w1,w2,^,wk £ L}

L+ can be considered as the closure of L under the function of concatenation.

L+ is the smallest language that includes L and all strings that are concatenation of
► strings in L.
Regular Expression

► The REGULAR EXPRESSION over the alphabet I are all strings over the

► Alphabet I U {(,),0,U,*} that can be obtained as follows.

► 1. 0 and each member of 2 is a regular expression.

► 2. If a and B are regular expression, then so is (aB).

► 3. If a and B are regular expression, then so is (aUB).

► 4. If a is a regular expression, then so is a*.


Regular Language
► Every regular expression represents a language, according to the interpretation of the
symbols U and * as set union and Kleene Star, and concatenation.

► If a is a regular expression, then f( a) is a language represented by a.


► The function f is defined as follows:

► 1. /(0) = 0, and /(a) = {a} for each a e I

► 2. If a and p are regular expressions, then f(ap) = /(a)/(P) .

► 3. If a and p are regular expressions, then f( aUP) = /(a)U/(P) .

► 4. If a is a regular expression, then f(a *) = f(a )*


Regular Languages

► Ex. What is /(((allb)*)a))?

► We have the following:

► /(((aUb)*)a)) =/((aUb)*)/(a) by (2)

► = /((aUb)*) {a} by (1)

► = /((aUb))* {a} by (4)

► = (/(a) U /(b))* {a} by (3)

► = ({a} U {b})* {a} by (1) twice

= (a,bj*{aj

= {w e {a,b}* : w ends with an a}
Regular Languages
► The class of regular languages over an alphabet I is defined to consist of all languages
L such that L = f( a) for some regular expression a over I.
► Regular languages are all languages that can be described by a regular expression,
► The class of regular languages over I is precisely the closure of the set of languages
► {{5} : 5 e 2 } U {0}
► with respect to the functions of union, concatenation and Kleene Star.

You might also like