You are on page 1of 5

11/8/2016

StatediagramWikipedia

Statediagram
FromWikipedia,thefreeencyclopedia

Astatediagramisatypeofdiagramusedincomputerscienceandrelated
fieldstodescribethebehaviorofsystems.Statediagramsrequirethatthe
systemdescribediscomposedofafinitenumberofstatessometimes,thisis
indeedthecase,whileatothertimesthisisareasonableabstraction.Many
formsofstatediagramsexist,whichdifferslightlyandhavedifferent
semantics.

Contents
1 Overview
2 Directedgraph
2.1 Example:DFA,NFA,GNFA,orMooremachine
2.2 Example:Mealymachine
3 Harelstatechart
4 Alternativesemantics
5 Statediagramsversusflowcharts
6 Otherextensions
7 Seealso
8 References
9 Externallinks

Astatediagramforadoorthatcan
onlybeopenedandclosed

Overview
Statediagramsareusedtogiveanabstractdescriptionofthebehaviorofasystem.Thisbehaviorisanalyzedand
representedasaseriesofeventsthatcanoccurinoneormorepossiblestates.Hereby"eachdiagramusuallyrepresents
objectsofasingleclassandtrackthedifferentstatesofitsobjectsthroughthesystem".[1]
Statediagramscanbeusedtographicallyrepresentfinitestatemachines.ThiswasintroducedbyC.E.ShannonandW.
Weaverintheir1949book"TheMathematicalTheoryofCommunication".AnothersourceisTaylorBoothinhis1967
book"SequentialMachinesandAutomataTheory".AnotherpossiblerepresentationistheStatetransitiontable.

Directedgraph
Aclassicformofstatediagramforafinitestatemachineorfiniteautomaton(FA)isadirected
graphwiththefollowingelements(Q,,Z,,q0,F):[2][3]
VerticesQ:afinitesetofstates,normallyrepresentedbycirclesandlabeledwithunique
designatorsymbolsorwordswritteninsidethem
Inputsymbols:afinitecollectionofinputsymbolsordesignators
OutputsymbolsZ:afinitecollectionofoutputsymbolsordesignators

Adirectedgraph

Theoutputfunctionrepresentsthemappingoforderedpairsofinputsymbolsandstatesonto
outputsymbols,denotedmathematicallyas:QZ.
Edges:representtransitionsfromonestatetoanotherascausedbytheinput(identifiedbytheirsymbolsdrawn
ontheedges).Anedgeisusuallydrawnasanarrowdirectedfromthepresentstatetothenextstate.This
https://en.wikipedia.org/wiki/State_diagram

1/5

11/8/2016

StatediagramWikipedia

mappingdescribesthestatetransitionthatistooccuroninputofaparticularsymbol.Thisiswritten
mathematicallyas:QQ,so(thetransitionfunction)inthedefinitionoftheFAisgivenbyboththe
pairofverticesconnectedbyanedgeandthesymbolonanedgeinadiagramrepresentingthisFA.Item(q,a)=
pinthedefinitionoftheFAmeansthatfromthestatenamedqunderinputsymbola,thetransitiontothestatep
occursinthismachine.InthediagramrepresentingthisFA,thisisrepresentedbyanedgelabeledbyapointing
fromthevertexlabeledbyqtothevertexlabeledbyp.
Startstateq0:(notshownintheexamplesbelow).Thestartstateq0Qisusuallyrepresentedbyanarrowwith
nooriginpointingtothestate.Inoldertexts,[2][4]thestartstateisnotshownandmustbeinferredfromthetext.
Acceptingstate(s)F:Ifused,forexampleforacceptingautomata,FQistheacceptingstate.Itisusually
drawnasadoublecircle.Sometimestheacceptstate(s)functionas"Final"(halt,trapped)states.[3]
Foradeterministicfiniteautomaton(DFA),nondeterministicfiniteautomaton(NFA),generalizednondeterministic
finiteautomaton(GNFA),orMooremachine,theinputisdenotedoneachedge.ForaMealymachine,inputandoutput
aresignifiedoneachedge,separatedwithaslash"/":"1/0"denotesthestatechangeuponencounteringthesymbol"1"
causingthesymbol"0"tobeoutput.ForaMooremachinethestate'soutputisusuallywritteninsidethestate'scircle,
alsoseparatedfromthestate'sdesignatorwithaslash"/".Therearealsovariantsthatcombinethesetwonotations.
Forexample,ifastatehasanumberofoutputs(e.g."a=motorcounterclockwise=1,b=cautionlightinactive=0")the
diagramshouldreflectthis:e.g."q5/1,0"designatesstateq5withoutputsa=1,b=0.Thisdesignatorwillbewritten
insidethestate'scircle.

