SlideShare a Scribd company logo
1 of 32
P re p a re d B y
S . Vi s n u D h a r s i n i
INTRO DUCTIO N
TO AUTOMATA
Prepared By
S.Visnu
Dharsini
It is a self- operating machineand a moving
mechanical device made in imitation of
living things.
An automata is an abstract
model of a digital computer .
A machinewhich performsa range of
functions according to a predetermined set
of coded instructions.
real world examples:computer,ATM and
hugo(robot)
Automata theory is the study of abstract machines and automata,
as well as the computational problems that can be solved using
them.
A SIMPLE COMPUTER :
INPUT : switch
OUTPUT : light bulb
ACTIONS : flip
switch STATES
: on,off
H O W A N A U T O M A T A C A N B E D E S I G N E D :
Transition diagram
Transition table
Transition functions
Bulb is "ON"if and if there was an
Odd number of flips
There are four types of automata :
Finite state machine (simple)
Push-down automata
(moderate) Turing
machine(complex)
Linear bound machine (
restricted form of turing machine)
The main idea of suggested approach is to construct computer programs
the same waythe automation of technological processes
Automata-based programming is a programming paradigm in which the
program or part of it is thought of a Machine or any formal automation . Each
automaton can take one "step"at a time, and the execution of the program is
broken downinto individual steps. The steps communicate with each other by
changing the value of a variable, representing the "state."The control flow of the
program is determined by the variable value.
Examples :telecommunication systems,
02
Finite State Machine is a mathematical model of
computation that models a sequential logic. FSM
consists of a finite number of states, transition
functions, input alphabets, a start state and end
state(s).
Finite State Machine for a Traffic Signal is
designed and rendered .Green is the start/initial
state, which upon receiving a trigger moves to
Yellow, which in turn, upon receiving a trigger,
transitions to Red. The Red then circles back to
Green and the loop
continues.An FSM must be in exactly one of the
finite states at any given point in time and then in
response to an input, it receives, the machine
transitions to another state. The transition rules
are defined for
While building FMS's , wemodel and
implement State and Transition
Functions.States could be modeled as Python
Coroutines that run an
infinite loop within which they accept the input,
decides the transition and updates the current
state of the FSM. The transition function could
be as simple as a bunch of if and elif statements
and in a more complex systemit could be a
decision function.
To dive into low-level details, webuild an FSM
for the regular expression ab*c, which means
if the given string matches the regexthen the
machine should end at the end state, only
We model the state "q2"as
def _create_q2():
while True:
# Wait till the input is received.
# once received store the input in `char`
char =yield
# depending on what wereceived as the
input
# change the current state of the fsm
if char =='b':
# on receiving `b`thestate moves to `q2`
current_state=q2
else:
elif char =='c':
# on receiving c̀`thestatemoves to q̀3`
current_state =q3
# on receiving any other input, break
the loop
# so that next time when someone sends
any input to
# the coroutine it raises StopIteration
break
The FSM class for the regular expression
ab*c
class FSM:
def init (self):
# initializing states
self.start = self._create_start()
self.q1= self._create_q1()
self.q2 = self._create_q2()
self.q3 = self._create_q3()
# setting current state of the system
self.current_state = self.start
# stopped flag to denote that iteration is stopped due to bad
# input against which transition was not defined.
self.stopped = False
def send(self, char):
"""The function sends the curretn input to thecurrent state
It captures the StopIteration exception and marks the stopped flag.
"""
try:
self.current_state.send(char)
except StopIteration:
def does_match(self):
"""The function at any point in time returns if till the current
input the string matches the given regular expression.
It does so by comparing the current state with the end state `q3.`
It also checks for s`topped`flag which sees that due to bad input the iteration of FSM had to
be stopped.
"""
if self.stopped:
return False
return self.current_state==self.q3
...
def grep_regex(text):
evaluator =FSM()
for ch in text:
evaluator.send(ch)
return
evaluator.does_match()
>>>grep_regex("abc")
True
>>>grep_regex("aba")
False
SIM PLE VENDING M ACHINE
# StateMachine/vendingmachine/VendingMachineTest.py
# Demonstrates use of StateMachine.py
vm =VendingMachine()
for input in [
Money.quarter,
Money.quarter,
Money.dollar,
FirstDigit.A,
SecondDigit.two,
FirstDigit.A,
SecondDigit.two,
FirstDigit.C,
SecondDigit.three,
FirstDigit.D,
SecondDigit.one,
Quit.quit]:
vm.nextState(input)
03
INPUT :String of Weather Data
Condition :
Heatwave :Temperature >=45degree celsius for two
consecutive days
q0 q1 q2
>=45
1 day 2 days
heatwave
<45
<45
>=45
<45
q0 q1 q2
1 day 2 days
heatwave
0
0
0,1
1 1
 In DFA, for each input symbol, one can determine the
