All Topics  
Finite state machine

 
Finite State Machine

   Email Print
   Bookmark   Link






 

Finite state machine



 
 
A finite state machine (FSM) or finite state automaton (plural: automata) or simply a state machine, is a model of behavior composed of a finite number of state
State (computer science)

In computer science and automata theory, a state is a unique configuration of information in a program or machine. It is a concept that occasionally extends into some forms of systems programming such as Lexical analysiss and parsers....
s, transitions between those states, and actions. A finite state machine is an abstract model of a machine with a primitive internal memory.

rrent state is determined by past states of the system.






Discussion
Ask a question about 'Finite state machine'
Start a new discussion about 'Finite state machine'
Answer questions from other users
Full Discussion Forum



Encyclopedia


A finite state machine (FSM) or finite state automaton (plural: automata) or simply a state machine, is a model of behavior composed of a finite number of state
State (computer science)

In computer science and automata theory, a state is a unique configuration of information in a program or machine. It is a concept that occasionally extends into some forms of systems programming such as Lexical analysiss and parsers....
s, transitions between those states, and actions. A finite state machine is an abstract model of a machine with a primitive internal memory.

Concepts and vocabulary

A current state is determined by past states of the system. As such, it can be said to record information about the past, i.e. it reflects the input changes from the system start to the present moment. A transition indicates a state change and is described by a condition that would need to be fulfilled to enable the transition. An action is a description of an activity that is to be performed at a given moment. There are several action types: Entry action: which is performed when entering the state Exit action: which is performed when exiting the state Input action: which is performed depending on present state and input conditions Transition action: which is performed when performing a certain transition

A FSM can be represented using a state diagram
State diagram

A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of state s; sometimes, this is indeed the case, while at other times this is a reasonable abstraction....
 (or state transition diagram) as in figure 1 above. Besides this, several state transition table
State transition table

In automata theory and sequential logic, a state transition table is a table showing what state a finite semiautomaton or finite state machine will move to, based on the current state and other inputs....
 types are used. The most common representation is shown below: the combination of current state (B) and condition (Y) shows the next state (C). The complete actions information can be added only using footnotes. An FSM definition including the full actions information is possible using state tables
Virtual finite state machine

The "virtual finite state machine" is a concept promoted by and implemented in their StateWORKS product. A VFSM is a finite state machine defined in a virtual environment....
 (see also VFSM).

In addition to their use in modeling reactive systems presented here, finite state automata are significant in many different areas, including electrical engineering
Electrical engineering

Electrical engineering, sometimes referred to as electrical and electronic engineering, is a field of engineering that deals with the study and application of electricity, electronics and electromagnetism....
, linguistics
Linguistics

Linguistics is the science study of natural language. Linguistics encompasses a number of sub-fields. An important topical division is between the study of language structure and the study of Meaning ....
, computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, philosophy
Philosophy

Philosophy is the study of general problems concerning matters such as existence, knowledge, truth, beauty, justice, validity, mind, and language....
, biology
Biology

Biology is a branch of the natural sciences concerned with the study of living organisms and their interaction with each other and their environment ....
, mathematics, and logic
Logic

Logic is the study of the principles of valid demonstration and inference. Logic is a branch of philosophy, a part of the classical Trivium . The word derives from Greek language ?????? , fem....
. A complete survey of their applications is outside the scope of this article. Finite state machines are a class of automata studied in automata theory
Automata theory

In theoretical computer science, automata theory is the study of abstract machines and problems which they are able to solve. Automata theory is closely related to formal language theory as the automata are often classified by the class of formal languages they are able to recognize....
 and the theory of computation
Theory of computation

The theory of computation is the branch of computer science that deals with whether and how efficiently problems can be solved on a model of computation, using an algorithm....
. In computer science, finite state machines are widely used in modeling of application behavior, design of hardware digital systems, software engineering, compilers, network protocols, and the study of computation and languages.

Classification

There are two different groups: Acceptors/Recognizers and Transducers.

Acceptors and recognizers


Acceptors and recognizers (also sequence detectors) produce a binary output, saying either yes or no to answer whether the input is accepted by the machine or not. All states of the FSM are said to be either accepting or not accepting. At the time when all input is processed, if the current state is an accepting state, the input is accepted; otherwise it is rejected. As a rule the input are symbols (characters); actions are not used. The example in figure 2 shows a finite state machine which accepts the word "nice". In this FSM the only accepting state is number 7.

The machine can also be described as defining a language, which would contain every word accepted by the machine but none of the rejected ones; we say then that the language is accepted by the machine. By definition, the languages accepted by FSMs are the regular language
Regular language

