0% found this document useful (0 votes)
54 views78 pages

Automata Theory: CS411-2004F-13 Unrestricted Grammars

The document discusses unrestricted grammars and their relationship to recursively enumerable languages and Turing machines. It begins by reviewing context-free grammars and introducing unrestricted grammars, which allow any string of terminals and nonterminals on the left-hand side of rules. It then proves that the class of languages generated by unrestricted grammars is equal to the class of recursively enumerable languages by showing inclusion in both directions.

Uploaded by

shekhar.mnnit
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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views78 pages

Automata Theory: CS411-2004F-13 Unrestricted Grammars

The document discusses unrestricted grammars and their relationship to recursively enumerable languages and Turing machines. It begins by reviewing context-free grammars and introducing unrestricted grammars, which allow any string of terminals and nonterminals on the left-hand side of rules. It then proves that the class of languages generated by unrestricted grammars is equal to the class of recursively enumerable languages by showing inclusion in both directions.

Uploaded by

shekhar.mnnit
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 PDF, TXT or read online on Scribd
You are on page 1/ 78

Automata Theory

CS411-2004F-13
Unrestricted Grammars
David Galles
Department of Computer Science
University of San Francisco
13-0: Language Hierarchy
Regular
Languaes
Context Free
Languages
Regular Expressions
Finite Automata
Context-Free Grammars
Push-Down Automata
Recusively Enumerable
Languages
??
Turing Machines
13-1: CFG Review
G = (\. . 1. o)
\ = Set of symbols, both terminals & non-terminals
\ set of terminals (alphabet for the language
being described)
1 ((\ ) \

) Set of rules
o (\ ) Start symbol
13-2: Unrestricted Grammars
G = (\. . 1. o)
\ = Set of symbols, both terminals & non-terminals
\ set of terminals (alphabet for the language
being described)
1 (\

(\ )\

) Set of rules
o (\ ) Start symbol
13-3: Unrestricted Grammars
1 (\

(\ )\

) Set of rules
In an Unrestricted Grammar, the left-hand side of a
rule contains a string of terminals and
non-terminals (at least one of which must be a
non-terminal)
Rules are applied just like CFGs:
Find a substring that matches the LHS of some
rule
Replace with the RHS of the rule
13-4: Unrestricted Grammars
To generate a string with an Unrestricted
Grammar:
Start with the initial symbol
While the string contains at least one
non-terminal:
Find a substring that matches the LHS of
some rule
Replace that substring with the RHS of the
rule
13-5: Unrestricted Grammars
Example: Grammar for 1 = {c
n
/
n
c
n
: : 0}
First, generate (1C)

Next, non-deterministically rearrange string


Finally, convert to terminals ( c. 1 /,
etc.), ensuring that string was reordered to form
c

13-6: Unrestricted Grammars


Example: Grammar for 1 = {c
n
/
n
c
n
: : 0}
o 1Co
o 1
C
C C
1 1
C1 1C
C1
C
1
C
c
1
C
1
B
11
B
1
B
/
1
B
1
A
1
A
1
A
c
1
A
c
13-7: Unrestricted Grammars
o 1Co 1
A
//cc
1C1Co 1
A
c//cc
1C1Co 1
A
cc//cc
1C1Co cc//cc
11CCo
11CC1
C
11C1
C
c
111
C
cc
111
B
cc
11
B
/cc
1
B
//cc
13-8: Unrestricted Grammars
o 1Co 1111CCC1
C
1C1Co 111CC1
C
c
1C1C1Co 111C1
C
cc
1C1C1Co 1111
C
ccc
1C1C1Co 1111
B
ccc
1C1C1Co 111
B
/ccc
1C1C1Co 11
B
//ccc
1C1C1Co 1
B
///ccc
1C1C1Co 1
A
///ccc
11CC1Co 1
A
c///ccc
11C1CCo 1
A
cc///ccc
111CCCo 1
A
ccc///ccc ccc///ccc
13-9: Unrestricted Grammars
Example: Grammar for 1 = {uu : u c. /

}
13-10: Unrestricted Grammars
Example: Grammar for 1 = {uu : u c. /

}
Hints:
What if we created a string, and then
rearranged it (like (c/c)

c
n
/
n
c
n
)
13-11: Unrestricted Grammars
Example: Grammar for 1 = {uu : u c. /

}
Hints:
What if we created a string, and then
rearranged it (like (c/c)

c
n
/
n
c
n
)
What about trying uu
R
...
13-12: Unrestricted Grammars
1 = {uu : u c. /

}
o o

2
o

co

/o

1
o