state to which the machine will move. Hence, it is called
Deterministic Automaton. As it has a finite number of
states, the machine is called Deterministic Finite Machine
or Deterministic Finite Automaton.
LANGUAGE OF DFA
The language of a DFA is the set of all strings ,starting from q0 and following
the transitions as the string is read left to right, will reach some accepting
state.
language = { all strings containing 11
}
M accepts 11
M accepts 110
M accepts 0110
so on.....
L1
= {0
{
,
0
0
0
,
0
,
0
0
1
,
0
,
0
1
0
,
0
1
0
,
0
1
,
1
0
1
1
,
0
0
,
0
0
0
0
0
}
1
,
0
0
0
C
B
A
= Dead state /Trap state
0 0,1
= Final state
1
0,1
1 0 1
0 0 1
Initial state
Initial state Not Final state
Final state
A B
B
A
B
C
C
C
0
0
0
1
1
1
A DFA can berepresented by a 5-tuple (Q,∑,δ,q0,F) where −
Q is a finiteset of states.
∑is a finiteset of symbols called thealphabet.
δ is thetransition function where δ:Q ×∑→ Q
q0 is the initial state from where any input is processed(q0 ∈
Q). F is a set of final state/states of Q (F ⊆ Q).
q0 q1 q2
1 day 2 days
heatwave
0
0
0,1
1 1
M = (Q, ∑, δ, q0, F)
Q =
∑ =
{ q0 , q1 , q2 }
{ 1 , 0 }
δ =
F =
q0 =
{ q2 }
#DFA which matchesall binary stringshaving
consecutive '1's
dfa =DFA( states={'q0',
'q1', 'q2'},
input_symbols={'0', '1'},
transitions={
'q0':{'0':'q0', '1':'q1'},
'q1':{'0':'q0', '1':'q2'},
'q2':{'0':'q2', '1':'q2'}
},
initial_state='q0',
final_states={'q2'}
)
if
dfa.accepts_input('011'):
print('accepted')
else:
print('rejected')
Automata based programming

More Related Content

What's hot

Turing machine Introduction
Turing machine IntroductionTuring machine Introduction
Turing machine IntroductionAram Rafeq
 
Turing Machine
Turing MachineTuring Machine
Turing Machineazmizryk
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)parmeet834
 
Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine Nadeem Qasmi
 
Turing machine - theory of computation
Turing machine - theory of computationTuring machine - theory of computation
Turing machine - theory of computationRubaya Mim
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 
Finite State Machine by M. Arokiasamy
Finite State Machine by M. ArokiasamyFinite State Machine by M. Arokiasamy
Finite State Machine by M. ArokiasamyMark Arokiasamy
 
Turing machine seminar report
Turing machine seminar reportTuring machine seminar report
Turing machine seminar reportYashwant Dagar
 
Train first in station
Train first in stationTrain first in station
Train first in stationKPIGroup
 
Toc(df avs nfa)avishek130650107020
Toc(df avs nfa)avishek130650107020Toc(df avs nfa)avishek130650107020
Toc(df avs nfa)avishek130650107020Avishek Sarkar
 

What's hot (19)

Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Introduction to Turing Machine
Introduction to Turing MachineIntroduction to Turing Machine
Introduction to Turing Machine
 
Turing machine Introduction
Turing machine IntroductionTuring machine Introduction
Turing machine Introduction
 
Automata Theory - Turing machine
Automata Theory - Turing machineAutomata Theory - Turing machine
Automata Theory - Turing machine
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Finite automata
Finite automataFinite automata
Finite automata
 
Turing Machines (TM)
Turing Machines (TM)Turing Machines (TM)
Turing Machines (TM)
 
Turing machine
Turing machineTuring machine
Turing machine
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Ch2 finite automaton
Ch2 finite automatonCh2 finite automaton
Ch2 finite automaton
 
Turing machine
Turing machineTuring machine
Turing machine
 
Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine Finite state Transducers and mealy Machine
Finite state Transducers and mealy Machine
 
Turing machine - theory of computation
Turing machine - theory of computationTuring machine - theory of computation
Turing machine - theory of computation
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 
Finite State Machine by M. Arokiasamy
Finite State Machine by M. ArokiasamyFinite State Machine by M. Arokiasamy
Finite State Machine by M. Arokiasamy
 
Turing machine seminar report
Turing machine seminar reportTuring machine seminar report
Turing machine seminar report
 
