Professional Documents
Culture Documents
Chapter 1 - 2 PDF
Chapter 1 - 2 PDF
Automata
Chapter 1: An Introduction to
the Theory of Computation (2)
• Models of Computation
• Automata
• Languages
• Grammars
2
Models of Computation
3
Computation
CPU memory
4
temporary memory
input memory
CPU
output memory
Program memory
5
3
Example: f ( x) = x
temporary memory
input memory
CPU
output memory
Program memory
compute x∗x
2
compute x ∗x
6
3
f ( x) = x
temporary memory
input memory
x=2
CPU
output memory
Program memory
compute x∗x
2
compute x ∗x
7
3
temporary memory f ( x) = x
z = 2*2 = 4
f ( x) = z * 2 = 8
input memory
x=2
CPU
output memory
Program memory
compute x∗x
2
compute x ∗x
8
3
temporary memory f ( x) = x
z = 2*2 = 4
f ( x) = z * 2 = 8
input memory
x=2
CPU
f ( x) = 8
Program memory output memory
compute x∗x
2
compute x ∗x
9
Automata
10
Automaton
temporary memory
Automaton
input memory
CPU
output memory
Program memory
11
Different Kinds of Automata
Automata are distinguished by the temporary memory
12
Finite Automaton
temporary memory
input memory
Finite
Automaton
output memory
input memory
Pushdown
Automaton
output memory
input memory
Turing
Machine
output memory
17
Languages
A language is a set of strings
Strings
a
ab u = ab
abba v = bbbaaa
baba w = abba
aaabbbaabab
19
String Operations
w = a1a2 an abba
v = b1b2 bm bbbaaa
Concatenation
20
w = a1a2 an ababaaabbb
Reverse
R
w = an a2 a1 bbbaaababa
21
String Length
w = a1a2 an
Length: w =n
Examples: abba = 4
aa = 2
a =1
22
Recursive Definition of Length
For any letter: a =1
uv = u + v
Example: u = aab, u = 3
v = abaab, v = 5
uv = aababaab = 8
uv = u + v = 3 + 5 = 8
24
Proof of Concatenation Length
Claim: uv = u + v
Induction basis: v =1
for v = 1,2,, n
for v = n +1
26
Inductive Step
Write v = wa, where w = n, a = 1
Thus: uv = u + w + 1 = u + wa = u + v
27
Empty String
A string with no letters: λ
Observations: λ =0
λw = wλ = w
String Substring
abbab ab
abbab abba
abbab b
abbab bbab
29
Prefix and Suffix
abbab
Prefixes Suffixes
λ abbab w = uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab λ
30
Another Operation
n
w =
ww
w
n
2
Example: (abba ) = abbaabba
0
Definition: w =λ
0
(abba ) = λ
31
The * Operation
Σ * : the set of all possible strings from
alphabet Σ
Σ = {a, b}
Σ* = {λ , a, b, aa, ab, ba, bb, aaa, aab,}
32
The + Operation
+ : the set of all possible strings from
Σ
alphabet Σ except λ
Σ = {a, b}
Σ* = {λ , a, b, aa, ab, ba, bb, aaa, aab,}
+
Σ = Σ * −λ
+
Σ = {a, b, aa, ab, ba, bb, aaa, aab,}
33
Language
A language is any subset of Σ*
Example: Σ = {a, b}
Σ* = {λ , a, b, aa, ab, ba, bb, aaa,}
Languages: {λ}
{a, aa, aab}
{λ , abba, baba, aa, ab, aaaaaa} 34
Note that:
Sets ∅ = { } ≠ {λ}
Set size {} = ∅ = 0
n n
An infinite language L = {a b : n ≥ 0}
λ
ab
∈L abb ∉ L
aabb
aaaaabbbbb
36
Operations on Languages
The usual set operations
R R
Definition: L = {w : w ∈ L}
R
Examples: {ab, aab, baba} = {ba, baa, abab}
n n
L = {a b : n ≥ 0}
R n n
L = {b a : n ≥ 0}
38
Concatenation
40
More Examples
n n
L = {a b : n ≥ 0}
2 n n m m
L = {a b a b : n, m ≥ 0}
2
aabbaaabbb ∈ L
41
Star-Closure
0 1 2
Definition: L* = L L L
Example:
λ ,
a, bb,
{a, bb}* =
aa , abb , bba , bbbb ,
aaa, aabb, abba, abbbb,
42
Positive Closure
Definition: + 1 2
L = L L
= L * −{λ }
a, bb,
+
{a, bb} = aa, abb, bba, bbbb,
aaa, aabb, abba, abbbb,
43
Grammars
44
Grammars
Grammars express languages
predicate → verb 45
article → a
article → the
noun → boy
noun → dog
verb → runs
verb → walks 46
A derivation of “the boy walks”:
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” }
49
Notation
noun → boy
noun → dog
Variable Terminal
Production
or
rule
Non-terminal
50
Another Example
Grammar: S → aSb
S →λ
Derivation of sentence ab :
S ⇒ aSb ⇒ ab
S → aSb S →λ
51
Grammar: S → aSb
S →λ
S → aSb S →λ
52
Other derivations:
53
Language of the grammar
S → aSb
S →λ
n n
L = {a b : n ≥ 0}
54
More Notation
Grammar G = (V , T , S , P )
V : Set of variables
Grammar G: S → aSb
S →λ
G = (V , T , S , P )
V = {S } T = {a, b}
P = {S → aSb, S → λ}
56
More Notation
Sentential Form:
A sentence that contains
variables and terminals
Example:
Instead of:
58
*
In general we write: w1 ⇒ wn
If: w1 ⇒ w2 ⇒ w3 ⇒ ⇒ wn
59
*
By default: w ⇒ w
60
Example
Grammar Derivations
S → aSb *
S ⇒λ
S →λ
*
S ⇒ ab
*
S ⇒ aabb
*
S ⇒ aaabbb
61
Example
Grammar Derivations
S → aSb ∗
S ⇒ aaSbb
S →λ
∗
aaSbb ⇒ aaaaaSbbbbb
62
Another Grammar Example
Grammar G : S → Ab
A → aAb
A→λ
Derivations:
S ⇒ Ab ⇒ b
S ⇒ Ab ⇒ aAbb ⇒ abb
∗
S ⇒ aAbb ⇒ aaAbbb ⇒ aabbb
63
More Derivations
S ⇒ Ab ⇒ aAbb ⇒ aaAbbb ⇒ aaaAbbbb
⇒ aaaaAbbbbb ⇒ aaaabbbbb
∗
S ⇒ aaaabbbbb
∗
S ⇒ aaaaaabbbbbbb
∗
n n
S ⇒a b b
64
Language of a Grammar
For a grammar G
with start variable S :
∗
L(G ) = {w : S ⇒ w}
String of terminals
65
Example
For grammar G: S → Ab
A → aAb
A→λ
n n
L(G ) = {a b b : n ≥ 0}
∗
n n
Since: S ⇒a b b
66
A Convenient Notation
A → aAb
A → aAb | λ
A→λ
article → a
article → a | the
article → the
67