0% found this document useful (0 votes)
29 views20 pages

Equivalence of Fas: Minimize Minimize

The document discusses formal languages and automata theory. It covers topics like equivalence of finite automata, minimizing deterministic finite automata (DFAs), context-free grammars (CFGs), context-free languages (CFLs) generated by CFGs, and examples of CFGs for different languages. It also includes examples of minimizing a DFA and deriving strings using CFG production rules.

Uploaded by

theresa.painter
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views20 pages

Equivalence of Fas: Minimize Minimize

The document discusses formal languages and automata theory. It covers topics like equivalence of finite automata, minimizing deterministic finite automata (DFAs), context-free grammars (CFGs), context-free languages (CFLs) generated by CFGs, and examples of CFGs for different languages. It also includes examples of minimizing a DFA and deriving strings using CFG production rules.

Uploaded by

theresa.painter
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

2014/2/3 CSC 3130 Formal Languages and Automata Theory 1

Equivalence of FAs
M
1

M
2

M
1
M
2

Minimize
Minimize

???
There is a unique minimum state DFA for
every regular set (unique up to isomorphism,
i.e., the states may have different names but
the structures are the same)
2014/2/3 CSC 3130 Formal Languages and Automata Theory 2
Minimizing a DFA
Two steps:
Removing the states that are inaccessible
from the start state.
Combining states that are equivalent.
Two states p and q are equivalent iff
For any string e, if p r and q s, r is
final iff s is final.
e e
2014/2/3 CSC 3130 Formal Languages and Automata Theory 3
Example of FA Minimization
a
Start
e
f b
c
g
d
h
1
1
1
1
1 1
1
1
0
0
0
0
0
0
0
0
a b c d e f g
h
g
f
e
d
c
b
2014/2/3 CSC 3130 Formal Languages and Automata Theory 4
Example of FA Minimization
We finally get:
Start
1
1
1 1
1
0
0
0
0
0
[c] [d,f]
[b,h]
[a,e]
[g]
2014/2/3 CSC 3130 Formal Languages and Automata Theory 5
Class Discussion
Minimize the following DFA:
0
0 0
1
1 1
a
b
c
d e
f
g
0 1 0
1
0
0
1
1
Start
2014/2/3 CSC 3130 Formal Languages and Automata Theory 6
Context Free Languages (CFL)
Many languages are not regular, e.g.,
balanced parentheses, begin-end matches,
{0
n
1
n
| n>0}, {1
n
2
| n>0}

In this second part, we will study another
class of languages higher in the hierarchy
that can describe a larger set of languages.
2014/2/3 CSC 3130 Formal Languages and Automata Theory 7
Context Free Grammar (CFG)
CFG is invented originally for describing natural
languages:
<sentence> <noun phrase><verb phrase>
<noun phrase> <adjective><noun phrase>
<noun phrase> <noun>
<noun> boy
<adjective> little

<sentence>, <noun phrase>, <verb phrase>, <adjective>
and <noun> are called non-terminals or variables. boy
and little are called terminals. The rules are called
productions.
2014/2/3 CSC 3130 Formal Languages and Automata Theory 8
Example of CFG
<expression> <expression> + <expression>
<expression> <expression> * <expression>
<expression> (<expression>)
<expression> id

Variables: <expression>
Terminals: +, *, (, ), id
2014/2/3 CSC 3130 Formal Languages and Automata Theory 9
Formal Definition of CFG
A CFG is denoted by a 4-tuple:
(V, T, P, S)
where V is a set of variables (non-terminals)
T is a set of terminals
P is a set of productions (rules) of the form:
A o
where A is a variable and o e (VT)*
S is a special variable called start symbol
2014/2/3 CSC 3130 Formal Languages and Automata Theory 10
Production Rules
A set of productions:
A o
1
A o
2
..
A o
k
The above can be written as A o
1
|o
2
|.. |o
k
|

The previous example for <expression> can be
written as E E+E | E*E | (E) | id
2014/2/3 CSC 3130 Formal Languages and Automata Theory 11
Derivation
Lets look the CFG G: E E+E | E*E | (E) | id
E * E
(E) * E
(E) * id
( E + E ) * id
( E + id ) * id
( id + id ) * id
We say o | if | can be obtained from o by applying a
production once. We say o | if | can be obtained from
o by applying the productions zero or more times. We use
to specify clearly which grammar we are using.
E
Derivation
*
G
2014/2/3 CSC 3130 Formal Languages and Automata Theory 12
Context Free Languages (CFL)
The language generated by a CFG G, denoted by
L(G), is :
L(G) = {e | e e T* and S e }

Therefore,
every string consists solely of terminals, and
every string can be derived from S

It is called a context free language (CFL).
*
G
2014/2/3 CSC 3130 Formal Languages and Automata Theory 13
CFL
Notice that:
We must start with the start symbol
We can use any production any number of
times.
The final string can only contain terminals.
2014/2/3 CSC 3130 Formal Languages and Automata Theory 14
Examples of CFG
Consider the following CFG G
1
:
S aSb
S ab

How to generate aabb?
S aSb (use Rule 1)
aabb (use Rule 2)
How to generate aaabbb?
S aSb (use Rule 1)
aaSbb (use Rule 1)
aaabbb (use Rule 2)

2014/2/3 CSC 3130 Formal Languages and Automata Theory 15
Examples of CFG
Consider the following CFG G
2
:
S SS
S (S)
S c
In this example, variables are {S}, terminals are
{(,)}, start symbol is S and productions are the
above three rules.
What language does this grammar generate?

2014/2/3 CSC 3130 Formal Languages and Automata Theory 16
Examples of CFG
How to generate () with G
2
?
S (S) (use Rule 2)
() (use Rule 3)
How to generate (()()) with G
2
?
S (S) (use Rule 2)
(SS) (use Rule 1)
((S)S) (use Rule 2)
((S)(S)) (use Rule 2)
(()(S)) (use Rule 3)
(()()) (use Rule 3)
G
2
:
S SS
S (S)
S c
2014/2/3 CSC 3130 Formal Languages and Automata Theory 17
Examples of CFG
How can we represent all the arithmetic expressions
with plus, minus, parentheses and variables x,
y and z, i.e., {x, y, z, x+y, x-y, y+x, x+(y-z), .. }?

Consider the following CFG G
3
:
E E + E E (E) V x V z
E E - E E V V y

In this example, variables are {E, V}, terminals are
{+, -, (, ), x, y, z}, start symbol is S and productions
are the above seven rules.

2014/2/3 CSC 3130 Formal Languages and Automata Theory 18
Examples of CFG
How to generate x+(y-z)?
E E + E (use Rule 1)
V + E (use Rule 4)
x + E (use Rule 5)
x + (E) (use Rule 3)
x + (E - E) (use Rule 2)
x + (V - E) (use Rule 4)
x + (y - E) (use Rule 6)
x + (y - V) (use Rule 4)
x + (y - z) (use Rule 7)

G
3
:
E E + E | E - E | (E) | V
V x | y | z
2014/2/3 CSC 3130 Formal Languages and Automata Theory 19
Class Discussion

Write a CFG for each of the following
languages:
The set of all palindromes over the alphabet
E={a,b}
{a
n
b
n
c
m
d
m
| n > 1, m > 1}
{a
n
b
m
c
m
d
n
| n > 1, m > 1}
2014/2/3 CSC 3130 Formal Languages and Automata Theory 20
Class Discussion

Consider the grammar:
S aB | bA
A a | aS | bAA
B b | bS | aBB
Generate 4 strings from this grammar.
Do you know what language does this CFG
represent?

You might also like