october 29, 2009introduction to cognitive science lecture 14: theory of computation i 1 finite...

12
October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I 1 Finite Automata Finite Automata Example 2: Example 2: Can we build a finite Can we build a finite automaton that accepts the language L = automaton that accepts the language L = {a {a [n] [n] b b [n] [n] | n > 0}? | n > 0}? That is, the language of all words that That is, the language of all words that start with a sequence of a’s followed by start with a sequence of a’s followed by the same number of b’s. the same number of b’s. No No , because with our finite number of , because with our finite number of states we have no way to memorize any states we have no way to memorize any number of a’s and determine whether it number of a’s and determine whether it matches the number of b’s. matches the number of b’s. But can we build such an automaton if we But can we build such an automaton if we set an set an upper limit upper limit for n? for n? Yes Yes , we can! , we can!

Post on 20-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

1

Finite AutomataFinite AutomataExample 2: Example 2: Can we build a finite automaton that Can we build a finite automaton that accepts the language L = {aaccepts the language L = {a [n][n]bb[n][n] | n > 0}? | n > 0}?

That is, the language of all words that start with a That is, the language of all words that start with a sequence of a’s followed by the same number of b’s.sequence of a’s followed by the same number of b’s.

NoNo, because with our finite number of states we have , because with our finite number of states we have no way to memorize any number of a’s and determine no way to memorize any number of a’s and determine whether it matches the number of b’s.whether it matches the number of b’s.

But can we build such an automaton if we set an But can we build such an automaton if we set an upper limitupper limit for n? for n?

YesYes, we can!, we can!

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

2

Finite AutomataFinite AutomataExample 3: Example 3: A finite automaton that accepts L = {aA finite automaton that accepts L = {a [n][n]bb[n][n] | 0 < n 2} = {ab, aabb}:| 0 < n 2} = {ab, aabb}:

qq11 qq66

qq44

a,ba,b

bb

qq22

qq33

aa bb

a,ba,b

aa

bb

aa

qq55

bb

aa

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

3

Regular LanguagesRegular LanguagesThe languages accepted by finite automata are called The languages accepted by finite automata are called the the regular languagesregular languages..

To understand the complexity of these languages, we To understand the complexity of these languages, we need to introduce some need to introduce some string operationsstring operations::

Union:Union: If A = {hello, world} and B = {here, I, am}, then If A = {hello, world} and B = {here, I, am}, thenA A B = {hello, world, here, I, am} B = {hello, world, here, I, am}

Concatenation:Concatenation: If A = {mouse, house} and B = {cat,hat}, If A = {mouse, house} and B = {cat,hat}, then A then A B = {mousecat, mousehat, housecat, B = {mousecat, mousehat, housecat, househat}.househat}.

Star Closure:Star Closure: If A = {wow, cool}, then If A = {wow, cool}, thenA* = {0, wow, cool, wowwow, wowcool, coolwow, A* = {0, wow, cool, wowwow, wowcool, coolwow, coolcool, wowcoolwow, coolcoolcool, …}coolcool, wowcoolwow, coolcoolcool, …}

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

4

Regular LanguagesRegular LanguagesThe class of regular languages is defined as follows:The class of regular languages is defined as follows:

(a)(a) The empty language (containing no word) is a The empty language (containing no word) is a regular language. regular language.(b)(b) The language containing only the empty word The language containing only the empty word (containing no letters) is a regular language. (containing no letters) is a regular language. (c)(c) The language containing only a one-symbol word The language containing only a one-symbol word ({a}, {b}, …) is a regular language. ({a}, {b}, …) is a regular language.(d)(d) If A and B are regular languages, then AIf A and B are regular languages, then AB, AB, AB, B, and A* are regular languages. and A* are regular languages.(e)(e) No other languages are regular.No other languages are regular.

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

5

Regular Languages: ExamplesRegular Languages: ExamplesWhat languages are specified by the following regular What languages are specified by the following regular expressions:expressions:

r = {1}*r = {1}*L(r) = {0, 1, 11, 111, …}L(r) = {0, 1, 11, 111, …}

r = {2}r = {2}{1}{1}L(r) = {21}L(r) = {21}

r = ({2}r = ({2}{2}{2}{1}){1})({3}({3}{1}){1})L(r) = {221, 31}L(r) = {221, 31}

r = (({3}r = (({3}{1}){1})({1}({1}{2}))*{2}))*L(r) = {0, 31, 12, 3112, 1231, 3131, 121212, …}L(r) = {0, 31, 12, 3112, 1231, 3131, 121212, …}

r = {1}r = {1}({1}({1}{2}{2}{3})*{3})*{2}{2}L(r) = {12, 132, 112, 122, 1312, 12232, …}L(r) = {12, 132, 112, 122, 1312, 12232, …}

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