Lecture: Automata
Lecture: AutomataLecture: Automata
Lecture: Automata
 
Train first in station
Train first in stationTrain first in station
Train first in station
 
Toc(df avs nfa)avishek130650107020
Toc(df avs nfa)avishek130650107020Toc(df avs nfa)avishek130650107020
Toc(df avs nfa)avishek130650107020
 

Similar to Automata based programming

Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! EdholeEdhole.com
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdfFariyaTasneem1
 
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfPreparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfrdjo
 
Finite state automaton
Finite state automatonFinite state automaton
Finite state automatonAmmAr mobark
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptxssuser47f7f2
 
state_machines1.pdf
state_machines1.pdfstate_machines1.pdf
state_machines1.pdfrdjo
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! EdholeEdhole.com
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introductionNAMRATA BORKAR
 
Mealy and moore machine
Mealy and moore machineMealy and moore machine
Mealy and moore machineEhatsham Riaz
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxamara jyothi
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxranjan317165
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxMeghnadh
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Editor IJARCET
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Editor IJARCET
 

Similar to Automata based programming (20)

Mba ebooks ! Edhole
Mba ebooks ! EdholeMba ebooks ! Edhole
Mba ebooks ! Edhole
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
Theory of computation and automata
Theory of computation and automataTheory of computation and automata
Theory of computation and automata
 
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf@vtucode.in-module-1-21CS51-5th-semester (1).pdf
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
 
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdfPreparatory_questions_final_exam_DigitalElectronics1 (1).pdf
Preparatory_questions_final_exam_DigitalElectronics1 (1).pdf
 
Finite state automaton
Finite state automatonFinite state automaton
Finite state automaton
 
03-FiniteAutomata.pptx
03-FiniteAutomata.pptx03-FiniteAutomata.pptx
03-FiniteAutomata.pptx
 
Unit iv
Unit ivUnit iv
Unit iv
 
state_machines1.pdf
state_machines1.pdfstate_machines1.pdf
state_machines1.pdf
 
Free Ebooks Download ! Edhole
Free Ebooks Download ! EdholeFree Ebooks Download ! Edhole
Free Ebooks Download ! Edhole
 
Automaton
AutomatonAutomaton
Automaton
 
Automata theory introduction
Automata theory introductionAutomata theory introduction
Automata theory introduction
 
Mealy and moore machine
Mealy and moore machineMealy and moore machine
Mealy and moore machine
 
CS 5th.pptx
CS 5th.pptxCS 5th.pptx
CS 5th.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
FiniteAutomata_anim.pptx
FiniteAutomata_anim.pptxFiniteAutomata_anim.pptx
FiniteAutomata_anim.pptx
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207
 
Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207Volume 2-issue-6-2205-2207
Volume 2-issue-6-2205-2207
 
flat unit1
flat unit1flat unit1
flat unit1
 

Recently uploaded

GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 

Recently uploaded (20)

young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

