Formal Languages: Review Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a set of strings String length: number of symbols.

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Formal Languages: Review Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a set of strings String length: number of symbols.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Historical Perspectives Stephen Kleene ( ) Founded recursive function theory Pioneered theoretical computer science Student of Alonzo Church; was.
YES-NO machines Finite State Automata as language recognizers.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
Lecture 5UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5.
Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Final Exam Review Cummulative Chapters 0, 1, 2, 3, 4, 5 and 7.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Regular Expressions: Review 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)
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
Basics of automata theory
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Theory of Computing Lecture 21 MAS 714 Hartmut Klauck.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
January 9, 2015CS21 Lecture 31 CS21 Decidability and Tractability Lecture 3 January 9, 2015.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Formal Languages Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a (possibly  ) set of strings String length: number.
Algorithms for hard problems Automata and tree automata Juris Viksna, 2015.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 Introduction to the Theory of Computation Regular Expressions.
Formal Languages Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a (possibly  ) set of strings String length: number.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Formal Languages Alphabet: a finite set of symbols String: a finite sequence of symbols Language: a (possibly  ) set of strings String length: number.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Non Deterministic Automata
CSE 105 theory of computation
Chapter 2 Finite Automata
Regular Expressions: Review
Complexity and Computability Theory I
Formal Languages: Review
Principles of Computing – UFCFA3-30-1
COSC 3340: Introduction to Theory of Computation
Non-Deterministic Finite Automata
Non Deterministic Automata
Historical Perspectives
Formal Languages: Review
Chapter 1 Regular Language
Formal Languages: Review
Presentation transcript:

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

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

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 } 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

Finite Automata: Review 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’

Finite Automata: Review 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: 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. L(M)=(ab) * L(M’)= b(a+b) * + (a+b) * a + (a+b) * (aa+bb)(a+b) * M’ “simulates” M and does the opposite! q1q1 a b q0q0 q2q2 b a a,b M q1q1 a b q0q0 q2q2 b a M’ Why are these complements?

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?

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

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, ,  1, q’, F 1 ) and M 2 =(Q 2, ,  2, q”, F 2 ) construct M=(Q, , , q, F) Q = Q 1  Q 2 F = F 1  F 2 q=(q’,q”)  :Q   Q  ((q i,q j ),x) = (  1 (q i,x),  2 (q j,x)) “cross product construction”

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  )  (Q   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  –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  –F 2 ))  ((Q  –F 1 )  F 2 ) Meta-Theorem: Identity-based proofs are easier!

Finite Automata: Review 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

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 have exponentially more states. “powerset construction” Q: Why doesn’t this work for PDAs?

Finite Automata: Review 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!

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!

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;

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!

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!   

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

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

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.

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’

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.

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

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’    -{  Ø Ø

Regular Experssion Minimization Problem: find smallest equivalent regular expression Decidable (why?) Hard: PSPACE-complete Turing Machine Minimization Problem: find smallest equivalent Turing machine Not decidable (why?) Not even recognizable (why?)

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