
Theory of Computer Science C2. Regular Languages: Finite Automata Gabriele R¨oger University of Basel March 23, 2020 Regular Grammars DFAs NFAs Summary Regular Grammars Regular Grammars DFAs NFAs Summary Overview Regular Languages Grammars & Grammars DFAs Regular NFAs Languages Automata & Regular Formal Languages Expressions Context-free Pumping Languages Lemma Minimal Context-sensitive & Automata Type-0 Languages Properties Rule X ! " is only allowed if X = S and S never occurs in the right-hand side of a rule. How restrictive is this? Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple hΣ; V ; P; Si with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V \ Σ = ;) 3 P ⊆ (V × (Σ [ ΣV )) [ fhS;"ig finite set of rules 4 if S ! " 2 P, there is no X 2 V ; y 2 Σ with X ! yS 2 P 5 S 2 V start variable. How restrictive is this? Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple hΣ; V ; P; Si with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V \ Σ = ;) 3 P ⊆ (V × (Σ [ ΣV )) [ fhS;"ig finite set of rules 4 if S ! " 2 P, there is no X 2 V ; y 2 Σ with X ! yS 2 P 5 S 2 V start variable. Rule X ! " is only allowed if X = S and S never occurs in the right-hand side of a rule. Regular Grammars DFAs NFAs Summary Repetition: Regular Grammars Definition (Regular Grammars) A regular grammar is a 4-tuple hΣ; V ; P; Si with 1 Σ finite alphabet of terminals 2 V finite set of variables (with V \ Σ = ;) 3 P ⊆ (V × (Σ [ ΣV )) [ fhS;"ig finite set of rules 4 if S ! " 2 P, there is no X 2 V ; y 2 Σ with X ! yS 2 P 5 S 2 V start variable. Rule X ! " is only allowed if X = S and S never occurs in the right-hand side of a rule. How restrictive is this? Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules For every type-0 language L there is a grammar where the start variable does not occur on the right-hand side of any rule. Theorem For every grammar G = hΣ; V ; P; Si there is a grammar G 0 = hΣ; V 0; P0; Si with rules P0 ⊆ (V 0 [ Σ)+ × (V 0 n fSg [ Σ)∗ such that L(G) = L(G 0). Note that the rules in P0 are not fundamentally different from the rules in P. In particular: If P ⊆ V × (Σ [ ΣV [ f"g) then P0 ⊆ V 0 × (Σ [ ΣV 0 [ f"g). If P ⊆ V × (V [ Σ)∗ then P0 ⊆ V 0 × (V 0 [ Σ)∗. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Proof Proof. Let G = hΣ; V ; P; Si be a grammar and S0 62 V be a new variable. Construct rule set P0 from P as follows: for every rule r 2 P, add a rule r 0 to P0, where r 0 is the result of replacing all occurences of S in r with S0. for every rule S ! w 2 P, add a rule S ! w 0 to P0, where w 0 is the result of replacing all occurences of S in w with S0. Then L(G) = L(hΣ; V [ fS0g; P0; Si). Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Proof Proof. Let G = hΣ; V ; P; Si be a grammar and S0 62 V be a new variable. Construct rule set P0 from P as follows: for every rule r 2 P, add a rule r 0 to P0, where r 0 is the result of replacing all occurences of S in r with S0. for every rule S ! w 2 P, add a rule S ! w 0 to P0, where w 0 is the result of replacing all occurences of S in w with S0. Then L(G) = L(hΣ; V [ fS0g; P0; Si). Note that the rules in P0 are not fundamentally different from the rules in P. In particular: If P ⊆ V × (Σ [ ΣV [ f"g) then P0 ⊆ V 0 × (Σ [ ΣV 0 [ f"g). If P ⊆ V × (V [ Σ)∗ then P0 ⊆ V 0 × (V 0 [ Σ)∗. Regular Grammars DFAs NFAs Summary Start Variable in Right-Hand Side of Rules: Example Regular Grammars DFAs NFAs Summary Epsilon Rules Theorem For every grammar G with rules P ⊆ V × (Σ [ ΣV [ f"g) there is a regular grammar G 0 with L(G) = L(G 0). Proof. Let G = hΣ; V ; P; Si be a grammar s.t. P ⊆ V × (Σ [ ΣV [ f"g). Use the previous proof to construct grammar G 0 = hΣ; V 0; P0; Si s.t. P0 ⊆ V 0 × (Σ [ Σ(V 0 n fSg) [ f"g). 0 Let V" = fA j A ! " 2 P g. Let P00 be the rule set that is created from P0 by removing all rules of the form A ! " (A 6= S). Additionally, for every rule of the form 0 00 B ! xA with A 2 V"; B 2 V ; x 2 Σ we add a rule B ! x to P . Then G 00 = hΣ; V 0; P00; Si is regular and L(G) = L(G 00). Regular Grammars DFAs NFAs Summary Epsilon Rules: Example Regular Grammars DFAs NFAs Summary Questions Questions? Regular Grammars DFAs NFAs Summary DFAs Regular Grammars DFAs NFAs Summary Overview Regular Languages Grammars & Grammars DFAs Regular NFAs Languages Automata & Regular Formal Languages Expressions Context-free Pumping Languages Lemma Minimal Context-sensitive & Automata Type-0 Languages Properties q1, q0, q0, q1, q2. When reading the input 01100 the automaton visits the states q0, Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, Regular Grammars DFAs NFAs Summary Finite Automata: Example 0 1 1 q1 q0 1 q2 0 0 When reading the input 01100 the automaton visits the states q0, q1, q0, q0, q1, q2. δ(q0; 0) = q1 δ 0 1 q0 q1 q0 δ(q0; 1) = q0 q1 q2 q0 δ(q1; 0) = q2 q2 q2 q0 δ(q1; 1) = q0 table form of δ δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g input alphabet Σ = f0; 1g transition function δ start state q0 end states fq2g δ(q0; 0) = q1 δ 0 1 q0 q1 q0 δ(q0; 1) = q0 q1 q2 q0 δ(q1; 0) = q2 q2 q2 q0 δ(q1; 1) = q0 table form of δ δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g input alphabet Σ = f0; 1g transition function δ start state q0 end states fq2g δ(q0; 0) = q1 δ 0 1 q0 q1 q0 δ(q0; 1) = q0 q1 q2 q0 δ(q1; 0) = q2 q2 q2 q0 δ(q1; 1) = q0 table form of δ δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g input alphabet Σ = f0; 1g transition function δ start state q0 end states fq2g δ 0 1 q0 q1 q0 q1 q2 q0 q2 q2 q0 table form of δ Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g δ(q0; 0) = q1 input alphabet Σ = f0; 1g δ(q0; 1) = q0 transition function δ δ(q1; 0) = q2 start state q0 δ(q1; 1) = q0 end states fq2g δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g δ(q0; 0) = q1 δ 0 1 q0 q1 q0 input alphabet Σ = f0; 1g δ(q0; 1) = q0 q1 q2 q0 transition function δ δ(q1; 0) = q2 q2 q2 q0 start state q0 δ(q1; 1) = q0 table form of δ end states fq2g δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g δ(q0; 0) = q1 δ 0 1 q0 q1 q0 input alphabet Σ = f0; 1g δ(q0; 1) = q0 q1 q2 q0 transition function δ δ(q1; 0) = q2 q2 q2 q0 start state q0 δ(q1; 1) = q0 table form of δ end states fq2g δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Finite Automata: Terminology and Notation 1 1 q1 q0 1 q2 0 0 0 states Q = fq0; q1; q2g δ(q0; 0) = q1 δ 0 1 q0 q1 q0 input alphabet Σ = f0; 1g δ(q0; 1) = q0 q1 q2 q0 transition function δ δ(q1; 0) = q2 q2 q2 q0 start state q0 δ(q1; 1) = q0 table form of δ end states fq2g δ(q2; 0) = q2 δ(q2; 1) = q0 Regular Grammars DFAs NFAs Summary Deterministic Finite Automaton: Definition Definition (Deterministic Finite Automata) A deterministic finite automaton(DFA) is a 5-tuple M = hQ; Σ; δ; q0; Ei where Q is the finite set of states Σ is the input alphabet (with Q \ Σ = ;) δ : Q × Σ ! Q is the transition function q0 2 Q is the start state E ⊆ Q is the set of end states German: deterministischer endlicher Automat, Zust¨ande, German: Eingabealphabet, Uberf¨uhrungs-/¨ Ubergangsfunktion,¨ German: Startzustand, Endzust¨ande Regular Grammars DFAs NFAs Summary DFA: Recognized Words Definition (Words Recognized by a DFA) DFA M = hQ; Σ; δ; q0; Ei recognizes the word w = a1 ::: an 0 0 if there is a sequence of states q0;:::; qn 2 Q with 1 0 q0 = q0, 2 0 0 δ(qi−1; ai ) = qi for all i 2 f1;:::; ng and 0 3 qn 2 E.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages77 Page
-
File Size-