1 / 65

Basic Concepts and Formal Language theory

Basic Concepts and Formal Language theory. Unit –I By T.H. Gurav. Elements of Formal Language. Symbols Alphabets Strings Languages. Alphabet. An alphabet is a finite, non-empty set of symbols We use the symbol ∑ (sigma) to denote an alphabet Examples: Binary: ∑ = {0,1}

yvon
Télécharger la présentation

Basic Concepts and Formal Language theory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Concepts and Formal Language theory Unit –I By T.H. Gurav

  2. Elements of Formal Language Symbols Alphabets Strings Languages

  3. 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} • …

  4. 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 = 010100 |x| = 6 • x = 01  0  1  00  |x| = ? • xy = concatentation of two strings x and y

  5. 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 (∑+)

  6. 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: • Let L be the language of all strings consisting of n 0’s followed by n 1’s: L = {,01,0011,000111,…} • 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

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

  8. Cartesian Product The Cartesian productof 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)}

  9. 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}

  10. 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}

  11. 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}

  12. x x y z A function 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.

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

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

  15. 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 R2 ,R3,R4,…. R2 = RoR = {(1,2),(2,3),(3,4),(5,4)} o {(1,2),(2,3),(3,4),(5,4)} = {(1,3),(2,4)} R3 = R2 oR = {(1,3),(2,4)}o{(1,2),(2,3),(3,4),(5,4)} = {(1,4)} R4 = R3 oR = {(1,4)}o{(1,2),(2,3),(3,4),(5,4)} =Ф R5 = Ф

  16. R+ = R U R2 U R3 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)}

  17. Example 2 Example 1 v3 v3 e3 e3 e1 e1 v2 v2 e7 e7 e8 e8 v7 v7 v1 v1 e10 e10 e4 e4 e6 e6 v8 v8 v5 v5 e5 e5 e9 e9 v4 v4 v9 v9 e2 e2 An undirected graph A directed graph (digraph) 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

  18. 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: • Show that P(0) is true.(basis step) • Show that if P(n) then P(n + 1) for any nN. (inductive step) • Then P(n) must be true for any nN. (conclusion)

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

  20. Induction • Show that if P(n) then P(n + 1) for any nN. (inductive step) 1 + 2 + … + n = n (n + 1)/2 1 + 2 + … + 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

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

  22. Introduction to Automata Theory

  23. 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”. The field is divided into three major branches:  • automata theory,  • Computability theory and  • computational complexity theory.

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

  25. Finite Automata • 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

  26. Components of Finite Automata left-end input: x …. no right-end x1 x2 x3 x4 x5 ……. xn Movable tape head (Read Only) Finite control (program) . . initial state . . Accept / Final state current state

  27. Components of Finite Automata 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.

  28. Finite Automaton – Formal Definition An automaton is represented formally by a 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. q0  is the start state, that is, the state of the automaton before any input has been processed, where q0∈ 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.

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

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

  31. Alternative ways of FA representation1. Transition Diagram Input Symbol Current State Next State

  32. Example- 0,1 • 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 q1 Start q0 0,1

  33. Transition Table Where: qi is the current state qj is the next state a is the current symbol

  34. 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 <Q,∑,,q0,F>

  35. Solution : Give entire sequence of states for the i/p string 110101 (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.

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

  37. 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 : • δ(q0,ε)=q0; • δ(q,w)= δ(δ ( q,w1),wn-1) where w=w1w2….wn

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

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

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

  41. 0 0  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.

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

  43. DFA vs NFA

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

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

  46. δ can be constructed as bellow : Draw Transition diagram :

  47. 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 1st any no. of a’s then any no. of b’s and then any no. of c’s.

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

  49. 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 • If (q, ) is empty, ECLOSE(q) = {q} • Else, Let (q, ) = {r1, r2,…, rn}.ECLOSE(q) = ECLOSE(ri)  {q}

  50. Example : find -closure for the following NFA with .   Solution : • -closure (q0) = {q0,q1,a2} means self state + reachable states . • -closure(q1) = {q1,q2} • -closure(q2)={q2} a c b q2 q1 q0

More Related