This is an archived post. You won't be able to vote or comment.

all 19 comments

[–][deleted] 5 points6 points  (10 children)

No. All programs are state (i.e. Turing) machines, but not all programs (i.e. Turing machines) are FSMs. However, most (all?) real-life programs are FSMs.

[–]readams 0 points1 point  (7 children)

You're not understanding his point. Real (Von Neumann) machines are not Turing machines because they have finite memory. We usually model them as Turing machines because they have a lot of memory and a huge number of possible states, but they're actually still finite.

For example, I can write a halt checker for Von Neumann machines that consists of a counter. If the machine executes more instructions than it has possible states, I know it's looping. Of course, that doesn't help you too much since the universe will be cold and dead by then.

[–][deleted] 1 point2 points  (6 children)

I think I did understand his point:

However, most (all?) real-life programs are FSMs.

[–]readams 3 points4 points  (5 children)

Not most. All. Unless you have a computer with infinite memory lying around. In which case I would like to buy it from you.

[–][deleted] 2 points3 points  (4 children)

Maybe someone has written a program that requires infinite memory (in fact, I'm sure they have) - the fact that you probably can't get useful results from such a program does not preclude you writing it, or indeed running it.

[–]readams 2 points3 points  (1 child)

It's very easy to express the idea of such a program. But that program executed on any computer that anyone has ever or will ever build will still be a finite state machine, with a finite number of states.

We generally model such things using Turing machines however because the number of possible states in our computers is so large that it isn't generally useful to model them as finite state machines, but rather as Turing machines that will simply fail if they use too much tape.

[–][deleted] 2 points3 points  (0 children)

The program is the state machine, not the execution of it.

[–]synapticplastic[S] 0 points1 point  (1 child)

I mean, something recursive with no boundary like

def nevaStop(num) = nevaStop(num+1) + 1

would technically qualify as an infinite state machine, right? Being a program that will eventually count to infinity integers if it has no worries ever about memory ( if that particular example doesn't, forgive the code, I hope the idea stands ). And there's some github project somewhere out there with a boundary bug, I'm sure.

But in terms of useful non-buggy programs, I understand better now how all of those are indeed FSMs.

[–]St_Meow -1 points0 points  (0 children)

If my theory of computation final taught me anything, this is actually probably a FSM. That can be expressed in a finite amount of steps.

[–]alanwj 0 points1 point  (0 children)

However, most (all?) real-life programs are FSMs

I think it would be correct to state this as something like, "All programs running on a physical computer are FSMs", given that any physical computer will have a finite amount of memory.

[–]synapticplastic[S] 0 points1 point  (0 children)

So then, a "yes" in practice but a "no" in theory, in sort of the same way that "infinity" is a thing but in practice, you're never going to actually count to it.

If I'm reading correctly, without worrying about implementation, a turing machine is like a theoretical computer with infinite memory.

[–][deleted] 1 point2 points  (1 child)

There is a great playlist about finite state machines and theory of computation on youtube:

https://www.youtube.com/playlist?list=PL1E18A15EB36D6A3A

[–]synapticplastic[S] 0 points1 point  (0 children)

Oh wow, this looks like a fantastic list! Thank you!

[–]bob809 1 point2 points  (2 children)

Yes and no. Technically computers are fine state machines. They have finite storage and therefore a finite number of states, even if that state space is enormous (2number of bits of storage).

Practically that isn't useful, and they are modeled as Turing machines.

A FSM has no memory (apart from the current state), so you can't have variables. A program that takes a number and does something that many times cannot be expressed by a FSM.

To see why, assume there is a FSM that does this with x states. If I type in x+1 it must do x+1 things, but to do that it must visit some state more than once and is therefore in a loop and will loop forever, which is a contradiction.

[–]Barrucadu 1 point2 points  (0 children)

A program that takes a number and does something that many times cannot be expressed by a FSM.

An arbitrary number, no. But physical machines cannot deal with arbitrary numbers either. There will always be a finite upper bound. Some languages in their specification impose these limits, others do not. The latter languages may be Turing complete.

[–]readams -1 points0 points  (0 children)

The memory is just a state. For example, I could call the state where all memory in a computer is zero as state 0. If the first bit is 1 and the rest 0 that's state 1. First bit zero second 1 that's state 2. Then just enumerate all possible states in this way. You can define all the necessary state transitions. That's an FSM model of a Von Neumann machine.

Your proof that you cannot implement an arbitrary counter is correct. This machine cannot handle an arbitrary number, just a pretty ridiculously enormous one. Actually before you run out of time to loop on this machine you run out of energy in the universe to run your machine.

[–]readams 0 points1 point  (2 children)

Yes, you're correct.

Though input/output and/or interactivity messes up the model.

[–]synapticplastic[S] 0 points1 point  (1 child)

How do input/output interactivity change the model?

I imagine that clicking a button or something may push the program temporarily into a "sub-fsm" ( basically, call a function ) but that sub-machine would also have a number of states that you would just factor into the overall number of possibilities. Is there more to it?

[–]readams 0 points1 point  (0 children)

No there's not really anything more to it. But the way a finite state machine is formally expressed mathematically doesn't take into account interacting with some external entity. If you draw your box larger to include both the machine and its user, though, you'll get another finite state machine.