Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory Theory of Computation CS3102 – Spring 2014 A tale.

Similar presentations


Presentation on theme: "Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory Theory of Computation CS3102 – Spring 2014 A tale."— Presentation transcript:

1 Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death

2 Finite Automata Basic idea: a FA is a “machine” that changes states while processing symbols, one at a time. Finite set of states: Q = {q 0, q 1, q 3,..., q k } Transition function:  : Q   Q Initial state:q 0  Q Final states:F  Q Finite automaton is M=(Q, , , q 0, F) Ex: an FA that accepts all odd-length strings of zeros: q0q0 q1q1 0 0 M=({q 0,q 1 }, {0}, {((q 0,0),q 1 ), ((q 1,0),q 0 )}, q 0, {q 1 }) q0q0 qiqi qjqj q1q1 qkqk

3 Finite Automata FA operation: consume a string w  * one symbol at a time while changing states Acceptance: end up in a final state Rejection: anything else (including hang-up / crash) Ex: FA that accepts all strings of form abababab…= (ab) * q1q1 a b M=({q 0,q 1 }, {a,b}, {((q 0,a),q 1 ), ((q 1,b),q 0 )}, q 0, {q 0 }) But M “crashes” on input string “abba”! Solution: add dead-end state to fully specify M M’=({q 0,q 1,q 2 }, {a,b}, {((q 0,a),q 1 ), ((q 1,b),q 0 ), ((q 0,b),q 2 ), ((q 1,b),q 2 ). ((q 2,a),q 2 ), ((q 2,b),q 2 ) }, q 0, {q 0 }) q0q0 q2q2 b a a,b M M’

4 Finite Automata Transition function  extends from symbols to strings:  :Q  *  Q  (q 0,wx) =  (  (q 0,w),x) where  (q i,  ) = q i Language of M is L(M)={w  *|  (q 0,w)  F} Definition: A language is regular iff it is accepted by some FA. L is regular iff there is a FA M where L(M)=L Equivalently: A language is regular iff it can be described by a regular expression (proof next time)

5

6 E a’s a a fail b O a’s a,b O b’s b E b’s b a b a even odd a,b b‘s b a‘s a a,b

7

8 Problem: design a DFA that accepts all strings over {a,b} where any a’s precede any b’s. Idea: skip over any contiguous a’s, then skip over any b’s, and then accept iff the end is reached. q 0 a q 1 b b q 2 a a,b L = a*b* Q: What is the complement of L?

9 Problem: what is the complement of L = a*b* ? Idea: write a regular expression and then simplify. L’= (a+b)*b + (a+b)*a + (a+b)* = (a+b)*b(a+b)*a(a+b)* = (a+b)*b + a(a+b)* = (a+b)*ba(a+b)* = a*b + a(a+b)* q 0 a q 1 b b q 2 a a,b

10 even odd a,b even odd a,b

11 even odd a,b b‘s b a‘s a a,b E b b E a a a,b O a a b a,b O b {w| w does not contain the letter ‘a’} {w| |w| is odd} {w| |w| is odd or contains no ‘a’s}

12 Cross Product Construction!

13

14 Problem: ? Why not both? Non-Determinism!

15 Finite Automata Non-determinism: generalizes determinism, where many “next moves” are allowed at each step: Old  :Q   Q New  :2 Q   2 Q Computation becomes a “tree”. Acceptance:  a path from root (start state) to some leaf (a final state) Ex: non-deterministically accept all strings where the 7 th symbol before the end is a “b”: a,b Input:ababbaaa ba,b  Accept! q2q2 q0q0 q7q7 q3q3 q4q4 q5q5 q6q6 q1q1

16 Finite Automata Theorem: Non-determinism in FAs doesn’t increase power. Proof: by simulation: Construct all super-states, one per each state subset. New super-transition function jumps among super-states, simulating old transition function Initial super state are those containing old initial state. Final super states are those containing old final states. Resulting DFA accepts the same language as original NFA, but can have exponentially more states. “powerset construction”

17 Finite Automata Note: Powerset construction generalizes the cross-product construction. More general constructions are possible. EC: Let HALF(L)={v |  v,w   *  |v|=|w| and vw  L} Show that HALF preserves regularity. A two way FA can move its head backwards on the input:  :Q   Q  {left,right} EC: Show that two-way FA are not more powerful than ordinary one-way FA.  -transitions: Theorem:  -transitions don’t increase FA recognition power. Proof: Simulate  -transitions FA without using  -transitions. i.e., consider  -transitions to be a form of non-determinism. qiqi qjqj  qiqi qjqj  One super-state!

18 The movie “Next” (2007) Based on the science fiction story “The Golden Man” by Philip Dick Premise: a man with the super power of non-determinism! At any given moment his reality branches into multiple directions, and he can choose the branch that he prefers! Transition function!

