I have drawn this diagram below. But i want to be sure of the answer as + and the * operator are confusing.
_
| \
--> q_|- 0,1,E
Here my DFA has only one state q. Both 0,1,empty are redirected to q itself.
(0+1) means you can select a 0 or 1 but not both. The + is analogous to OR.
The star means that you can do this selection Zero or more times.
Hence, (0+1)* will include any String of 0s and 1s including the empty string.
5 years late but heres what I got:
Start at A. A is also an end state.
From A: Input 0 goes to B. B is an end state.
Input 1 goes to C. C is an end state.
From B: Input 0 goes to B.
Input 1 goes to C.
From C: Input 0 goes to B.
Input 1 goes to C.
I'm pretty sure this is right (studying for an exam atm)...
It may be hard to visualise from that but if you draw a diagram from my instructions it should be more clear.
Hope this helps anyone looking this up.
Related
I have to write a program which selects a random led and lights it up ,however I am having trouble getting the RANDOM function work. I have included the code i have below.
main:
RANDOM w0
w1 = w0// 10+ 1
SELECTCASE w1
Case1:
high b.1
pause 1000
low b.1
Case2:
high b.2
pause 1000
low b.2
ENDSELECT
goto main
Two observations:
1) The code w1 = w0// 10+ 1 sets w1 to a value between 1 and 10, but your select case structure only handles cases 1 and 2. That shouldn't actually be a problem though, as the unhandled values will do nothing - but your code may loop several times before the random sequence produces a 1 or 2. If you want a value between 1 and 2, use w1 = w0 // 2 + 1.
2) As posted your code has some unnecessary colons and lacks some spaces where they should be, at least according to the manual entry for select case. I would try correcting these just in case that's the problem.
Aside from that, can you give more detail on what isn't working? Are you sure that your wiring is correct and a high on those two pins does in fact light the two LEDs? You could try adding sertxd commands within your case structure to confirm whether the code actually reaches each case.
I'm learning KMP algorithm in the Book Algorithms 4th. I could understand most of the algorithm but have been stuck at process of dfa construction for a couple of days.
Take the pattern ABABAC for example. When there's a mismatch at C(state of dfa is 5), we should shift right a character in the text. So the pattern characters that we have known are BABA. However, how to figure out the next state of the dfa during construction? I failed to understand the text below:
For example, to decide what the DFA should do when we have a mismatch at j=5, for ABABAC, we use the DFA to learn that a full backup would leave us in state 3 for BABA, so we can copy dfa[][3] to dfa[][5].
What does it mean by "a full backup would leave us in state 3 for BABA", and how to get this conclusion while there's no specified input? And I can't understand the graph left to the text. Could anyone explain what it means? I have tried to understand it by myself for a couple days, but still could not get it. Thank you!
And you can read the segment of Algorithms 4th here.
When you're matching the input string, you can only get into state 5 after matching the first 5 characters of the pattern, and the first 5 characters of the pattern are ABABA. So no matter which input string you use, you know that the text preceding state 5 is "ABABA".
So you if you get a mismatch in state 5, you could back up 4 characters and try matching again. But since you know what text has to appear before state 5, you don't actually need the input text to figure out what would happen. You can figure out beforehand what state you'd end up in when you got back to the same place.
backup 4 characters and go to state 0:
0 : BABA
A doesn't match, so advance and go to state 0
0: ABA
A matches, so go to state 1
1: BA
B matches, go to state 2
2: A
A matches, go to state 3
3:
now we're back to the place in the input where we saw state 5 before, but now we're in state 3.
This will always happen when we get a mismatch in state 5, so instead of actually doing this, we just make a note that says "when we get a mismatch in state 5, go to state 3".
Note that most KMP implementations will actually make a failure table where failure_table[5]=3. Your example implementation is building the full DFA[char][state] instead, so it copies all the transitions from state 3 into state 5 for the failure cases. That says "when we get a mismatch in state 5, do whatever state 3 does", which works out the same.
UNDERSTAND EVERYTHING ABOVE BEFORE MOVING ON
Now let's speed up the calculation of those failure states...
When we get a mismatch in state 5, we can use the DFA we have so far to figure out what would happen if we backed up and rescanned the input starting at the next possible match, by applying the DFA to "BABA". We end up in state 3, so let's call state 3 the "failure state" for state 5.
It looks like we have to process 4 pattern charcters to calculate the failure state for state 5, but we already did most of that work when we calculated the failure state for state 4 -- we applied the DFA to "BAB" and ended up in state 2.
So to figure out the failure state for state 5, we just start in the failure state for state 4 (state 2), and process the next character in the pattern -- the "A" that came after state 4 in the input.
Recently I had an exam where we were tested on logic circuits. I encountered something on that exam that I had never encountered before. Forgive me for I do not remember the exact problem given and we have not received our grade for it; however I will describe the problem.
The problem had a 3 or 4 inputs. We were told to simplify then draw a logic circuit design for that simplification. However, when I simplified, I ended up eliminating the other inputs and ended up literally with just
A
I had another problem like this as well where there was 4 inputs and when I simplified, I ended up with three. My question is:
What do I do with the eliminated inputs? Do I just not have it on the circuit? How would I draw it?
Typically an output is a requirement which would not be eliminated, even if it ends up being dependent on a single input. If input A flows through to output Y, just connect A to Y in the diagram. If output Y is always 0 or 1, connect an incoming 0 or 1 to output Y.
On the other hand, inputs are possible, not required, factors in the definition of the problem. Inputs that have no bearing on the output need not be shown in the circuit diagram at all.
Apparently it not eliminating inputs but the resulted expression is the simplified outcome which you need to think of implementing with logic circuit.
As an example if you have a expression given with 3 inputs namely with the combination of A, B & c, possible literals can be 2^9 = 9 between 000 through 111. Now when you said your simplification lead to just A that mean, when any of those 9 input combinations will result in to value which contain by A.
An example boolean expression simplified to output A truth table is as follows,
A B | Output = A
------------------
0 0 | 0
0 1 | 0
1 0 | 1
1 1 | 1
I'm getting involved with ZPL (a little bit) since a few days, so I'm sorry if the questions will look stupid.
I've got to build a bar code 128 and I finally realized: I got to make it as shorter as possible.
My main question is: is it possible to switch to subset C and then back to B for just 2 digits? I read the documentation and subset C will ready digits from 00 to 99, so in theory it should work, practically, will it be worth it?
Basically when I translate a bar code with Zebra designer, and print it to a file, it doesn't bother to switch to subset C for just a couple of digits.
This is the text I need to see in the bar code:
AB1C234D567890123456
By the documentation I read, I would build something like this:
FD>:AB1C>523>64D>5567890123456
Instead Zebra Designer does:
FD>:AB1C234D>5567890123456
So the other question is, will the bar code be the same length? Actually, will mine be shorter? [I don't have a printer with me at the moment]
Last question:
Let's say I don't want to spend much time scripting this up, will the following work ok, or will it make the bar code larger?
AB1C>523>64D>556>578>590>512>534>556
So I can just build a very simple script which checks two chars per time, if they're both numbers, then add >5 to the string.
Thank you :)
Ah, some nice loose terminology. Do you mean couple="exactly 2" or couple="a few"?
Changing from one subset to another takes one code element, so for exactly 2 digits, you'd need one element to change and one to represent the 2 digits in subset C. On the other hand, staying with your original subset would take 2 elements - so no, it's not worth the change.
Further, if you were to change to C for 2 digits and then back to your original, the change would actually be costly - C(12)B = 3 elements whereas 12 would only be 2.
If you repeat the exercise for 4 digits, then switching to C would generate C(12)(34) = 3 elements against 4 to stay with what you have; or C(12)(34)B = 4 elements if you switch and change back, or 4 elements if you stick - so no gain.
With 6 or more successive numerics, then you gain regardless of whether or not you switch back.
So overall,
2-digit terminal : No difference
2-digit other : code is longer
4-digit terminal : code is shorter
4-digit other : no difference
more than 4 digits : code is shorter.
And an ODD number of digits would need to be output in code A or B for the first digit and then the above table applies to the remainder.
This may not be the answer you're looking for, but specifying A (Automatic Mode) as the final parameter to the ^BC command will make the printer do this for you.
Example:
^XA
^FO100,100
^BY3
^BCN,100,N,N,A
^FD0123456789^FS
^XZ
I've been struggling with this one for a while and am not able to come up with anything. Any pointers would be really appreciated.
The problem is: given the language of all DFAs that receive only words of even-length, prove whether it is in P or not.
I've considered making a turing machine that goes over the given DFA in something like BFS/Dijkstra's algorithm in order to find all the paths from the starting state to the accepting one, but have no idea how to handle loops?
Thanks!
I think it's in P, at worst quadratic. Each state of the DFA can have four parity states
unvisited -- state 0
known to be reachable in an odd number of steps -- state 1
known to be reachable in an even number of steps -- state 2
known to be reachable in both, odd and even numbers of steps -- state 3
Mark all states as unvisited, put the starting state in a queue (FIFO, priority, whatever), set its parity state to 2.
child_parity(n)
switch(n)
case 0: error
case 1: return 2
case 2: return 1
case 3: return 3
while(queue not empty)
dfa_state <- queue
step_parity = child_parity(dfa_state.parity_state)
for next_state in dfa_state.children
old_parity = next_state.parity_state
next_state.parity_state |= step_parity
if old_parity != next_state.parity_state // we have learnt something new
add next_state to queue // remove duplicates if applicable
for as in accept_states
if as.parity_state & 1 == 1
return false
return true
Unless I'm overlooking something, each DFA state is treated at most twice, each time checking at most size children for required action.
It would seem this only requires two states.
Your entry state would be empty string, and would also be an accept state. Adding anythign to the string would move it to the next state, which we can call the 'odd' state, and not make it an accept state. Adding another string puts us back to the original state.
I guess I'm not sure on the terminology anymore of whether a language is in P or not, so if you gave me a definition there I could tell you if this fits it, but this is one of the simplest DFA's around...