
Regular Languages CSCI 2670 LaTex Help From Dr. Frederick W Maier Fall 2014 CSCI 2670 Regular Languages Strings and Languages Definition An alphabet is a nonempty, finite set of objects (symbols). I Σ and Γ are usually used to indicate alphabets. I For instance, Σ1 = fa; b; c; d; e; f g,Σ2 = f0; 1g Definition A string over Σ is any finite sequence of symbols from Σ. The empty string " (sometimes λ) is the string consisting of no symbols. If w = a1a2 ::: an, n ≥ 0 and each ai 2 Σ, is a string over Σ, then I the length jwj of w is n. The length of " is 0. R I w = an ::: a2a1 is the reverse of w. I a substring u of w is any consecutive sequence of 0 or more symbols of w. I 0, 101, and 0101111 are strings over Σ = f0; 1g. I j0j = 1, j101j = 3, and j0101111j = 7. CSCI 2670 Regular Languages Strings and Languages Definition Let x = x1 ::: xn and y = y1 ::: ym be strings over some alphabet. xy = x1 ::: xny1 ::: ym is the concatenation of x and y. I Σ = f0; 1g, I x = 01, y = 001. I xy = 01001, yx = 00101. Definition If w is a string and k 2 N, then w k is the concatenation of k w's. 3 I If w = 001, then w = 001001001. 0 I w = " for any string w. CSCI 2670 Regular Languages Σ∗ and Languages Definition Let Σ be some alphabet. Σ∗ is the set of strings defined as follows: ∗ I Basis: " 2 Σ . ∗ ∗ I If w 2 Σ and a 2 Σ, then wa 2 Σ . I Nothing but strings in the basis or formed by a finite number of applications of the above rule are members of Σ∗. Definition A language L over an alphabet Σ is any subset of Σ∗. In other words, a language is a set of strings. CSCI 2670 Regular Languages Regular Operations Definition Let A and B be languages. The regular operations are: I Union A [ B: fwjw 2 A or w 2 Bg. I Concatenation A ◦ B: fuvju 2 A and v 2 Bg. ∗ I (Kleene) Star A : fw1w2 ::: wnj n ≥ 0 and each wi 2 Ag. ∗ I Observe that for any language A, " 2 A . ∗ I If Σ is a set of symbols, then Σ is just the set of finite strings made from symbols of Σ. I We often write AB rather than A ◦ B. CSCI 2670 Regular Languages Regular Operations Example Let A = fgood; badg and B = fboy; girlg I A [ B: fgood; bad; boy; girlg. I A ◦ B: fgoodboy; badboy; goodgirl; badgirlg. ∗ I A : f"; good; bad; goodgood; goodbad; badgood; badbad;:::g. ∗ I B : f"; boy; girl; boyboy; boygirl; girlboy; girlgirl;:::g. CSCI 2670 Regular Languages Regular Operations I There are several equivalent definitions for regular languages. I They can be defined recursively via regular operations. Let Σ be an alphabet. I Basis: I ? is a regular language over Σ. I f"g is a regular language over Σ. I For each a 2 Σ, fag is a regular language over Σ. I Recursion: I If A and B are regular languages over Σ, A [ B is a regular language over Σ. I If A and B are regular languages over Σ, A ◦ B is a regular language over Σ. ∗ I If A is a regular language over Σ, A is a regular language over Σ. I Closure: Only languages formed via finite applications of the above rules are regular languages over Σ. I The above will work. However, instead we will define regular languages via automata. CSCI 2670 Regular Languages Finite Automata (FA) I A simple model of computation I Read an input string from tape I Determine if the input string is in a language I Determine if the answer for the problem is \YES" or \NO" for the given input on the tape CSCI 2670 Regular Languages How Does a FA Work? I At the beginning, I the FA is in the start state (initial state) I its tape head points at the first cell I For each move, the FA I reads the symbol under its tape head I changes its state (according to the transition function) to the next state determined by the symbol read from the tape and its current state I move its tape head to the right one cell CSCI 2670 Regular Languages How Does a FA Work? I a FA stops I when it reads all symbols on the tape I Then, it gives an answer if the input string is in the specific language: I Answer \YES" if its last state is an accept state I Answer \NO" if its last state is not an accept state CSCI 2670 Regular Languages Deterministic Finite Automata (Informal) I Regular languages can be defined using deterministic finite automata (DFAs). I Informally, a DFA M consists of a set of states q0, q1,... qn. I q0 is called the start state. I Some subset of q0, q1,... qn comprises the accept states. I DFA M reads an input string w = w1 ::: wm, m ≥ 0: I M operates in discrete steps. I M occupies exactly one state at any given time. I M begins in state q0. I M reads w one character at a time, moving left to right. I A transition function, together with the current state and character determines M's next state. I If M reaches the end of w in an accept state, then M accepts string w. Otherwise, it rejects it. I The language L(M) of M is the set of strings M accepts. I A language is regular if and only if there is some DFA that accepts it. CSCI 2670 Regular Languages State Diagrams Figure: An example DFA M1. I A state diagram, a directed graph, is often used to represent DFAs. I Nodes represent states. I Nodes circled twice represent accept states. I An edge with no starting node indicates the start state. I Labelled edges represent the transition function. −! I An edge qi a qj means that if M is in state qi and reads an a, it should move to state qj . Here, L(M1), the language of M1, is the set of strings that have at least one 1, and the last 1 is followed by an even number of 0s. CSCI 2670 Regular Languages Deterministic Finite Automata (Formal) Definition I deterministic finite automaton (DFA) is a 5-tuple (Q; Σ; δ; q0; F ): I Q is a finite, nonempty set of states. I Σ is a finite, nonempty set (the alphabet). I δ : Q × Σ ! Q is total function, the transition function. I q0 2 Q is the start state. I F ⊆ Q is the set of accept states. I Observe that Q and Σ must be finite and nonempty. I q0 must be in Q. I δ is a total function and so maps every pair (q; a) of state q and symbol a to some state q0. I F might be empty. CSCI 2670 Regular Languages Deterministic Finite Automata The above DFA can be formally defined as follows: I Q = fq1; q2; q3g. I Σ = f0; 1g. I δ is given by the table: δ 0 1 q1 q1 q2 q2 q3 q2 q3 q2 q2 I q0 = q1. I F = fq2g CSCI 2670 Regular Languages Deterministic Finite Automata The above DFA M2 can be formally defined as follows: I Q = fq1; q2g. I Σ = f0; 1g. I δ is given by the table: δ 0 1 q1 q1 q2 q2 q1 q2 I q0 = q1. I F = fq2g L(M2) = fwj w ends in a 1g. CSCI 2670 Regular Languages Deterministic Finite Automata The above DFA M3 can be formally defined as follows: I Q = fq1; q2g. I Σ = f0; 1g. I δ is given by the table: δ 0 1 q1 q1 q2 q2 q1 q2 I q0 = q1. I F = fq1g L(M3) = fwj w ends in a 0g [ f"g. CSCI 2670 Regular Languages Deterministic Finite Automata DFA M4 can be formally defined as follows: I Q = fs; q1; q2; r1; r2g. I Σ = fa; bg. I δ is given by the table: δ a b s q1 r1 q1 q1 q2 q2 q1 q2 r1 r2 r1 r2 r2 r1 I q0 = s. I F = fq1; r1g L(M4) = fwjw begins and ends in ag [ fwjw begins and ends in bg. CSCI 2670 Regular Languages Language Acceptance/Recognition for DFAs (Formal) Definition I Let M = (Q; Σ; δ; q0; F ) be a DFA. I Let w = w1 ::: wn be a string such that each wi 2 Σ. I M accepts w if and only if there exists a sequence r0, r1, :::, rn of states of Q such that I r0 = q0. I For each 0 ≤ i < n, δ(ri ; wi+1) = ri+1. I rn 2 F . I Otherwise, M rejects w. Definition If M is a DFA, then M recognizes language L if L = fwjM accepts wg. Definition Language L is regular if there exists some DFA M such that M recognizes L. CSCI 2670 Regular Languages How to Construct a DFA? I Determine what a DFA needs to memorize in order to recognize stings in the language I Hint: the property of the strings in the language I Determine how many states are required to memorize what we want I Accept state(s) memorize the property of the string in the language I Find out how the thing we memorize is changed once the next input symbol is read I From this change, we get the transition function CSCI 2670 Regular Languages Example: Constructing a DFA I Suppose that Σ = f0; 1g and the language consists of all strings with an odd number of 1s.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages41 Page
-
File Size-