The real issue was in reasoning out how to build from any one accepting state. Once we had a string that ended in 0000, what would happen if we added a 1 to make it end in 0001, or another 0 to have it remain 0000? The 0000 would stay at the same state, so I have an arrow labelled 0 looping back to 0000. Then, an arrow labelled 1 going from the state 0000 to the state 0001. Any string that, with a bit added, still had its 4th last bit as 0 was easy to figure out - just go from one accepting state to the next.
The more difficult cases were the ones like 0100. If I add another bit to that, the new string no longer goes into an accepting state. Where does it go? Here is where I had to really think about my state invariants. What defines states q0-q7, the non-accepting states? I decided to define them by the certainty of their sequence of bits as it relates to their distance from an accepting state (because we know that once we have a 0, it is three bits away from an accepting state). So, what we know about q0 is that any string residing there has 1 as a fourth-last digit, and is at least 4 transitions away from an accepting state, because it will need at least 4 bits added because its fourth-last digit isn't 0. So, the state invariants are as follows...
q0 - fourth-last bit definitely isn't 0. Definitely needs at least 4 bits until it reaches an accepting state, but we don't know what any of those bits will be. This is the start state, as this applies to the empty string as well.
q1 - fourth-last bit, once we reach an accepting state, will definitely be 0. Needs at least 3 more bits to hit an accepting state, but we don't know what those three bits will be.
q2 - last two bits, once we reach an accepting state, will definitely be 01. Needs at least 2 more bits to hit an accepting state, but we don't know what those two bits will be.
q3 - last two bits, once we reach an accepting state, will definitely be 00. Needs at least 2 more bits to hit an accepting state, but we don't know what those two bits will be.
q4 - last three bits, once we reach an accepting state, will definitely be 011. Needs at least 1 more bit to hit an accepting state, but we don't know what that bit will be.
q5 - last three bits, once we reach an accepting state, will definitely be 010. Needs at least 1 more bit to hit an accepting state, but we don't know what that bit will be.
q6 - last three bits, once we reach an accepting state, will definitely be 001. Needs at least 1 more bit to hit an accepting state, but we don't know what that bit will be.
q7 - last three bits, once we reach an accepting state, will definitely be 000. Needs at least 1 more bit to hit an accepting state, but we don't know what that bit will be.
q8 - last four bits are 0111. Accepting state.
q9 - last four bits are 0110. Accepting state.
q10 - last four bits are 0101. Accepting state.
q11 - last four bits are 0100. Accepting state.
q12 - last four bits are 0100. Accepting state.
q13 - last four bits are 0010. Accepting state.
q14 - last four bits are 0001. Accepting state.
q15 - last four bits are 0000. Accepting state.
So, when we run into a situation such as 0100 with 1 added, what do we do with it? Its last four bits are 1000, so its third-last bit is 0. That means it needs one more bit added to reach an accepting state, so we choose among the states where 1 more bit needs to be added before an accepting state is reached. 1000 will reach an accepting state in one bit, so its "last three bits once we reach an accepting state" are definitely 000, which is state q7. Then, depending on whether a 1 or a 0 is added, it will hit accepting state q14 or q15.
I used this reasoning to finalize the DFSA and add all the transitions coming out of each accepting state, whether a 0 or a 1 is added. No one state has two transition arrows going into the same state, which is in accordance with the proof we wrote for assignment 3.
From Polya's method...
Looking Back
- Fourth. Examine the solution obtained.
- Can you check the result? Can you check the argument?
- I checked all 16 binary strings of length 4, either by building from an empty string or by adding a 1 or a 0 to all 8 accepting states - plus the empty string. I might write a proof of the state invariant tomorrow, if I have time - but I feel I have made significant progress on this problem already.
- Can you derive the solution differently? Can you see it at a glance?
- There may be a different solution, but I feel that this one is elegant (well, if I had better mouse control in MS Paint it would have been, but you can appreciate the branching form despite the jittering) and easy to read. I definitely can't see another one at a glance. You can easily see how each accepting state, as it branches out with a 1 or a 0 being added, transitions to the next available accepting state that hasn't had an arrow pointing back up at it.
- This problem was interesting in that we were already provided with a lot of structure for it - we proved in assignment 3 that such a DFSA would need at least 16 states, and on the discussion board we were asked to prove that it can have exactly 16 states. If we were asked - draw a DFSA that accepts the language of binary strings whose fourth-last digit is 0, and weren't given any hints about looking at the 16 binary strings of length 4, I would have been a lot more confused by this problem. So, my
- Can you use the result, or the method, for some other problem?
- I might run into other problems where I can break a seemingly quite complex problem down to a certain small set of binary strings, and look at how changes affect each one in that set. I don't know that the actual result here will be terribly useful, but the method probably will be.