regular languages

Download Regular Languages

If you can't read please download the document

Upload: dulcea

Post on 08-Jan-2016

54 views

Category:

Documents


1 download

DESCRIPTION

Giorgi Japaridze Theory of Computability. Regular Languages. Chapter 1. 1.1.a. Giorgi Japaridze Theory of Computability. How a finite automaton works. 1. q 0. 0. q 2. 1. 1. 0. q 1. 0. 0 1 1 0 0. 1.1.b. Giorgi Japaridze Theory of Computability. The language of a machine. - PowerPoint PPT Presentation

TRANSCRIPT

  • Regular LanguagesChapter 1 Giorgi Japaridze Theory of Computability

  • How a finite automaton works1.1.aGiorgi Japaridze Theory of Computability q2q0q10001110 1 1 0 0

  • The language of a machine1.1.bGiorgi Japaridze Theory of Computability q2q0q1000111 L(M), the language of M, or the language recognized by M --- the set of all strings that the machine M acceptsWhat is the language recognized by our automaton A?

  • Formal definition of a finite automaton 1.1.cGiorgi Japaridze Theory of Computability A (deterministic) finite automaton (DFA) is a 5-tuple (Q, , , s, F), where:

    Q is a finite set whose elements are called the states

    is a finite set called the alphabet

    is a function of the type Q Q called the transition function

    s is an element of Q called the start state

    F is a subset of Q called the set of accept states

  • Our automaton formalized1.1.dGiorgi Japaridze Theory of Computability q2q0q1000111 Q:

    :

    :

    s:

    F: 0 1q0

    q1

    q2 A = (Q, , , s, F)

  • Formal definition of computation1.1.eGiorgi Japaridze Theory of Computability M = (Q, , , s, F)M accepts the string u1 u2 un iff there is a sequence r1, r2, , rn, rn+1 of states such that:

    r1=s

    ri+1 = (ri,ui), for each i with 1 i n

    rn+1 Fq2q0q1001110 1 1 0 0q0 q2 q0 q0 q2 q1u1 u2 unr1, r2, , rn, rn+10

  • Designing finite automata1.1.fGiorgi Japaridze Theory of Computability Task:

    Design an automaton that accepts a bit string iff it contains an even number of 1s.

  • NFAs (Nondeterministic Finite Automata)1.2.aGiorgi Japaridze Theory of Computability q1q2q30,110,10 1 0 1 0q1q1 q2q1 q3q1 q2q1q1 q301010

  • NFAs (Nondeterministic Finite Automata)1.2.aGiorgi Japaridze Theory of Computability q1q2q30,110,1What language does this NFA recognize?

  • Formal definition of a nondeterministic finite automaton1.2.bGiorgi Japaridze Theory of Computability An NFA is a 5-tuple (Q, , , s, F), where:

    Q is a finite set whose elements are called the states

    is a finite set called the alphabet

    is a function of the type Q P(Q) called the transition function

    s is an element of Q called the start state

    F is a subset of Q called the set of accept states

  • Example1.2.cGiorgi Japaridze Theory of Computability Q:

    :

    :

    s:

    F: a b 1

    2

    3 A = (Q, , , s, F) 321aaba,bb

  • Formal definition of accepting1.2.dGiorgi Japaridze Theory of Computability M = (Q, , , s, F)M accepts the string u1 u2 un iff there is a sequence r1, r2, , rn, rn+1 of states such that:

    r1=s

    ri+1 = (ri,ui), for each i with 1 i n

    rn+1 FWhen M is a DFA M accepts the string u1 u2 un iff there is a sequence r1, r2, , rn, rn+1 of states such that:

    r1=s

    ri+1 (ri,ui), for each i with 1 i n

    rn+1 FWhen M is an NFA

  • What language does this NFA recognize?1.2.eGiorgi Japaridze Theory of Computability 0000000

  • What language does this DFA recognize?1.2.fGiorgi Japaridze Theory of Computability 0000

    00054321

  • Equivalence of NFAs and DFAs1.2.gGiorgi Japaridze Theory of Computability Two machines are said to be equivalent if they recognize the same language.Theorem 1.39 Every NFA has an equivalent DFA.Proof. Consider an NFA N = (Q, , , s, F)

    We need construct an equivalent DFA D = (Q, , , s, F)

    using a procedure called the subset construction described on the next slide.

  • The subset construction1.2.hGiorgi Japaridze Theory of Computability Constructing DFA D = (Q, , , s, F) from NFA N = (Q, , , s, F) Q = P (Q)

    (R,a) = {q | q=(p,a) for some pR} s = {s}

    F= {R | R is a subset of Q containing an accept state of N}

    D obviously works correctly: at every step in the computation, it clearly enters a state that corresponds to the subset of states that N could be in at that point.

  • Example of applying the subset construction 1.2.iGiorgi Japaridze Theory of Computability Q:

    :

    :

    s:

    F: a b {1}{2}{3}{1,2}{1,3}{2,3}{1,2,3} N = (Q, , , s, F) 321aaba,bbQ = P (Q) (R,a) = {q | q=(p,a) for some pR} s = {s} F= {R | R is a subset of Q containing an accept state of N}

  • The resulting DFA 1.2.jGiorgi Japaridze Theory of Computability {3}{1}{1,3}{2,3}{1,2}{1,2,3}{2}ba,baabababba,babaD

  • Removing unreachable states 1.2.kGiorgi Japaridze Theory of Computability {3}{1}{2,3}{1,2,3}ba,baabbabaD

  • Testing in work 1.2.lGiorgi Japaridze Theory of Computability {3}{1}{2,3}{1,2,3}ba,baabbabaD321aaba,bbNb a a

  • Regular operations1.3.aGiorgi Japaridze Theory of Computability Union: L1 L2 = {x | xL1 or xL2}

    {Good,Bad} {Boy,Girl} =

    {0,00,000,} {1,11,111,} =

    L =

    Concatenation: L1 L2 = {xy | xL1 and yL2}

    {Good,Bad}{Boy,Girl} =

    {0,00,000,}{1,11,111,} =L =

    Star: L* = {x1xk | k0 and each xi is in L}

    {Boy,Girl}* =

    {0,00,000,}* =

    * =

  • Regular expressions1.3.bGiorgi Japaridze Theory of Computability We say that R is a regular expression (RE) iff R is one of the following:

    1. a, where a is a symbol of the alphabet

    2.

    3.

    4. (R1)(R2), where R1 and R2 are RE

    5. (R1) (R2), where R1 and R2 are RE

    6. (R1)*, where R1 is a RE

    What language is represented by the expression:

    {a}

    {}

    The union of the languages represented by R1 and R2The concatenation of the languages represented by R1 and R2The star of the language represented by R1 Conventions: The symbol is often omitted in RE Some parentheses can be omitted. The precedence order for the operators is: * (highest), (medium), (lowest)

  • Regular languages1.3.cGiorgi Japaridze Theory of Computability A language is said to be regular iff it can be represented by a regular expression. Language Expression{11}{Boy, Girl, Good, Bad}{,0,00,000,0000,}{0,00,000,0000,}{,01,0101,010101,01010101,}{x | x = 0k where k is a multiple of 2 or 3}{x | x is divisible by 8}{x | x MOD 4 = 3}

  • Exercising reading regular expressions1.3.dGiorgi Japaridze Theory of Computability Expression Language0*10* (Good Bad)(Boy Girl)(Tom Bob)_is_(good bad){Name_is_adjective | Name is an uppercaseletter followed by zero or more lowercase letters, and adjective is a lowercase letterfollowed by zero or more lowercase letters}(0 1)*101(0 1)*((0 1)(0 1))*

  • Regular languages and DFA-recognizable languages are the same1.3.eGiorgi Japaridze Theory of Computability Theorem 1.54* A language is regular if and only if some NFA (DFA) recognizes it. The textbook describes an algorithm for converting any given regular expression to an equivalent NFA, and an algorithm for converting anygiven NFA to an equivalent regular expression. Proof omitted (but given in the textbook).

  • The limitations of the power of DFAs 1.4.aGiorgi Japaridze Theory of Computability The computing power of finite automata is severely limited by the fact that their memory (= set of states) is small (= of a fixed size) while inputs can be arbitrarily large. To summarize, DFAs are not as powerful as computers can generally be. While the memories of real computers are also finite, they are not fixed, in the sense that we assume one can always supply additional memory if needed. The next slide gives several examples of non-regular languages, i.e. languages that no DFA can handle (recognize). The non-regularity ofthose languages can be strictly proven using the tool called pumping lemma. We omit the pumping lemma in this course (but it is in the textbook). Instead, we will simply rely on intuitive arguments. Warning: Generally one cannot safely rely on intuition when making important conclusions, because intuition can sometimes be deceptive. Only strict mathematical proofs can be trusted.

  • Non-regular languages 1.4.bGiorgi Japaridze Theory of Computability Do the following languages look regular to you? A = { ww | w {0,1}* }Is not regular.Intuitively, this is so because a DFA processing a long input will have forgotten much of the previously seen part of the input when it gets to the middle of the string. But without fully remembering the first half of the string, it is impossible to tell whether the second half coincides with it or not. B = { 0n1n | n0}Is not regular.Intuitively, this is so because a DFA processing a long input 0n1n will be unable to remember exactly how many 0s it has seen by the time when the 1s start. But without that information it is impossible to tell whether the remaining 1* part of input has the same length as the already seen 0* part. C = {w | w contains the same number of 0s as 1s}Is not regular.An intuitive reason here is similar to the one for language B. D = {w | w contains the same number of 01s as 10s}Is regular.Intuitively, it may appear to you that if C is irregular, even more so should be D. Butyouve been warned about the deceptiveness of intuition. The following slide shows a DFA that recognizes D, so that D is regular!

  • A DFA recognizing D1.4.cGiorgi Japaridze Theory of ComputabilityD = {w | w contains the same number of 01s as 10s}0110110001

    ****************************