In Depth
See Also

Finite state machine

A finite state machine or finite automaton is a model of behavior composed of states, transitions and actions. A state stores 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: execute the action when entering the state ;Exit action: execute the action when exiting the state

Discussions

  Discussion Features

   Ask a question about 'Finite state machine'

   Start a new discussion about 'Finite state machine'

   Answer questions about 'Finite state machine'

   'Finite state machine' discussion forum


Encyclopedia



A finite state machine or finite automaton is a model of behavior composed of states, transitions and actions. A state stores 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: execute the action when entering the state
;Exit action: execute the action when exiting the state
;Input action: execute the action dependent on present state and input conditions
;Transition action: execute the action when performing a certain transition

FSM can be represented using a state diagram State diagram

State diagrams are used to graphically represent finite state machine [i]s. ... 

  as in figure 1. Besides this, several state transition table State transition table

In Automata Theory [i], a state transition table is a table describing the transiti ... 

 types are used. The most common representation is shown below: the combination of current state and condition shows the next state . 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

A finite state machine [i] defined in a virtual environment is called virtual finite state machine.... 

 .

   Current State/
Condition
State A State B State C
Condition X ... ... ...
Condition Y ... State C ...
Condition Z ... ... ...
Caption | State transition table


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 is a professional engineering [i] discipline that deals with the study and appli ... 

, linguistics, computer science, philosophy Philosophy

[i]
... 

, biology Biology

Biology is the branch of science [i] dealing with the study of life [i]. ... 

, mathematic Mathematics

Mathematics is the discipline that deals with concepts such as quantity [i], structure [i], space [i] a ... 

s, and logic. A complete survey of their applications is outside the scope of this article. Finite state machines are one type of the automata studied in automata theory and the theory of computation.
In computer science, finite state machines are widely used in modelling of application behaviour, design of hardware digital systems, software engineering, compilers, and the study of computation and languages.

Classification

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

Acceptors and recognizers



This kind of machine gives 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. If when all input is processed the current state is an accepting state, the input is accepted; otherwise it is rejected. As a rule the input are symbols ; 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 languages - 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"
Accept State
An accept 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 left in this diagram of a deterministic finite automaton Deterministic finite state machine

In the theory of computation [i], a deterministic finite state machine or deterministic finite automa ... 

 which determines if the binary Binary numeral system

The binary numeral system [i] represents numeric values using two symbols, typically 0 [i] and 1 [i] ... 

 input contains an even number of 0s:



S1 indicates the state at which an even number of 0s has been inputted and is therefore defined as an accepting state.

Transducers

Transducers generate output based on a given input and/or a state using actions. They are used for control applications. Here two types are distinguished:

;Moore machine Moore machine

In the theory of computation [i], a Moore machine is a finite state automaton [i] where the outputs are ... 

: 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. The example in figure 3 shows a Moore FSM of an elevator door. The state machine recognizes two commands: "command_open" and "command_close" which trigger state changes. The entry action 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 the situation: "door is open" or "door is closed".


;Mealy machine Mealy machine

