We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24
Formal Methods
Finite State Machines
Dr. Nargis Fatima
Assistant Professor
Department of Software Engineering
National University of Modern Languages, Islamabad Finite State Machine • Finite state machine (FSM) is a term used by programmers, mathematicians, engineers and other professionals to describe a mathematical model for any system that has a limited number of conditional states of being. Finite State Machine • A practical example of a finite state machine is a set of buttons on a video game controller that are connected to a specific set of actions within the game. When a user inputs hitting certain buttons, the system knows to implement the actions that correspond. Finite State Machine • The makeup of a finite state machine consists of the following • A set of potential input events. • A set of probable output events that correspond to the potential input events. • A set of expected states the system can exhibit. Finite State Machine • State transition • When a finite state machine switches between states, it is called a state transition. • Testing the quality of a system includes checking each state and state transition by considering all of the potential inputs that might be entered. Finite State Machine For simpler problems, the same information can be displayed in tables, matrices, illustrations and flow charts, but finite state machines allow researchers to model larger and more complicated scenarios. Finite state machine diagrams show the flow of logic between input and output combinations that may appear within a specific machine. Finite State Machine A finite state machine (FSM) is an abstract model of computation that is used to model logic. A language is considered regular if — and only if — it can be recognized by a FSM. Finite State Machine Conceptual machine with finite number of states ◦ – a.k.a. finite state machine Graphical representation of State Machine ◦ – States are rounded boxes ◦ – Transitions are arcs Finite State Machine • State Machine ◦ – Relates events and states • Event ◦ – Causes change of state • Referred to as state transition • State ◦ – A recognizable situation ◦ – Exists over an interval of time ◦ – Represents an interval between successive events Finite State Machine Finite State Machine State transition label – Event [condition] / action(s) • Event – When event occurs, condition must be true for state transition to occur. – If condition is false, state transition does not occur Finite State Machine • Action ◦ – Executed as a result of state transition ◦ – Executes instantaneously at state transition ◦ – Terminates itself Finite State Machine Finite state machines are usually drawn as state transition diagrams, which is a useful way to visualize the FSM. Finite State Machine- Example Consider a simple robot. Think about the robot existing within a finite number of states. These need to be discrete (i.e. states cannot be concurrent or overlap). The robot can be turned on (in the on state) or turned off (in the off state) — it cannot be both on and off at the same time. It is conventional to give each state a number: S0, S1, etc. Finite State Machine- Example These numbers make supporting diagrams less cluttered and easier to interpret. For the robot to be able to change states, an input is needed. This causes a transition: a movement between the states. The same input may have a different effect depending on the machine's state when the input is detected. Finite State Machine- Example For example, the robot may have a single on/off push button. If you push the button when the robot is in its off state, it will turn on (or we could say 'transition to its on state'). If you push the button when the robot is in its on state, it will transition to its off state. Even the simplest of robots is likely to have many states. For now, consider the three states which are numbered and described as follows: Finite State Machine- Example Itis now possible to draw a state transition diagram to model the robot as a finite state machine. Observe that each transition is labelled with the input that triggers the movement between states: Example II A Safe • States: Multiple “locked” states, one “unlocked” state • Transitions: Correct combinations move us from initial locked states to locked states closer to the unlocked state, until we finally get to the unlocked state. Incorrect combinations land us back in the initial locked Example 1 Traffic Light • States: Red, Yellow, Green • Transitions: After a given time, Red will change to Green, Green to Yellow, and Yellow to Red THANK YOU