In theoretical computer science, a regular language is a formal language that satisfies the following equivalent properties:* it can be accepted by a deterministic finite state machine...
s - that is, a language is regular if there is some FSM that accepts it.

Start state
The start state is usually shown drawn with an arrow "pointing at it from nowhere" (Sipser (2006) p.34).

Accept state
Dfaexample
An accept state (sometimes referred to as an accepting state) is a state at which the machine has successfully performed its procedure. It is usually represented by a double circle.

An example of an accepting state appears on the right in this diagram of a deterministic finite automaton (DFA) which determines if the binary
Binary numeral system

The binary numeral system, or notation with a radix of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers....
 input contains an even number of 0s.

S1 (which is also the start state) indicates the state at which an even number of 0s has been input and is therefore defined as an accepting state. This machine will give a correct end state if the binary number contains an even number of zeros including a string with no zeros. Examples of strings accepted by this DFA are epsilon (the empty string), 1, 11, 11..., 00, 010, 1010, 10110 and so on.

Transducers

Transducers
Finite state transducer

A finite-state transducer is a finite state machine with two tapes: an input tape and an output tape. This contrasts with an ordinary finite state automaton , which has a single tape....
 generate output based on a given input and/or a state using actions. They are used for control applications and in the field of computational linguistics
Computational linguistics

Computational linguistics is an interdisciplinary field dealing with the Statistics and/or rule-based modeling of natural language from a computational perspective....
. Here two types are distinguished:

Moore machine
Moore machine

In the theory of computation, a Moore machine is a finite state transducer where the outputs are determined by the current state alone . The state diagram for a Moore machine will include an output signal for each state....
: The FSM uses only entry actions, i.e. output depends only on the state. The advantage of the Moore model is a simplification of the behaviour. Consider an elevator door. The state machine recognizes two commands: "command_open" and "command_close" which trigger state changes. The entry action (E:) in state "Opening" starts a motor opening the door, the entry action in state "Closing" starts a motor in the other direction closing the door. States "Opened" and "Closed" don't perform any actions. They signal to the outside world (e.g. to other state machines) the situation: "door is open" or "door is closed".

Fsm Mealy Model Door Control
Mealy machine
Mealy machine

In the theory of computation, a Mealy machine is a finite state transducer that generates an output based on its current state and an input....
: The FSM uses only input actions, i.e. output depends on input and state. The use of a Mealy FSM leads often to a reduction of the number of states. The example in figure 4 shows a Mealy FSM implementing the same behaviour as in the Moore example (the behaviour depends on the implemented FSM execution model and will work e.g. for virtual FSM
Virtual finite state machine

The "virtual finite state machine" is a concept promoted by and implemented in their StateWORKS product. A VFSM is a finite state machine defined in a virtual environment....
 but not for event driven FSM). There are two input actions (I:): "start motor to close the door if command_close arrives" and "start motor in the other direction to open the door if command_open arrives". The "opening" and "closing" intermediate states are not shown.

In practice mixed models are often used.

More details about the differences and usage of Moore and Mealy models, including an executable example, can be found in the external technical note

A further distinction is between deterministic (DFA
Deterministic finite state machine

In the theory of computation, a deterministic automaton finite state machine is a finite state machine where for each pair of state and input symbol there is one and only one transition to a next state....
) and non-deterministic (NDFA
Nondeterministic finite state machine

In the theory of computation, a nondeterministic finite state machine or nondeterministic finite automaton is a finite state machine where for each pair of state and input symbol there may be several possible next states....
, GNFA) automata. In deterministic automata, for each state there is exactly one transition for each possible input. In non-deterministic automata, there can be none, one, or more than one transition from a given state for a given possible input. This distinction is relevant in practice, but not in theory, as there exists an algorithm which can transform any NDFA into an equivalent DFA, although this transformation typically significantly increases the complexity of the automaton.

The FSM with only one state is called a combinatorial FSM and uses only input actions. This concept is useful in cases where a number of FSM are required to work together, and where it is convenient to consider a purely combinatorial part as a form of FSM to suit the design tools.edited by eng.mahmoud

FSM logic


The next state and output of an FSM is a function of the input and of the current state. The FSM logic is shown in Figure 5.

Mathematical model