[i], a [[finite state machine]... 

: 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 . There are two input actions : "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".

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 and non-deterministic automata. In deterministic automata, for each state there is exactly one transition for each possible input. In non-deterministic automata, there can be none 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.

FSM logic



The next state and output of a 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. An acceptor finite state machine is a quintuple , where:
  • is the input alphabet Alphabet

    An alphabet is a complete standardized set of letters [i] — basic written symbols &mda ... 

     .
  • is a finite non empty set of states.
  • is an initial state, an element of . In a Nondeterministic finite state machine Nondeterministic finite state machine

    In the theory of computation [i], a nondeterministic finite state machine or nondeterministic finite ... 

    , is a set of initial states.
  • is the state transition function: .
  • is the set of final states, a subset of .


A transducer finite state machine is a six tuple , where:
  • is the input alphabet Alphabet

    An alphabet is a complete standardized set of letters [i] — basic written symbols &mda ... 

     .
  • is the output alphabet .
  • 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 [i], a nondeterministic finite state machine or nondeterministic finite ... 

    , 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. If the output function depends only on a state that definition corresponds to the Moore model.

Optimization

Optimizing an FSM means finding the machine with the minimum number of states that performs the same function. This problem can be solved using a coloring algorithm Graph coloring

In graph theory [i], graph coloring is an assignment of "colors",, to certain objects in a graph [i] ... 

.

Implementation


Hardware applications

In a digital circuit Digital circuit

A digital circuit is based on a number of discrete voltage [i] levels, as distinct from an analog circuit [i] ... 

, a FSM may be built using a programmable logic device Programmable logic device

A programmable logic device or PLD is an electronic [i] component used to build digital circuit [i]... 

, a programmable logic controller Programmable logic controller

A Programmable Logic Controller, PLC, or Programmable Controller is a small computer [i] us... 

, logic gate Logic gate

A logic gate performs a logical operation on one or more logic inputs and produces a single logic output... 

s and flip flop Flip-flop

In footwear [i] and fashion [i], flip-flops are a kind of flat, backless sandal [i] that consist ... 

s or relay Relay

A relay is an electrical switch [i] that opens and closes under control of another electrical circuit. ... 

s. More specifically, a hardware implementation requires a register 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 a FSM.

Software applications

Following concepts are commonly used to build software applications with finite state machines:
  • event driven FSM
  • virtual FSM Virtual finite state machine

    A finite state machine [i] defined in a virtual environment is called virtual finite state machine.... 

  • Automata-Based Programming

Tools


  • [state] method
  • AT&T FSM Library™
  • AutoFSM
  • Automata
  • AsmL
  • Bandera
  • Boost Statechart Library
  • CAZE - FSM-based .NET authorization library
  • Cellogica - State machine for gene expression
  • Covered
  • Concurrent Hierarchical State Machine
  • DescoGUI 
  • Dynamic Attachment Finite State Machine
  • Exorciser
  • Finite State Kernel Creator
  • Finite State Machine Editor
  • Finite State Machine Explorer
  • FIRE Engine, Station and Works
  • FSMGenerator 
  • Grail+
  • FSA Utilities 
  • Libero
  • Java Finite Automata
  • JFLAP
  • jFAST
  • jrexx-Lab
  • JSpasm
  • Kara
  • MetaAuto
  • MIT Finite-State Transducer Toolkit
  • Nunni FSM Generator
  • Petrify
  • PyFSA
  • Qfsm
  • Quantum-Leaps
  • Ragel
  • RWTH FSA Toolkit 
  • SCXML SCXML

    SCXML stands for State Chart XML : State Machine Notation for Control Abstraction.... 

     
  • SFST, the Stuttgart Finite State Transducer Tools
  • Stateflow 
  • Statestep
  • StateWORKS
  • SMC - Finite State Machine Compiler
  • Supremica
  • UniMod 
  • Vaucanson
  • Visio2Switch
  • visualSTATE
  • WhatOS
  • Xerox Finite-State Software Tools
  • XTND 


  • References

    • Wagner, F., "Modeling Software with Finite State Machines: A Practical Approach", Auerbach Publications, 2006, ISBN 0-8493-8086-3.
    • 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.

    References: Finite State Machines 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 .


    • 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 in chapter 29.

    References: Abstract State Machines in Theoretical Computer Science


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

    References: 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.

    References: 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.

    References: Finite Markov chain processes

    "We may think of a Markov chain as a process that moves successively through a set of states s1, s2, ..., sr. ... if it is in state sj 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"
    • 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”.

    See also

    • Abstract state machine
    • Automata analyzer
    • Coverage analysis
    • Markov process
    • Marvin Minsky Marvin Minsky

      Marvin Lee Minsky , sometimes affectionately known as "Old Man Minsky", is an American [i]... 

    • Microcode
    • Petri net Petri net

      A Petri net is one of several mathematical [i] representation [i]s of discrete ... 

    • Protocol development
    • Pushdown automaton
    • Regular expression
    • Regular grammar
    • Simulation Simulation

      A simulation is an imitation of some real thing, state of affairs, or process.... 

    • Sequential logic
    • Sparse matrix
    • Supervisory control theory
    • Transition system

    External links

    • NIST Dictionary of Algorithms and Data Structures