Title: Reverse of a Regular Language
1Reverse of a Regular Language
2Theorem
The reverse of a regular language is a
regular language
3Proof
Since is regular, there is NFA that
accepts
Example
4Invert Transitions
5Make old initial state a final state
6Add a new initial state
7Resulting machine accepts
is regular
8Grammars
9Grammars
- Grammars express languages
- Example the English language
10 11- A derivation of the boy walks
12- A derivation of a dog runs
13L a boy runs, a boy walks,
the boy runs, the boy walks,
a dog runs, a dog walks, the
dog runs, the dog walks
14Notation
Variable or Non-terminal
Terminal
Production rule
15Another Example
- Grammar
- Derivation of sentence
16- Grammar
- Derivation of sentence
17 18 19More Notation
Set of variables
Set of terminal symbols
Start variable
Set of Production rules
20Example
21More Notation
- Sentential Form
- A sentence that contains
- variables and terminals
- Example
Sentential Forms
sentence
22 23 24 25Example
Grammar
Derivations
26Example
Grammar
Derivations
27Another Grammar Example
Derivations
28More Derivations
29Language of a Grammar
- For a grammar
- with start variable
String of terminals
30Example
Since
31A Convenient Notation
32Linear Grammars
33Linear Grammars
- Grammars with
- at most one variable at the right side
- of a production
- Examples
-
34A Non-Linear Grammar
Grammar
35Another Linear Grammar
36Right-Linear Grammars
- All productions have form
- Example
or
37Left-Linear Grammars
- All productions have form
- Example
or
38Regular Grammars
39Regular Grammars
- A regular grammar is any
- right-linear or left-linear grammar
- Examples
40Observation
- Regular grammars generate regular languages
- Examples
41Regular Grammars GenerateRegular Languages
42Theorem
Languages Generated by Regular Grammars
Regular Languages
43Theorem - Part 1
Languages Generated by Regular Grammars
Regular Languages
Any regular grammar generates a regular language
44Theorem - Part 2
Languages Generated by Regular Grammars
Regular Languages
Any regular language is generated by a regular
grammar
45Proof Part 1
Languages Generated by Regular Grammars
Regular Languages
The language generated by any
regular grammar is regular
46The case of Right-Linear Grammars
- Let be a right-linear grammar
- We will prove is regular
- Proof idea We will construct NFA
- with
47Example
48- Construct NFA such that
- every state is a grammar variable
special final state
49- Add edges for each production
50 51 52 53 54 55NFA
Grammar
56In General
- A right-linear grammar
- has variables
- and productions
or
57- We construct the NFA such that
- each variable corresponds to a node
special final state
58- For each production
- we add transitions and intermediate nodes
59- For each production
- we add transitions and intermediate nodes
60- Resulting NFA looks like this
It holds that
61The case of Left-Linear Grammars
- Let be a left-linear grammar
- We will prove is regular
- Proof idea
- We will construct a right-linear
- grammar with
62 Since is left-linear grammar the
productions look like
63- Construct right-linear grammar
In
In
64Construct right-linear grammar
In
In
65- It is easy to see that
- Since is right-linear, we have
-
-
Regular Language
Regular Language
Regular Language
66Proof - Part 2
Languages Generated by Regular Grammars
Regular Languages
Any regular language is generated by
some regular grammar
67Any regular language is generated by
some regular grammar
Proof idea
Let be the NFA with .
Construct from
a regular grammar such that
68- Since is regular
- there is an NFA such that
Example
69- Convert to a right-linear grammar
70 71 72 73In General
For any transition
Add production
variable
terminal
variable
74For any final state
Add production
75- Since is right-linear grammar
-
- is also a regular grammar
- with