Example:DFA,NFA,GNFA,orMooremachine
S1andS2arestatesandS1isanacceptingstateorafinalstate.Eachedgeislabeledwiththeinput.Thisexample
showsanacceptorforstringsover{0,1}thatcontainanevennumberofzeros.

Example:Mealymachine
S0,S1,andS2arestates.Eachedgeislabeledwith"j/k"wherejistheinputandkistheoutput.

Harelstatechart

https://en.wikipedia.org/wiki/State_diagram

2/5

11/8/2016

StatediagramWikipedia

Harelstatecharts[5]aregainingwidespreadusagesinceavarianthasbecomepartoftheUnifiedModelingLanguage
(UML).Thediagramtypeallowsthemodelingofsuperstates,orthogonalregions,andactivitiesaspartofastate.
Classicstatediagramsrequirethecreationofdistinctnodesforeveryvalidcombinationofparametersthatdefinethe
state.Thiscanleadtoaverylargenumberofnodesandtransitionsbetweennodesforallbutthesimplestofsystems
(stateandtransitionexplosion).Thiscomplexityreducesthereadabilityofthestatediagram.WithHarelstatechartsitis
possibletomodelmultiplecrossfunctionalstatediagramswithinthestatechart.Eachofthesecrossfunctionalstate
machinescantransitioninternallywithoutaffectingtheotherstatemachinesinthestatechart.Thecurrentstateofeach
crossfunctionalstatemachineinthestatechartdefinesthestateofthesystem.TheHarelstatechartisequivalenttoa
statediagrambutitimprovesthereadabilityoftheresultingdiagram.

Alternativesemantics
Thereareothersetsofsemanticsavailabletorepresentstatediagrams.Forexample,therearetoolsformodelingand
designinglogicforembeddedcontrollers.[6]Thesediagrams,likeHarel'soriginalstatemachines,[7]support
hierarchicallynestedstates,orthogonalregions,stateactions,andtransitionactions.[8]

Statediagramsversusflowcharts
Newcomerstothestatemachineformalismoftenconfusestatediagramswithflowcharts.Thefigurebelowshowsa
comparisonofastatediagramwithaflowchart.Astatemachine(panel(a))performsactionsinresponsetoexplicit
events.Incontrast,theflowchart(panel(b))doesnotneedexpliciteventsbutrathertransitionsfromnodetonodeinits
graphautomaticallyuponcompletionofactivities.[9]

Nodesofflowchartsareedgesintheinducedgraphofstates.Thereasonisthateachnodeinaflowchartrepresentsa
programcommand.Aprogramcommandisanactiontobeexecuted.Soitisnotastate,butwhenappliedtothe
program'sstate,itresultsinatransitiontoanotherstate.
Inmoredetail,thesourcecodelistingrepresentsaprogramgraph.Executingtheprogramgraph(parsingand
interpreting)resultsinastategraph.Soeachprogramgraphinducesastategraph.Conversionoftheprogramgraphto
itsassociatedstategraphiscalled"unfolding"oftheprogramgraph.
Theprogramgraphisasequenceofcommands.Ifnovariablesexist,thenthestateconsistsonlyoftheprogram
counter,whichkeepstrackofwhereintheprogramweareduringexecution(whatisthenextcommandtobeapplied).

