Basic Concepts and Formal Language theory Unit –I By T.H. Gurav 8 October 2015.

Slides:



Advertisements
Similar presentations
Automata Theory Part 1: Introduction & NFA November 2002.
Advertisements

4b Lexical analysis Finite Automata
Lecture 6 Nondeterministic Finite Automata (NFA)
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
CS5371 Theory of Computation
1 Languages and Finite Automata or how to talk to machines...
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Topics Automata Theory Grammars and Languages Complexities
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
1 Introduction to Automata Theory Reading: Chapter 1.
Finite-State Machines with No Output
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
AUTOMATA THEORY Reference Introduction to Automata Theory Languages and Computation Hopcraft, Ullman and Motwani.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
By: Er. Sukhwinder kaur.  What is Automata Theory? What is Automata Theory?  Alphabet and Strings Alphabet and Strings  Empty String Empty String 
1 Chapter 2 Finite Automata (part b) Windmills in Holland.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 203: Introduction to Formal Languages and Automata
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Modeling Computation: Finite State Machines without Output
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Lecture Notes 
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Introduction to Automata Theory
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Finite Automata.
CIS Automata and Formal Languages – Pei Wang
Introduction to the Theory of Computation
Languages.
Lexical analysis Finite Automata
CIS Automata and Formal Languages – Pei Wang
Chapter 11 Finite State Machine
Two issues in lexical analysis
Recognizer for a Language
Jaya Krishna, M.Tech, Assistant Professor
Introduction to Automata Theory
Jaya Krishna, M.Tech, Assistant Professor
Hierarchy of languages
THEORY OF COMPUTATION Lecture One: Automata Theory Automata Theory.
Non-Deterministic Finite Automata
4b Lexical analysis Finite Automata
Deterministic Finite Automaton (DFA)
4b Lexical analysis Finite Automata
Finite-State Machines with No Output
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

Basic Concepts and Formal Language theory Unit –I By T.H. Gurav 8 October 2015

Elements of Formal Language Symbols Alphabets Strings Languages 8 October 2015

Alphabet An alphabet is a finite, non-empty set of symbols We use the symbol ∑ (sigma) to denote an alphabet Examples: Binary: ∑ = {0,1} All lower case letters: ∑ = {a,b,c,..z} Alphanumeric: ∑ = {a-z, A-Z, 0-9} DNA molecule letters: ∑ = {a,c,g,t} … 8 October 2015

Strings A string or word is a finite sequence of symbols chosen from ∑ Empty string is  (or “epsilon”) Length of a string w, denoted by “|w|”, is equal to the number of (non-  ) characters in the string E.g., x = |x| = 6 x = 01  0  1  00  |x| = ? xy = concatentation of two strings x and y 8 October 2015

Kleen Closure ( ∑* ) Given an alphabet ∑, we wish to define a language in which any string of letters from ∑ is a word/string, even null string. This language we shall call the closure of the alphabet. Positive Closure (∑ + ) 8 October 2015

Languages L is a said to be a language over alphabet ∑, only if L  ∑*  this is because ∑* is the set of all strings (of all possible length including 0) over the given alphabet ∑ Examples: 1. Let L be the language of all strings consisting of n 0’s followed by n 1’s: L = { ,01,0011,000111,…} 2. Let L be the language of all strings of with equal number of 0’s and 1’s: L = { ,01,10,0011,1100,0101,1010,1001,…} Definition:Ø denotes the Empty language Let L = {  }; Is L=Ø? NO 8 October 2015

Definition 1. A set is a group of objects . The objects in a set are called the elements, or members, of the set. Example 1 The set of positive integers less than 100 can be denoted as {1,2,3,…99} Definition 2. Two sets are equal if and only if they have the same elements. Sets 8 October 2015

Cartesian Product The Cartesian product of two sets is defined as: A  B = {(a, b) | a  A  b  B} Example: A = {x, y}, B = {a, b, c} A  B = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)} 8 October 2015

