Download - Formal Grammars and Abstract Machines
![Page 1: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/1.jpg)
Formal Grammars and Abstract Machines
Sahar Al Seesi
![Page 2: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/2.jpg)
What are Formal Languages
• Describing the sentence structure of a language in a formal way
• Used in – Natural Language Processing Applications (translators,
grammar checking tools, etc..) • Language: English, French, Spanish, Chinese, etc..
– RNA/Protein Structure Analysis • RNA in general, ribosomal RNA, protein, etc..
– Compilers for programming languages • C, Java, Python, Linux shell script, Assembly, etc..
• To build a program for any of the above applications, the language rules must be described in a formal inclusive way.
![Page 3: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/3.jpg)
Formal Languages and Grammars
• G={ Σ, R, S }
• Σ : Non-terminals (NT) Terminals (T) {S, VERB, SUBJECT, OBJECT} {children, sam, play, eat, ball} {S, A1, A2} {a, c, g, t} {a,c,g,u}
• R : Production rules {S SUBJECT VERB OBJECT}
• S : Starting symbol
• L(G) : The language defined by G; a finite or infinite set of strings (words/sentences)
• L(G) ⊆ T*
![Page 4: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/4.jpg)
Chomsky Hierarchy
Regular
Context-free
Context-sensitive
Unrestricted Grammars Recursively Enumerable Languages
Pow
er o
f ex
pre
ssio
n
Ru
le c
om
ple
xity
Pa
rsin
g ti
me
com
ple
xity
![Page 5: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/5.jpg)
Parsing/Accepting Abstract Machines
Grammar Parsing Automaton
Regular grammars Finite State Machine (FSM)
Context free grammars Push-Down Automaton (PDA)
Context sensitive grammars Linear-Bounded Automaton (LBA)
Unrestricted grammars Turing Machine (TM)
![Page 6: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/6.jpg)
Regular Languages & Regular Expressions
• A regular language can be represented by a regular expression
• Let Σ = {a,b} • Let Lr be the language defined by regular
expression r. r Lr
Σ* the set of all strings over Σ of length 0 or more (includes the empty string, ) Σ+ the set of all strings over Σ of length 1 or more (does not include ) a+ the set of all strings of 1 or more a’s {a, aa, aaa, …} b* the set of all strings of 0 or more b’s {, b, bb, bbb, …}
![Page 7: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/7.jpg)
Combining Regular Languages
• Concatenation
– Let r and s be 2 regular expressions, rs corresponds to the language LrLs
– Example:
• r = a*, s = b+
• LrLs : the set of strings consisting of 0 or more a’s followed by 1 or more b’s
• {b, bb, ab, aabbbb} ⊂ LrLs
![Page 8: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/8.jpg)
Combining Regular Languages
• Union
– Let r and s be 2 regular expressions, r+s corresponds to the language Lr∪Ls
– Example:
• r = a*, s = b+
• Lr∪Ls : the set of strings consisting of 0 or more a’s and strings of 1 or more b’s
• {b, bb, a, aa, bbbb} ⊂Lr ∪ Ls
![Page 9: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/9.jpg)
Combining Regular Languages
• Closure
– Let r be a regular expression, r* corresponds to the language Lr*
– Example:
• r = ab
• Lr* : the set of strings consisting of 0 or more “ab”s (ab)*
• {, ab, abab, abab, ababab} ⊂ Lr*
![Page 10: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/10.jpg)
Example
• R = (a+c+t)ykk(p+q)*vdt(l+z+)pq
• Strings that belong to the language defined by R
ayykppvdtlpq
cyykpqppqvdtpq
tyykqvdtzpq
![Page 11: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/11.jpg)
Regular Grammars
• Can be represented by a regular expression
• Grammar rules are of the form NT T NT
NT T
• Example: The set of all DNA strings
• Regular Expression: {a,c,g,t}+
• G= { Σ, {S}, R, S }
• Σ = {S, a, c, g, t}
• R = {S aS | cS | gS | tS | a | c | g | t}
![Page 12: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/12.jpg)
Finite State Machine
• M={Q, Σ, , q0, F}
• Q: Finite set of states
• Σ: Language alphabet
• : Transition function (Qx Σ Q)
• q0 : Starting state
• F : Set of final states
![Page 13: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/13.jpg)
Finite State Machine Example • M={Q, Σ, , q0, F}
• A FSM for
R = {S aS | cS | gS | tS | a | c | g | t}
2
a,c,g,t
Q = {1,2} Σ = {a, c, g, t}
q0 = 1 F = {2}
(1,a) = 2 (1,c) = 2
(1,g) = 2 (1,t) = 2
(2,a) = 2 (2,c) = 2
(2,g) = 2 (2,t) = 2
a,c,g,t 1
![Page 14: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/14.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input1: 0100
![Page 15: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/15.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input1: 0100
![Page 16: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/16.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input: 0100
![Page 17: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/17.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input1: 0100
![Page 18: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/18.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input1: 0100
![Page 19: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/19.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input1: 0100
![Page 20: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/20.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 21: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/21.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 22: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/22.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 23: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/23.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 24: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/24.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 25: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/25.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input2: 1101
![Page 26: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/26.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input3: 11011
![Page 27: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/27.jpg)
Another Example
L = The set of all strings in {0,1}*that either begin or end (or both) with 01
R = (01(0+1)*)+((0+1)*01)
S B A
E C D
1
0
1
1
1
1 0
0,1
0
0
0
Input3: 11011
![Page 28: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/28.jpg)
Context Free Grammars (CFG) and Languages
• CFGs Can represent nested pair-wise correlation between terminal symbols in the string
• Famous example: palindrome language (wwr) a b a a a a b a
• Can you write a regular grammar for wwr?
• Grammar rules are of the form – NT (T+NT)+
![Page 29: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/29.jpg)
• M={Q, Σ, , , q0, F}
• Q: Finite set of states
• Σ: Language alphabet
• : Stack alphabet
• : Transition function (Q x Σ x Q x *)
• q0 : Starting state
• F : Set of final states
CFG and Push Down Automata
http://epsilonvectorplusplus.wordpress.com
![Page 30: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/30.jpg)
Grammar wwr
• G={ Σ, V, R, S }
• Σ = {a, b} , V = {S}
• R = {S aSa| bSb | aa | bb}
Parse tree for string: abbbba
S
a S a
b S b
b b
![Page 31: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/31.jpg)
Context Free Grammar for an RNA stem loop
• Language : wvwcr
• G={ Σ, R, S }
• Σ = {S, L, a, c, g, u}
• R = {S aSu| uSa | gSc | cSg | L,
L aL | cL | gL | uL | a |c |g | u}
Durbin et. al., Biological Sequence Analysis, adapted
![Page 32: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/32.jpg)
Context Sensitive Grammars and Languages
• Can represent crossing pair-wise correlation between terminal symbols in the string
• Famous example: copy language (ww) a a b b a a b b
• Grammar rules are of the form:
– (T+NT)*NT (T+NT)* (T+NT)+
– |LHS| <= |RHS| (generated RHS cannot shrink from one production step to the next)
![Page 33: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/33.jpg)
CSG and Linear Bounded Automata
SKIP FOR NOW
![Page 34: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/34.jpg)
Non-deterministic and stochastic models
• A stochastic grammar has a probability associated with each rule in the grammar
• Similarly, in automata, a probability would be associated with each transition
![Page 35: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/35.jpg)
Unrestricted Grammars and Recursively Enumerable Languages
• Grammar rules are of the form:
- (T+NT)*NT (T+NT)* (T+NT)*
- The only rule is that the left hand side must
contain at least one variable
• A recursively enumerable language is one that can be represented by an unrestricted grammar
![Page 36: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/36.jpg)
• M={Q, Σ, , , q0, B, F}
• Q: Finite set of states
• Σ: Language alphabet
• : tape alphabet (Σ ⊆ )
• : Transition function (Q x Σ Q x x {L,R})
• q0 : Starting state
• B: The blank symbol
• F : Set of final states
Turing Machines
![Page 37: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/37.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
![Page 38: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/38.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # a a b b # # # # # # #
![Page 39: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/39.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X a b b # # # # # # #
![Page 40: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/40.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X a b b # # # # # # #
![Page 41: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/41.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X a Y b # # # # # # #
![Page 42: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/42.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X a Y b # # # # # # #
![Page 43: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/43.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X a Y b # # # # # # #
![Page 44: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/44.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y b # # # # # # #
![Page 45: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/45.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y b # # # # # # #
![Page 46: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/46.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 47: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/47.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 48: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/48.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 49: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/49.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 50: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/50.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 51: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/51.jpg)
Example
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X X Y Y # # # # # # #
![Page 52: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/52.jpg)
What is the language this TM accepts?
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
![Page 53: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/53.jpg)
Example -cont. (input 2)
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # a b a b # # # # # # #
![Page 54: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/54.jpg)
Example -cont. (input 2)
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X b a b # # # # # # #
![Page 55: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/55.jpg)
Example -cont. (input 2)
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X Y a b # # # # # # #
![Page 56: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/56.jpg)
Example -cont. (input 2)
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X Y a b # # # # # # #
![Page 57: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/57.jpg)
Example -cont. (input 2)
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
# # # # X Y a b # # # # # # #
![Page 58: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/58.jpg)
Language: anbn
q0 q1 q2 q3 q4
a/X,R
Y/Y,R
b/Y,L
a/a,R Y/Y,R
a/a,L Y/Y,L
X/X,R
Y/Y,R
#/#,R
![Page 59: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/59.jpg)
Computing with Turing Machines
Examples: A TM that accepts a number x divisible by 3 in unary format and outputs the results of the computation x/3
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 60: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/60.jpg)
Divide by 3 TM
# # # # 111111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 61: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/61.jpg)
Divide by 3 TM
# # # # X11111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 62: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/62.jpg)
Divide by 3 TM
# # # # XX1111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 63: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/63.jpg)
Divide by 3 TM
# # # # XXX111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 64: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/64.jpg)
Divide by 3 TM
# # # # XXX111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 65: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/65.jpg)
Divide by 3 TM
# # # # XXX111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 66: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/66.jpg)
Divide by 3 TM
# # # # XXX111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 67: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/67.jpg)
Divide by 3 TM
# # # # XXX111 # # # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 68: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/68.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 69: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/69.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 70: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/70.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 71: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/71.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 72: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/72.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 73: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/73.jpg)
Divide by 3 TM
# # # # XXX111 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 74: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/74.jpg)
Divide by 3 TM
# # # # XXXX11 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 75: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/75.jpg)
Divide by 3 TM
# # # # XXXXX1 # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 76: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/76.jpg)
Divide by 3 TM
# # # # XXXXXX # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 77: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/77.jpg)
Divide by 3 TM
# # # # XXXXXX # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 78: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/78.jpg)
Divide by 3 TM
# # # # XXXXXX # 1 # # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 79: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/79.jpg)
Divide by 3 TM
# # # # XXXXXX # 11 # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 80: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/80.jpg)
Divide by 3 TM
# # # # XXXXXX # 11 # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 81: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/81.jpg)
Divide by 3 TM
# # # # XXXXXX # 11 # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 82: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/82.jpg)
Divide by 3 TM
# # # # XXXXXX # 11 # # # #
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 83: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/83.jpg)
Divide by 3 TM Try to parse 1111
q0 q1 q2 q3 q5 1/X,R 1/X,R
1/1,R
#/#,R q4
1/X,R
1/1,R
#/1,L
1/1,L
q6
#/#,L
q8
X/X,R
q7
1/1,L
1/1,L X/X,R
![Page 84: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/84.jpg)
More complex TM models
• Several tapes
• Several read/write heads
A Turing machine can simulate a computer.
![Page 85: Formal Grammars and Abstract Machines](https://reader030.vdocument.in/reader030/viewer/2022012713/61ac73c01cfb0f208246180e/html5/thumbnails/85.jpg)
Back to Linear Bounded Automata
state
$ $
boundary boundary
• LBA is a TM whose read/write head never moves off the portion of the tape occupied by the input string