Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computability Review homework. Regular Operations. Nondeterministic machines. NFSM = FSM Homework: By hand, build FSM version of specific NFSM. Try to.

Similar presentations


Presentation on theme: "Computability Review homework. Regular Operations. Nondeterministic machines. NFSM = FSM Homework: By hand, build FSM version of specific NFSM. Try to."— Presentation transcript:

1 Computability Review homework. Regular Operations. Nondeterministic machines. NFSM = FSM Homework: By hand, build FSM version of specific NFSM. Try to think of a language that is not a regular language.

2 Q&A video problems? Discussion

3 Regular operations Suppose we have 2 languages A and B –remember these are sets. They may be infinite, that is, defined by patterns… More on this later. Consider the following languages –A union B (A ⊔B) : all strings in either A or B –A concatenate B (A ⃘ B or AB): all strings made up of a string in A followed by a string in B. Note: may include all of A and/or all of B depending on whether or not the empty string is in B or in A. –A*: finite strings in A, concatenated together

4 Aside Generally, thinking about these logical, formal definitions, proofs, constructions, improves programming skills. Specifically, important in considering a problem to think about finiteness,memory, states, etc.

5 Examples Let the alphabet be: {a, b, c, d, e}. Let A by the language consists of all strings with only a's {a, aa, aaa….} and B the language consisting of strings with only b's {b, bb, bbb, …}. What is A ⊔B ? What is AB ? Trick question: what is A* ?

6 Examples (from book) A is {good, bad}. B is {boy, girl} What is A*? What is B*? What is A ⊔B ? What is AB? What is BA? What is ( A ⊔B)* ?

7 Method We can (and will) prove that if A and B are regular languages, then so are A union B, AB, and A* We say the class of regular languages is closed under the union operation, concatenate operation and star operation. From the machine M that accepts A and N that accepts B, build/design/specify machines for those 3 languages.

8 General method for proving for union If our machine could scan the input twice, we would be done! Instead, simulate scanning it twice (by each of M and N) by keeping track of what would have happened using each machine.

9 Proof for union Construct a new machine with states defined as pairs, one from M and one from N. –formal math. term: cartesian product Initial state (Ms1, Ns1). Transition function: if in M, state s, letter a went to Mt and in N, state v, letter a went to Nw, then in the new machine (Ms,Nv) reading a goes to (Mt,Nw) Final states: all states in which at least one of the two are final. –F={(m,n) | m ∊M final or n ∊ N final }

10 Need to do concatenation and star… Instead of tackling this directly, make a diversion, which will make these proofs easier….

11 New type of machine: Nondeterministic FSM Add non-determinism to transition table State s reading symbol a can go to 0, 1 or more different states. There also can be empty/free links between states: symbol ∊. –Think of this as trying alternate paths, guesses, parallel processes. A string is accepted if there is at least one set of choices, one path that leads from the start state to an accepting state. Will give examples and then surprise!

12 piece of graph 0 e1 1 0

13 Example Alphabet {English alphabet plus _} Build a NDFSM that accepts any string in which some where in the string there occurs "GOOD_JOB". Initial state: I StateG, StateO1,StateO2,StateD,Date_,StateJ,StateO3,StateB. Transitions: All letters go from I to itself plus I on letter G to StateG, StateG on letter O to StateO1, …. StateB: all letters to itself. StateB is accepting state. Think: system tries all possibilities. Only one has to work for starting off with the G. Note: If there isn't a transition, then nothing happens. Machine stays in that state. Does this work?

14 General example Building a machine to accept languages A ⊔B, given M that accepts A and N that accepts B Take M and N and combine (overlay) the initial states. From the initial state have all the possibilities, going off to the two machines… A string is accepted if there is a path to one of the finite states. This NDFSM has less states than the one with the cartesian product.

15 Surprise For every NFSM, we can design a FSM that does the same thing! So, the non-determinism don't really add more capability. Paradox: since every FSM is a NFSM, it seems that there are more NFSM. But for every NFSM, there is a FSM that does the same thing!!!! Since the numbers of FSM and NFSM are infinite, can't make arguments made for finite sets.

16 Rough analogy In programming languages, switch statements are nice! However, everything you can do with a switch statement, you can do with (combinations of) if statements.

17 Why bother with nondeterminism? It can be easier to prove certain things with NFSM. –see A ⊔B example! Even easier for AB case. Generally speaking, the NDFSM will have smaller number of states.

18 Proof that for every NDFSM there is a FSM that does the same job Similar to method for union, in which we kept track of the possibilities using the paired states (cartesian product). Given the NDFSM. Construct a FSM with states the set of all subsets of the states of the NDFSM. So if the NDFSM had states: S1, S2, S3…Sn, the FSM will have states corresponding to the subsets. We use those names for the names of the (new) states. {Ssi,sj,sk…sq | si,sj, sk,…sq are states in NDFSM} The list of subsets is finite. It may be large, in fact, if N is the number of states in the NDFSM, then 2 N is the number of subsets.

19 Subset example Set {a,b,c}, write the subsets. I'll start off by writing two subsets: the empty set and the set {a, b, c} ? How many?

20 Proof NDFSM can be replaced by a FSM Transition: make a transition from state subsetX to state subsetY on letter a if there is a transition on a from any member of subsetX to any member of subsetY Final states: states in which at least one member of the subset is a final state. Claim: if there was a path in the NDFSM to a final state, there will be a path in the constructed FSM to a final state.

21 Proof that a FSM exists to accept the language AB, if A and B each have FSMs Have FSM M accepting A and N accepting B. We can build a NDFSM to accept AB. The states are the union of the two sets of states. The starting state is the starting state of M. The accepting states are the accepting states of N. Add transitions using the empty string ∊ from the accepting states of M to the initial state of N. Claim: this does it!

22 Exercise Build (design) a NDFSM to accept A*.

23 Terminology The set of languages accepted by FSM are called the regular languages. The set of regular languages is closed with respect to union, concatenation and star. –Proof: union done directly, concatenation done using NSFSM, star left to you! We can use NDFSM in place of FSM for proofs (proof by construction).

24 Regular expressions These are used in programming to define acceptable sets fitting some pattern using a specific, fixed way of writing patterns. What are the ways? –you can specify a finite set of strings. –if R and Q are regular expressions, then R concatenated with Q means any string in R concatenated with any string in Q. –if R and Q are regular expressions, you can specify the union to be a regular expression. –if R is a regular expression, then you can specify * operator over R, meaning concatenation of any (finite) number of elements in R.

25 Examples over alphabet {0,1} (0,1) This is a regular expression defining a language with exactly 2 members. This also could be written (0 UNION 1). (0 UNION 1)* This is the language of all possible strings holding 0s and 1s, including the empty string. (1)* This is the language of any number of 1s including no 1s, that is, the empty string, also indicated by ∊. 1

26 Examples What is a regular expression for social security numbers? What is a regular expression for email addresses? –email addresses for people at Purchase College

27 Homework Complete proofs. Invent more examples. Think of a language for which there does not exact a FSM. Next class: –regular expressions –Languages defined by a regular expression ARE regular languages One direction: from regular expression, build the FSM (or NDFSM) Other direction: from a FSM, produce the regular expression –Pumping lemma (way to prove something is NOT a regular language) –Uses of FSM


Download ppt "Computability Review homework. Regular Operations. Nondeterministic machines. NFSM = FSM Homework: By hand, build FSM version of specific NFSM. Try to."

Similar presentations


Ads by Google