2

I've been working on this project for almost a week now, however it's honestly above my understanding and I just cannot find help elsewhere.

My problem now is that, I just don't know how to combine FSA's. To what I understand I have to combine my 2 FSA's which is the main FSA and the Odd 0 Parity FSA.

This is the main FSA: Main FSA

This is the Odd 0 Parity FSA: Odd 0

I've been confused about this project of almost a week now, and it was already due awhile ago so it's too late to submit it, but I have still been stuck on it and I really want closure on it.

Also can anyone explain why this expression didn't work? (Rejects 0100)

((00100|00011|010)(00100|00011|010))*0|((00100|00011|010)(00100|00011|010))*(00100|00011|010)1
Ice Art
  • 57
  • 1
  • 7

3 Answers3

1

I don't know of a general way of merging FSAs like this, but here's an approach for your specific problem.

Make two copies of your original FSA, call them 'Even' and 'Odd'. The invariant is that whenever you're in a state of one of the sub-FSAs, the parity is as indicated by its name. To achieve this, every 0 transition must jump to the corresponding node in the other FSA; 1 transitions continue in the same FSA.

The start state is in Even. The corresponding node in Odd is unreachable, and can be deleted.

All of your original accepting states are no longer valid, as you haven't verified the parity bit yet. In Odd, each of those states needs a 1 transition to the new accepting state. In Even, a 0 from a former accepting state needs to be an accepting state; all of those transitions exist already, so their target (node #1) becomes the new accepting state.

