Professional Documents
Culture Documents
Chapter One - Introduction
Chapter One - Introduction
Chapter One - Introduction
1
Introduction to Automata and Formal Language
CHAPTER ONE
2
Introduction
Computer science has two major components
I. The fundamental ideas and models underlying computing
II. Engineering techniques for the design of computing system (both
hardware and software)
Automata and formal language is in the first category
Automata is an abstract model of a digital computer.
3
Introduction
Automata theory: is the study of abstract machine (a theoretical model of a
computer hardware and software) and problems they are able to solve.
Language is a system suitable for the expression of certain ideas, facts or concepts,
including a set of symbols and rules of formation.
There are two types of languages
Natural language
Formal language: developed by applying strict rules (E.g.: programming languages)
4
Introduction
Why we study Automata and formal language?
To get concepts and principles that help us understand the general
nature of the discipline.
To construct abstract models of a computer
It has immediate and important applications in
Compiler design
Programming languages
Software engineering
Artificial intelligence
etc
5
Why finite Automata?
The applications of Finite Automata are as follows −
Design of the lexical analysis of a compiler
Recognize the pattern by using regular expressions
Helpful in text editors
Used for spell checkers
Implementation of stack applications
Used in the genetic programming implementation
Used for neural networks implementation
Used in Robotics Applications
Used in the implementation of artificial intelligence
6
Symbol, alphabet and String
Symbol: an arbitrary datum which has some meaning to or effect on
the machine.
Letters and digits are examples of frequently used symbols. S= {a, b, 0, 2, 7, ^, -, …., }
Alphabet (Σ): is a finite set of symbols.
Example:- Σ = {a, b, c, d}, Σ = {0, 1}
String ( or Word): is a finite sequence of symbols.
Example:- W = abc, V = 123, Z = 01010110
Length of a string W, denoted by |W| , is the number of symbols
composing the string.
Example: if W = abbab, then
|W| = 5
|W|b = 3 (length of a word w with respect to b )
7
Cont…
8
Cont…
Example If Σ = {a, b, c} then
Σ* = {ɛ, a, b, c, aa, ab, bc, abc, , …}
Σ+ = { a, b, c, aa, ab, ac, abc, aabc, …}
Σ1 = Σ
Σ3 = {aab, abc, ccc, abb, …}
If w is a string then w0 = ɛ
Note that
Σ* =
Σ+ =
9
Cont…
Given a string w = abc
Prefix of w are ɛ, a, ab, & abc
Suffix of w are ɛ, c, bc, & abc
Proper prefix or suffix is a prefix or suffix other than the
string itself
Proper Prefix of w are ɛ, a, & ab
Proper Suffix of w are ɛ, c, & bc
10
Concatenation of String
The concatenation of two strings is obtained by appending the second
string to the right of the first string.
Example: -
Given w = a1a2..an & v = a1a2..am then concatenation of w & v , denoted as wv, is given as wv =
a1a2..ana1a2..am
a3.a2.= aaabb
Two strings are equal if they have the same number of symbols and
these symbols match, character for character.
Concatenation operation is associative, and it is not commutative.
The empty string serves as the identity element for
concatenation.
That is, for all strings x, x.ɛ = ɛ.x = x
11
String Reversal
String Reversal:- Let w = a1a2…an be a string, then the string
reversal of w, reverse (w) or wR, is anan-1…a1
E.g. If w = abc, then reverse(w) = wR =cba
12
Language
A set of strings all of which are chosen from some 𝛴 ∗ , where 𝛴 is a particular
alphabet, is called a language. If 𝛴 is an alphabet, and 𝐿 ⊆ 𝛴 ∗ , then 𝐿 is said to be
language over alphabet 𝛴.
Language comprises of:
Set of characters – 𝛴
Set of strings (words) defined from set of character - 𝛴 ∗
Language L is defined from 𝛴 ∗ , and 𝐿 ⊆ 𝛴 ∗ because 𝛴 ∗ contains many string
which may not satisfy the rules of language.
Example:
𝛴 = {a, b}
𝛴 ∗ = {^, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, …}
13
Operations over Language
Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +
hopeless
15
Operations over Language
Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +
If 𝐿 is a set of words then by 𝐿∗ we mean the set of all finite strings formed by concatenating
words from S, where any word may be used as often we like, and where the null string is also
included. ∞
𝐿∗ = 𝐿𝑖
𝑖=0
Example: 𝐿 = {ab}
If 𝐿 is a set of words then by 𝐿+ we mean the set of all finite strings formed by concatenating
words from L, where any word may be used as often we like, and where the null string is not
included. ∞
𝐿+ = 𝐿𝑖
𝑖=1
Example:𝐿 = {ab}
18
Grammar
cont…
S ϵ N is a start symbol
There should be at least one production that has S at left hand side.
(S ϵ (NUT)*).
The derivation of a string of a language should start with S.
Let G = (N, T, S, P) be a grammar. Then the set L(G) = { w e T* :
S => w} is the language generated by G.
19
Grammar cont…
Example1: S ɛ (2) So, ɛ e L(G)
Consider the grammar S aSb using (1) ab e L(G)
ab using (2) So,
G = ({S}, {a, b}, S, P) with p
S aSb ……..(1) S aSb using (1) aabb e L(G)
aaSbb Using (1) So, or
S ɛ ………..(2) aabb using (2) a2b2 e L(G)
Find the language
S aSb using (1) aaabbb e L(G)
generated by G aaSbb Using (1) So, or
Solution aaaSbbb Using (1) a3b3 e L(G)
aaabbb Using (2)
Let the language be L(G)
Look how strings of the language are produced and the general
formula for the language produced by the grammar is given
So, L(G) = {ɛ, ab, aabb, aaabbb, aaaabbbb, etc} L(G) = {anbn : n≥0}
20
Grammar
cont…
Example 2:
Find the language generated by the following grammar G = {N, T, S,
P} where
N = {S, B}
T = {a, b, c}
P : S aBSc….(1)
S abc….(2)
Ba aB….(3)
Bb bb….(4)
Answer: L(G) = {anbncn : n e N}
21
Grammar
cont…
Example 3:
Find a grammar that generates L(G) = {anbn+1: n ≥ N}
Answer
G = (N, T, S, P) where
N = {S, A}, T = {a, b}, S = S
P: S Ab, S aSb, A ɛ
Or
P: S Ab, A aS, A ɛ
22
Exercise
1. Find a grammar that generates
a) L(G) = {an: n ≥ N}
b) L(G) = {(ab)n: n ≥ 0}
2. Find the language generated by the following grammar
a) G = (N, T, S, P) where
N = {A, S}
T = {a, b}
P: S Ab
A aA | a | b | bA
23
Automata
24
Automata
Control
Storage
Unit
Output
25
Automata
BATTERY
input: switch
output: light bulb
Actions (Control Unit): flip switch
States (Storage): on, off
26
Automata
A particular state of the control unit, input file, and temporary storage
is known as configuration.
A move is the transition of the automaton from one configuration to
the next.
One automaton differs from the other in the way in which the output
can be produced and the nature of the temporary storage.
26
27
Automata
An automaton can be
Deterministic or
Non-deterministic
A deterministic automaton is the one in which each move is uniquely
determined by the current configuration.
i.e. if the internal state, the input and the content of the temporary
storage, we can predict the future behavior of the automaton.
28
Automata
29
Question
30