Chapter One - Introduction

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Hawassa University Daye Campus

Department of Computer Science


Automata and complexity theory

Course code: CoSc3071


By: Mekonen M.

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…

Empty string is denoted by ε or λ, |ɛ| = 0


If Σ = {a, b}, then ab, abb, a, b, are some of the strings over Σ
Σ* = All strings of symbols from Σ (Kleene closure)
 Σ+ = Σ* - {ε} ( Positive closure)
 Σi = Set of Strings over Σ having length i.

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. +

If 𝐿1 , 𝐿2 ⊆ 𝛴 ∗ then concatenation is defined as


𝐿1𝐿2 = 𝑥𝑦 𝑥 𝜖 𝐿1 𝑎𝑛𝑑 𝑦 𝜖 𝐿2}
Example:
𝐿1 = {hope, fear} and 𝐿2 = {less, fully}

hopeless

𝐿1𝐿2 = {hopeless, hopefully, fearless, fearfully}


14
Operations over Language
 Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +

If 𝐿1 , 𝐿2 ⊆ 𝛴 ∗ then union is defined as


𝐿1 | 𝐿2 = 𝑥 𝑥 𝜖 𝐿1 𝑜𝑟 𝑥 𝜖 𝐿2}
Example:
𝐿1 = {hope, fear} and 𝐿2 = {less, fully}

𝐿1 | 𝐿2 = {hope, fear, less, fully}

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}

𝐿* = {^, ab, abab, ababab, abababab, ….}


16
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 L, where any word may be used as often we like, and where the null string is not
included. ∞

𝐿+ = 𝐿𝑖
𝑖=1
Example:𝐿 = {ab}

𝐿+ = {ab, abab, ababab, abababab, ….}


17
Grammar
A set of rules used to generate the string for a particular language.
A Grammar is defined as a quadruple G = (N, T, S, P), where
N: (sometimes denoted as V) is the set of finite set of objects called non-terminals or
variables.
 They are place holders and are denoted by capital letters.
 There should exist rules in P that tells us how to replace the non-terminals.
T: (sometimes denoted as Σ ) is a finite set of objects called terminals.
 Used to construct strings of a language, How?
 Are usually represented by small letters and digits.
P stands for production rules, are hearts of grammar
 Each production rule is in the form of (N U T)+  (N U T)*
 The left hand side should contain at least one non-terminal
 A production rule Xy implies replace X by y in some string
Example: wXv  wyv … using production Xy

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

An automata is an abstract model of a digital computer (= it is


a self operating machine).
Every automaton includes some essential features.
 Mechanism for reading input: the input is a string over a
given alphabet written on an input file
 Produce an output in some form
 Have temporary storage device: the storage cells can be
read and changed.

24
Automata

Has a control unit


• Can be in any one of a finite number of internal states
• The internal state of the control unit is determined by the next-state or
transition function
Input

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

In non-deterministic automaton there may have several possible


moves, so we can only predict a set of possible actors.
An automaton whose output response is limited to a simple “yes” or
“no” is called an accepter (because it accepts or rejects)
A more general automaton, capable of producing strings of symbols as
output is called a transducer.

29
Question
30

You might also like