https://en.wikipedia.org/wiki/State_diagram

3/5

11/8/2016

StatediagramWikipedia

Inthiscasebeforeexecutingacommandtheprogramcounterisatsomeposition(statebeforethecommandis
executed).Executingthecommandmovestheprogramcountertothenextcommand.Sincetheprogramcounteristhe
wholestate,itfollowsthatexecutingthecommandchangedthestate.Sothecommanditselfcorrespondstoatransition
betweenthetwostates.
Nowconsiderthefullcase,whenvariablesexistandareaffectedbytheprogramcommandsbeingexecuted.Then
betweendifferentprogramcounterlocations,notonlydoestheprogramcounterchange,butvariablesmightalso
changevalues,duetothecommandsexecuted.Consequentlyevenifwerevisitsomeprogramcommand(e.g.inaloop),
thisdoesn'timplytheprogramisinthesamestate.
Inthepreviouscase,theprogramwouldbeinthesamestate,becausethewholestateisjusttheprogramcounter,soif
theprogramcounterpointstothesameposition(nextcommand)itsufficestospecifythatweareinthesamestate.
However,ifthestatecomprisesalsoofvariables,thenifthosechangevalue,wecanbeatthesameprogramlocation
withdifferentvariablevalues,meaninginadifferentstateintheprogram'sstatespace.Theterm"unfolding"originates
fromthismultiplicationoflocationswhenproducingthestategraphfromtheprogramgraph.
Arepresentativeexampleisadoloopincrementingsomecounteruntilitoverflowsandbecomes0again.Althoughthe
doloopexecutesthesameincrementcommanditeratively,sotheprogramgraphexecutesacycle,initsstatespaceis
notacycle,butaline.Thisresultsfromthestatebeingtheprogramlocation(herecycling)combinedwiththecounter
value,whichisstrictlyincreasing(untiltheoverflow),sodifferentstatesarevisitedinsequence,untiltheoverflow.
Aftertheoverflowthecounterbecomes0again,sotheinitialstateisrevisitedinthestatespace,closingacycleinthe
statespace(assumingthecounterwasinitializedto0).
Thefigureaboveattemptstoshowthatreversalofrolesbyaligningthearcsofthestatediagramswiththeprocessing
stagesoftheflowchart.
Youcancompareaflowcharttoanassemblylineinmanufacturingbecausetheflowchartdescribestheprogressionof
sometaskfrombeginningtoend(e.g.,transformingsourcecodeinputintoobjectcodeoutputbyacompiler).Astate
machinegenerallyhasnonotionofsuchaprogression.Thedoorstatemachineshownatthetopofthisarticle,for
example,isnotinamoreadvancedstagewhenitisinthe"closed"state,comparedtobeinginthe"opened"stateit
simplyreactsdifferentlytotheopen/closeevents.Astateinastatemachineisanefficientwayofspecifyinga
particularbehavior,ratherthanastageofprocessing.

Otherextensions
Aninterestingextensionistoallowarcstoflowfromanynumberofstatestoanynumberofstates.Thisonlymakes
senseifthesystemisallowedtobeinmultiplestatesatonce,whichimpliesthatanindividualstateonlydescribesa
conditionorotherpartialaspectoftheoverall,globalstate.TheresultingformalismisknownasaPetrinet.
AnotherextensionallowstheintegrationofflowchartswithinHarelstatecharts.Thisextensionsupportsthe
developmentofsoftwarethatisbotheventdrivenandworkflowdriven.

Seealso
DavidHarel
DRAKON
SCXMLanXMLlanguagethatprovidesagenericstatemachinebasedexecutionenvironmentbasedonHarel
statecharts.
UMLstatemachine

References
https://en.wikipedia.org/wiki/State_diagram

4/5

11/8/2016

StatediagramWikipedia