As for why your regexp solution didn't work, consider the first subgroup within it: (00100|00011|010). That includes subpatterns with both even and odd numbers of 0s; you have no way to tell which one matched, so you've ALREADY permanently lost track of what the final parity will be. You'd have to somehow arrange for each individual part of the overall regex to match only things with the same parity - I'm not entirely sure that this is even possible in a traditional regex. (If I was solving this using a modern computer implementation of regular expressions, I'd use a lookahead assertion to verify the overall parity as an entirely separate process from verifying the concatenation of your three patterns.)

EDIT: Illustrated!

We start by making two copies of your original FSA, labelled for even or odd parity. You could also think of this as making a copy of the nodes in your 2nd FSA for each node in your first FSA. enter image description here The start state is in Even, since you initially have zero 0s. State o0 is unreachable, and will be omitted in further diagrams. The labels aren't valid yet, since every time there's a 0 transition, the parity changes - those transitions need to go to the other copy of the FSA. I couldn't get graphviz to produce anything that's even slightly comprehensible with all of these crossovers, so I'm going to have to drop the boxes around the even/odd states. Here's the diagram with crossovers applied: enter image description here This FSA matches exactly the same sentences your original one did, except that you always know whether you have odd or even parity at each state. The accepting states are still the same as the original ones: to handle your final parity bit, we need to add one final transition from each of those states to a new accepting state. From all three Odd accepting states, there is a 1 transition to the new state labelled "o". From all four Even accepting states, the final parity bit would be a 0 transition - which happens to correspond to the existing "o1" state. Here is the final diagram, with the updated accepting states: enter image description here

jasonharper
  • 9,450
  • 2
  • 18
  • 42
  • Thanks for the explanation! The process you mentioned, would this work with my main FSA? So I make 2 copies of it? I'm not quite sure if I understand how the process will go. Can you elaborate further or draw out the first few states so I have a general idea of how to do it? – Ice Art May 04 '17 at 18:39
  • Yes, make a copy - leave `1` links unchanged (Ex: #1->#3), swap destinations of `0` links (so Even#1->Odd#2, Odd#1->Even#2). – jasonharper May 04 '17 at 18:56
  • Hi so I just need a few things cleared up to attempt this, everytime there is a swap destination, is it a new state? I drew up my first attempt where I just label if the state is Even or Odd, I don't think it's the correct process of what you explained though. I have this: http://i.imgur.com/x7kgMmi.png ...... Is that what you meant when you said swap destination or have I interpreted it incorrectly? – Ice Art May 05 '17 at 09:13
  • The only new state needed would be the accept state from Odd (Even's accept state is an existing node). If "swap" isn't making sense to you, perhaps try "crossover"? Delete the node #1 -> node #2 transition in both Even and Odd (since it changes the parity), and instead have #1 in Even go to #2 in Odd, and vice versa. – jasonharper May 05 '17 at 12:31
  • Do you mind going it through with me, I just can't figure out the swap/crossover like you're suggesting T_T – Ice Art May 05 '17 at 13:39
  • Thank you so much for illustrating! The letters you added in the states helped me understand exactly now what you meant! The DFA works, but now its time to make it prettier and reduced which I'll begin to learn about now. Thanks again for helping me and allowing me to get through this. – Ice Art May 05 '17 at 19:48
0

Okay so, here are my thoughts jason pointed quite well the problems you will encounter, first I would create a table with my codes, and create a set of strings that can be accepted

A = 00100
B = 00011
c = 010

and a set of acceptable strings according to your guidelines would be 000110 001000100001110

Give your letter codes expressions like 001000 won't be acceptable with an even 0 parity property. Please notices that that's just an A so A or C messages won't be accepted. I would encourage you to redo your letter codes, a 3 digits code will be easier, because you'll have a larger set of accepted strings and your DFA will be probably smaller.

Give your codes, it is hard to implement a DFA only solution, or a simple DFA only solution. Also remember that codes between letters shouldn't be prefixes of other codes, this will simplify your problem.

Let's say our codes are

A = 101
B = 001
C = 110

then we have the following set of acceptable messages with an even 0 pairing property:

1010
1011010
1100
0011100

Notices that in human language you'll have an amount of A's followed by a 0 any amount of BC's followed by a 0 and so on. You can start forming your regex from there. I hope this is clear enough.

Taro
  • 126
  • 9
  • Well to sum it up, my goal is to create a Deterministic finite automaton that handled the regular language (00100 + 00011 + 010)* and had a parity bit at the end to make sure 0's where odd. Here is my project guideline: http://i.imgur.com/AxHkH4q.png – Ice Art May 04 '17 at 17:56
  • Hi I see that your regular expression is not well generated. If I understand properly from your project guideline I can tell that A=00100 B=00011 and C=010 your regular expression will accept only ABC, ABBBC AAAABC for what I see. Please correct me if I am wrong to give you my final answer. btw you're missing a 0 on the second expression you submitted – Taro May 04 '17 at 18:19
  • Yes that is correct, and the initial regular expression isn't generated well? I figured that may be true since I just used a software to create the regular expression. Also where am I missing a 0 exactly? – Ice Art May 04 '17 at 18:29
  • Btw, the submission is in table form like in the following: http://i.imgur.com/XhBYZ8I.png. Just wondering, would forming the correct regex and converting in into a FSA table work for my submission? I have been trying to do this since the beginning and I'm not too sure if it would work like that. – Ice Art May 04 '17 at 18:55
  • @IceArt yes, the right path to do it is actually that, the table is a representation of your fsa – Taro May 05 '17 at 06:52
  • What process do you recommend for me to get the answer? I've been trying to do the other suggested answers but it's taking me awhile and they're quite difficult to understand. – Ice Art May 05 '17 at 07:07
  • Remember that this is all about patterns, and the reason why other solutions won't work is because we all see different patterns. I would use a lot of paper. One more hint, you don't really need to merge the two DFAs you'll waste much time, what you really need from there is the regex that accepts your paring property. – Taro May 05 '17 at 19:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/143540/discussion-between-taro-diaz-and-ice-art). – Taro May 05 '17 at 19:56
0

What you want is a DFA that accepts what is called the intersection of two languages:

  1. The language (00100 + 00011 + 010)*(0+1)
  2. The language of strings with an odd number of 0s

(Note: I add (0+1) to stand for the extra bit you intend to add to the end. If this is not what you meant, please ignore).

I posted a well-reviewed answer to the question of how to combine DFAs in this manner: see here. A brief summary:

  1. Create DFAs M1 and M2 for both of your languages
  2. Create a new DFA M3 as follows:
    • Q3 = Q1 x Q2 (states of M3 are ordered pairs of states from M1 and M2)
    • S3 = (S1, S2) (the initial state is the ordered pair of initial states of M1, M2)
    • A3 = {(q1, q2) | q1 in A1, q2 in A2} (accepting states are ordered pairs of states where both elements are accepting states in their respective machines. This gives you intersection. For union, at least one must be accepting. For difference, q1 must be accepting and q2 must not be. Etc.)
    • f3 : Q3 x E -> Q3 is defined such that f3((q1, q2)) = (q1', q2') wherever f1(q1) = q1' and f2(q2) = q2'.

In your case, you will get a DFA with twice as many states as the first DFA. The first "copy" of that DFA will represent even parity and the second "copy" will represent odd parity. Your machine will work the same as before but will bounce back and forth between "copies" whenever you see a 0. Only the odd-parity copy will keep its accepting states.

Community
  • 1
  • 1
Patrick87
  • 27,682
  • 3
  • 38
  • 73
  • Hi, I'm going to have an attempt at this now, but for the meantime I generated an DFA with (00100 + 00011 + 010)*(0+1), and I created one for Odd 0. http://i.imgur.com/Q4OU9n2.png Are those diagrams correct for what I need to begin the process of intersection of 2 languages? – Ice Art May 05 '17 at 05:03