Depending on the type, there are several definitions:
  • A deterministic finite state machine is a quintuple
    Tuple

    In mathematics, a tuple is a sequence of a specific number of values, called the components of the tuple. These components can be any kind of mathematical objects, where each component of a tuple is a value of a specified type....
     , where:
    • is the input alphabet
      Alphabet (computer science)

      In computer science, an alphabet is a, usually finite, set of characters or digits. The most common alphabet is , the binary alphabet. A finite String is a finite sequence of characters from an alphabet; for instance a binary string is a string drawn from the alphabet ....
       (a finite, non-empty set of symbols).
    • is a finite, non-empty set of states.
    • is an initial state, an element of .
    • is the state-transition function: . In a Nondeterministic finite state machine
      Nondeterministic finite state machine

      In the theory of computation, a nondeterministic finite state machine or nondeterministic finite automaton is a finite state machine where for each pair of state and input symbol there may be several possible next states....
      , , returns a set of states.
    • is the set of final states, a (possibly empty) subset of .


  • An acceptor finite-state machine is a quintuple
    Tuple

    In mathematics, a tuple is a sequence of a specific number of values, called the components of the tuple. These components can be any kind of mathematical objects, where each component of a tuple is a value of a specified type....
     , where:
    • is the input alphabet
      Alphabet (computer science)

      In computer science, an alphabet is a, usually finite, set of characters or digits. The most common alphabet is , the binary alphabet. A finite String is a finite sequence of characters from an alphabet; for instance a binary string is a string drawn from the alphabet ....
       (a finite, non-empty set of symbols).
    • is a finite, non-empty set of states.
    • is an initial state, an element of .
    • is the state-transition function: .
    • is the set of final states, a (possibly empty) subset of .


  • A finite state transducer
    Finite state transducer

    A finite-state transducer is a finite state machine with two tapes: an input tape and an output tape. This contrasts with an ordinary finite state automaton , which has a single tape....
     is a sextuple , where:
    • is the input alphabet
      Alphabet (computer science)

      In computer science, an alphabet is a, usually finite, set of characters or digits. The most common alphabet is , the binary alphabet. A finite String is a finite sequence of characters from an alphabet; for instance a binary string is a string drawn from the alphabet ....
       (a finite non empty set of symbols).
    • is the output alphabet (a finite, non-empty set of symbols).
    • is a finite, non-empty set of states.
    • is the initial state, an element of . In a Nondeterministic finite state machine
      Nondeterministic finite state machine

      In the theory of computation, a nondeterministic finite state machine or nondeterministic finite automaton is a finite state machine where for each pair of state and input symbol there may be several possible next states....
      , is a set of initial states.
    • is the state-transition function: .
    • is the output function.


If the output function is a function of a state and input alphabet that definition corresponds to the Mealy model, and can be modelled as a Mealy machine
Mealy machine

In the theory of computation, a Mealy machine is a finite state transducer that generates an output based on its current state and an input....
. If the output function depends only on a state that definition corresponds to the Moore model, and can be modelled as a Moore machine
Moore machine

In the theory of computation, a Moore machine is a finite state transducer where the outputs are determined by the current state alone . The state diagram for a Moore machine will include an output signal for each state....
. A finite-state machine with no output function at all is known as a semiautomaton
Semiautomaton

In theoretical computer science, a semiautomaton is an deterministic finite state machine having only an input, and no output. It consists of a Set Q of state , a set S called the input alphabet, and a function T: Q ? S ? Q called the transition function....
 or transition system.

Optimization

Optimizing an FSM means finding the machine with the minimum number of states that performs the same function. The fastest known algorithm doing this is the Hopcroft minimization algorithm. Other techniques include using an Implication table
Implication table

An implication table is a tool used to facilitate the minimization of state in a state machine. The concept is to start assuming that every state may be able to combine with every other state, then eliminate combinations that are not possible....
, or the Moore reduction procedure
Moore reduction procedure

The Moore reduction procedure is a method used for minimizing state in a state machine. The concept is to start assuming that every state may be able to combine with every other state, then separate distinguishable states into separate groups called equivalence partitions....
. Additionally, acyclic FSAs can be optimized using a simple bottom up algorithm.

Implementation


Hardware applications

4 Bit Counter
In a digital circuit
Digital circuit

Digital electronics are electronics systems that use digital signals. Digital electronics are representations of Boolean algebra and are used in computers, mobile phones, and other consumer products....
, an FSM may be built using a programmable logic device
Programmable logic device

A programmable logic device or PLD is an electronics component used to build Reconfigurable Computing digital circuits. Unlike a logic gate, which has a fixed function, a PLD has an undefined function at the time of manufacture....
, a programmable logic controller
Programmable logic controller

A programmable logic controller or programmable controller is a digital computer used for automation of electromechanical processes, such as control of machinery on factory assembly lines, control of amusement rides, or control of lighting fixtures....
, logic gate
Logic gate

