0% found this document useful (0 votes)
11 views34 pages

Lect 02

Uploaded by

1026884611shc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views34 pages

Lect 02

Uploaded by

1026884611shc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

XJCO2321 Formal Languages and

Finite Automata

02: Languages & Mathematical


Notations
Today’s Objectives
• To define a language in the context of
Finite Languages and Finite Automata
(FLFA)
• To introduce basic mathematical notations
we expect to use in this module

Based on slides by Costas Busch 1


Language: a set of strings

String: a sequence of symbols


from some alphabet

Example:
Strings: cat, dog, house
Language: {cat, dog, house}
Alphabet: Σ = a,b,c,…,z

Based on slides by Costas Busch 2


Languages are used to describe
computation problems:

PRIMES = {2,3,5,7,11,13,17,}

EVEN = {0,2,4,6,}

Alphabet:  = {0,1,2,,9}

Based on slides by Costas Busch 3


Computation is translated to set membership

Example computation problem:


Is number x prime?

Equivalent set membership problem:

x  PRIMES = {2,3,5, 7,11,13,17, }?

Based on slides by Costas Busch 4


Alphabets and Strings
An alphabet is a set of symbols
Example Alphabet:  = a, b
A string is a sequence of
symbols from the alphabet
String variables
a
u = ab
ab
Example Strings v = bbbaaa
abba w = abba
aaabbbaabab
Based on slides by Costas Busch 5
Decimal numbers alphabet  = {0,1,2,,9}

102345 567463386

Binary numbers alphabet  = {0,1}


100010001 101101111

Based on slides by Costas Busch 6


Unary numbers alphabet  = {1}

Unary number: 1 11 111 1111 11111


Decimal number: 1 2 3 4 5

Based on slides by Costas Busch 7


String Operations

w = a1a2  an abba
v = b1b2 bm bbbaaa

Concatenation

wv = a1a2  anb1b2 bm abbabbbaaa

Based on slides by Costas Busch 8


w = a1a2 an ababaaabbb

Reverse

w = an  a2 a1
R
bbbaaababa

Based on slides by Costas Busch 9


String Length
w = a1a2 an
Length: w =n

Examples: abba = 4
aa = 2
a =1
Based on slides by Costas Busch 10
Length of Concatenation

uv = u + v

Example: u = aab, u = 3
v = abaab, v = 5

uv = aababaab = 8
uv = u + v = 3 + 5 = 8
Based on slides by Costas Busch 11
Empty String
A string with no letters is denoted:  or 
Acts as a neutral element
Observations:  = 0

 w = w = w

 abba = abba = ab ba = abba


Based on slides by Costas Busch 12
Substring
Substring of string:
a subsequence of consecutive characters

String Substring
abbab ab
abbab abba
abbab b
abbab bbab
Based on slides by Costas Busch 13
Prefix and Suffix
string abbab
Prefixes Suffixes
 abbab w = uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab 
Based on slides by Costas Busch 14
Exponent Operation
w = ww
n


w
n

Example: (abba ) = abbaabba


2

Definition: w =
0

(abba ) 0
=
Based on slides by Costas Busch 15
The * (Kleene star) Operation
 *
: the set of all possible strings from
alphabet 

 = a, b
 =  , a, b, aa, ab, ba, bb, aaa, aab,
*

Based on slides by Costas Busch 16


The + Operation
+ : the set of all possible strings from

alphabet  except 

 = a, b
 =  , a, b, aa, ab, ba, bb, aaa, aab,
*

 =  −  
+ *

+
 = a, b, aa, ab, ba, bb, aaa, aab,
Based on slides by Costas Busch 17
Languages
A language over alphabet 
is any subset of *

Example:  = a, b
 =  , a, b, aa, ab, ba, bb, aaa,
*

Languages: {}
 
a, aa, aab
{ , abba, baba, aa, ab, aaaaaa}
Based on slides by Costas Busch 18
More Language Examples

