Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma.

Similar presentations


Presentation on theme: "Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma."— Presentation transcript:

1 Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma. Homework: Postings? Watch videos.

2 Regular expressions, cont. Want to prove relationship. Two directions. –Regular expressions are defined by an inductive process so need to show that steps of induction can lead to definitions by FSM (or NDFSM) –Take ANY FSM and show a way to define its regular expression. Will use [yet another type of] machine. Use induction.

3 Regular expression definition. For given alphabet: the empty string is a regular expression the empty set is a regular expression any single letter is a regular expression For any regular expressions R and S, then –R union S is a regular expession –R concatenate S is a regular expression –R star is a regular expression

4 Building the FSMs for any regular expression There is a FSM for any the empty string, any single letter, the empty set. [Though the Sipser text did not mention this, I believe it is necessary to do an induction on the length of the expression…] If there is a regular expression R that is defined by R1 union R2, then we can define a FSM for R using the FSMs for R1 and R2. Similarly, for concatenation and for star.

5 Opposite direction Given a FSM, produce the regular expression that describes the same language. Use (yet another) new machine: generalized nondeterministic finite state machine: –arrows from state to state will be regular expressions –start state has no incoming arrows; outgoing to every state –single accepting state with no outgoing arrows; incoming from every state –start state different from accepting state –there are arrows between all the other states, but note: there are some arrows labeled with the empty set –GNFSM accepts a string by going from state to state using transition labels as regular expressions and ending in the single accepting state.

6 Process of proof Convert any FSM to a GNFSM –add a new start state and arrow labeled with the empty string from it to the original start state –add a new real accepting state, and add labels with the empty string going to it from all old accepting states –if there are more than one arrow from any state S to any state T, replace by one new arrow with the union of the labels –add arrows labeled with empty set between any pair of states without arrows –CLAIM: this GNFSM accepts the same languages as the FSM. Convert any GNFSM to a GNFSM with exactly 2 states, the arrow from start to accepting is the regular expression

7 Break for joke(s) Theorem: All horses have an infinite number of legs. Lemma: All horses are of the same color. Homework: make a posting of explanation of problem with the lemma.

8 Induction proof Take any GNFSM. It must have at least two states. –If it has just 2 states, then we are done. –if it has >2 states, show we can reduce it by one state.

9 Inductive step Select a state, call it Q, different from starting and accepting state. We will remove Q from the machine and/but modify all other arcs to include what Q did. For any two states Si and Sj in the remaining states, –let R 1 by the label from Si to Q –R 2 by the label from Q to itself, –R 3 be the label from Q to Sj and –R 4 be the (original) label from Si to Sj. Then the new label from Si to Sj is R 1 R 2 *R 3 ⊔ R 4 Claim this new GNFSM accepts the same strings as the former one and has 1 fewer states.

10 Pumping lemma The term pumping is for pumping out new strings. If A is a regular language, there is a number p such that if a string s in A of length at least p, then we can divide s into 3 parts: s = xyz, so that –xy i z is in A, for i>=0. That is, repeat the y substring –|y| (length of y) >0 –|xy| < p Note: this means that if there are strings of arbitrarity large size (length), then we can take one and pump out others….

11 Proof of pumping lemma There are [only] a finite number of states. Let p be the number of states of the FSM for A. Assume there is a string of length at least p. This string must have visited at least one state more than one time. –pigeonhole principle –call one such state Q Let x be the string up to Q, y be the string that comes back to Q, z be the rest of the string. xyz satisfies the conditions.

12 Examples of non-regular languages B = {0 i 1 i | i>=0}. B is strings with the a set number of 0s followed by the same number of 1s –Apply pumping lemma. Take a string and what could it look like? C = {w | w has equal number of 0s and 1s} –Apply pumping lemma to strings of form 0 i 1 i to get strings with different number of 0s and 1s

13 Reflection FSM only have finite number of states. The next type of machine (push down automata) also has only a finite number of states BUT will have a way of saving information. Turing machines have a finite number of states BUT allow for writing (and reading) on the tape.

14 Applications Virtual dog: http://faculty.purchase.edu/jeanine.meyer/ pet3.html http://faculty.purchase.edu/jeanine.meyer/ pet3.html –states corresponded to images –nearly or not quite FSM since I did keep a variable weight

15 Lexical scanning First step in compiling or interpreting is to go from string of characters to string of lexical units. –units delimited by spaces AND by definitions sum = old + total*12.50 ; Want to reduce this string of 26 characters to 8 typed lexical units: –name(sum), operator(=), name(old), operator(+), name(total), operator(*), number(12.50), statement-ender(;) Construct a FSM-like machine that has accepting states for each of name, operator, number, statement-ender, and scans strings of alphanumeric characters plus operators.

16 Homework Continue to look out for computability OR complexity in the news –What is status of the P and NP proof? Watch videos Determine problem in my proof of the 'all horses are of the same color' lemma. Finish lexical scanning exercise

17 Next class push down automata and context-free languages


Download ppt "Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma."

Similar presentations


Ads by Google