A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits....
s and flip flop
Flip-flop (electronics)

In digital circuits, a flip-flop is a term referring to an electronic circuit that has two stable states and thereby is capable of serving as one bit of computer storage....
s or relay
Relay

A relay is an electrical switch that opens and closes under the control of another electrical circuit. In the original form, the switch is operated by an magnet to open or close one or many sets of contacts....
s. More specifically, a hardware implementation requires a register
Processor register

In computer architecture, a processor register is a small amount of Computer storage available on the CPU whose contents can be accessed more quickly than storage available elsewhere....
 to store state variables, a block of combinational logic which determines the state transition, and a second block of combinational logic that determines the output of an FSM. One of the classic hardware implementations is the Richards controller.

Software applications

The following concepts are commonly used to build software applications with finite state machines:
  • Event driven FSM
  • Virtual FSM (VFSM)
    Virtual finite state machine

    The "virtual finite state machine" is a concept promoted by and implemented in their StateWORKS product. A VFSM is a finite state machine defined in a virtual environment....
  • Automata-based programming
    Automata-Based Programming

    Automata-based programming is a programming paradigm in which the program or its part is thought of as a model of a finite state machine or any other formal automata ....


See also

  • Abstract state machine
  • Decision tables
  • Extended finite state machine
    EFSM

    In a conventional finite state machine, the transition is associated with a set of input Boolean conditions and a set of output Boolean functions. In an extended finite state machine model, the transition can be expressed by an ?if statement? consisting of a set of trigger conditions....
  • Finite state machine with datapath
    FSMD

    An FSMD is a digital system composed of a finite state machine, which controls the program flow, and a datapath, which performs operations....
  • Petri net
    Petri net

    A Petri net is one of several mathematical modeling languages for the description of discrete distributed systems. A Petri net is a directed bipartite graph, in which the nodes represent transitions , places , and directed arcs ....
  • Pushdown automaton
    Pushdown automaton

    In automata theory, a pushdown automaton is a finite state machine that can make use of a Stack containing data....
  • Quantum finite automata
    Quantum finite automata

    In quantum computing, quantum finite automata or QFA are a quantum analog of probabilistic automata. They are related to quantum computers in a similar fashion as finite automata are related to Turing machines....
  • Sequential logic
    Sequential logic

    In digital circuit theory, sequential logic is a type of logic circuit whose output depends not only on the present input but also on the history of the input....
  • Statechart
  • Transition system
  • Turing machine
    Turing machine

    Turing machines are basic abstract symbol-manipulating devices which, despite their simplicity, can be adapted to simulate the logic of any computer algorithm....
  • Hidden Markov model
    Hidden Markov model

    A hidden Markov model is a statistical model in which the system being modeled is assumed to be a Markov process with unknown parameters; the challenge is to determine the hidden parameters from the observable data....
  • Artificial Intelligence
    Artificial intelligence

    Artificial intelligence is the intelligence of machines and the branch of computer science which aims to create it. Major AI textbooks define the field as "the study and design of intelligent agents,"...
  • Control System
    Control system

    A control system is a device or set of devices to manage, command, direct or regulate the behavior of other devices or systems.There are two common classes of control systems, with many variations and combinations: logic gate, and feedback or linear controls....
  • SCXML
    SCXML

    SCXML stands for State Chart XML: State Machine Notation for Control Abstraction. It is an XML-based markup language which provides a generic state-machine based execution environment based on Statechart#Harel statechart....


Further reading


General

  • Wagner, F., "Modeling Software with Finite State Machines: A Practical Approach", Auerbach Publications, 2006, ISBN 0-8493-8086-3.
  • Samek, M., , CMP Books, 2002, ISBN 1-57820-110-1.
  • Samek, M., , Newnes, 2008, ISBN 0-75068-706-1.
  • Gardner, T., , 2007
  • Cassandras, C., Lafortune, S., "Introduction to Discrete Event Systems". Kluwer, 1999, ISBN 0-7923-8609-4.
  • Timothy Kam, Synthesis of Finite State Machines: Functional Optimization. Kluwer Academic Publishers, Boston 1997, ISBN 0-7923-9842-4
  • Tiziano Villa, Synthesis of Finite State Machines: Logic Optimization. Kluwer Academic Publishers, Boston 1997, ISBN 0-7923-9892-0
  • Carroll, J., Long, D. , Theory of Finite Automata with an Introduction to Formal Languages. Prentice Hall, Englewood Cliffs, 1989.
  • Kohavi, Z., Switching and Finite Automata Theory. McGraw-Hill, 1978.
  • Gill, A., Introduction to the Theory of Finite-state Machines. McGraw-Hill, 1962.
  • Ginsburg, S., An Introduction to Mathematical Machine Theory. Addison-Wesley, 1962.


