regular languages
play

Regular Languages Today we continue looking at our first class - PDF document

Regular Languages Today we continue looking at our first class Kleene Theorem I of languages: Regular languages Means of defining: Regular Expressions Machine for accepting: Finite Automata Kleene Theorem Proving Kleene Theorem A


  1. Regular Languages • Today we continue looking at our first class Kleene Theorem I of languages: Regular languages – Means of defining: Regular Expressions – Machine for accepting: Finite Automata Kleene Theorem Proving Kleene Theorem A language L over Σ is regular iff there • Approach • – Define 2 variants of the Finite Automata exists an FA that accepts L. • Nondeterministic Finite Automata (NFA) 1. If L is regular there exists an FA M such that • Nondeterministic Finite Automata with ε transitions ( ε -NFA) L = L(M) – Prove that FA, NFA, and ε -NFA are equivalent w.r.t. 2. For any FA, M, L(M) is regular the languages they accept – For a regular expression, build a ε -NFA that accepts L(M), the language accepted by the FA can be expressed as a regular expression. the same language – For a DFA build a regular expression that describes the language accepted by the DFA. Proving Kleene Theorem Proving Kleene Theorem • We already showed the equivalence of • Tonight: DFA, NFA, and ε -NFA – Given a RE, find a DFA that accepts the language described by the RE • Left to do • Actually find a ε -NFA – Given a RE, find a DFA that accepts the • Wednesday: language described by the RE • Actually find a ε -NFA – Given a RE, find a DFA that accepts the language described by the RE – Given a DFA, find an RE that describes the • Actually find a ε -NFA language accepted by the DFA

  2. Theory Hall of Fame Pt 1: RE -> DFA • Since ε -NFA are equivalent to DFA w.r.t • Steven Cole Kleene – 1909-1994 the class of languages they accept – b. Hartford, Conn. – We can, given an RE, build an ε -NFA instead of an DFA that accepts the language described – PhD – Princeton (1934) by the RE – Prof at U of Wisc at Madison (1935 – 1979) – We can always then convert that ε -NFA to an equivalent DFA (using the algorithms presented – Introduced Kleene Star op last week) – Defined regular expressions – Anyone with a Theorem named after him/her gets in the THOF! Regular Expression Regular Expression • Recursive definition of regular languages / 4. If L 1 and L 2 are regular languages with regular expression over Σ : expressions r 1 and r 2 then -- L 1 ∪ L 2 is a regular language with regular expression 1. ∅ is a regular language and its regular (r 1 + r 2 ) expression is ∅ -- L 1 L 2 is a regular language with regular expression 2. { ε } is a regular language and ε is its regular (r 1 r 2 ) * is a regular language with regular expression (r 1 expression -- L 1 * ) 3. For each a ∈ Σ , { a } is a regular language and Only languages obtainable by using rules 1-4 are regular its regular expression is a languages . RE -> DFA RE -> DFA • We will build our ε -NFA by structural – Induction: • Assume R 1 and R 2 are regular expressions that induction: describe languages L 1 and L 2 . Then, by the induction hypothesis, there exists ε -NFA , M 1 and – Base case: Build an ε -NFA for ∅ , { ε } , and M 2 that accept L 1 and L 2 { a } , a ∈ Σ • Create ε -NFA that accept the languages described a by: – R 1 + R 2 – R 1 R 2 – R 1 * { a} ∅ { ε }

  3. RE -> DFA RE -> DFA: Union • Basic idea • Induction Hypothesis: – L 1 = L(M 1 ) where M 1 = (Q 1 , Σ , q 1 , δ 1 , F 1 ) – Using ε transitions, create a “branch” where the – L 2 = L(M 2 ) where M 2 = (Q 2 , Σ , q 2 , δ 2 , F 2 ) machine can either following one branch • Assume Q 1 and Q 2 are disjoint (representing one RE) or the other branch (representing the other RE) • Will build ε Start state of M Start state of M 1 – M u = (Q u , Σ , q u , δ u ,F u ) L(M u ) = L 1 + L 2 – M c = (Q c , Σ , q c , δ c , F c ) L(M c ) = L 1 L 2 ε Start state of M 2 – M k = (Q k , Σ , q k , δ k , F k ) L(M k ) = L 1 * RE -> DFA: Union RE -> DFA: Union • Basic idea • Let’s formalize this: – M u = (Q u , Σ , q u , δ u , F u ) – If a string is accepted by either of the existing – Q u = Q 1 ∪ Q 2 ∪ {q u } Ms, it will be accepted by the new M. – F u = F 1 ∪ F 2 • The set of accepting states of M will include each of – Transition function: δ u the accepting states from M 1 and M 2 . • δ u (q u , ε ) = {q 1 , q 2 } • δ u (q u , a) = ∅ for all a ∈ Σ • δ u (q, a) = δ 1 (q, a) if q ∈ Q 1 • δ u (q, a) = δ 2 (q, a) if q ∈ Q 2 RE -> DFA: Union RE -> DFA: Concatenation • Basic idea – Build M to start at the start state of M 1 and from any accepting state of M 1 move directly to the start state of M 2 via a ε transition. ε … … ε -NFA for L 2 ε -NFA for L 1

  4. RE -> DFA: Concatenation RE -> DFA: Concatenation • Basic idea • Let’s formalize this: – M c = (Q c , Σ , q c , δ c , F c ) – After being accepted by the first machine, a string will immediately be tested on the 2 nd – Q c = Q 1 ∪ Q 2 machine – Q c = q 1 • The set of accepting states of the new M will be the – F c = F 2 same as that of the 2 nd machine. RE -> DFA: Concatenation RE -> DFA: Concatenation • Let’s formalize this: – Transition function δ c : • δ c (q, a) = δ 1 (q, a) if q ∈ Q 1 • δ c (q, a) = δ 2 (q, a) if q ∈ Q 2 • For all q ∈ F 1 , δ c (q, ε ) = δ 1 (q, ε ) ∪ {q 2 } RE -> DFA: Kleene Star RE -> DFA: Kleene Star • Basic idea • Basic idea – Create a new start state – Make new start state the accepting state. • Go from new start state to original start state via a ε – Note that you can get from any excepting state transition to the new start state via a ε transition. • Go from any accepting state back to the new start state via a ε transition ε … ε

  5. RE -> DFA: Kleene Star RE -> DFA: Kleene Star • Let’s formalize this: – M k = (Q k , Σ , q k , δ k , F k ) – Q k = Q 1 ∪ {q k } – F k = {q k } – Transition function δ k • δ k (q, a) = δ 1 (q, a) if q ∈ Q 1, • δ k (q k , ε ) = {q 1 } • δ u (q u , a) = ∅ for all a ∈ Σ • For all q ∈ A 1 , δ k (q, ε ) = δ 1 (q, ε ) ∪ {q k } RE -> DFA: Example RE -> DFA: Example • Let’s try an example • (00 + 1) * (10) * – Create an ε -NFA for the regular expression: 0 • (00 + 1) * (10) * � (00 + 1) * (10) * ε 0 0 RE -> DFA: Example RE -> DFA: Example • (00 + 1) * (10) * • (00 + 1) * (10) * ε 1 1 ε ε ε ε ε 0 0 0 0 ε ε ε

  6. RE -> DFA: Example RE -> DFA: Example • (00 + 1) * (10) * • (00 + 1) * (10) * ε 1 1 ε 0 ε ε ε � (00 + 1) * (10) * 0 0 ε ε ε ε ε 1 ε 0 1 ε 0 ε ε Next Time RE -> DFA: Summary • What have we shown: • Kleene II – Given a language L described by a regular expression, – DFA -> RE we can build an ε -NFA that accepts L – Problem Session – Since ε -NFA are equivalent to DFAs, we can, if we wanted to, build an DFA to accept L. – Part 1 of the proof is complete. – Questions?

Recommend


More recommend