Lec-1 Introduction To TOC

You might also like

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

HEWAD UNIVERSITY

Theory of Computing (TOC) ‫هیــــواد پوهنــتون‬

Introduction to TOC

Lecturer : Mirajuddin Haidari

Department
HEWAD University of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

INTRODUCATION
• Course Name: TOC
• Lecturer Name: Mirajuddin Haidari
• Email: Mearajuddin.haidary@gmail.com
• WhatsApp: +93772709870

2
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

CONTENTS OF THE LECTURE


1. Why study automata theory?
2. Introduction to languages, alphabets.
3. Kinds of Languages.
4. Deterministic and Nondeterministic Finite automata.
5. Finite states/infinite states
6. Recognized and recognizable languages.

3
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recommended Readings
• Introduction to Computer Theory Daniel I.A.
Cohen, Second Edition
• Introduction to Languages and Theory of
Computation J. C. Martin, Third Edition

4
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Pre-Requisite
• Discrete Mathematics

5
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Why study theory of computation?


• Mathematical theory behind computers rather
computing
• Foundation for the course of Compiler
Construction

6
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Automata?
•It is the plural of automaton, and it
means “something that works
automatically”.
• e.g. traffic signals

7
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Automata Theory/TOC
• In theoretical computer science, automata
theory is the study of abstract machines and
the problems which they are able to solve.
• These abstract machines are called automata.
An automaton is a mathematical model for a
Finite State Machine (FSM).

8
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Automata Theory (cont…)


• Automata Theory is an exciting, theoretical
branch of computer science.
• It established its roots during the 20th
Century, as mathematicians began developing -
both theoretically and literally - machines
which imitated certain features of man,
completing calculations more quickly and
reliably.
• automata theory deals with the logic of
computation with respect to simple machines,
referred to as automata
9
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Automaton & automata


• In automata we will simulates parts of
computers.
• Or we will make mathematical models of
computers
• Automata are more powerful than any real
computer because we can design any machine
on papers that can do everything we want.

10
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Automaton & automata (cont.)


• Automatons are abstract models of machines
that perform computations on an input by
moving through a series of states or
configurations.
• At each state of the computation, a transition
function determines the next configuration on
the basis of a finite portion of the present
configuration.
• As a result, once the computation reaches an
accepting configuration, it accepts that input.
11
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Four major families of automaton


• Finite-state machine
• Pushdown automata
• Linear-bounded automata
• Turing machine

12
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Finite Automata
• Finite automata (FA) is the simple machine to
recognize pattern.
• It takes string of symbols as input and change
its state accordingly.
• Finite automata has two state, accept state and
reject state.
1. When the input string processed successfully, and
automata reached its final state, then it will accept.

2. Otherwise reject

13
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Finite Automata
• An important way to describe certain simple, but
highly useful languages called “regular languages."
• A graph with a finite number of nodes, called states.
• Arcs are labeled with one or more symbols from
some alphabet.
• One state is designated the start state or initial
state. u Some states are final states or accepting
states.
• The language of the FA is the set of strings that
label paths that go from the start state to some
accepting state.

14
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Formal Definition of Finite Automaton


 An automaton is represented formally by the 5-
tuple {Q,Σ,δ,q0,F}, where:
 Q is a finite set of states.
 Σ is a finite set of symbols, called the alphabet of
the automaton.
 δ is the transition function, that is, δ: Q x Σ → Q.
 q0 is the start state, that is, the state which the
automaton is in when no input has been processed
yet, where q0∈ Q.

15
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Formal Definition of Finite Automaton


• F is a set of states of Q (i.e. F⊆Q) called
accept states.
• Delta (uppercase Δ, lower case δ )
• Sigma (upper case Σ, lower case σ )

16
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

δ function
• This function takes a state and input symbol
as arguments.
• Returns a state.
• One “rule" of d would be written (q; a) = p,
where q and p are states, and a is an input
symbol.

17
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Example
•M1 = (Q, Σ, δ,q0,F) where
– Q={0,1,2,3}, Σ={a,b}, q0 = 0, F = {3} and d
is define by: – δ(0,a) = 1; δ(1,a) = 2; δ(2,a)
= δ(3,a) = 3 and – δ(q,b)=q if q = {0,1,2,3}.
– problem: Although precise but tedious
and not easy to understand (the behavior
of) the machine.

18
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Example
– Represent M1 by a table:

– Represent M1 by a diagram:
(state-transition diagram for M1)

19
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Strings accepted by DFAs


• Operations of M1 on the input 'baabbaab':

• Since M1 can reach a final state (3) after


scanning all input symbols starting from initial
state, we say the string 'baabbaab' is accepted by
M1.

20
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

FA for switch
• Example:
• Finite automaton modelling an on/off switch

21
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

FA continue …

• Accept the string 01101

22
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Types of Automata
• Deterministic automaton (DFA).
• Nondeterministic automaton (NFA).

23
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Deterministic
• For a given current state and an input
symbol, if an automaton can only jump to
one and only one state then it is a
deterministic automaton.

24
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Nondeterministic
• An automaton that, after reading an input
symbol, may jump into any of a number of
states, as licensed by its transition relation.
• Notice that the term transition function
is replaced by transition relation: The
automaton non-deterministically decides
to jump into one of the allowed choices.
Such automaton are called
nondeterministic automaton.
25
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Finite states/infinite states


