formal languages review
play

Formal Languages: Review Alphabet: a finite set of symbols S={a,b} - PowerPoint PPT Presentation

Formal Languages: Review Alphabet: a finite set of symbols S={a,b} String: a finite sequence of symbols ababbaab Language: a set of strings L={a,aa,aaa ,} String length: number of symbols in it |aba|=3 String concatenation:


  1. Formal Languages: Review • Alphabet: a finite set of symbols S={a,b} • String: a finite sequence of symbols ababbaab • Language: a set of strings L={a,aa,aaa ,…} • String length: number of symbols in it |aba|=3 • String concatenation: w 1 w 2 ab • ba=abba • Empty string: e or ^ " w w • e = e • w = w • Language concatenation: {1,2} • {a,aa ,…} L 1 L 2 ={w 1 w 2 | w 1  L 1 , w 2  L 2 } ={1a,2a,1aa,2aa,…} • String exponentiation: w k = ww …w (k times) a 3 =aaa • Language exponentiation: L k = LL…L (k times) {0,1} 32 LL = L 2 L k =LL k-1 L 0 ={e}

  2. Formal Languages: Review • String reversal: w R (aabc) R =cbaa • Language reversal: L R ={w R | w  L} {ab,cd} R ={ba,dc} • Kleene closure: L * = L 0  L 1  L 2  L 3  ... {a} * L + = L 1  L 2  L 3  L 4  ... {a} + Theorem: L + = LL * { e } • L=L • { e }=L • Trivial language: { e } Ø * ={ e } • Empty language: Ø L S * " L {a,aa,aaa ,…} • All finite strings: S * Theorem :S * is countable, | S * | = |Z| dovetailing Theorem :2 S * is uncountable. diagonalization Theorem :S * contains no infinite strings. finite strings in S i L *  (L * ) * & (L * ) *  L * Theorem: (L * ) * =L *

  3. Finite Automata: Review 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 } q 1 d : Q S  Q • Transition function: q i q j q 0  Q • Initial state: q 0 F  Q • Final states: q k • Finite automaton is M=(Q, S , d , q 0 , F) Ex: an FA that accepts all odd-length strings of zeros: 0 q 0 q 1 M=({q 0 ,q 1 }, {0}, {((q 0 ,0),q 1 ), ((q 1 ,0),q 0 )}, q 0 , {q 1 }) 0

  4. Finite Automata: Review FA operation: consume a string w S * 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) * M=({q 0 ,q 1 }, {a,b}, {((q 0 ,a),q 1 ), ((q 1 ,b),q 0 )}, q 0 , {q 0 }) M a q 0 q 1 But M “crashes” on input string “abba”! b Solution: add dead-end state to fully specify M a b q 2 M’=( {q 0 ,q 1 ,q 2 }, {a,b}, {((q 0 ,a),q 1 ), ((q 1 ,b),q 0 ), M’ a,b ((q 0 ,b),q 2 ), ((q 1 ,b),q 2 ). ((q 2 ,a),q 2 ), ((q 2 ,b),q 2 ) }, q 0 , {q 0 })

  5. Finite Automata: Review Transition function d extends from symbols to strings: d :Q S *  Q d (q 0 ,wx) = d ( d (q 0 ,w),x) where d (q i , e ) = q i Language of M is L(M)={w S *| d (q 0 ,w)  F} Definition: language is regular iff it is accepted by some FA. Theorem: Complementation preserves regularity. Proof: Invert final and non-final states in fully specified FA. a a L(M)=(ab) * M’ q 0 q 1 q 0 q 1 M L(M’)= b(a+b) * + (a+b) * a b b + (a+b) * (aa+bb)(a+b) * a a b b q 2 q 2 M’ “ simulates ” M and a,b a,b does the opposite!

  6. 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. a a,b b b a q 0 q 1 q 2 L = a*b* Q: What is the complement of L?

  7. 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)* a a,b b b a q 0 q 1 q 2

  8. Finite Automata: Review Theorem: Intersection perserves regularity. Proof: ( “parallel” simulation ): • Construct all super-states, one per each state pair. • New super-transition function jumps among super-states, simulating old transition function • Initial super state contains both old initial states. • Final super states contains pairs of old final states. • Resulting DFA accepts same language as original NFA (but size can be the product of two old sizes). GivenM 1 =(Q 1 , S , d 1 , q’ , F 1 ) and M 2 =(Q 2 , S , d 2 , q” , F 2 ) construct M=(Q, S , d , q, F) Q = Q 1  Q 2 F = F 1  F 2 q=( q’ ,q ” ) d :Q S  Q d ((q i ,q j ),x) = ( d 1 (q i ,x), d 2 (q j ,x))

  9. Finite Automata: Review Theorem: Union preserves regularity. Proof: De Morgan's law: L 1  L 2 = L 1  L 2 Or cross-product construction, i.e., parallel simulation with F = (F 1  Q 2 )  (Q 1  F 2 ) Theorem: Set difference preserves regularity. Proof: Set identity L 1 – L 2 = L 1  L 2 Or cross-product construction, i.e., parallel simulation with F = (F 1 ( Q 2 – F 2 )) Theorem: XOR preserves regularity. Proof: Set identity L 1  L 2 = (L 1  L 2 ) – (L 1  L 2 ) Or cross-product construction, i.e., parallel simulation with F = (F 1 ( Q 2 – F 2 ))  ((Q 1 – F 1 )  F 2 ) Meta-Theorem: Identity-based proofs are easier!

  10. Finite Automata: Review Non-determinism: generalizes determinism, where many “ next moves ” are allowed at each step: d :Q S  Q Old d :2 Q S  2 Q New 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”: b a,b a,b a,b a,b a,b a,b q 0 q 1 q 2 q 3 q 4 q 5 q 6 q 7  Accept! Input: ababbaaa a,b

  11. Finite Automata: Review 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 Q: Why doesn’t this have exponentially more states. work for PDAs?

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

  13. 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!

  14. 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;

  15. 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!

  16. Regular Expressions Regular expressions are defined recursively as follows: { e } {x} " x S Ø empty set trivial language singleton language x q 0 q 0 q 0 q 1 Inductively, if R and S are regular expressions, then so are: R * (R+S) RS union concatenation Kleene closure M 1 e e M 2 e M 1 M e e M 2 Compositions! e aa(a+b) * bb (a+b) * b(a+b) * a(a+b) * Examples: Theorem: Any regular expression is accepted by some FA.

  17. 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) * Why? = (a+b) * ba(a+b) * e e e e a a a a e e e e e e b b a a e e e e e e e e e e e e e e e e b b b b e e e e e e e e a a a a e e e e e e b b e e a a e e e e e e e e e e e e e e b b b b e e Remove previous start/final states e e

  18. FA Minimization Idea : “ Equivalent ” states can be merged: e e a a e e e b a e e e e e e e e b b e e e e a a e e e b a e e e e e e b b e e e e e e b a,b e a a,b e e a,b a,b e b e a e a,b a,b a b

  19. 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.

Recommend


More recommend