Finite state machines (automata theory) in theoretical computer science


  • Extensive, wide-ranging book meant for specialists, written for both theoretical computer scientists as well as electrical engineers. With detailed explanations of state minimization techniques, FSMs, Turing machines, Markov processes, and undecidability. Excellent treatment of Markov processes.


  • Excellent. Has been in print in various editions and reprints since 1974 (1974, 1980, 1989, 1999).


  • Approaches Church-Turing thesis from three angles: levels of finite automata as acceptors of formal languages, primitive and partial recursive theory, and power of bare-bones programming languages to implement algorithms, all in one slim volume.




  • A difficult book centered around the issues of machine-interpretation of "languages", NP-Completeness, etc.


  • Distinctly different and less intimidating than the first edition.


  • Minsky spends pages 11-20 defining what a “state” is in context of FSMs. His state diagram convention is unconventional. Excellent, i.e. relatively readable, sometimes funny.


  • Abstract algebra is at the core of the book, rendering it advanced and less accessible than other texts.


  • cf Finite state machines (finite automata) in chapter 29.


Abstract state machines in theoretical computer science


  • Yuri Gurevich (2000), Sequential Abstract State Machines Capture Sequential Algorithms, ACM Transactions on Computational Logic, vl. 1, no. 1 (July 2000), pages 77-111. http://research.microsoft.com/~gurevich/Opera/141.pdf


Machine learning using finite-state algorithms


  • A broad brush but quite thorough and sometimes difficult, meant for computer scientists and engineers. Chapter 13 Reinforcement Learning deals with robot-learning involving state-machine-like algorithms.


Hardware engineering: state minimization and synthesis of sequential circuits


  • Extensive, wide-ranging book meant for specialists, written for both theoretical computer scientists as well as electrical engineers. With detailed explanations of state minimization techniques, FSMs, Turing machines, Markov processes, and undecidability. Excellent treatment of Markov processes.
  • Meant for electrical engineers. More focused, less demanding than his earlier book. His treatment of computers is out-dated. Interesting take on definition of ‘algorithm’.
  • Meant for hardware electrical engineers. With detailed explanations of state minimization techniques and synthesis techniques for design of combinatory logic circuits.
  • Meant for hardware electrical engineers. Excellent explanations of state minimization techniques and synthesis techniques for design of combinatory and sequential logic circuits.


Finite Markov chain processes

"We may think of a Markov chain
Markov chain

In mathematics, a Markov chain, named after Andrey Markov, is a stochastic process with the Markov property. Having the Markov property means that, given the present state, future states are independent of the past states. In other words, the description of the present state fully captures all the information that could influence th...
 as a process that moves successively through a set of states s1, s2, ..., sr. ... if it is in state si it moves on to the next stop to state sj with probability pij. These probabilities can be exhibited in the form of a transition matrix" (Kemeny (1959), p. 384) Finite Markov-chain processes are also known as subshifts of finite type.

  • Extensive, wide-ranging book meant for specialists, written for both theoretical computer scientists as well as electrical engineers. With detailed explanations of state minimization techniques, FSMs, Turing machines, Markov processes, and undecidability. Excellent treatment of Markov processes.
  • Classical text . cf Chapter 6 ‘’Finite Markov Chains”.


External links

  • NIST Dictionary of Algorithms and Data Structures
  • - Cogs is a open source, small FSM and HSM ( hierarchical state machine) library for use with Flash / Flex Actionscript 3.0 projects. An introductory talk
  • - FSMGenerator is a turn-key solution for FSM (Finite State Machine) automatic generation and integration within user's software
  • - An open-source tool for the graphical development of FSMs and automatic Verilog code generation
  • - StateWizard: a ClassWizard-like round-trip UML dynamic modeling/development framework and tool running in popular IDEs.
  • - generates human readable c-code from state-charts especially targeting embedded real-time systems
  • - An open-source C library for automata computations
  • - A tool to model and compile statemachines for a number of languages; java, C# etc. As well as display them as graphically.
  • - Provider of open source, state machine-based frameworks. Includes several examples and C/C++ code.
  • - An open source implementation of FSM (Finite State Machine) programming framework in C.
  • - An open source C++ finite state machine manipulation platform, consisting of a library and tools implemented on top of it.
  • - An open source plugin for Eclipse for automata-based programming.
  • - A simple but effective FSM implementation integrated seamlessly into the PureMVC Framework.