Set Operations Union: A  B = {x | x  A OR x  B} Example: A = {a, b}, B = {b, c, d} A  B = {a, b, c, d} Intersection: A  B = {x | x  A AND x  B} Example: A = {a, b}, B = {b, c, d} A  B = {b} 8 October 2015

Set Operations Two sets are called disjoint if their intersection is empty, that is, they share no elements: A  B =  The difference between two sets A and B contains exactly those elements of A that are not in B: A-B = {x | x  A  x  B} Example: A = {a, b}, B = {b, c, d}, A-B = {a} 8 October 2015

Set Operations The complement of a set A contains exactly those elements under consideration that are not in A: -A = U-A Example: U = N, B = {250, 251, 252, …} -B = {0, 1, 2, …, 248, 249} 8 October 2015

x y z A function x Not a function Functions and Relations Let A and B be the sets. A function f from A to B is an assignment of exactly one element of B to each element of A. We write f(a)=b if b is the unique element of B assigned by the function f to the element a of A. If f is a function from A to B, we write f : A  B. 8 October 2015

Relations Let A and B be the sets. A relation R from A to B is a subset of A X B From the defination, relation R is a set of pairs. If (a,b) ɛ R, we say a has a relation R with b, denoted as aRb. Functions can be consider as relations, but relations are more general than functions. 8 October 2015

R is an equivalence relation if for any pair (x,y) of R xRx for all x (reflexivity) If xRy then yRx (symmetry) If xRy and yRz, then xRz. (transitivity) We usually use to denote equivalence relation. Example : if A= {a,b} then Reflexive relation = {(a,a),(b,b)} Transitive relation = {(a,b),(b,a),(a,a)} Symmetric relation = {(a,b),(b,a)} Properties of Relation 8 October 2015

Transitive Closure (R + ) Reflexive and Transitive Closure(R*) of a relation R Eg: R ={(1,2),(2,3),(3,4),(5,4)} Solution : for R + we will compute R 2, R 3,R 4,…. R 2 = RoR = {(1,2),(2,3),(3,4),(5,4)} o {(1,2),(2,3),(3,4),(5,4)} = {(1,3),(2,4)} R 3 = R 2 oR = {(1,3),(2,4)}o{(1,2),(2,3),(3,4),(5,4)} = {(1,4)} R 4 = R 3 oR = {(1,4)}o{(1,2),(2,3),(3,4),(5,4)} =Ф R 5 = Ф 8 October 2015

R + = R U R 2 U R 3 {(1,2),(2,3),(3,4),(5,4)} {(1,3),(2,4)} {(1,4)} R + = {(1,2),(2,3),(3,4),(5,4)} U {(1,3),(2,4)} U {(1,4)} R + = {(1,2),(1,3),(1,4),(2,3),(2,4),(3,4),(5,4)} R* = R + U { (1,1),(2,2),(3,3),(4,4),(5,5)} = {(1,2),(1,3),(1,4),(2,3),(2,4),(3,4),(5,4)} U { (1,1),(2,2),(3,3),(4,4),(5,5)} ={(1,2),(1,3),(1,4),(2,3),(2,4),(3,4),(5,4),(1,1),(2,2),(3,3),(4,4),(5,5)} 8 October 2015

Example 1 v7 v1 v2 v5 v4 v9 v8 v3 e1 e3 e4 e5 e7 e6 e2 e8 e9 e10 A directed graph (digraph) Example 2 v7 v1 v2 v5 v4 v9 v8 v3 e1 e3 e4 e5 e7 e6 e2 e8 e9 e10 An undirected graph Graphs A Graph is a construct of two sets, denoted as G=(V,E) where V={v1,v2,v3…,vn} is a set of vertices and E={e1,e2,…em} is a set of edges. Each eage is pair from V 8 October 2015