c
2 A2 12 1 2
A A 1 1
1A A1 11 1 1
cA cc c1 c/
/A /c /1 //
13-13: Unrestricted Grammars
1
UG
is the set of languages that can be described
by an Unrestricted Grammar:
1
UG
= {1 : Unrestricted Grammar
G. 1[G] = 1}
Claim: 1
UG
= 1
re
To Prove:
Prove 1
UG
1
re
Prove 1
re
1
UG
13-14: 1
lG
1
:c
Given any Unrestricted Grammar G, we can create
a Turing Machine ` that semi-decides 1[G]
13-15: 1
lG
1
:c
Given any Unrestricted Grammar G, we can create
a Turing Machine ` that semi-decides 1[G]
Two tape machine:
One tape stores the input, unchanged
Second tape implements the derivation
Check to see if the derived string matches the
input, if so accept, if not run forever
13-16: 1
lG
1
:c
To implement the derivation on the second tape:
Write the initial symbol on the second tape
Non-deterministically move the read/write head
to somewhere on the tape
Non-deterministically decide which rule to apply
Scan the current position of the read/write
head, to make sure the LHS of the rule is at
that location
Remove the LHS of the rule from the tape, and
splice in the RHS
13-17: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S
13-18: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S
13-19: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S ABC
13-20: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S ABC
13-21: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S ABCABC
13-22: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S ABCABC
13-23: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AB C A BC
13-24: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AB C A BC
13-25: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AA C B BC
13-26: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AA C B BC
13-27: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AA B B CC
13-28: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
S AA B B CC
13-29: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B CCT
C
13-30: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B CCT
C
13-31: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B C c T
C
13-32: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B C c T
C
13-33: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B c c T
C
13-34: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B c c T
C
13-35: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B c c T
B
13-36: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA B B c c T
B
13-37: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b B c c T
B
13-38: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b B c c T
B
13-39: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b b c c T
B
13-40: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b b c c T
B
13-41: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b b c c T
A
13-42: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
AA b b c c T
A
13-43: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
A a b b c c T
A
13-44: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
A a b b c c T
A
13-45: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
a a b b c c T
A
13-46: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
a a b b c c T
A
13-47: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
a a b b c c
13-48: 1
lG
1
:c
a
...
...
a b b c c
Input Tape
Work Tape
a a b b c c
13-49: 1
:c
1
lG
Given any Turing Machine ` that semi-decides
the language 1, we can create an Unrestricted
Grammar G such that 1[G] = 1
13-50: 1
:c
1
lG
Given any Turing Machine ` that semi-decides
the language 1, we can create an Unrestricted
Grammar G such that 1[G] = 1
Will assume that all Turing Machines accept in
the same conguration: (/. >)
Not a major restriction why?
13-51: 1
:c
1
lG
Given any Turing Machine ` that semi-decides
the language 1, we can create an Unrestricted
Grammar G such that 1[G] = 1
Will assume that all Turing Machines accept in
the same conguration: (/. >)
Not a major restriction why?
Add a tape erasing machine right before the
accepting state, that erases the tape, leaving
the read/write head at the beginning of the tape
13-52: 1
:c
1
lG
Given any Turing Machine ` that semi-decides
the language 1, we can create an Unrestricted
Grammar G such that 1[G] = 1
Grammar: Generates a string
Turing Machine: Works from string to accept
state
Two formalisms work in different directions
Simulating Turing Machine with a Grammar can be
difcult ..
13-53: 1
:c
1
lG
Two formalisms work in different directions
Simulate a Turing Machine in reverse!
Each partial derivation represents a
conguration
Each rule represents a backwards step in
Turing Machine computation
13-54: 1
:c
1
lG
Given a TM `, we create a Grammar G:
Language for G:
Everything in
M
Everything in 1
M
Start symbol o
Symbols > and
13-55: 1
:c
1
lG
Conguration (Q. >ncu) represented by the string:
>ncQu
For example, (Q. > c/c c) is represented by the
string > c/cQ c
13-56: 1
:c
1
lG
For each element in
M
of the form:
((Q
1
. c). (Q
2
. /))
Add the rule:
/Q
2
cQ
1
Remember, simulating backwards computation
13-57: 1
:c
1
lG
For each element in
M
of the form:
((Q
1
. c). (Q
2
. 1))
Add the rule:
Q
2
c cQ
1
13-58: 1
:c
1
lG
For each element in
M
of the form:
((Q
1
. ). (Q
2
. 1))
Add the rule
Q
2
Q
1

(undoing erasing extra blanks)


13-59: 1
:c
1
lG
For each element in
M
of the form:
((Q
1
. c). (Q
2
. 1))
Add the rule
c/Q
2
cQ
1
/
For all /
13-60: 1
:c
1
lG
For each element in
M
of the form:
((Q
1
. c). (Q
2
. 1))
Add the rule
c Q
2
cQ
1

(undoing moving to the right onto unused tape)


13-61: 1
:c
1
lG
Finally, add the rules:
o > /
> Q
s
c
c
13-62: 1
:c
1
lG
If the Turing machine can move from
>u to >/
Then the Grammar can transform
> Q
h
to > Q
s
u
Then, remove > Q
s
and to leave u
13-63: 1
:c
1
lG
Example:
Create a Turing Machine that accepts (c/)

,
halting in the conguration (/. >)
(assume conguration starts out as u)
13-64: 1
:c
1
lG
Example:
Create a Turing Machine that accepts (c/)

,
halting in the conguration (/. >)
R
a
R R
b
a
L yes
a,b
L yes
13-65: 1
:c
1
lG
c /

0
(
1
. ) (
1
. ) (
1
. )

1
(
2
. ) (
h
. )

2
(
3
. )

3
(
2
. ) (
4
. )

4
(
5
. ) (
5
. ) (
h
. )

5
(
4
. )
13-66: 1
:c
1
lG
((
0
. c). (
1
. ))
ccQ
1
cQ
0
c
c/Q
1
cQ
0
/
c Q
1
cQ
0

c Q
1
cQ
0

13-67: 1
:c
1
lG
((
0
. /). (
1
. ))
/cQ
1
/Q
0
c
//Q
1
/Q
0
/
/ Q
1
/Q
0

/ Q
1
/Q
0

13-68: 1
:c
1
lG
((
0
. ). (
1
. ))
cQ
1
Q
0
c
/Q
1
Q
0
/
Q
1
Q
0

Q
1
Q
0

13-69: 1
:c
1
lG
((
1
. c). (
2
. ))
ccQ
2
cQ
1
c
c/Q
2
cQ
1
/
c Q
2
cQ
1

c Q
2
cQ
1

13-70: 1
:c
1
lG
((
1
. ). (
h
. ))
/ Q
1
13-71: 1
:c
1
lG
((
2
. /). (
3
. ))
/cQ
3
/Q
2
c
//Q
3
/Q
2
/
/ Q
3
/Q
2

/ Q
3
/Q
2

13-72: 1
:c
1
lG
((
3
. c). (
4
. ))
ccQ
4
cQ
3
c
c/Q
4
cQ
3
/
c Q
4
cQ
3

c Q
4
cQ
3

13-73: 1
:c
1
lG
((
4
. c). (
5
. ))
Q
5
cQ
4
((
4
. /). (
5
. ))
Q
5
/Q
4
((
4
. ). (
h
. ))
/ Q
4
((
5
. ). (
4
. ))
Q
4
Q
5
13-74: 1
:c
1
lG
S h aQ
1
Q
0
a b Q
3
bQ
2

Q
0
bQ
1
Q
0
b b Q
3
bQ
2

Q
1
Q
0
aaQ
4
aQ
3
a
aaQ
1
aQ
0
a Q
1
Q
0
abQ
4
aQ
3
b
abQ
1
aQ
0
b aaQ
2
aQ
1
a a Q
4
aQ
3

a Q
1
aQ
0
abQ
2
aQ
1
b a Q
4
aQ
3

a Q
1
aQ
0
a Q
2
aQ
1
Q
5
aQ
4
baQ
1
bQ
0
a a Q
2
aQ
1
Q
5
bQ
4
bbQ
1
bQ
0
b h Q
1
h Q
4
b Q
1
bQ
0
baQ
3
bQ
2
a Q
4
Q
5
b Q
1
bQ
0
bbQ
3
bQ
2
b
13-75: 1
:c
1
lG
Generating c/c/
o > /
>/ >Q
4

> Q
4
> Q
5

> Q
5
> cQ
4

> cQ
4
> cQ
5

> cQ
5
> c/Q
4

> c/Q
4
> c/Q
5

> c/Q
5
> c/cQ
4

> c/cQ
4
> c/cQ
5

> c/cQ
5
> c/c/Q
4

13-76: 1
:c
1
lG
Generating c/c/
> c/c/Q
4
> c/c/Q
3

> c/c/ Q
3
> c/c/Q
2

> c/c/Q
2
> c/cQ
3
/
> c/cQ
3
/ > c/Q
2
c/
> c/Q
2
c/ > cQ
1
/c/
>cQ
1
/c/ >Q
0
c/c/
> Q
0
c/c/ c/c/>
c/c/ c/c/

You might also like