Você está na página 1de 16

Lovely Professional University

TERM PAPER CSE 526 Software Testing and Q ality Ass ran!e

To"i!# Co$"arison of vario s %inite state Ma!&ines for testing


" r"oses for a given in" t'

S ($itted )y# *a$e# Ro&it Roll *o# A+5 Reg *o# ++,,,556

S ($itted To# Mr' S d&ans Pra-as& Tiwari

Acknowledgement:-

. wo ld e/"ress $y gratit de to all t&ose w&o gave $e t&e "ossi(ility to !o$"lete t&is ter$ wor-' . want to t&an- t&e de"art$ent of CSE0526 for giving $e "er$ission to !o$$en!e t&is wor- in t&e first instan!e and to se t&e resear!& data' . a$ dee"ly inde(ted to $y tea!&er Mr' S d&ans& Pra-as& Tiwari w&ose s ggestions and en!o rage$ent &el"ed $e in all ti$e of resear!& for writing t&is ter$ wor-' . will always (e t&an-f l to $y tea!&er for s ""ort and g idan!e d ring !o$"letion of t&e ter$ "a"er' . also e/"ress $y t&an-s to $y friends and $y !lass$ates for en!o raging $e to !o$"lete t&e ter$ "a"er'

Introduction:
T&e si$"lest ty"e of !o$" ting $a!&ine t&at is wort& !onsidering is !alled a 1finite state $a!&ine2' As it &a""ens3 t&e finite state $a!&ine is also a sef l a""roa!& to $any "ro(le$s in software ar!&ite!t re3 only in t&is !ase yo don2t ( ild one yo si$ late it' Essentially a finite state $a!&ine !onsists of a n $(er of states finite nat rally4 5&en a sy$(ol3 a !&ara!ter fro$ so$e al"&a(et say3 is in" t to t&e $a!&ine it !&anges state in s !& a way t&at t&e ne/t state de"ends only on t&e ! rrent state and t&e in" t sy$(ol' *oti!e t&at t&is is $ore so"&isti!ated t&an yo $ig&t t&in- (e!a se in" tting t&e sa$e sy$(ol doesn2t always "rod !e t&e sa$e (e&avio r or res lt (e!a se of t&e !&ange of state'

T&e new state de"ends on t&e old state and t&e in" t'

5&at t&is $eans t&at t&e entire &istory of t&e $a!&ine is s $$ari6ed in its ! rrent state' All t&at $atters is t&e state t&at it is in and not &ow it rea!&ed t&is state' )efore yo write off t&e finite state $a!&ine as so fee(le as to (e not wort& !onsidering as a $odel of !o$" tation it is wort& "ointing o t t&at as yo !an &ave as $any states as yo !are to invent t&e $a!&ine !an re!ord ar(itrarily long &istories' All yo need is a state for ea!& of t&e "ossi(le "ast &istories and t&en t&e state t&at yo find t&e $a!&ine in is an indi!ation of not only its ! rrent state ( t &ow it arrived in t&at state' )e!a se a finite state $a!&ine !an re"resent any &istory and a rea!tion3 (y regarding t&e !&ange of state as a res"onse to t&e &istory3 it &as (een arg ed t&at it is a s ffi!ient $odel of & $an (e&avio r i'e' & $ans are finite state $a!&ines' .f yo -now so$e "ro(a(ility t&eory yo will re!ogni6e a !onne!tion (etween finite state $a!&ines and Mar-ov !&ains' A Mar-ov !&ain s $s " t&e "ast &istory in ter$s of t&e ! rrent state and t&e "ro(a(ility of transition to t&e ne/t state only de"ends on t&e ! rrent state' T&e Mar-ov !&ain is a sort of "ro(a(ilisti! version of t&e finite state $a!&ine

Representation of Finite State Machines :

7ra"&i!al re"resentation of a %inite State Ma!&ine 8ere t&e nodes are re"resenting t&e states of t&e $a!&ines and t&e val es on t&e arrows re"resents t&e different in" ts given to different states of fiite state $a!&ine and o t" t !o$ing fro$ t&at state'

Ta( lar 9es!ri"tion of %inite0State Ma!&ine#'

current state start state f f g g & &

input symbol , + , + , +

next state g & g & g &

ypes of Finite State Machines :


:n t&e (asis of t&e o t" t generating s!&e$es t&e finite state $a!&ine are divided in two $a;or !ategories w&i!& are# +' 9eter$inisti! %inite State Ma!&ines <9eter$inisti! %inite A to$ata= 2' *on09eter$inisti! %inite State Ma!&ines <*on09eter$inisti! %inite A to$ata=

!eterministic Finite Automata "!FA#:


.t is a finite state $a!&ine t&at a!!e"ts>re;e!ts finite strings of sy$(ols and only "rod !es a ni? e !o$" tation <or r n= of t&e a to$aton for ea!& in" t string' 9eter$inisti! refers to t&e ni? eness of t&e !o$" tation' .n sear!& of si$"lest $odels to !a"t re t&e finite state $a!&ines3

M!C llo!& and Pitts were a$ong t&e first resear!&ers to introd !e a !on!e"t si$ilar to finite a to$aton in +@AB' T&e fig re on t&e rig&t ill strates a deter$inisti! finite a to$aton sing a state diagra$' .n t&e a to$aton3 t&ere are t&ree states# S,3 S+3 and S2 <denoted gra"&i!ally (y !ir!les=' T&e a to$aton ta-es a finite se? en!e of ,s and +s as in" t' %or ea!& state3 t&ere is a transition arrow leading o t to a ne/t state for (ot& , and +' U"on reading a sy$(ol3 a 9%A ; $"s deterministically fro$ a state to anot&er (y following t&e transition arrow' %or e/a$"le3 if t&e a to$aton is ! rrently in state S, and ! rrent in" t sy$(ol is + t&en it deter$inisti!ally ; $"s to state S+' A 9%A &as a start state <denoted gra"&i!ally (y an arrow !o$ing in fro$ now&ere= w&ere !o$" tations (egin3 and a set of accept states <denoted gra"&i!ally (y a do (le !ir!le= w&i!& &el" define w&en a !o$" tation is s !!essf l' A 9%A is defined as an a(stra!t $at&e$ati!al !on!e"t3 ( t d e to t&e deter$inisti! nat re of a 9%A3 it is i$"le$enta(le in &ardware and software for solving vario s s"e!ifi! "ro(le$s' %or e/a$"le3 a 9%A !an $odel software t&at de!ides w&et&er or not online ser0in" t s !& as e$ail addresses are valid' 9%As re!ogni6e e/a!tly t&e set of reg lar lang ages w&i!& are3 a$ong ot&er t&ings3 sef l for doing le/i!al analysis and "attern $at!&ing' 9%As !an (e ( ilt fro$ nondeter$inisti! finite a to$ata t&ro g& t&e "ower set !onstr !tion

Formal !efinition : A deter$inisti! finite a to$aton M is a 50t "le3 <Q3 C3 D3 q03 F=3 !onsisting of

a finite set of states <Q= a finite set of in" t sy$(ols !alled t&e al"&a(et <C= a transition f n!tion <D # Q E C F Q= a start state <q0 Q= a set of final states <F Q=

Let w = a1a2 ... an (e a string over t&e al"&a(et C' T&e a to$aton M a!!e"ts t&e string w if a se? en!e of states3 r0,r1, ..., rn3 e/ists in Q wit& t&e following !onditions# +' r0 G q0 2' ri+1 G D<ri3 ai+1=3 for i G 0, ..., n1 3. rn F'

.n words3 T&e first !ondition says t&at t&e $a!&ine starts in t&e start state q,' T&e se!ond !ondition says t&at given ea!& !&ara!ter of string w3 t&e $a!&ine will transition fro$ state to state a!!ording to t&e transition f n!tion D' T&e last !ondition says t&at t&e $a!&ine a!!e"ts w if t&e last in" t of w !a ses t&e $a!&ine to &alt in one of t&e a!!e"ting states'

:t&erwise3 it is said t&at t&e a to$aton rejects t&e string' T&e set of strings M a!!e"ts is t&e lang age re!ogni6ed (y M and t&is lang age is denoted (y L(M)'

*ote # A deter$inisti! finite a to$aton wit&o t a!!e"t states and wit&o t a starting state is -nown as a transition syste$ or se$i a to$ation' E/a$"le#

M G <Q3 C3 D3 q03 F= w&ere


Q G H +3

I3

C G H,3 +I3

q0 G

F G H +I3 and D is defined (y t&e following state transition ta(le#


table for DFA :

$ S% S& Modes of !FA:


2 +

A 9%A re"resenting a reg lar lang age !an (e sed eit&er in

Accepting mode: .n t&e a!!e"t $ode an in" t string is "rovided w&i!& t&e a to$aton !an read in left to rig&t3 one sy$(ol at a ti$e' T&e !o$" tation (egins at t&e start state and "ro!eeds (y reading t&e first sy$(ol fro$ t&e in" t string and following t&e state transition !orres"onding to t&at sy$(ol' T&e syste$ !ontin es reading sy$(ols and following transitions ntil t&ere are no $ore sy$(ols in t&e in" t3 w&i!& $ar-s t&e end of t&e !o$" tation' .f after all in" t sy$(ols &ave (een "ro!essed t&e syste$ is in an a!!e"t state t&en we -now t&at t&e in" t string was indeed "art of t&e lang age3 and it is said to (e a!!e"ted3 ot&erwise it is not "art of t&e lang age and it is not a!!e"ted'

'enerating mode: .t is si$ilar e/!e"t t&at rat&er t&an validating an in" t string its goal is to "rod !e a list of all t&e strings in t&e lang age' .nstead of following a single transition o t of ea!& state3 it follows all of t&e$' .n "ra!ti!e t&is !an (e a!!o$"lis&ed (y $assive "arallelis$ <&aving t&e "rogra$ (ran!& into two or $ore "ro!esses ea!& ti$e it is fa!ed wit& a de!ision= or t&ro g& re! rsion' As (efore3 t&e !o$" tation (egins at t&e start state and t&en "ro!eeds to follow ea!& availa(le transition3 -ee"ing tra!- of w&i!& (ran!&es it too-' Every ti$e t&e a to$aton finds itself in an a!!e"t state it -nows t&at t&e se? en!e of (ran!&es it too- for$s a valid string in t&e lang age and it adds t&at string to t&e list t&at it is generating' .f t&e lang age t&is a to$aton des!ri(es is infinite <i'e' !ontains an

infinite n $(er or strings3 s !& as Jall t&e (inary string wit& an even n $(er of ,s= t&en t&e !o$" tation will never &alt' 7iven t&at reg lar lang ages are3 in general3 infinite3 a to$ata in t&e generating $ode tends to (e $ore of a t&eoreti!al !onstr !t

(losure properties of !FA : .f 9%A re!ogni6e t&e lang ages t&at are o(tained (y a""lying an o"eration on t&e 9%A re!ogni6a(le lang ages t&en 9%As are said to (e !losed nder t&e o"eration' T&e 9%As are !losed nder t&e following o"erations'

Union .nterse!tion Con!atenation *egation Reversal Q otient S (stit tion

Ad)antages and !isad)antages of !FA : 9%As were invented to $odel real w!rld finite state $a!&ines in !ontrast to t&e !on!e"t of a T ring $a!&ine3 w&i!& was too general to st dy "ro"erties of real world $a!&ines' 9%As are one of t&e $ost "ra!ti!al $odels of !o$" tation3 sin!e t&ere is a trivial linear ti$e3 !onstant0s"a!e3 online algorit&$ to si$ late a 9%A on a strea$ of in" t' Also3 t&ere are effi!ient algorit&$s to find a 9%A re!ogni6ing#

t&e !o$"le$ent of t&e lang age re!ogni6ed (y a given 9%A' t&e nion>interse!tion of t&e lang ages re!ogni6ed (y two given 9%As'

)e!a se 9%As !an (e red !ed to a can!nical "!rm t&ere are also effi!ient algorit&$s to deter$ine#

w&et&er a 9%A a!!e"ts any strings w&et&er a 9%A a!!e"ts all strings w&et&er two 9%As re!ogni6e t&e sa$e lang age t&e 9%A wit& a $ini$ $ n $(er of states for a "arti! lar reg lar lang age

:n t&e ot&er &and3 finite state a to$ata are of stri!tly li$ited "ower in t&e lang ages t&ey !an re!ogni6eK $any si$"le lang ages3 in!l ding any "ro(le$ t&at re? ires $ore t&an !onstant s"a!e to solve3 !annot (e re!ogni6ed (y a 9%A' T&e !lassi!al e/a$"le of a si$"ly des!ri(ed lang age t&at no 9%A !an re!ogni6e is (ra!-et lang age3 i'e'3 lang age t&at !onsists of "ro"erly "aired (ra!-ets s !& as word J<<=<==J' *o 9%A !an re!ogni6e t&e (ra!-et lang age (e!a se t&ere is no li$it to re! rsion3 i'e'3 one !an always e$(ed anot&er "air of (ra!-ets inside' .t wo ld re? ire an infinite a$o nt of states to re!ogni6e'

*on-!eterministic Finite Automata "*!FA#:

.n a to$ata t&eory3 a nondeter$inisti! finite a to$aton <*9%A=3 or nondeter$inisti! finite state $a!&ine3 is a finite state $a!&ine t&at 9oes not re? ire in" t sy$(ols for state transitions

.s !a"a(le of transitioning to 6ero or two or $ore states for a given start state and in" t sy$(ol'

T&is disting is&es it fro$ a deter$inisti! finite a to$aton <9%A=3 in w&i!& all transitions are ni? ely deter$ined and in w&i!& an in" t sy$(ol is re? ired for all state transitions' Alt&o g& *9%A and 9%A &ave distin!t definitions3 all *9%As !an (e translated to e? ivalent 9%As sing t&e s (set !onstr !tion algorit&$3 i'e'3 !onstr !ted 9%As and t&eir !orres"onding *9%As re!ogni6e t&e sa$e for$al lang age' Li-e 9%As3 *9%As only re!ogni6e reg lar lang ages'

*9%As were introd !ed in +@5@ (y Mi!&ael :' Ra(in and 9ana S!ott3 w&o also s&owed t&eir e? ivalen!e to 9%As' *9%As &ave (een generali6ed in $ lti"le ways3 e'g'3 nondeter$inisti! finite a to$aton wit& L0 $oves3 " s&down a to$aton3 M0a to$aton3 and "ro(a(ilisti! a to$ata'

Formal !efinition : An #$F% is re"resented for$ally (y a 50t "le3 <Q3 C3 N3 q03 F=3 !onsisting of

a finite set of states Q a finite set of in" t sy$(ols C a transition relation N # Q E C F &<Q=' an initial <or start= state q, Q a set of states F disting is&ed as acceptin' <or "inal= states F Q'

8ere3 &<Q= denotes t&e "ower set of Q' Let w = a1a2 ... an (e a word over t&e al"&a(et C' T&e a to$aton M a!!e"ts t&e word w if a se? en!e of states3 r0,r1, ..., rn3 e/ists in Q wit& t&e following !onditions# +' r0 G q0 2. ri+1 N<ri3 ai+1=3 for i G 0, ..., n1 3. rn F' .n words3 t&e first !ondition says t&at t&e $a!&ine starts in t&e start state q,' T&e se!ond !ondition says t&at given ea!& !&ara!ter of string w3 t&e $a!&ine will transition fro$ state to state a!!ording to t&e transition relation N'

T&e last !ondition says t&at t&e $a!&ine a!!e"ts w if t&e last in" t of w !a ses t&e $a!&ine to &alt in one of t&e a!!e"ting states'

:t&erwise3 it is said t&at t&e a to$aton rejects t&e string' T&e set of strings M a!!e"ts is t&e lang age rec!'ni(ed (y M and t&is lang age is denoted (y L(M)' 5e !an also define L(M) in ter$s of NO# Q E CO F &<Q= s !& t&at# +' NO<r3 L=G HrI w&ere L is t&e e$"ty string3 and 2. .f ) CO3 a C3 and NO<r3 /=GHr+3 r23'''3 r-I t&en NO<r3 )a=G N<r+3 a='''N<r-3 a=' *ow L<M= G Hw P NO<?,3 w= Q F R I' *ote t&at t&ere is a single initial state3 w&i!& is not ne!essary' So$eti$es3 *9%As are defined wit& a set of initial states' T&ere is an easy !onstr !tion t&at translates a *9%A wit& $ lti"le initial states to a *9%A wit& single initial state3 w&i!& "rovides a !onvenient notation'

E/a$"le #

T&e state diagra$ for M Let M (e a *9%A3 wit& a (inary al"&a(et3 t&at deter$ines if t&e in" t ends wit& a +'
In formal notation, let M = ({p, q}, {0, 1}, %an be &efine& b' t#i$ $tate tran$ition table: , p, {q}! "#ere t#e tran$ition relation

$ p q HpI

% Hp3qI

*ote t&at N<p3+= &as $ore t&an one state t&erefore M is nondeter$inisti!' T&e lang age of M !an (e des!ri(ed (y t&e reg lar lang age given (y t&e reg lar e/"ression <,P+=O+'

9eter$inisti! finite a to$aton <9%A=# .n t&is a to$aton3 for ea!& state and al"&a(et3 t&e

transition relation &as e/a!tly one state'


*ondeter$inisti! finite a to$aton wit& L0$oves<*9%A0L=# T&is a to$aton re"la!es t&e

transition relation wit& t&e one t&at allows t&e e$"ty string L as a "ossi(le in" t3 so t&e transition relation is defined as N #Q E <C HLI= F &<Q='

+,ui)alence to !FA : %or ea!& *9%A3 t&ere is a 9%A s !& t&at (ot& re!ogni6e t&e sa$e for$al lang age' T&e 9%A !an (e !onstr !ted sing t&e "owerset !onstr !tion' .t is i$"ortant in t&eory (e!a se it esta(lis&es t&at *9%As3 des"ite t&eir additional fle/i(ility3 are na(le to re!ogni6e any lang age t&at !annot (e re!ogni6ed (y so$e 9%A' .t is also i$"ortant in "ra!ti!e for !onverting easier0to0!onstr !t *9%As into $ore effi!iently e/e! ta(le 9%As' 8owever3 if t&e *9%A &as n states3 t&e res lting 9%A $ay &ave " to 2n states3 an e/"onentially larger n $(er3 w&i!& so$eti$es $a-es t&e !onstr !tion i$"ra!ti!al for large *9%As'

(losure -roperties : *9%As are said to (e !losed nder a <(inary> nary= o"erator if *9%As re!ogni6e t&e lang ages t&at are o(tained (y a""lying t&e o"eration on t&e *9%A re!ogni6a(le lang ages' T&e *9%As are !losed nder t&e following o"erations'

Union .nterse!tion Con!atenation *egation Sleene !los re

Sin!e *9%As are e? ivalent to nondeter$inisti! finite a to$aton wit& L0$oves<*9%A0L=3 t&e a(ove !los res are "roved sing !los re "ro"erties of *9%A0L' T&e a(ove !los re "ro"erties i$"ly t&at *9%As only re!ogni6e reg lar lang ages'

-roperties of *!FA : T&e $a!&ine starts in t&e s"e!ified initial state and reads in a string of sy$(ols fro$ its al"&a(et' T&e a to$aton ses t&e state transition f n!tion N to deter$ine t&e ne/t state sing t&e ! rrent state3 and t&e sy$(ol ; st read or t&e e$"ty string' 8owever3 Jt&e ne/t state of an *9%A de"ends not only on t&e ! rrent in" t event3 ( t also on an ar(itrary n $(er of s (se? ent in" t events' Until t&ese s (se? ent events o!! r it is not "ossi(le to deter$ine w&i!& state t&e $a!&ine is inJ' .f3 w&en t&e a to$aton &as finis&ed reading3 it is in an a!!e"ting state3 t&e *9%A is said to a!!e"t t&e string3 ot&erwise it is said to re;e!t t&e string' T&e set of all strings a!!e"ted (y an *9%A is t&e lang age t&e *9%A a!!e"ts' T&is lang age is a reg lar lang age' %or every *9%A a deter$inisti! finite a to$aton <9%A= !an (e fo nd t&at a!!e"ts t&e sa$e lang age' T&erefore it is "ossi(le to !onvert an e/isting *9%A into a 9%A for t&e " r"ose of i$"le$enting a <"er&a"s= si$"ler $a!&ine' T&is !an (e "erfor$ed sing t&e "ower set !onstr !tion3 w&i!& $ay lead to an e/"onential rise in t&e n $(er of ne!essary states' A for$al "roof of t&e "ower set !onstr !tion is given &ere.

Implementation of *!FA : T&ere are $any ways to i$"le$ent a *9%A#

Convert to t&e e? ivalent 9%A' .n so$e !ases t&is $ay !a se e/"onential (low " in t&e si6e of t&e a to$aton and t& s a /iliary s"a!e "ro"ortional to t&e n $(er of states in t&e *9%A <as storage of t&e state val e re? ires at $ost one (it for every state in t&e *9%A=

See" a set data str !t re of all states w&i!& t&e $a!&ine $ig&t ! rrently (e in' :n t&e !ons $"tion of t&e last in" t sy$(ol3 if one of t&ese states is a final state3 t&e $a!&ine a!!e"ts t&e string' .n t&e worst !ase3 t&is $ay re? ire a /iliary s"a!e "ro"ortional to t&e

n $(er of states in t&e *9%AK if t&e set str !t re ses one (it "er *9%A state3 t&en t&is sol tion is e/a!tly e? ivalent to t&e a(ove'

Create $ lti"le !o"ies' %or ea!& n way de!ision3 t&e *9%A !reates " to

!o"ies

of t&e $a!&ine' Ea!& will enter a se"arate state' .f3 "on !ons $ing t&e last in" t sy$(ol3 at least one !o"y of t&e *9%A is in t&e a!!e"ting state3 t&e *9%A will a!!e"t' <T&is3 too3 re? ires linear storage wit& res"e!t to t&e n $(er of *9%A states3 as t&ere !an (e one $a!&ine for every *9%A state'=

E/"li!itly "ro"agate to-ens t&ro g& t&e transition str !t re of t&e *9%A and $at!& w&enever a to-en rea!&es t&e final state' T&is is so$eti$es sef l w&en t&e *9%A s&o ld en!ode additional !onte/t a(o t t&e events t&at triggered t&e transition' <%or an i$"le$entation t&at ses t&is te!&ni? e to -ee" tra!- of o(;e!t referen!es &ave a loo- at Tra!e$at!&es'=

Application of *!FA : *%As and 9%As are e? ivalent in t&at if a lang age is re!ogni6ed (y an *%A3 it is also re!ogni6ed (y a 9%A and vi!e versa' T&e esta(lis&$ent of s !& e? ivalen!e is i$"ortant and sef l' .t is sef l (e!a se !onstr !ting an *%A to re!ogni6e a given lang age is so$eti$es $ !& easier t&an !onstr !ting a 9%A for t&at lang age' .t is i$"ortant (e!a se *%As !an (e sed to red !e t&e !o$"le/ity of t&e $at&e$ati!al wor- re? ired to esta(lis& $any i$"ortant "ro"erties in t&e t&eory of !o$" tation' %or e/a$"le3 it is $ !& easier to "rove !los re "ro"erties of reg lar lang ages sing *%As t&an 9%As'

T&e nion of two reg lar lang ages is reg lar' T&e !on!atenation of two reg lar lang ages is reg lar'

References :
+' T&eory of Co$" ter S!ien!e 0 S'L'P S&ar$a
2. www'te!&news'!o$ 3. www'!seed '!o'in

A' A to$ation T&eory 0 T'S Prasad

Você também pode gostar