Induction If we have a propositional function P(n), and we want to prove that P(n) is true for any natural number n, we do the following: 1. Show that P(0) is true. (basis step) 2. Show that if P(n) then P(n + 1) for any n  N. (inductive step) 3. Then P(n) must be true for any n  N. (conclusion) 8 October 2015

Induction … + n = n (n + 1)/2 1. Show that P(0) is true. (basis step) For n = 0 we get 0 = 0. True. 8 October 2015

Induction 2. Show that if P(n) then P(n + 1) for any n  N. (inductive step) … + n = n (n + 1)/ … + n + (n + 1) = n (n + 1)/2 + (n + 1) = (n + 1) (n/2 + 1) = (n + 1) (n + 2)/2 = (n + 1) ((n + 1) + 1)/2 8 October 2015

Induction 3. Then P(n) must be true for any n  N. (conclusion) … + n = n (n + 1)/2 is true for all n  N. End of proof. 8 October 2015

Introduction to Automata Theory 8 October 2015

Theory of computation Theory of Computation aims at studying “How and how efficiently problems can be solved on a model of computation, using an algorithm”.model of computationalgorithm The field is divided into three major branches: automata theory, automata theory Computability theory and Computability theory computational complexity theory. computational complexity theory 8 October 2015

Automata Automaton = an abstract computing device(Note: A “device” need not even be a physical hardware!)Automata theory is theory of models. Working of every process can be represented by means of model. 8 October 2015

Finite Automata states An automaton with a set of states, and its “control” moves from state to state in response to external “inputs” is called a finite automaton. FA, provides the simplest model of a computing device. It has a central processor of finite capacity 8 October 2015

Components of Finite Automata 8 October 2015 left-end x 1 x 2 x 3 x 4 x 5 ……. x n input: x.... Accept / Final state current state initial state Finite control (program) Movable tape head (Read Only) …. no right-end

Components of Finite Automata 8 October 2015 The components of FA model are Input tape, Read control and finite control. The input tape is divided into number of cells. Each cell can hold one i/p symbol. The read head reads one symbol at a time and moves ahead. Finite control acts like a CPU. Depending on the current state and input symbol read from the input tape it changes state.

Finite Automaton – Formal Definition An automaton is represented formally by a 5-tuple5-tuple (Q,Σ,δ,q 0,F), where: Q is a finite set of states. Σ is a finite set of symbols, called the alphabet of thesymbolsalphabet automaton. q 0 is the start state, that is, the state of the automaton before any input has been processed, where q 0 ∈ Q. F is a set of states of Q (i.e. F ⊆ Q) called accept states. δ is the transition function, that is, δ: Q × Σ → Q. For elements q, r  Q; a  Σ; the formula δ(q,a) = {r} specifies the next state (r) by M after reading symbol ‘a’ while in state q. 8 October 2015

How does an FA work? At the beginning, an FA is in the start state (initial state) its tape head points at the first cell For each move, FA reads the symbol under its tape head changes its state (according to the transition function) to the next state determined by the symbol read from the tape and its current state move its tape head to the right one cell 8 October 2015

When does an FA stop working? When it reads all symbols on the tape Then, it gives an answer if the input is in the specific language: Answer “YES” if its last state is a final state Answer “NO” if its last state is not a final state 8 October 2015

Alternative ways of FA representation 1. Transition Diagram Current State Input Symbol Next State 8 October 2015

Example- The circles indicates the states If accepting state is marked with double circle The arrows pointing from a state q indicates how to move on reading a character when current state is q 0,1 Startq0 q1 8 October 2015

Transition Table stateFor all Tape Symbols (a) qiqi q j Where: q i is the current state q j is the next state a is the current symbol

Acceptability of a string by FA A string ‘s’ is accepted by a FA if  (q0,x)=q for some qЄF. Eg : Q = { q0,q1,q2,q3} ∑ = {0,1} F = {q0} Transition function is given as : States i/p 0 1 q0 q2 q1 q1 q3 q0 q2 q0 q3 q3 q1 q2