Alphabet  = {a, b}
An infinite language L = {a b : n  0}
n n

 bbabb  L
ab abb  L
L
aabb
aaaaabbbbb
Based on slides by Costas Busch 19
Prime numbers
Numbers divisible by 1 and itself

Alphabet  = {0,1,2,,9}
Language:

PRIMES = {x : x   and x is prime} *

PRIMES = {2,3,5,7,11,13,17,}

Based on slides by Costas Busch 20


Even and odd numbers

Alphabet  = {0,1,2,,9}
Languages:
EVEN = {x : x   and x is even} *

EVEN = {0,2,4,6,}

ODD = {x : x   and x is odd} *

ODD = {1,3,5,7,}
Based on slides by Costas Busch 21
Addition (of unary numbers)

Alphabet  = {1,+, =}
Language:
ADDITION = {x + y = z : x = 1 ,y = 1 ,z = 1 , n m k

n + m = k , n  1, m  1}
11 + 111 = 11111 ADDITION
111 + 111 = 111 ADDITION
ADDITION = {1 + 1 = 11,1 + 11 = 111,11 + 1 = 111,11 + 11 = 1111, ...}
Based on slides by Costas Busch 22
Squares (of unary numbers)

Alphabet  = {1, # }
Language:
SQUARES = {x#y : x = 1 ,y = 1 , m = n } n m 2

11#1111 SQUARES
111#1111 SQUARES
SQUARES = {1#1,11#1111,111#111111111, ...}
Based on slides by Costas Busch 23
Two special languages

Language with
Empty language empty string
{ } or  { }
Size of a language (number of elements):
| {} |= 0
|  |= 1
| a, aa, ab|= 3
| { , aa, bb, abba, baba} |= 5
Based on slides by Costas Busch 24
Note that:

Sets  = { }  { }

Set size {} =  = 0

Set size { } = 1

String length  =0
Based on slides by Costas Busch 25
Operations on Languages
The usual set operations:

a, ab, aaaa bb, ab = {a, ab, bb, aaaa} union
a, ab, aaaa bb, ab = {ab} intersecti on
a, ab, aaaa− bb, ab = a, aaaa difference

Complement: L = −L
*

a, ba =  , b, aa, ab, bb, aaa,


Based on slides by Costas Busch 26
Reverse

Definition: L = {w : w  L}
R R

Examples: ab, aab, baba = ba, baa, abab


R

L = {a b : n  0}
n n

L = {b a : n  0}
R n n

Based on slides by Costas Busch 27


Concatenation

Definition: L1L2 = xy : x  L1, y  L2 

Example: a, ab, bab, aa

= ab, aaa, abb, abaa, bab, baaa

Based on slides by Costas Busch 28


Another Operation
Definition: L =
n

LL L
n

a, b = a, ba, ba, b =


3

aaa, aab, aba, abb, baa, bab, bba, bbb


Special case: L =  
0

a, bba, aaa =  


0

Based on slides by Costas Busch 29


Example

L = {a b : n  0}
n n

L = {a b a b : n, m  0}
2 n n m m

2
aabbaaabbb L

Based on slides by Costas Busch 30


Star-Closure (Kleene *)
All strings that can be constructed from L

Definition: L = L  L  L 
* 0 1 2

Example:
 , L 0

a, bb,  L1
 
a, bb = 
*
 2
 aa , abb, bba , bbbb,  L
aaa, aabb, abba, abbbb,  L3
Based on slides by Costas Busch 31
Positive Closure

+
Definition: L = L  L  L 
1 2 3

Note that: L = L  L
* 0 +

a, bb, L
1

+   2
a, bb = aa, abb, bba, bbbb, L
aaa, aabb, abba, abbbb, L3
 
Based on slides by Costas Busch 32
Follow-Up / Further Reading
• Read Chapter 0.1, 0.2, 0.3, and 0.4 of
Sipser

Based on slides by Costas Busch 33

You might also like