Ok. Here's the definition from the page you quoted:
No, that's the formal definition of the mathematical model that can represent any finite-state machine. Here's the actual definition, shortened a bit:
Finite-state machine is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition. An FSM is defined by a list of its states, its initial state, and the conditions for each transition.
Doesn't look much different from the Mealy page
Well of course the mathematical definition is the same, for chrissakes! What part of
all Mealy machines are finite-state machines did you miss?
The flowchart describes an implementation of a finite-state machine. I chose a flowchart, rather than a table, because I thought that at StackOverflow new programmers would find it much easier to convert a flowchart to code. (Do note that I forgot to add an edge from "Output D O G" to the top node.)
To convert it to a flowchart where each state is clearly delineated, I would have to duplicate the diamond corresponding to the
char = C test twice (to the two states below it). In an implementation, the single test suffices,
as the transition caused by that test is always the same, and it nicely simplifies the code as well. Nevertheless, repeating that test twice more, the three non-final states would be vertically stacked, with the fourth final Done state on the right side.
If that is your objection, I'd be inclined to agree, and be more than happy to fix the flowchart, and add the states as say shaded background areas.
Mathematically, the input alphabet set
Σ is the set of values C
fgetc() function may return. Of this set, values
EOF,
'c',
'a', and
't' are used in determining the appropriate action and state transition, and all other values use a common action and state transition.
The set of states
S has three states:
Initial state,
C state, and
C A state. The initial state
S0 should be obvious. There is one final state in
F ,
Done . The transition function
δ(state, input) can be described thus:
δ(Initial, EOF) = Doneδ(Initial, 'c') = Cδ(Initial, other) = Initialδ(C, EOF) = Doneδ(C, 'a') = C Aδ(C, 'c') = Cδ(C, other) = Initialδ(C A, EOF) = Doneδ(C A, 't') = Initialδ(C A, 'c') = Cδ(C A, other) = CIn Mealy machine terms, the output alphabet
Λ is the input set
Σ except for EOF. The output function
G: S×Σ can be defined as
G(Initial, EOF) = NothingG(Initial, 'c') = NothingG(Initial, other) = otherG(C, EOF) = 'c'G(C, 'a') = NothingG(C, 'c') = 'c'G(C, other) = 'c'G(C A, EOF) = 'c' 'a'G(C A, 't') = 'd' 'o' 'g'G(C A, 'c') = 'c'G(C A, other) = 'c' 'a'I was not trying to be snide, when I said that if you have difficulty reading the flow chart into a finite-state machine, I could show the state table also. Like tggzzz wrote, it is not obvious.
Looking at the code you wrote for your cat->dog machine, can you point out where is the "set of states" and where is the "state-transition function"?
The model the code implements is a finite state machine. It does not mean that the code must contain identifiable elements that correspond to the mathematical description.
This is exactly what I mean by there being a gap between "coding" and "computer science".
The model the code implements is
a finite-state machine. The design pattern it uses to do so is a simple loop; not something often used for finite-state machines. Yet, that does not mean the code does not implement a finite-state machine.
Is your cat->dog machine Mealy?
So funny, ha-ha. Only if your definition of a Mealy machine allows the output function
G to output more than one symbol at a time.