Solution : Give entire sequence of states for the i/p string  (q0,110101) =  (q1,10101) =  (q0,0101) =  (q2,101) =  (q3,01) =  (q1,1) =  (q0,^)=q0 Hence q0 1 q1 1 q0 0 q2 1 q3 0 q1 1 q0 Thus string is accepted. 8 October 2015

Extended Transition function to Strings It is slightly cumbersome to use a transition function for every i/p symbol. This problem can be resolved using a transition function for the whole string. This extended transition function is defined as δ :Q X ∑ *  Q 8 October 2015

Extended Transition function to Strings Language of DFA : DFA defines a language which contains all the strings that reach to the final state of DFA starting with the start state. If δ is transition function then δ is extended transition function to strings. δ gives resultant o/p state ‘q’ from state q0 by i/p of string w. δ is defined as : 1. δ(q0,ε)=q0; 2. δ(q,w)= δ(δ ( q,w 1 ),w n-1 ) where w=w 1 w 2 ….w n

Determinism and Non-determinism A Finite Automaton may be ‘Deterministic’ or ‘Non- Deterministic’:  Deterministic Automaton means that the machine cannot be in more state than one at any point of time.  Non-Deterministic Automaton means that the machine can be in two or more states at any point of time. 8 October 2015

DFA The FA is called as Deterministic FA,if there is only one path for a specific i/p from current state to next state. Definition: DFA is mathematically represented as a 5- uple(Q,∑,δ,q0, F) The transition function is a function in Q × ∑ → Q 1. a finite set of states (often denoted Q) 2. a finite set of symbols (alphabet) 3. a transition function that takes as argument a state and a symbol and returns a state (often denoted ) 4. a start state often denoted q0 5. a set of final or accepting states (often denoted F) We have q0 Є Q and F Є Q

Example : Password When does an automata accepts a word ? It reads a word and accepts it if it stops in an accepting state. Only word then is accepted q5 is stuck or dead state

NFA Similar to DFA Nondeterministic move On reading an input symbol, the automaton can choose to make a transition to one of selected states. Without reading any symbol, the automaton can choose to make a transition to one of selected states or not. 0 0 

NFA definition A nondeterministic finite automaton M is a five- tuple M = (Q, , , q 0, F), where: 1. Q is a finite set of states of M 2.  is the finite input alphabet of M 3.  : Q    2 Q (power set of Q), is the state transition function mapping a state-symbol pair to a subset of Q 4. q 0 is the start state of M 5. F  Q is the set of accepting states or final states of M

DFA vs NFA DFANFA 1For Every symbol of the alphabet, there is only one state transition in DFA 1We do not need to specify how does the NFA react according to some symbol. 2DFA can not use Empty String transition 2NFA can use Empty String transition. 3DFA can be understood as one machine. 3NFA can be understood as multiple little machines computing at the same time. 4DFA will reject the string if it end at other than accepting state. 4If all of the branches of NFA dies or rejects the string, we can say that NFA reject the string.

NFA to DFA conversion Subset Construction Subset Construction method : Given an NFA with states Q, inputs Σ, transition function δ N, state state q 0, and final states F, construct equivalent DFA with:  states 2 Q (Set of subsets of Q).  Inputs Σ.  Start state {q 0 }.  Final states = all those with a member of F.

Eg: Construct a DFA equivalent to N=({q0,q1},{0,1},δ,q0,{q0}) δ is given in following table: Solution : the states in DFA are subsets of {q0,q1} ie Ф,{q0},{q1},{q0,q1} Initial state : {q0} Final states : {q0} and {q0,q1}... As q0 present in these sets State01 q0 q1 q0,q1

δ can be constructed as bellow : Draw Transition diagram : State01 q0 q1 q0,q1 {q0,q1}

NFA with  -transitions NFA that allows the transition of an empty string from a state Jumping to a state is possible even without input Situation: strings from a lang with 1 st any no. of a’s then any no. of b’s and then any no. of c’s.

