270 likes | 358 Views
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. Q&A video problems?. Discussion. Regular operations.
E N D
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.
Q&A video problems? • Discussion
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
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.
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* ?
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)* ?
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.
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.
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 ∊Mfinal or n ∊ Nfinal }
Need to do concatenation and star… • Instead of tackling this directly, make a diversion, which will make these proofs easier….
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!
piece of graph e 1 1 0 0
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?
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.
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.
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.
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.
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 statescorresponding 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 2N is the number of subsets.
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?
Proof NDFSM can be replaced by a FSM • Transition: make a transition from statesubsetX to statesubsetY 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.
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!
Exercise • Build (design) a NDFSM to accept A*.
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).
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.
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
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
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