19 Top-10 Reasons to Study Non-determinism 1.Helps us understand the ubiquitous concept of parallelism / concurrency; 2.Illuminates the structure of problems; 3.Can help save time & effort by solving intractable problems more efficiently; 4.Enables vast, deep, and general studies of “completeness” theories; 5.Helps explain why verifying proofs & solutions seems to be easier than constructing them;

20 Why Study Non-determinism? 6.Gave rise to new and novel mathematical approaches, proofs, and analyses; 7.Robustly decouples / abstracts complexity from underlying computational models; 8.Gives disciplined techniques for identifying “hardest” problems / languages; 9.Forged new unifications between computer science, math & logic; 10.Non-determinism is interesting fun, and cool!

21 Regular Expressions Regular expressions are defined recursively as follows: {}{} trivial language {x}  x  singleton language Ø empty set q0q0 Inductively, if R and S are regular expressions, then so are: q0q0 q0q0 q1q1 x (R+S) union RS concatenation R*R* Kleene closure Examples:aa(a+b) * bb(a+b) * b(a+b) * a(a+b) * Theorem: Any regular expression is accepted by some FA. M2M2 M1M1   M2M2  M1M1 M Compositions!   

22 Regular Expressions A FA for a regular expressions can be built by composition: Ex: all strings over S={a,b} where  a “b” preceding an “a” (a+b) * b(a+b) * a(a+b) * = (a+b) * ba(a+b) * baba      ba    Why?        b a b a      b a           b a b a      b a           b a b a      b a           Remove previous start/final states

23 FA Minimization Idea: “Equivalent” states can be merged: b a a,b 3 states! 16 states! b a b a      b a           b a b a     b a           b a a,b       b a    merge

24 FA Minimization Theorem [Hopcroft 1971]: the number N of states in a FA can be minimized within time O(N log N). Based on earlier work [Huffman 1954] & [Moore 1956]. Conjecture: Minimizing the number of states in a nondeterministic FA can not be done in polynomial time. Theorem: Minimizing the number of states in a pushdown automaton (or TM) is undecidable. Project idea: implement a finite automaton minimization tool. Try to design it to run reasonably efficiently. Consider also including: A regular-expression-to-FA transformer, A non-deterministic-to-deterministic FA converter.

25 M FAs and Regular Expressions Theorem: Any FA accepts a language denoted by some RE. Proof: Use “generalized finite automata” where a transition can be a regular expression (not just a symbol), and: Only 1 super start state and 1 (separate) super final state. Each state has transitions to all other states (including itself), except the super start state, with no incoming transitions, and the super final state, which has no outgoing transitions. Original FA M M         Ø Ø Ø Ø Ø Ø Ø Ø Ø  Generalized FA (GFA) M’ M’

26 FAs and Regular Expressions Now reduce the size of the GFA by one state at each step. A transformation step is as follows: qiqi qjqj q’ R S T P qiqi qjqj P RS * T qiqi qjqj P + RS * T Such a transformation step is always possible, until the GFA has only two states, the super-start and super-final states: Label of last remaining transition is the regular expression corresponding to the language of the original FA! M’ P Corollary: FAs and REs denote the same class of languages.

27 Regular Expressions Identities R+S = S+R R(ST) = (RS)T R(S+T) = RS+RT (R+S)T = RT+ST Ø * =  * =  R+Ø  = Ø+R = R R  =  R = R (R * ) * = R * (  + R) * = R * (R * S * ) * = (R+S) * R+  ≠ R RØ ≠ R

28 Decidable Finite Automata Problems Def: A problem is decidable if  an algorithm which can determine (in finite time) the correct answer for any instance. Given a finite automata M 1 and M 2 : Q 1 : Is L(M 1 ) = Ø ? Hint: graph reachability Q 2 :Is L(M 2 ) infinite ? Hint: cycle detection Q 3 : Is L(M 1 ) = L(M 2 ) ? Hint: consider L 1 -L 2 and L 2 -L 1 M’  M’    -{  Ø Ø

29 Extra credit: use this tool! (to implement some nontrivial TMs, PDAs, grammars, etc.)

30 Give a FA and a regular expression for the following language over the Sesame Street Alphabet: L = {w | w satisfies “i before e except after c”} This means we want any string where an i does not immediately succeed an e, unless we see a c, in which case an e may not succeed an i. Accepted words: believe, fierce, receipt Rejected words: seize, their, science

31 L = {w | w satisfies “i before e except after c”} safe fail i e e c c ci c c c e i e


Download ppt "Nathan Brunelle Department of Computer Science University of Virginia www.cs.virginia.edu/~njb2b/theory Theory of Computation CS3102 – Spring 2014 A tale."

Similar presentations


Ads by Google