NFA with  -transitions A nondeterministic finite automaton with  -transitions (or  -NFA) is a five-tuple M = (Q, , , q 0, F), where: 1. Q is a finite set of states of M 2.  is the finite input alphabet of M 3.  : Q  (  +  )  power set of Q, is the state transition function mapping a state-symbol pair to a subset of Q 4. q 0 is the start state of M 5. F  Q is the set of accepting states or final states of M

Epsilon closure In an NFA M, let q  Q ECLOSE(q) represents all states r that can be reached from q using only  -transitions including itself. Recursive definition for ECLOSE o If  (q,  ) is empty, ECLOSE(q) = {q} o Else, Let  (q,  ) = {r 1, r 2,…, r n }. ECLOSE(q) =  ECLOSE(r i )  {q}

Example : find  -closure for the following NFA with .  Solution : 1.  -closure (q0) = {q0,q1,a2} means self state + reachable states. 2.  -closure(q1) = {q1,q2} 3.  -closure(q2)={q2} q0 q2 q1 ac b

Steps to convert  -NFA to NFA If  -NFA(Q, , , q 0, F) is given then we need to find NFA (Q, ,  ’’, q 0, F’). If  (0,1) then find  ’’(q,0) and  ’’(q,1) for all q ε Q. Steps to find  ’’(q,0) 1. Find  -closure of q. Outcome is set of states. Let that set is P 2. Find  (pi,0) for all pi ε P i>=1 3. Take union of all states obtained from step Find  -closure of all states obtained in step 3. Same steps are repeated for  ’’(q,1) for i/p alphabet 1.

Final states NFA M’ = (Q, ,  ’’, q 0, F’) such that F’ is described as follows F’ = F plus all states q such that ECLOSE(q) contains a state in F

Converting  -NFA into DFA Step1 : first convert  NFA into NFA Step 2: then convert NFA into DFA by sub- state construction method.

Minimization of FA The minimization of FA means reducing no. of states in FA. We need to find equivalent states and then represent them by one representative state. Find equivalent classes ( ie groups of equivalent states) Step 1: Divide FA’s states into two groups a. accepting group b. rejecting group Step 2: Find out if states in groups go to same group on given i/p or create new group. Step 3: Repeat step 2 till no new groups are created.

Finite Automaton Some Applications Software for designing and checking the behavior of digital circuits Lexical analyzer of a typical compiler Software for scanning large bodies of text (e.g., web pages) for pattern finding Software for verifying systems of all types that have a finite number of states (e.g., stock market transaction, communication/network protocol) 8 October 2015

Mealy and Moore Machines Theory of Computation

Specialized FA DFA used to recognize a language. Need: But computers often have to do more useful function of performing calculations and conveying results. Solution: Need m/c that have output capability.

Melay and Moore models Moore Machines : output depend only on the present state. Mealy Machines : output depends on the present state and the present input.

Primitive State Diagram, Moore state/ output input A/0 C/0D/0 B/1 etc. off on off

Definition of a Moore Machine It is a six tuple (Q,∑,Δ,δ,λ,q0) where 1. Q = A finite set of states 2. ∑ = Alphabet of input letters 3. Δ = Alphabet of output letters 4. δ = Transition function ∑ x Q into Q A unique one for each letter and each state 5. λ = Output Table. Maps Q into Δ 6. q0 = is the start state.

Primitive State Diagram, Mealy state input/output A CD B etc. off/1 on/0 off /0

TG for Mealy m/c Q Σ 01 Stateo/pStateo/p

Definition of a Mealy Machine It is a six tuple (Q,∑,Δ,δ,λ,q0) where all the symbols have the same meaning as Moore machine except λ. λ is the output function mapping ∑x Q into Δ

Interconversion Mealy to Moore Moore to mealy 8 October 2015

Thanking you… 8 October 2015