• Finite states: An automaton that contains
only a finite number of states.
• The above introductory definition describes
automata with finite numbers of states.

26
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Finite states/infinite states


• Infinite states: An automaton that may not
have a finite number of states, or even a
uncountable number of states.

27
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

DFA Example
• Convert DFA tuple to graph.
• Let a deterministic finite automata be:
• Q = {a, b, c} Inputs
States
• Σ = {0,1} 0 1
a a b
• q0 = a
• F = {c} and δ define in table b c a

c b c

28
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Major objective
• The major objective of automata theory is to
develop methods by which computer scientists
can describe and analyze the dynamic behavior
of discrete systems, in which signals are sampled
periodically.
• The behavior of these discrete systems is
determined by the way that the system is
constructed from storage and combinational
elements.
29
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Applications of automata
 Each model in automata theory play varied
roles in several applied areas.
 Finite automata is used in text processing,
compilers, and hardware design.
 Context-free grammar is used in
programming languages and artificial
intelligence.
 Originally, CFG were used in the study of
the human languages.
30
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Applications of automata
 Cellular automata is used in the field of biology.
 Stephen Wolfram claims that the entire
universe could be explained by machines with a
finite set of states and rules with a single
initial condition.
 Software for verifying systems of all types
that have a finite number of distinct states,
such as communications protocols or protocols
for secure exchange of information.
31
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Languages
• Alphabet = finite set of symbols,e.g.{0; 1} (binary
alphabet) or ASCII.
• String = finite sequence of symbols chosen from some
alphabet, e.g., 01101 or abracadabra.
• Language = set of strings chosen from some
alphabet.
• Distinctive point: the language may be infinite, but
there is some finite set of symbols of which all its
strings are composed.
32
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Example of Languages
• The set of all binary strings consisting of some
number of 0's followed by an equal number of 1's;
that is,{ 01; 0011; 000111}.
• C (the set of compliable C programs).
• English.
• A formal language is an abstraction of the general
characteristics of programming languages.

33
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Example of Languages
• A formal language consists of a set of symbols
and some rules of formation by which these
symbols can be combined into entities called
sentences.
• A formal language is the set of all strings
permitted by the rules of formation.

34
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• 1- Talking language: (e.g.: English language.):
• It has alphabetic: Σ={a,b,c,….z , A,B,C,..Z ,….}
• From these alphabetic we make sentences that
belong to English language.
• Now we want to know is this sentence is true or
false so- We need grammar in English.

35
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• Example:
• Ali is a good boy. (It is a sentence Є English
language.)
• It's semantic (meaning) & syntax (structure) is true
according to English grammar.
• Ahmad eats papers. (It is a sentence Є English
language.)
• It's semantic (meaning) is false but it's syntax
(structure) is true according to English grammar.

36
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• 2- Programming language: (e.g.: c++ language.):
• It has alphabetic: Σ={a,b,c,….z , A,B,C,…..Z , ?, /, - ,\.}.
• From these alphabetic we make sentences that
belong to programming language.
• Now we want to know is this sentence is true or false
so we need a compiler to make sure that syntax is
true and we don't need to check the meaning because
we talk to computer that doesn't know any thing.

37
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• 3- Formal language: (any language we want.).
• It has strings.
• From these strings we make sentences that
belong to this formal language.
• Now we want to know is this sentence is true or
false so- We need rules.

38
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• Example:
• Alphabetic:
• Σ={0,1}.
• Sentences:
• 0000001.
• 1010101.
• Rules:
• Accept any sentence start with zero and refuse sentences
that start with one.
39
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Kinds of languages
• So we accept: 0000001, As a sentence satisfy the
rules.
• And refuse: 1010101. As a sentence doesn't satisfy
the rules.
• So we can make our formal language but we must
take in mind it's:
• Σ alphabetic. (Arguments)
• Rules.
• From which we can get the language elements and
vice versa.
40
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recognized/recognizable languages
• An automaton can recognize a formal language.
• The recognized language L Σ* by an automaton
is the set of all the words that are accepted by the
automaton.
• The recognizable languages is the set of
languages that are recognized by some
automaton.

41
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recognized/recognizable languages
• For above definition of automata the recognizable
languages are regular languages.
• For different definitions of automata, the
recognizable languages are different.

42
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recognized language
• The automaton reads the input word one symbol
after another in the sequence and transits from
state to state according to the transition function,
until the word is read completely.
• Once the input word has been read, the
automaton is said to have been stopped and the
state at which automaton has stopped is called
final state.
43
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recognized language
• Depending on the final state, it's said that the
automaton either accepts or rejects an input
word.
• There is a subset of states of the automaton,
which is defined as the set of accepting states.

44
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Recognized language
• If the final state is an accepting state, then the
automaton accepts the word.
• Otherwise, the word is rejected.
• The set of all the words accepted by an
automaton is called the language recognized by

45
HEWAD University
Department
of Computing & Technology ‫کمپیوتر ساینس پوهنځی‬ ‫هیــــواد پوهنــتون‬

Let’s Stop
it Here
46

You might also like