1.Archivecopy(https://web.archive.org/web/*/http://atlas.ke
nnesaw.edu/~dbraun/csis4650/A&D/UML_tutorial/state.ht
m)attheWaybackMachine ThetemplateWaybackisbeingconsideredfor
merging.
2.TaylorBooth(1967)SequentialMachinesandAutomata
Theory,JohnWileyandSons,NewYork.
3.JohnHopcroftandJeffreyUllman(1979)Introductionto
AutomataTheory,Languages,andComputation,Addison
WesleyPublishingCompany,ReadingMass,ISBN0201
02988X
4.EdwardJ.McClusky,IntroductiontotheTheoryof
SwitchingCircuits,McGrawHill,1965
5.DavidHarel,Statecharts:Avisualformalismforcomplex
systems.ScienceofComputerProgramming(http://www.
wisdom.weizmann.ac.il/~dharel/SCANNED.PAPERS/Stat
echarts.pdf),8(3):231274,June1987.

6.Tiwari,A.(2002).FormalSemanticsandAnalysis
MethodsforSimulinkStateflow.(http://www.csl.sri.com/u
sers/tiwari/papers/stateflow.pdf)
7.Harel,D.(1987).AVisualFormalismforComplex
Systems.ScienceofComputerProgramming,231274.
(http://www.fceia.unr.edu.ar/asist/harel01.pdf)
8.Alur,R.,Kanade,A.,Ramesh,S.,&Shashidhar,K.C.
(2008).Symbolicanalysisforimprovingsimulation
coverageofSimulink/Stateflowmodels.International
ConferenceonEmbeddedSoftware(pp.8998).Atlanta,
GA:ACM.(http://drona.csa.iisc.ernet.in/~kanade/publicati
ons/symbolic_analysis_for_improving_simulation_coverag
e_of_simulink_stateflow_models.pdf)
9.Samek,Miro(2008).PracticalUMLStatechartsin
C/C++,SecondEdition:EventDrivenProgrammingfor
EmbeddedSystems.Newnes.p.728.ISBN97807506
87065.

Externallinks
IntroductiontoUML2StateMachineDiagrams(http://www.agilemodelin
WikimediaCommonshas
g.com/artifacts/stateMachineDiagram.htm)byScottW.Ambler
mediarelatedtoState
UML2StateMachineDiagramGuidelines(http://www.agilemodeling.co
diagrams.
m/style/stateChartDiagram.htm)byScottW.Ambler
IntelliwizardUMLStateWizard(http://www.intelliwizard.com)AClassWizardlikeroundtripUMLdynamic
modeling/developmentframeworkandtoolrunninginpopularIDEsunderopensourcelicense.
YAKINDUStatechartTools(http://www.statecharts.org)anOpenSourceToolforthespecificationand
developmentofreactive,eventdrivensystemswiththehelpofstatemachines.
UnderstandingandUsingStateMachines(http://www.mathworks.com/videos/techtalks/statemachines/)
MATLABTechTalksonStateMachines
FSM:OpenSourceFiniteStateMachineGenerationinJavabyAlexanderSakharovFSM(http://sakharov.net/fs
m.html)
scxmlcc(http://scxmlcc.org)AnefficientscxmlstatemachinetoC++compiler.
SMC:AnOpenSourceStateMachineCompilerthatgeneratesFSMformanylanguagesasC,Python,Lua,
Scala,PHP,Java,VB,etcSMC(http://smc.sourceforge.net/)
Retrievedfrom"https://en.wikipedia.org/w/index.php?title=State_diagram&oldid=728176477"
Categories: Modelsofcomputation UnifiedModelingLanguagediagrams Diagrams Infographics
Applicationspecificgraphs Graphdrawing
Thispagewaslastmodifiedon3July2016,at18:59.
TextisavailableundertheCreativeCommonsAttributionShareAlikeLicenseadditionaltermsmayapply.By
usingthissite,youagreetotheTermsofUseandPrivacyPolicy.Wikipediaisaregisteredtrademarkofthe
WikimediaFoundation,Inc.,anonprofitorganization.

https://en.wikipedia.org/wiki/State_diagram

5/5

You might also like