theory of computation (fall 2014): decision algorithms for regular sets: emptiness, infinity,...

19
Theory of Computation Decision Algorithms for Regular Sets; Finite Automata in Robot Navigation Vladimir Kulyukin http://www.vkedco.blogspot.com/

Upload: vladimir-kulyukin

Post on 24-Jun-2015

135 views

Category:

Science


13 download

TRANSCRIPT

Page 1: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Theory of Computation

Decision Algorithms for Regular Sets;Finite Automata in Robot Navigation

Vladimir Kulyukin

http://www.vkedco.blogspot.com/

Page 2: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Outline

● Decision Algorithms for Regular Languages:Emptiness InfinityEquivalence

● Finite Automata in Robot Navigation

Page 3: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Emptiness & Infinity Theorem

Theorem: The language of a DFA M with n > 0

states is

1) L(M) is not empty iff M accepts a string s such that |s| < n2) L(M) infinite iff M accepts s such that n <= |s| < 2n

Page 4: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Emptiness Proof

1) If M accepts a string s such that |s|<n then L(M) is obviously not empty.

2) If M is not empty, then let s be a string as short as any other string in L(M). If |s|<n, we are done. If |s| >= n, then, by the Pumping Lemma, s = uvw and |v| > 0 so that uw is also in the language, but then s is not a shortest string, which is a contradiction.

Page 5: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Infinity Proof

1) Let s be is in L(M) and n<=|s|<2n, then, by the Pumping Lemma, L(M) is infinite, because uviw is in L(M) for all i.

2) If L(M) is infinite, there is s in L(M), where |s| >= n. If |s| < 2n, we are done. Assume that there are no words whose length is in the range [n, 2n-1]. Let |s| be a shortest string such that |s|>=2n. Let s = uvw. But then, by the Pumping Lemma, uv is also in L(M). Thus, either s is not a shortest string or |uv| is in the range [n, 2n-1]. A contradiction in either case.

Page 6: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Emptiness & Infinity Algorithms

● An algorithm to decide if L(M) is empty: Generate all strings in the range [0, n-1] If one of them is accepted, L(M) is not empty

● Can you think of a better algorithm to decide the emptiness of L(M)?● An algorithm to decide if L(M) is infinite:

Generate all strings in the range [n, 2n-1] If one of them is accepted, L(M) is infinite

● Can you think of a better algorithm that decides the infinity of L(M)?

Page 7: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Better Emptiness & Infinity Algorithms

There is a more efficient algorithm to check the emptiness & infinity properties. Let M be a DFA.

1) Represent M as a graph.

2) Determine all states that are not reachable from the start state. If at least one final state is reachable, L(M) is not empty.

3) Delete all states from which no final state is reachable. L(M) is a infinite if M has a cycle.

Page 8: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Equivalence Theorem

There is an algorithm that determines if two DFAs M1 and

M2 accept the same language.

Page 9: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Proof

. iffempty not is 7.

.for DFA a be Let 6.

regular. is 5.

regular. is 4.

regular. is 3.

regular. is 2.

regular. is 1.

Then . and

such that DFAs twobe and Let

213

12213

1221

12

1

21

2

2211

21

LLML

LLLLM

LLLL

LL

L

LL

L

MLLMLL

MM

Page 10: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Summary

● Deciding if the language of an FA is not empty is effectively computable

● Deciding if the language of an FA is infinite is effectively computable● Deciding if two FAs accept the same language is effectively

computable

Page 11: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Finite Automata in Robot Navigation

Page 12: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Junun Mark III Robot

Page 13: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Line Following Problem

How can we make a robot follow a black line on the floor?

Page 14: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Line Following

Left Sensor

Middle Sensor

Right Sensor

Left Sensor returns black_on_left when it detects blackness.Middle Sensor returns black_on_center when it detects blackness.Right Sensor returns black_on_right when it detects blackness.

Page 15: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Line Following

if ( black_on_center ) move_forward;

We assume that the robotstarts with the middle sensoraligned with the line. So, ifthe middle sensor detectsblackness, the robot movesforward.

LEFT CENTER RIGHT

Page 16: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Line Following

if ( black_on_left ) turn_left;

If the left sensor detectsblackness, the robot turnsleft to align the middlesensor with the line.

LEFT CENTER RIGHT

Page 17: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

Line Following

if ( black_on_right ) turn_right;

If the right sensor detectsblackness, the robot turnsright to align the middlesensor with the line.

LEFT CENTER RIGHT

Page 18: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

An FA for Line Following

read_sensors

turn_left

black_on_left

move_completed

turn_right

black_on_rightmove_completed

move_forward

black_on_center/no_black

move_completed

Page 19: Theory of Computation (Fall 2014): Decision Algorithms for Regular Sets: Emptiness, Infinity, Equivalence; Finite Automata in Robot Navigation

References

● Brooks Webber. Formal Language: A Practical Introduction, Franklin, Beedle & Associates, Inc

● Hopcroft and Ullman. Introduction to Automata Theory, Languages, and Computation, Narosa Publishing House

● Davis, Weyuker, Sigal. Computability, Complexity, and Languages, 2nd Edition, Academic Press

● http://docs.oracle.com/javase/tutorial/essential/regex/