Solving Feynman's Unsolved Puzzle? 90
An anonymous reader asks: "In The Feynman Lectures on Computation, Richard Feynman poses an interesting little puzzle involving the synchronization of finite state machines acting as generals and soldiers. While he was able to find an answer to the problem, the minimum time solution apparently eluded him, and he ended his description of the puzzle with the following Fermat-like declaration: 'Somebody has actually found a solution with this minimum time. That is very difficult though, and you should not be so ambitious. It is a nice problem, however, and I often spend time on airplanes trying to figure it out. I haven't cracked it yet.' My best attempt performs at about 3N, not quite the minimum time of 2N-2. So I'm asking Slashdot: Has anyone ever come across the minimum time solution to this puzzle? Or maybe someone here can figure it out!"
"Here is the full description of the problem, in Feynman's own words. Please remember that these are finite state machines, so you can't use any methods that involve counting the number of soldiers or assigning a number to each soldier.
Problem 3.4: Before turning to Turing machines, I will introduce you to a nice FSM problem that you might like to think about. It is called the 'Firing Squad' problem. We have an arbitrarily long line of identical finite state machines that I call 'soldiers'. Let us say there are N of them. At one end of the line is a 'general', another FSM. Here is what happens. The general shouts 'Fire'. The puzzle is to get all of the soldiers to fire simultaneously, in the shortest possible time, subject to the following constraints: firstly, time goes in units; secondly, the state of each FSM at time T+1 can only depend on the state of its next-door neighbors at time T; thirdly, the method you come up with must be independent of N, the number of soldiers. At the beginning, each FSM is quiescent. Then the general spits out a pulse, 'fire', and this acts as an input for the soldier immediately next to him. This soldier reacts as in some way, enters a new state, and this in turn affects the soldier next to him and so on down the line. All the soldiers interact in some way, yack yack yack, and at some point they become synchronized and spit out a pulse representing their 'firing'. (The general, incidentally, does nothing on his own initiative after starting things off.)
There are different ways of doing this, and the time between the general issuing his order and the soldiers firing is usually found to be between 3N and 8N. It is possible to prove that the soldiers cannot fire earlier than T=2N-2 since there would not be enough time for all the required information to move around. Somebody has actually found a solution with this minimum time. That is very difficult though, and you should not be so ambitious. It is a nice problem, however, and I often spend time on airplanes trying to figure it out. I haven't cracked it yet."
Solving Feynman's Unsolved Puzzle? (Score:1, Funny)
I'm no math wiz (Score:2, Insightful)
Seriously, the straight line might just be the solution to that problem.
That thought just popped up in my head, feel free to flame me for being open.
Hmmmmmm (Score:1)
As I said, I'm no math wiz, haven't any credits under my name past Mat121 (College Algebra, being interested in calc based phys that'll change). But it seems that problem like these are solved not by the math, but the logic.
That's one of the great things about being young and dumb like me, everything is open to interpretation.
Re:Hmmmmmm (Score:1)
Re:Hmmmmmm (Score:1)
I know I don't know shit. Didn't I say that earlier?
A new kind of science (Score:5, Interesting)
Re:A new kind of science (Score:1)
I don't have a link handy, and I'm too tired to google. Anybody else recall the same?
Re:A new kind of science (Score:2)
Re:A new kind of science (Score:2)
Re:A new kind of science (Score:1)
As I understand it (someone correct me if I'm wrong), cellular automata have an FSM at their heart. Their inputs are determined spatially -- eg. their neighbors outputs serve as inputs. Also, I believe the output of cellular automata's FSM is generally of the form "alive" or "dead". Think, for instance, of Conway's "Life", or the various "Rule XX" that Wolfram examined that lead to him writing ANKOS.
So, in other words, cellular automata are a bunch of specialized FSMs.
More arbitrary FSMs can take more arbitrary inputs and produce more arbitrary outputs (or sets of outputs).
--JoeThe relationship between FSMs and CAs (Score:3, Informative)
I've seen many 3- and 4-state CA systems that have been simulated. I've also seen many CA systems with widely divergent definitions of what a "neighbor" is. (The most common cases are where the neighbor is a cell adjacent on one of the four cardinal directions, or where the neighbor is a cell on one of the eight adjacent squares. This assumes a rectilinear or chessboard space.)
Another error in your description is the statement that cellular automata are a bunch of specialized finite state machines. This implies that each cell could be running a different "program." The truth is, most if not all CA systems run the same "program" on every cell, in lockstep. In other words, cellular automata are a special case of SIMD processing. (I suppose it's possible to construct a MIMD example of CA, but then you run into the problem of how you assign your initial conditions -- i.e., not only do you need to assign an initial state to each cell, but you also need to assign a "program" to each cell.)
Re:The relationship between FSMs and CAs (Score:1)
Thanks for the clarifications! I guess from your description, the Feynman's FSM Firing Squad can be considered a 1-D array of cellular automata, correct?
BTW, by "specialized", I meant that the notion of FSM embodied in a cellular automata is specialized over the more general notion of a state machine -- that is, cellular automata are a specialized form of FSM. I didn't mean to imply by the word "specialized" that different cells have different programs--although, you could provide for that in a single program by providing disconnected subsets of the states in your single "program" (which also solves the "MIMD initialization problem" you mention offhand).
Here's an example of what I mean by disconnected subsets. Suppose each cell has 6 states labelled A through F. Suppose A, B and C all have rules for transitioning among A, B and C. Similarly, suppose D, E, F have rules for transitioning among D, E and F. You can't reach A, B, or C if you start in D, E, or F, and vice-versa. If all your cells have programs of this form, then which subprogram a given cell 'runs' depends only on which subset of the allowed statespace you allocate that cell's starting state from.
--JoeRe:A new kind of science (Score:2)
Re:A new kind of science (Score:2, Funny)
This is Slashdot. You don't have to write that part.
Re:A new kind of science (Score:2, Insightful)
Cellular automata are exactly what this problem is asking about! A CA is a bunch of FSMs hooked together. More precisely, a quick Googling says: [herts.ac.uk]
Re:A new kind of science (Score:1)
The solution is indeed reproduced in Wolfram's book, which I will excerpt in a separate reply if it has not already been quoted.
Re:A new kind of science (Score:1)
An optimum solution ... (Score:3, Informative)
Waksman, A. An optimum solution to the firing squad synchronization problem. Information and Control 9 (1966), 66--78.
Unfortunately, the article does not seem to be available online.
If anyone decides to take a quick trip down to the library, I would be delighted if they could share the answer.
Re:An optimum solution ... (Score:5, Informative)
isn't this the same as (Score:2)
Where the prisoners get released after each one has switched the light on.
You get a best of 2n-2 for this
2n for switching on and off and -2 because of the first and last prisoner.
The worst case could be infinate.
The Prisoners and the Light (Score:2, Informative)
That's tricky (Score:1)
If prisoner X has entered the room previously on this batch of days, he switches the light on. After the 100th day, if the light is off, the prisoner states that all people have entered the room. Otherwise turn the light off.
This is arather inefficient thouygh. It relies on all 100 prisoners being randomly selected once in a batch of 100 days. We could probable find some optimisations to this solution though.
Re:The Prisoners and the Light (Score:2)
To quote, "Each day one prisoner is chosen at random [...]"
If the same prisoner happened to be chosen at random EVERY TIME then the prisoners would never be released. Now, the odds of that happening to infinity are 0, but there is a chance that it could happen until the maximum age of the prisoners. It's even more likely that every prisoner gets randomly selected except for one, until they all die.
To make it possible, we have to assume that each prisoner will only be picked again after every other prisoner has. Perhaps we just shuffle the prisoners into a random order, and loop it. But then the prisoner can just wait until selected again, and then he'll know. Unless we assume that they're all selected before looping back, but that the prisoners don't know that.
Is that last condition necessary for solving the problem without making it trivial, or did I make a mistake somewhere?
Solutions (Score:4, Informative)
probably wrong (Score:1, Interesting)
ok, as the thing said, first all soldiers are in a default do-nothing state, then the first gets the fire! message, with a counter 0, then increments the counter and passes it to the next soldier and goes to the "wait-reply" state. then the next soldier does the same thing and so on, until the end of the line. now, when the last soldier recieves the message - fire, counter is x, it goes to the state "fire after x time ticks", decrements x and passes it on, the next one (since it is in the wait-reply state, it knows to go into this state) recieves the counter, goes into "fire after x ticks", decrements x and passes it on, until we reach the first soldier, who immediately fires (since x is zero), as do all the others, since their counters run out at the same time..
and since the message passes the line twice, it should take N-2 ticks, assuming we start counting from the time the first soldier gets the message..
Re:probably wrong (Score:4, Informative)
Conditional logic (Score:1)
How does an FSM work then? Can we only trigger a change based on a change?
Think of it as a table. (Score:1)
Re:Conditional logic (Score:4, Insightful)
This is why this is such a good problem -- because a giant FSM has the overlying assumption that there are no unknowns, but the problem definition seems to have an unknown in N. It's not really unknown once the system is running, though. The problem is just to build the smaller pieces in such a way that when stuck together, they work correctly regardless of what N is. That's different from saying "they work correctly *because* they know what N is, or can otherwise predict it."
Re:Conditional logic (Score:1, Informative)
Re:Conditional logic (Score:1)
When I've programmed with FSMs, I've always thought of them as graphs of states (points) and transitions (edges). An input (message pulse, word, signal, whatever) then can trigger a state change, which I've usually implemented via some kind of table. The state change is accomplished by a function; in a useful program the state transition could call an arbitrary list of functions that might involve sending other messages to other state machines, etc., or doing other "stuff" with arbitrary side effects, but as far as the state machine is concerned, you would always just move to either a different state or the same state again.
So I need a little more info to crack this: to pin down some definitions. Just how restrictive are the rules of this little universe?
- Can each soldier have a DIFFERENT state machine?
- Obviously the state machine consists of states and transitions. What I'm hearing from dmorin is that my soldier can't distinguish between different messages. In other words, when it gets a "hut!" message it always moves on to the next state. It can't distinguish between hearing the general shout "fire" and some other message like "put your gun away and go home."
- Time is passing in discrete intervals, say, seconds, but can the "tick" of some global clock also be a message? or is the only message each soldier can hear just the generic "hut!" message from the general at one end or the soldiers on either side?
- Maybe this is needlessly picky, but would "firing" count as a state? The way I usually think of state machines, "fire" would be what happened when the state machine got a message that triggered the transition between "waiting to fire" and "fired." And "speaking" (issuing a "hut!" message to the soldier on the left and right would also be a transition.
- Lastly, can the soldier "aim" (distinguish) which soldier he yells "hut!" to? Or will both the soldier on the left and right "hear" him?
Paul
Re:Conditional logic (Score:1, Informative)
- Can each soldier have a DIFFERENT state machine?
No. This isn't really a restriction, because you could simply encode the different state machines on different subsets of the state set.
- Obviously the state machine consists of states and transitions. What I'm hearing from dmorin is that my soldier can't distinguish between different messages. In other words, when it gets a "hut!" message it always moves on to the next state. It can't distinguish between hearing the general shout "fire" and some other message like "put your gun away and go home."
The soldier looks at his own state and the states of his direct neighbors and then chooses his next state. The "messages" are state changes of neighbors. You can also code it so that a single soldier oscillates: *a*->b, *b*->c (* for arbitrary states of the neighbors).
- Time is passing in discrete intervals, say, seconds, but can the "tick" of some global clock also be a message? or is the only message each soldier can hear just the generic "hut!" message from the general at one end or the soldiers on either side?
There is no central time information or counter. All FSMs decide on their next state at the same time, based on their current state. If the soldiers need to wait a certain number of time intervals, they have to count themselves.
- Maybe this is needlessly picky, but would "firing" count as a state? The way I usually think of state machines, "fire" would be what happened when the state machine got a message that triggered the transition between "waiting to fire" and "fired." And "speaking" (issuing a "hut!" message to the soldier on the left and right would also be a transition.
Firing in this context is when an FSM enters a special state. The task is to create the FSM so that all instances enter one state at the same time and no instance enters this state before that.
- Lastly, can the soldier "aim" (distinguish) which soldier he yells "hut!" to? Or will both the soldier on the left and right "hear" him?
If you want to think of it in communication terms: At each time intervall, every soldier tells his direct neighbors his own state. That's it.
Re:Conditional logic (Score:1)
Each soldier can view the state of its two adjacent neighbors, and then those states are used to look in the transition table to determine the soldier's state for the next time step.
Time's only effect is to cause the system to advance to the next time step; i.e., at a clock tick, each soldier examines the state of its two neighbors, looks up the proper transition in its transition table, and changes state accordingly.
Yes, "fire" is a state, and is generally regarded as required to be a unique state. Transitions have no effect on neighbors until the next clock tick (when the neighbors examine their neighbors' states), so "speaking" isn't a transition. Technically, "speaking" doesn't even occur.
The soldiers to the left and right of a particular soldier are the only ones who can examine the state of that soldier. They do so only at a clock tick.
Hope this helps!
Okay, thanks guys (Score:1)
So am I corrent if I say my above example is a valid state transition?
Re:probably wrong (Score:1)
Re:probably wrong (Score:2)
Re:probably wrong (Score:1)
A quote from the article:
Also probably wrong... (Score:1)
As for finite states, well you can turn this into a state table if you want to (a large number of states to be sure, but not a very large number of bits) but you can only cope with a finite number of soldiers.
http://xraysgi.ims.uconn.edu/fsquad/firing-solu
Having read the state tables for the alleged solutions I am clueless as to how they're supposed to work. A synopsis of the strategy being adopted would be very helpful.
It seems to me that the initial message to fire MUST take N ticks to propagate to the Nth soldier. The message that the final soldier has been located MUST take N ticks to propagate back to the first soldier. Hence a theoretical limit of 2N + some number.
Exactly how you store the intermediate information ("wait, you'll get another message soon!") is really just a technical detail for folks who want to program a formal finite state machine (I think they live near people with infinitely long spools of tape) which can't store integers. The rest of us would use your (or a similar) solution and get on with our lives.
Re:probably wrong (Score:2)
Actually, your solution would be quite correct if you knew in advance the maximum number of soldiers that are allowed.
Contrary to what others have said, you can implement counters and conditional logic in FSMs, but in order for it to be a finite state machine, you must specify in the design of the FSM exactly how many states there are as well as the transition rules. Now each possible value for a counter is a separate state, so they must be enumerated in advance. Your soldiers would have 2k+1 states where k is the maximum value allowed for the counter. There is the initial wait state, plus k states after recieving the first message and waiting to pass it along to the next soldier, plus k decrement states.
Now, the total number of soldiers must be finite, but unlimited. If you design your soldiers with k counter states, what if there are k+1 soldiers? Then your solution would fail.
So, if the problem were modified so that the maximum possible number of soldiers were specified in advance, then your solution would be a correct minimum-time solution. But if no such maximum is specified, then the solution must be more complicated.
Surely You're Joking (Score:3, Funny)
Know who could solve this? (Score:1, Offtopic)
:)
Chick? (Score:1)
How can you dare not remembering Princess Nell?
Solutions (Score:5, Informative)
Re:Solutions (Score:1)
Links to several solutions (Score:5, Informative)
I have a solution... (Score:4, Funny)
Re:I have a solution... (Score:2)
;-)
Re:Hmm, I tried (Score:1)
That's my understanding anyway. My first idea when reading this problem was to have a soldier as a FSM with N+1 states (a state for each soldier but not the last, a quiescent state, and a fire state) the first soldier recieves the instruction from the general (to the left) and gets set to state N-1, the next second the soldier to the right sees he's in N-1 and gets in state N-2. All the N-1 states if recieving no input move n-- for all inputs checking every second, the 1 state (last state in the N chain) decrements to fire. This is essentially a counter and the last guy will get the fire state immediately, all will hit the fire state at the same time. It's done in N seconds (not 2N-2) so obviously my understanding of FSMs isn't in line with the version being used here.
Re:Hmm, I tried (Score:1)
Surely you realize digital logic is really just a FSM in most cases. I'm surprised you have never studied it that way.
Re:Hmm, I tried (Score:2)
Re:Hmm, I tried (Score:1)
This is tough problem. So far, I haven't been able to come up with any solution independent of N, much less one that finishes within 2N - 2 steps.
I refuse to lookup a solution. I will try to make one myself. It's kind of odd; I couldn't care less about most of the social ills of the world, and yet mathematical games like this one really inspire me.
Wow! (Score:3, Funny)
Do you feel the community, people? Because I am totally feeling it right now.
There are so many things I'd like to know...
(waits for the inevitible)
Re:Wow! (Score:1)
Feeling short (Score:4, Funny)
thoughts (Score:1)
in fact, their would be absolutely no way to get a simple state machine to function in this manner, or to fire simultaniously, as it would have either a 0(no function or no action) or a 1(action) state, theirfor the general would be 0 at start, then would change to 1 for fire. the first soldier would then fire as he went to state 1, as a simple state machine has no logic to decide to "fire" or to "pass it on". so by this reasoning, the total time to have all soldiers fire would be N+1, N for the number of soldiers as the second soldier would of coarse fire as a result of the first soldier fireing and etc, and the general would have a time of 1 to give the order.
N+1.
now if the soldiers had logic to decide to "ass it on" AND memory and logic to calculate time decimation and N, then 2N-2 would be the only functional solution. this also assumes that not only the general, but the last soldier have different capabilities from the rest of the soldiers, as the last solider must calculate the total and also know to reverse the movement of data back towards the general.
Re:thoughts (Score:2)
Why do you assume that there are only two states in the state machine?
N+1, N for the number of soldiers as the second soldier would of coarse fire as a result of the first soldier fireing and etc, and the general would have a time of 1 to give the order.
The problem stipulates that all fire at the same time.
now if the soldiers had logic to decide to "ass it on" AND memory and logic to calculate time decimation and N, then 2N-2
FSMs only have if-then relationships. They don't have any "memory" to store anything, they only tell you what the next state is going to be based on some input. Nothing about the FSM changes during runtime, thus they can't store arbitrary values.
Also, I don't follow your logic for saying 2N-2 would be the only solution. Do you actually understand the problem?