6

Regular Languages: ExamplesRegular Languages: ExamplesHere is a difficult one:Here is a difficult one:

What language is described by the following regular What language is described by the following regular expression?expression?

r = ({x}r = ({x}{y})*{y})*{x}{x}{x}{x}({x}({x}{y})*{y})*

L(r) = {xx, xxx, yxx, yxxy, xyxxyy, …}L(r) = {xx, xxx, yxx, yxxy, xyxxyy, …}

The language of all strings of xs and ys containing at The language of all strings of xs and ys containing at least two consecutive xs.least two consecutive xs.

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

7

Turing MachinesTuring MachinesNow what happens if we remove the restriction on Now what happens if we remove the restriction on memory and its accessibility?memory and its accessibility?

This gives us Turing’s original theoretical concept of a This gives us Turing’s original theoretical concept of a computer, the computer, the Turing machineTuring machine..

Just like a finite automaton, the Turing machine’s next Just like a finite automaton, the Turing machine’s next state is always determined by its current state and the state is always determined by its current state and the current symbol under the head.current symbol under the head.

However, each transition also includes However, each transition also includes printing a printing a symbolsymbol or or moving the headmoving the head one square to the left or one square to the left or right.right.

This way the tape serves as This way the tape serves as unlimited, freely unlimited, freely accessible memoryaccessible memory..

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

8

Languages Accepted by Turing MachinesLanguages Accepted by Turing MachinesNotation:Notation: “If we are in state q “If we are in state q11 and read symbol a, the head and read symbol a, the head

moves one position to the right, and the state changes to qmoves one position to the right, and the state changes to q22:”:”

qq11 qq22

a/Ra/R

““If we are in state qIf we are in state q44 and read symbol b, the head moves one and read symbol b, the head moves one

position to the left, and the state changes to qposition to the left, and the state changes to q33:”:”

qq44 qq33

b/Lb/L

““If we are in state qIf we are in state q33 and read symbol B, the head writes the and read symbol B, the head writes the

symbol c and does not move, and the state changes to qsymbol c and does not move, and the state changes to q11:”:”

qq33 qq11

B/cB/c

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

9

Turing MachinesTuring Machines

The input is written to the tape before the Turing The input is written to the tape before the Turing machine is started.machine is started.

The tape head is set onto the leftmost symbol of the The tape head is set onto the leftmost symbol of the input string.input string.

All cells to the left and to the right of the input string All cells to the left and to the right of the input string are initialized with the blank symbol B. are initialized with the blank symbol B.

The Turing machine halts if there is no transition and The Turing machine halts if there is no transition and accepts the input if its last state was an accepting accepts the input if its last state was an accepting one.one.

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

10

Languages Accepted by Turing MachinesLanguages Accepted by Turing Machines

Now let us take a look at examples for Turing Now let us take a look at examples for Turing machines and the languages they accept.machines and the languages they accept.

Example 1: Example 1:

Language L = {bb, bab, baab, baaab, …} Language L = {bb, bab, baab, baaab, …} on the alphabet {a, b}. qon the alphabet {a, b}. q44 is the only accepting state. is the only accepting state.

qq11 qq22 qq33

b/Rb/R

a/Ra/R

b/Rb/R B/RB/Rqq44

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

11

Languages Accepted by Turing MachinesLanguages Accepted by Turing Machines

Example 2: Example 2:

Language L = {aLanguage L = {a[n][n]bb[n][n] | n > 0} on the alphabet {a, b}. | n > 0} on the alphabet {a, b}.

qq77

qq11 qq22

B/BB/B

a/Ba/Bqq33

qq88 qq66 qq55

b/Lb/L

a/La/L

b/Lb/L

B/LB/Lqq44

b/Bb/B

B/RB/R

a/Ra/R

b/Rb/R

B/LB/LB/RB/R

October 29, 2009 Introduction to Cognitive Science Lecture 14: Theory of Computation I

12

TMs as ComputersTMs as Computers

Church’s thesis:Church’s thesis:

Any function that can be algorithmically computed Any function that can be algorithmically computed can also be computed by a Turing machine.can also be computed by a Turing machine.

Why is it only a Why is it only a thesisthesis??

There is no general mathematical definition of There is no general mathematical definition of algorithm – it is always specific to a particular scheme, algorithm – it is always specific to a particular scheme, i.e., a programming language.i.e., a programming language.

Therefore, Church’s thesis cannot be proved.Therefore, Church’s thesis cannot be proved.

However, no counterexample has been found, and no However, no counterexample has been found, and no scientist seriously doubts that Church’s thesis is scientist seriously doubts that Church’s thesis is correct.correct.