Automata based programming

  • 1. P re p a re d B y S . Vi s n u D h a r s i n i
  • 2. INTRO DUCTIO N TO AUTOMATA Prepared By S.Visnu Dharsini
  • 3. It is a self- operating machineand a moving mechanical device made in imitation of living things. An automata is an abstract model of a digital computer . A machinewhich performsa range of functions according to a predetermined set of coded instructions. real world examples:computer,ATM and hugo(robot)
  • 4. Automata theory is the study of abstract machines and automata, as well as the computational problems that can be solved using them. A SIMPLE COMPUTER : INPUT : switch OUTPUT : light bulb ACTIONS : flip switch STATES : on,off
  • 5. H O W A N A U T O M A T A C A N B E D E S I G N E D : Transition diagram Transition table Transition functions Bulb is "ON"if and if there was an Odd number of flips
  • 6. There are four types of automata : Finite state machine (simple) Push-down automata (moderate) Turing machine(complex) Linear bound machine ( restricted form of turing machine)
  • 7.
  • 8. The main idea of suggested approach is to construct computer programs the same waythe automation of technological processes Automata-based programming is a programming paradigm in which the program or part of it is thought of a Machine or any formal automation . Each automaton can take one "step"at a time, and the execution of the program is broken downinto individual steps. The steps communicate with each other by changing the value of a variable, representing the "state."The control flow of the program is determined by the variable value. Examples :telecommunication systems,
  • 9. 02
  • 10. Finite State Machine is a mathematical model of computation that models a sequential logic. FSM consists of a finite number of states, transition functions, input alphabets, a start state and end state(s).
  • 11. Finite State Machine for a Traffic Signal is designed and rendered .Green is the start/initial state, which upon receiving a trigger moves to Yellow, which in turn, upon receiving a trigger, transitions to Red. The Red then circles back to Green and the loop continues.An FSM must be in exactly one of the finite states at any given point in time and then in response to an input, it receives, the machine transitions to another state. The transition rules are defined for
  • 12. While building FMS's , wemodel and implement State and Transition Functions.States could be modeled as Python Coroutines that run an infinite loop within which they accept the input, decides the transition and updates the current state of the FSM. The transition function could be as simple as a bunch of if and elif statements and in a more complex systemit could be a decision function. To dive into low-level details, webuild an FSM for the regular expression ab*c, which means if the given string matches the regexthen the machine should end at the end state, only
  • 13. We model the state "q2"as def _create_q2(): while True: # Wait till the input is received. # once received store the input in `char` char =yield # depending on what wereceived as the input # change the current state of the fsm if char =='b': # on receiving `b`thestate moves to `q2` current_state=q2 else: elif char =='c': # on receiving c̀`thestatemoves to q̀3` current_state =q3 # on receiving any other input, break the loop # so that next time when someone sends any input to # the coroutine it raises StopIteration break
  • 14. The FSM class for the regular expression ab*c class FSM: def init (self): # initializing states self.start = self._create_start() self.q1= self._create_q1() self.q2 = self._create_q2() self.q3 = self._create_q3() # setting current state of the system self.current_state = self.start # stopped flag to denote that iteration is stopped due to bad # input against which transition was not defined. self.stopped = False def send(self, char): """The function sends the curretn input to thecurrent state It captures the StopIteration exception and marks the stopped flag. """ try: self.current_state.send(char) except StopIteration: def does_match(self): """The function at any point in time returns if till the current input the string matches the given regular expression. It does so by comparing the current state with the end state `q3.` It also checks for s`topped`flag which sees that due to bad input the iteration of FSM had to be stopped. """ if self.stopped: return False return self.current_state==self.q3 ...
  • 15. def grep_regex(text): evaluator =FSM() for ch in text: evaluator.send(ch) return evaluator.does_match() >>>grep_regex("abc") True >>>grep_regex("aba") False
  • 16. SIM PLE VENDING M ACHINE # StateMachine/vendingmachine/VendingMachineTest.py # Demonstrates use of StateMachine.py vm =VendingMachine() for input in [ Money.quarter, Money.quarter, Money.dollar, FirstDigit.A, SecondDigit.two, FirstDigit.A, SecondDigit.two, FirstDigit.C, SecondDigit.three, FirstDigit.D, SecondDigit.one, Quit.quit]: vm.nextState(input)
  • 17. 03
  • 18. INPUT :String of Weather Data Condition : Heatwave :Temperature >=45degree celsius for two consecutive days
  • 19. q0 q1 q2 >=45 1 day 2 days heatwave <45 <45 >=45 <45
  • 20. q0 q1 q2 1 day 2 days heatwave 0 0 0,1 1 1
  • 21.  In DFA, for each input symbol, one can determine the state to which the machine will move. Hence, it is called Deterministic Automaton. As it has a finite number of states, the machine is called Deterministic Finite Machine or Deterministic Finite Automaton.
  • 22. LANGUAGE OF DFA The language of a DFA is the set of all strings ,starting from q0 and following the transitions as the string is read left to right, will reach some accepting state.
  • 23. language = { all strings containing 11 } M accepts 11 M accepts 110 M accepts 0110 so on.....
  • 25. 1 0 1 0 0 1 Initial state Initial state Not Final state Final state A B B A B C C C 0 0 0 1 1 1
  • 26. A DFA can berepresented by a 5-tuple (Q,∑,δ,q0,F) where − Q is a finiteset of states. ∑is a finiteset of symbols called thealphabet. δ is thetransition function where δ:Q ×∑→ Q q0 is the initial state from where any input is processed(q0 ∈ Q). F is a set of final state/states of Q (F ⊆ Q).
  • 27. q0 q1 q2 1 day 2 days heatwave 0 0 0,1 1 1
  • 28. M = (Q, ∑, δ, q0, F) Q = ∑ = { q0 , q1 , q2 } { 1 , 0 }
  • 29. δ = F = q0 = { q2 }
  • 30.
  • 31. #DFA which matchesall binary stringshaving consecutive '1's dfa =DFA( states={'q0', 'q1', 'q2'}, input_symbols={'0', '1'}, transitions={ 'q0':{'0':'q0', '1':'q1'}, 'q1':{'0':'q0', '1':'q2'}, 'q2':{'0':'q2', '1':'q2'} }, initial_state='q0', final_states={'q2'} ) if dfa.accepts_input('011'): print('accepted') else: print('rejected')