Reverse of a Regular Language - PowerPoint PPT Presentation

About This Presentation
Title:

Reverse of a Regular Language

Description:

1. Reverse of a Regular Language. 2. Theorem: The reverse of a regular language ... invert the transitions of the NFA. that accepts. 3. Proof. Since is regular, ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 76
Provided by: costas
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Reverse of a Regular Language


1
Reverse of a Regular Language

2
Theorem
The reverse of a regular language is a
regular language
3
Proof
Since is regular, there is NFA that
accepts
Example
4
Invert Transitions
5
Make old initial state a final state
6
Add a new initial state
7
Resulting machine accepts
is regular
8
Grammars

9
Grammars
  • Grammars express languages
  • Example the English language

10

11
  • A derivation of the boy walks

12
  • A derivation of a dog runs

13
  • Language of the grammar

L a boy runs, a boy walks,
the boy runs, the boy walks,
a dog runs, a dog walks, the
dog runs, the dog walks
14
Notation

Variable or Non-terminal
Terminal
Production rule
15
Another Example
  • Grammar
  • Derivation of sentence

16
  • Grammar
  • Derivation of sentence

17
  • Other derivations

18
  • Language of the grammar

19
More Notation
  • Grammar

Set of variables
Set of terminal symbols
Start variable
Set of Production rules
20
Example
  • Grammar

21
More Notation
  • Sentential Form
  • A sentence that contains
  • variables and terminals
  • Example

Sentential Forms
sentence
22
  • We write
  • Instead of

23
  • In general we write
  • If

24
  • By default

25
Example

Grammar
Derivations
26
Example
Grammar
Derivations
27
Another Grammar Example
  • Grammar

Derivations
28
More Derivations

29
Language of a Grammar
  • For a grammar
  • with start variable

String of terminals
30
Example
  • For grammar

Since
31
A Convenient Notation

32
Linear Grammars

33
Linear Grammars
  • Grammars with
  • at most one variable at the right side
  • of a production
  • Examples

34
A Non-Linear Grammar

Grammar
35
Another Linear Grammar
  • Grammar

36
Right-Linear Grammars
  • All productions have form
  • Example

or
37
Left-Linear Grammars
  • All productions have form
  • Example

or
38
Regular Grammars

39
Regular Grammars
  • A regular grammar is any
  • right-linear or left-linear grammar
  • Examples

40
Observation
  • Regular grammars generate regular languages
  • Examples

41
Regular Grammars GenerateRegular Languages

42
Theorem
Languages Generated by Regular Grammars
Regular Languages
43
Theorem - Part 1
Languages Generated by Regular Grammars
Regular Languages
Any regular grammar generates a regular language
44
Theorem - Part 2
Languages Generated by Regular Grammars
Regular Languages
Any regular language is generated by a regular
grammar
45
Proof Part 1
Languages Generated by Regular Grammars
Regular Languages
The language generated by any
regular grammar is regular
46
The case of Right-Linear Grammars
  • Let be a right-linear grammar
  • We will prove is regular
  • Proof idea We will construct NFA
  • with

47
  • Grammar is right-linear

Example
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

55
NFA
Grammar

56
In 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
61
The 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
64

Construct right-linear grammar
In
In
65
  • It is easy to see that
  • Since is right-linear, we have

Regular Language
Regular Language
Regular Language
66
Proof - Part 2
Languages Generated by Regular Grammars
Regular Languages
Any regular language is generated by
some regular grammar
67
Any 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

73
In General
For any transition
Add production
variable
terminal
variable
74
For any final state
Add production
75
  • Since is right-linear grammar
  • is also a regular grammar
  • with
Write a Comment
User Comments (0)
About PowerShow.com