51
Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel- Girshin Lea Epstein Yael Moses

Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Embed Size (px)

Citation preview

Page 1: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Complexity and Computability Theory I

Lecture #13

Instructor: Rina Zviel-Girshin

Lea Epstein

Yael Moses

Page 2: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 2

Overview

• Usage of pumping lemma for CFL• Review of the course • Decidability• Decision problems in FA• Turing machine

Page 3: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 3

L={aibic2i |i>0}

We will use the pumping lemma to prove that L={aibic2i |i>0} is not CFL.

Proof: • We assume that L is CFL and obtain a

contradiction. • Let p be the pumping length for L.• We select a string w= apbpc2p . wL and |w|

>p, so it can be pumped.

Page 4: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 4

• Lets divide w into five parts uvxyz such that |vy|>0 and |vxy|p.

• We have two major partition cases:1. vxy contains a single alphabet symbol ( 3

types of partition: or a’-s or b’-s or c’-s)2. vxy contains two symbols of the alphabet (

2 types of partition: or a’-s and b’-s or b’-s and c’-s)

L={aibic2i |i>0}

Page 5: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 5

• If vxy contains only one type of alphabet symbol then i=2 will give us a word w2=uv2xy2z and w2 L .

• WHY?• Because w2 does not contain the same

number of a's, b's and twice c's.

L={aibic2i |i>0}

Page 6: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 6

