Language Recognition 12 4 Longin Jan Latecki Temple

  • Slides: 24
Download presentation
Language Recognition (12. 4) Longin Jan Latecki Temple University Based on slides by Costas

Language Recognition (12. 4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the course http: //www. cs. rpi. edu/courses/spring 05/modcomp/ and … 1

Three Equivalent Representations Regular expressions Finite automata Each can describe the others Regular languages

Three Equivalent Representations Regular expressions Finite automata Each can describe the others Regular languages Kleene’s Theorem: For every regular expression, there is a deterministic finite-state automaton that defines the same language, and vice versa. 2

EXAMPLE 1 Consider the language { ambn | m, n N}, which is represented

EXAMPLE 1 Consider the language { ambn | m, n N}, which is represented by the regular expression a*b*. A regular grammar for this language can be written as follows: S | a. S | B B b | b. B. 3

Regular Expression Regular Grammar a* (a+b)* a* + b* a*b ba* (ab)* S |

Regular Expression Regular Grammar a* (a+b)* a* + b* a*b ba* (ab)* S | a. S | b. S S |A|B A a | a. A B b | b. B S b | a. S S b. A A | a. A S | ab. S 4

NFAs Regular grammars Thus, the language recognized by FSA is a regular language Every

NFAs Regular grammars Thus, the language recognized by FSA is a regular language Every NFA can be converted into a corresponding regular grammar and vice versa. Each symbol A of the grammar is associated with a nonterminal node of the NFA s. A, in particular, start symbol S is associated with the start state s. S. Every transition is associated with a grammar production: T(s. A, a) = s. B A a. B. Every production B is associated with final state s. B. 5

Equivalent FSA and regular grammar, Ex. 4, p. 772. G=(V, T, S, P) V={S,

Equivalent FSA and regular grammar, Ex. 4, p. 772. G=(V, T, S, P) V={S, A, B, 0, 1} with S=s 0, A=s 1, and B=s 2, T={0, 1}, and productions are S 0 A | 1 B | 1 | λ A 0 A | 1 B | 1 B 0 A | 1 B | 1 | λ 6

Kleene’s Theorem Languages Generated by Regular Expressions Languages Recognized by FSA 7

Kleene’s Theorem Languages Generated by Regular Expressions Languages Recognized by FSA 7

We will show: Languages Generated by Regular Expressions Languages Recognized by FSA 8

We will show: Languages Generated by Regular Expressions Languages Recognized by FSA 8

Proof - Part 1 Languages Generated by Regular Expressions Languages Recognized by FSA For

Proof - Part 1 Languages Generated by Regular Expressions Languages Recognized by FSA For any regular expression the language is recognized by FSA (= is a regular language) Proof by induction on the size of 9

Induction Basis Primitive Regular Expressions: NFAs regular languages 10

Induction Basis Primitive Regular Expressions: NFAs regular languages 10

Inductive Hypothesis Assume for regular expressions and that and are regular languages 11

Inductive Hypothesis Assume for regular expressions and that and are regular languages 11

Inductive Step We will prove: Are regular Languages 12

Inductive Step We will prove: Are regular Languages 12

By definition of regular expressions: 13

By definition of regular expressions: 13

By inductive hypothesis we know: and are regular languages We need to show: Regular

By inductive hypothesis we know: and are regular languages We need to show: Regular languages are closed under: Union Concatenation Star This fact is illustrated in Fig. 2 on p. 769. 14

Therefore: Are regular languages And trivially: is a regular language 15

Therefore: Are regular languages And trivially: is a regular language 15

Proof - Part 2 Languages Generated by Regular Expressions Languages Recognized by FSA For

Proof - Part 2 Languages Generated by Regular Expressions Languages Recognized by FSA For any regular language there is a regular expression with Proof by construction of regular expression 16

Since NFA is regular take that accepts it Single final state 17

Since NFA is regular take that accepts it Single final state 17

From construct the equivalent Generalized Transition Graph in which transition labels are regular expressions

From construct the equivalent Generalized Transition Graph in which transition labels are regular expressions Example: 18

Another Example: 19

Another Example: 19

Reducing the states: 20

Reducing the states: 20

Resulting Regular Expression: 21

Resulting Regular Expression: 21

In General Removing states: 22

In General Removing states: 22

The final transition graph: The resulting regular expression: 23

The final transition graph: The resulting regular expression: 23

Three Equivalent Representations Regular expressions Finite automata Each can describe the others Regular languages

Three Equivalent Representations Regular expressions Finite automata Each can describe the others Regular languages 24