• If vxy contains only two type of alphabet symbols (can't have three because |vxy|<=p) then i=2 will give us a word w2=uv2xy2z and w2 L .

• WHY?

• Because w2 does not contain the same number of a's, b's and twice c's. We pumped only two alphabet symbols.

L={aibic2i |i>0}

Page 7: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 7

L={aibic2i |i>0}

• One of these cases must occur.

• In both cases we have a contradiction to lemma.

• So the assumption that L is CFL must be false.

• L is not CFL.

Page 8: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 8

Review

Among the aims:

• practical techniques - useful in compilation, translation, data compression etc.

• formalization of the concept of language - useful in formal linguistics etc.

• computational models - useful in answering basic questions about computations.

Page 9: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 9

Computational Model

•  A simplistic and minimal model for computation.

 

• Computation - not only arithmetic but also solving a problem, anything a computer can or is expected to perform.

Page 10: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 10

Computational Model Usage

• To answer basic questions about our ability to solve problems and better understand the formal (algorithmic/logical/mathematical) computation.

 • Understanding of the computer abilities and

its limits.

Page 11: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 11

Formal Languages

• One, very important, formalization of computation, in addition to its usefulness in other aspects.

• The computation determines if a word is in a language.

• Any problem can be reduced to this problem of a word belonging to a language.

Page 12: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 12

Example

• An arithmetical problem of finding the answer to:

3*7=X • This problem can be formulated as a question:

– which of the following words belong to the language of correct arithmetic:

3*7=0 3*7=1 3*7=2 ...3*7=21 3*7=22 3*7=23 ...

 

Page 13: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 13

Computational Models Families

• Two families of Computational Models were studied:

– machines/automata

– rewriting systems

Page 14: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 14

Machine model

• The machines/automata use or built on basic machine model:– states– transition between states– control and memory

Page 15: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 15

Rewriting systems

• The rewriting systems compute by rewriting a string:

– from input to output string

– from empty string to output

Page 16: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 16

Automata

• We studied two least powerful models in the hierarchy:

– finite automata FA

– pushdown automata PDA

• We have seen that the first is less powerful than the second.

Page 17: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 17

Automata

• The type of problems the FA can solve (regular languages) is therefore a proper subset of the type of problems the PDA can solve (CFL – context-free languages).

Page 18: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 18

The Turing-Church thesis

• We did not study the most powerful machine –Turing Machine.

• TM has less restrictions on the availability of memory than PDA.

•  The Turing-Church thesis is that TM can do what any computer can do, and there isn’t a more powerful computational model than TM.

Page 19: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 19

Determinism versus Non-determinism

• We have seen one very important attribute of a computational model: – its being deterministic/nondeterministic.

• Do we have only one possibility on each input or more?

• We saw that in different automata the attribute does not add power (FA) or it does (PDA).

• We will see that in TM it again does not.

Page 20: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 20

Rewriting Systems

• We studied one such system – grammars.• It has by itself great practical usage in

compilation, languages etc.• It is also one of the major Computational

Models.• We saw here again two parallel hierarchies

of:– grammars and – parallel language families

Page 21: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 21

Rewriting Systems(cont.)

• We did not study the most powerful grammar – the one with no restrictions, and especially no forbidding of deleting terminals.

• This grammar is a full-power Computational Model, not less powerful than any other, not less powerful than TM.

Page 22: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 22

Decision Problems

• Problems for which the answer is “yes/no”.

• Any problem can be reduced to decision problem.

Page 23: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 23

Example• An arithmetical problem of finding the answer to :

3*7=X• This problem can be formulated as a decision

problem:– for each of the following answer “yes/no”:

3*7=0 3*7=1 3*7=2

...

3*7=21 3*7=22 3*7=23

...

Page 24: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 24

Decidability• One of the major usages of computational models. Informally:• Decidability of problem X – whether the problem

has an algorithm which solves it (decides it).• Decidability of a problem – whether the problem

is decidable, i.e. whether there is a correct algorithm which:

Always haltsWith the correct answer

Page 25: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 25

Decidability

• A decidable problem has such an algorithm/TM/grammar.

 

• An undecidable problem does not have such an algorithm/TM/grammar.

Page 26: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 26

Undecidable problems

• There are problems which are undecidable.

 

Examples:

• The barber

• The Cretan

Page 27: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 27

The barber problem

• All and only citizens of a town that do not cut their own hair themselves, have their hair cut by the only barber in the town.

• Who cuts the hair of the barber?

• Does the barber cut its own hair?

Page 28: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 28

The Cretan problem  

• All Cretans always lie.

• All non-Cretans never lie.

• A man says: “I am a Cretan.”

• Is he?

Page 29: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 29

Decidability of Decision Problems in FA

• The following are the most basic Decision Problems in FA:

– membership

– Emptiness

– Finiteness/Infiniteness

Page 30: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 30

membership

• Informally: whether a word is in a language of given DFA?

• Input: DFA A and a string w• Output: “yes” if wL(A); “no” otherwise.

Page 31: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 31

Proof of decidability

• The algorithm to decide the problem is:– start A on w from q0

– if ’(q0,w) F return “yes”– otherwise return “no”

• The algorithm will always halt after |w| steps.

Page 32: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 32

Emptiness

• Informally: whether the language of an FA is empty?

• Input: FA A

• Output: “yes” if L(A)=; “no” otherwise.

Page 33: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 33

Proof of decidability

• The algorithm to decide the problem is:

– find all states of A reachable from q0 and

enter them into a set called Reachable

– if FReachable= return “yes”

– otherwise return “no”

Page 34: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 34

Correctness (or halting)• Determining the reachable states can be

done in BFS, DFS or any other graph traversing algorithm in O(E) steps, i.e. the algorithm will always halt after |arcs in A| steps.

• This number is bounded from above by the square of the number of states of A, which is finite.

•  Determining for each state in Reachable whether it is accepting or not, is O(1).

Page 35: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 35

Finiteness

• Informally: whether the number of words in a language of an FA is finite?

 

• Input: FA A

• Output: “yes” if L(A) is finite; “no” otherwise.

Page 36: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 36

Proof of decidability

• The algorithm to decide the problem is:– find all the reachable states: set R– find among them all the states that have path

from them to an accepting state: set RF– find if the graph of A has cycles with one of the

states in RF in it– if it does not return “yes”– otherwise return “no”

Page 37: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 37

Correctness (or halting)

• Determining the existence of cycles can be done using BFS, DFS or any other graph traversing algorithm in O(E) steps, i.e. the algorithm will always halt after |arcs in A| steps.

• This number is bounded from above by the square of the number of states of A, which is finite.

Page 38: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 38

Infiniteness

• Informally: whether the number of words in a language of an FA is infinite?

 

• Input: FA A

• Output: “yes” if L(A) is infinite; “no” otherwise.

Page 39: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 39

Proof

• The same algorithm as in finiteness but in the last stage gives reverse answers:– if it contains circle that leads to an

accepting state return “yes”– otherwise return “no”

• Correctness or halting – as before

Page 40: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 40

Turing Machines

First proposed by Alan Turing 1936.

• Unlimited and unrestricted memory.

• A model of a general purpose computer.

• Can do anything that a real computer can do.

• Cannot solve all problems!!

Page 41: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 41

Turing Machine

• An infinite tape - unlimited memory.

• A tape head - can move left and right,can read and write.

b b a c b

head

b d a c __

Page 42: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 42

Input/Output

*...21 nwwww0 0 1 1 1 _ _ _

qaccept

*...21 nwwww0 1 0 _ _ _ _ _ ...q0

...

_

Initial Configuration

Final Configuration

Input

Output

Page 43: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 43

Initialization

• Input: appears on the leftmost n squares of the tape.

• The rest of the tape is blank.

• Head starts on the left-most square.

• State: q0

*...21 nwwwwb b a _ _ _ _ _ ...head

Page 44: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 44

Output

• State: accept or reject.

• Can also return a value: the symbols to the left of the head.

• Does a program always has an output?

Can also run forever - loop.

Page 45: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 45

Final Configuration• q {qaccept , qreject}

• The tape contains uw.– Example: u = 00 w=101,

• The rest of the tape is blank.

• The output is u.– Example: u = 00

...*...21 nwwww0 0 1 0 1 _ _ _

qaccept

Page 46: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 46

Example: B={w#w|w{0,1}*}

0 1 0 0 # 0 1 ...0 0 _

...x 1 0 0 # 0 1 0 0 _

x 1 0 0 # x 1 0 0 _ ...x x x x # x x x x _ ...accept

Page 47: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 47

Example: B={w#w|w{0,1}*}

M1=“On input string w:1. Scan and check that the input contains a

single #. If not reject.2. Zig-zag to check whether corresponding positions

on either sides of # contain the same symbol. If not, reject. Cross off the checked symbols.

3. When all symbols to the left of # are crossed, check for remaining symbols to the right of #. If any symbol, reject. Otherwise, accept. ”

Page 48: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 48

Differences Between Finite Automata and TM

• A TM can both read and write.

• The head can move left and right.

• The tape is infinite.

• The special cases of reject and accept take an immediate action.

Page 49: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 49

Formally: (Q, , , , q0, qaccept, qreject)

• Q is the set of states. is the input alphabet _ . is the tape alphabet, _ and .:Qx Qxx{R,L} the transition

function.

• q0, qaccept, qreject the start, accept and reject states. qaccept qreject

Page 50: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 50

Example: B={w#w|w{0,1}*}

• Q={q0, qaccept,qreject,q1,q2,…}

={0,1,#}= {_,x} :Qx Qxx{R,L}

• q0, qaccept, qreject

=?

...

...

...0 1 0 0 # 0 1 0 0 _

x 1 0 0 # 0 1 0 0 _

x 1 0 0 # x 1 0 0 _

x x x x # x x x x _

qaccept

...

q0

Page 51: Complexity and Computability Theory I Lecture #13 Instructor: Rina Zviel-Girshin Lea Epstein Yael Moses

Rina Zviel-Girshin @ASC 51

Any Questions?