:: Equivalence of Epsilon, Nondeterministic [Finite] Automata and Deterministic [Finite] Automata
:: by Micha{\l} Trybulec
::
:: Received May 25, 2009
:: Copyright (c) 2009-2011 Association of Mizar Users


begin

theorem Th1: :: FSM_3:1
for i, k, l being Nat st i >= k + l holds
i >= k
proof end;

theorem :: FSM_3:2
for a, b being FinSequence st ( a ^ b = a or b ^ a = a ) holds
b = {}
proof end;

theorem Th3: :: FSM_3:3
for k being Nat
for p, q being FinSequence st k in dom p & (len p) + 1 = len q holds
k + 1 in dom q
proof end;

theorem Th4: :: FSM_3:4
for E being non empty set
for u being Element of E ^omega st len u = 1 holds
ex e being Element of E st
( <%e%> = u & e = u . 0 )
proof end;

theorem Th5: :: FSM_3:5
for E being non empty set
for u being Element of E ^omega
for k being Nat st k <> 0 & len u <= k + 1 holds
ex v1, v2 being Element of E ^omega st
( len v1 <= k & len v2 <= k & u = v1 ^ v2 )
proof end;

theorem Th6: :: FSM_3:6
for x, y being set
for p, q being XFinSequence st <%x%> ^ p = <%y%> ^ q holds
( x = y & p = q )
proof end;

theorem Th7: :: FSM_3:7
for E being non empty set
for u being Element of E ^omega st len u > 0 holds
ex e being Element of E ex u1 being Element of E ^omega st u = <%e%> ^ u1
proof end;

registration
let E be non empty set ;
cluster Lex E -> non empty ;
coherence
not Lex E is empty
proof end;
end;

theorem Th8: :: FSM_3:8
for E being non empty set holds not <%> E in Lex E
proof end;

theorem Th9: :: FSM_3:9
for E being non empty set
for u being Element of E ^omega holds
( u in Lex E iff len u = 1 )
proof end;

theorem Th10: :: FSM_3:10
for E being non empty set
for u, v being Element of E ^omega st u <> v & u in Lex E & v in Lex E holds
for w being Element of E ^omega holds
( not u ^ w = v & not w ^ u = v )
proof end;

theorem :: FSM_3:11
canceled;

theorem Th12: :: FSM_3:12
for E being non empty set
for TS being transition-system of Lex E st the Tran of TS is Function holds
TS is deterministic
proof end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let TS be non empty transition-system of F;
func _bool TS -> strict transition-system of Lex E means :Def1: :: FSM_3:def 1
( the carrier of it = bool the carrier of TS & ( for S being Subset of TS
for w being Element of E ^omega
for T being Subset of TS holds
( [[S,w],T] in the Tran of it iff ( len w = 1 & T = w -succ_of (S,TS) ) ) ) );
existence
ex b1 being strict transition-system of Lex E st
( the carrier of b1 = bool the carrier of TS & ( for S being Subset of TS
for w being Element of E ^omega
for T being Subset of TS holds
( [[S,w],T] in the Tran of b1 iff ( len w = 1 & T = w -succ_of (S,TS) ) ) ) )
proof end;
uniqueness
for b1, b2 being strict transition-system of Lex E st the carrier of b1 = bool the carrier of TS & ( for S being Subset of TS
for w being Element of E ^omega
for T being Subset of TS holds
( [[S,w],T] in the Tran of b1 iff ( len w = 1 & T = w -succ_of (S,TS) ) ) ) & the carrier of b2 = bool the carrier of TS & ( for S being Subset of TS
for w being Element of E ^omega
for T being Subset of TS holds
( [[S,w],T] in the Tran of b2 iff ( len w = 1 & T = w -succ_of (S,TS) ) ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def1 defines _bool FSM_3:def 1 :
for E being non empty set
for F being Subset of (E ^omega)
for TS being non empty transition-system of F
for b4 being strict transition-system of Lex E holds
( b4 = _bool TS iff ( the carrier of b4 = bool the carrier of TS & ( for S being Subset of TS
for w being Element of E ^omega
for T being Subset of TS holds
( [[S,w],T] in the Tran of b4 iff ( len w = 1 & T = w -succ_of (S,TS) ) ) ) ) );

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let TS be non empty transition-system of F;
cluster _bool TS -> non empty strict deterministic ;
coherence
( not _bool TS is empty & _bool TS is deterministic )
proof end;
end;

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let TS be non empty finite transition-system of F;
cluster _bool TS -> finite strict ;
coherence
_bool TS is finite
proof end;
end;

theorem Th13: :: FSM_3:13
for x, y being set
for E being non empty set
for e being Element of E
for F being Subset of (E ^omega)
for TS being non empty transition-system of F st x,<%e%> ==>* y, <%> E, _bool TS holds
x,<%e%> ==>. y, <%> E, _bool TS
proof end;

theorem Th14: :: FSM_3:14
for X being set
for E being non empty set
for w being Element of E ^omega
for F being Subset of (E ^omega)
for TS being non empty transition-system of F
for S being Subset of TS st len w = 1 holds
( X = w -succ_of (S,TS) iff S,w ==>* X, _bool TS )
proof end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
attr c3 is strict ;
struct semiautomaton of F -> transition-system of F;
aggr semiautomaton(# carrier, Tran, InitS #) -> semiautomaton of F;
sel InitS c3 -> Subset of the carrier of c3;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be semiautomaton of F;
attr SA is deterministic means :Def2: :: FSM_3:def 2
( transition-system(# the carrier of SA, the Tran of SA #) is deterministic & card the InitS of SA = 1 );
end;

:: deftheorem Def2 defines deterministic FSM_3:def 2 :
for E being non empty set
for F being Subset of (E ^omega)
for SA being semiautomaton of F holds
( SA is deterministic iff ( transition-system(# the carrier of SA, the Tran of SA #) is deterministic & card the InitS of SA = 1 ) );

registration
let E be non empty set ;
let F be Subset of (E ^omega);
cluster non empty finite strict deterministic semiautomaton of F;
existence
ex b1 being semiautomaton of F st
( b1 is strict & not b1 is empty & b1 is finite & b1 is deterministic )
proof end;
end;

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be non empty semiautomaton of F;
cluster transition-system(# the carrier of SA, the Tran of SA #) -> non empty ;
coherence
not transition-system(# the carrier of SA, the Tran of SA #) is empty
;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be non empty semiautomaton of F;
func _bool SA -> strict semiautomaton of Lex E means :Def3: :: FSM_3:def 3
( transition-system(# the carrier of it, the Tran of it #) = _bool transition-system(# the carrier of SA, the Tran of SA #) & the InitS of it = {((<%> E) -succ_of ( the InitS of SA,SA))} );
existence
ex b1 being strict semiautomaton of Lex E st
( transition-system(# the carrier of b1, the Tran of b1 #) = _bool transition-system(# the carrier of SA, the Tran of SA #) & the InitS of b1 = {((<%> E) -succ_of ( the InitS of SA,SA))} )
proof end;
uniqueness
for b1, b2 being strict semiautomaton of Lex E st transition-system(# the carrier of b1, the Tran of b1 #) = _bool transition-system(# the carrier of SA, the Tran of SA #) & the InitS of b1 = {((<%> E) -succ_of ( the InitS of SA,SA))} & transition-system(# the carrier of b2, the Tran of b2 #) = _bool transition-system(# the carrier of SA, the Tran of SA #) & the InitS of b2 = {((<%> E) -succ_of ( the InitS of SA,SA))} holds
b1 = b2
;
end;

:: deftheorem Def3 defines _bool FSM_3:def 3 :
for E being non empty set
for F being Subset of (E ^omega)
for SA being non empty semiautomaton of F
for b4 being strict semiautomaton of Lex E holds
( b4 = _bool SA iff ( transition-system(# the carrier of b4, the Tran of b4 #) = _bool transition-system(# the carrier of SA, the Tran of SA #) & the InitS of b4 = {((<%> E) -succ_of ( the InitS of SA,SA))} ) );

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be non empty semiautomaton of F;
cluster _bool SA -> non empty strict deterministic ;
coherence
( not _bool SA is empty & _bool SA is deterministic )
proof end;
end;

theorem Th15: :: FSM_3:15
for E being non empty set
for F being Subset of (E ^omega)
for SA being non empty semiautomaton of F holds the carrier of (_bool SA) = bool the carrier of SA
proof end;

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be non empty finite semiautomaton of F;
cluster _bool SA -> finite strict ;
coherence
_bool SA is finite
proof end;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let SA be non empty semiautomaton of F;
let Q be Subset of SA;
func left-Lang Q -> Subset of (E ^omega) equals :: FSM_3:def 4
{ w where w is Element of E ^omega : Q meets w -succ_of ( the InitS of SA,SA) } ;
coherence
{ w where w is Element of E ^omega : Q meets w -succ_of ( the InitS of SA,SA) } is Subset of (E ^omega)
proof end;
end;

:: deftheorem defines left-Lang FSM_3:def 4 :
for E being non empty set
for F being Subset of (E ^omega)
for SA being non empty semiautomaton of F
for Q being Subset of SA holds left-Lang Q = { w where w is Element of E ^omega : Q meets w -succ_of ( the InitS of SA,SA) } ;

theorem Th16: :: FSM_3:16
for E being non empty set
for w being Element of E ^omega
for F being Subset of (E ^omega)
for SA being non empty semiautomaton of F
for Q being Subset of SA holds
( w in left-Lang Q iff Q meets w -succ_of ( the InitS of SA,SA) )
proof end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
attr c3 is strict ;
struct automaton of F -> semiautomaton of F;
aggr automaton(# carrier, Tran, InitS, FinalS #) -> automaton of F;
sel FinalS c3 -> Subset of the carrier of c3;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let A be automaton of F;
attr A is deterministic means :Def5: :: FSM_3:def 5
semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) is deterministic ;
end;

:: deftheorem Def5 defines deterministic FSM_3:def 5 :
for E being non empty set
for F being Subset of (E ^omega)
for A being automaton of F holds
( A is deterministic iff semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) is deterministic );

registration
let E be non empty set ;
let F be Subset of (E ^omega);
cluster non empty finite strict deterministic automaton of F;
existence
ex b1 being automaton of F st
( b1 is strict & not b1 is empty & b1 is finite & b1 is deterministic )
proof end;
end;

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty automaton of F;
cluster transition-system(# the carrier of A, the Tran of A #) -> non empty ;
coherence
not transition-system(# the carrier of A, the Tran of A #) is empty
;
cluster semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) -> non empty ;
coherence
not semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) is empty
;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty automaton of F;
func _bool A -> strict automaton of Lex E means :Def6: :: FSM_3:def 6
( semiautomaton(# the carrier of it, the Tran of it, the InitS of it #) = _bool semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) & the FinalS of it = { Q where Q is Element of it : Q meets the FinalS of A } );
existence
ex b1 being strict automaton of Lex E st
( semiautomaton(# the carrier of b1, the Tran of b1, the InitS of b1 #) = _bool semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) & the FinalS of b1 = { Q where Q is Element of b1 : Q meets the FinalS of A } )
proof end;
uniqueness
for b1, b2 being strict automaton of Lex E st semiautomaton(# the carrier of b1, the Tran of b1, the InitS of b1 #) = _bool semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) & the FinalS of b1 = { Q where Q is Element of b1 : Q meets the FinalS of A } & semiautomaton(# the carrier of b2, the Tran of b2, the InitS of b2 #) = _bool semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) & the FinalS of b2 = { Q where Q is Element of b2 : Q meets the FinalS of A } holds
b1 = b2
;
end;

:: deftheorem Def6 defines _bool FSM_3:def 6 :
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F
for b4 being strict automaton of Lex E holds
( b4 = _bool A iff ( semiautomaton(# the carrier of b4, the Tran of b4, the InitS of b4 #) = _bool semiautomaton(# the carrier of A, the Tran of A, the InitS of A #) & the FinalS of b4 = { Q where Q is Element of b4 : Q meets the FinalS of A } ) );

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty automaton of F;
cluster _bool A -> non empty strict deterministic ;
coherence
( not _bool A is empty & _bool A is deterministic )
proof end;
end;

theorem Th17: :: FSM_3:17
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F holds the carrier of (_bool A) = bool the carrier of A
proof end;

registration
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty finite automaton of F;
cluster _bool A -> finite strict ;
coherence
_bool A is finite
proof end;
end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty automaton of F;
let Q be Subset of A;
func right-Lang Q -> Subset of (E ^omega) equals :: FSM_3:def 7
{ w where w is Element of E ^omega : w -succ_of (Q,A) meets the FinalS of A } ;
coherence
{ w where w is Element of E ^omega : w -succ_of (Q,A) meets the FinalS of A } is Subset of (E ^omega)
proof end;
end;

:: deftheorem defines right-Lang FSM_3:def 7 :
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F
for Q being Subset of A holds right-Lang Q = { w where w is Element of E ^omega : w -succ_of (Q,A) meets the FinalS of A } ;

theorem Th18: :: FSM_3:18
for E being non empty set
for w being Element of E ^omega
for F being Subset of (E ^omega)
for A being non empty automaton of F
for Q being Subset of A holds
( w in right-Lang Q iff w -succ_of (Q,A) meets the FinalS of A )
proof end;

definition
let E be non empty set ;
let F be Subset of (E ^omega);
let A be non empty automaton of F;
func Lang A -> Subset of (E ^omega) equals :: FSM_3:def 8
{ u where u is Element of E ^omega : ex p, q being Element of A st
( p in the InitS of A & q in the FinalS of A & p,u ==>* q,A )
}
;
coherence
{ u where u is Element of E ^omega : ex p, q being Element of A st
( p in the InitS of A & q in the FinalS of A & p,u ==>* q,A )
}
is Subset of (E ^omega)
proof end;
end;

:: deftheorem defines Lang FSM_3:def 8 :
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F holds Lang A = { u where u is Element of E ^omega : ex p, q being Element of A st
( p in the InitS of A & q in the FinalS of A & p,u ==>* q,A )
}
;

theorem Th19: :: FSM_3:19
for E being non empty set
for w being Element of E ^omega
for F being Subset of (E ^omega)
for A being non empty automaton of F holds
( w in Lang A iff ex p, q being Element of A st
( p in the InitS of A & q in the FinalS of A & p,w ==>* q,A ) )
proof end;

theorem Th20: :: FSM_3:20
for E being non empty set
for w being Element of E ^omega
for F being Subset of (E ^omega)
for A being non empty automaton of F holds
( w in Lang A iff w -succ_of ( the InitS of A,A) meets the FinalS of A )
proof end;

theorem :: FSM_3:21
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F holds Lang A = left-Lang the FinalS of A
proof end;

theorem :: FSM_3:22
for E being non empty set
for F being Subset of (E ^omega)
for A being non empty automaton of F holds Lang A = right-Lang the InitS of A
proof end;

theorem Th23: :: FSM_3:23
for E being non empty set
for e being Element of E
for u being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)}
for R being RedSequence of ==>.-relation TS st (R . 1) `2 = <%e%> ^ u & (R . (len R)) `2 = <%> E & not (R . 2) `2 = <%e%> ^ u holds
(R . 2) `2 = u
proof end;

theorem Th24: :: FSM_3:24
for E being non empty set
for u being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)}
for R being RedSequence of ==>.-relation TS st (R . 1) `2 = u & (R . (len R)) `2 = <%> E holds
len R > len u
proof end;

theorem Th25: :: FSM_3:25
for E being non empty set
for u, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)}
for R being RedSequence of ==>.-relation TS st (R . 1) `2 = u ^ v & (R . (len R)) `2 = <%> E holds
ex l being Nat st
( l in dom R & (R . l) `2 = v )
proof end;

definition
let E be non empty set ;
let u, v be Element of E ^omega ;
func chop (u,v) -> Element of E ^omega means :Def9: :: FSM_3:def 9
for w being Element of E ^omega st w ^ v = u holds
it = w if ex w being Element of E ^omega st w ^ v = u
otherwise it = u;
existence
( ( ex w being Element of E ^omega st w ^ v = u implies ex b1 being Element of E ^omega st
for w being Element of E ^omega st w ^ v = u holds
b1 = w ) & ( ( for w being Element of E ^omega holds not w ^ v = u ) implies ex b1 being Element of E ^omega st b1 = u ) )
proof end;
uniqueness
for b1, b2 being Element of E ^omega holds
( ( ex w being Element of E ^omega st w ^ v = u & ( for w being Element of E ^omega st w ^ v = u holds
b1 = w ) & ( for w being Element of E ^omega st w ^ v = u holds
b2 = w ) implies b1 = b2 ) & ( ( for w being Element of E ^omega holds not w ^ v = u ) & b1 = u & b2 = u implies b1 = b2 ) )
proof end;
consistency
for b1 being Element of E ^omega holds verum
;
end;

:: deftheorem Def9 defines chop FSM_3:def 9 :
for E being non empty set
for u, v, b4 being Element of E ^omega holds
( ( ex w being Element of E ^omega st w ^ v = u implies ( b4 = chop (u,v) iff for w being Element of E ^omega st w ^ v = u holds
b4 = w ) ) & ( ( for w being Element of E ^omega holds not w ^ v = u ) implies ( b4 = chop (u,v) iff b4 = u ) ) );

theorem Th26: :: FSM_3:26
for x, y being set
for E being non empty set
for u, w, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)}
for p being RedSequence of ==>.-relation TS st p . 1 = [x,(u ^ w)] & p . (len p) = [y,(v ^ w)] holds
ex q being RedSequence of ==>.-relation TS st
( q . 1 = [x,u] & q . (len q) = [y,v] )
proof end;

theorem Th27: :: FSM_3:27
for x, y being set
for E being non empty set
for u, w, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)} st ==>.-relation TS reduces [x,(u ^ w)],[y,(v ^ w)] holds
==>.-relation TS reduces [x,u],[y,v]
proof end;

theorem Th28: :: FSM_3:28
for x, y being set
for E being non empty set
for u, w, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)} st x,u ^ w ==>* y,v ^ w,TS holds
x,u ==>* y,v,TS
proof end;

theorem Th29: :: FSM_3:29
for E being non empty set
for u, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)}
for p, q being Element of TS st p,u ^ v ==>* q,TS holds
ex r being Element of TS st
( p,u ==>* r,TS & r,v ==>* q,TS )
proof end;

theorem Th30: :: FSM_3:30
for X being set
for E being non empty set
for w, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)} holds (w ^ v) -succ_of (X,TS) = v -succ_of ((w -succ_of (X,TS)),TS)
proof end;

theorem Th31: :: FSM_3:31
for E being non empty set
for TS being non empty transition-system of (Lex E) \/ {(<%> E)} holds _bool TS is non empty transition-system of (Lex E) \/ {(<%> E)}
proof end;

theorem Th32: :: FSM_3:32
for X being set
for E being non empty set
for w, v being Element of E ^omega
for TS being non empty transition-system of (Lex E) \/ {(<%> E)} holds w -succ_of ({(v -succ_of (X,TS))},(_bool TS)) = {((v ^ w) -succ_of (X,TS))}
proof end;

theorem Th33: :: FSM_3:33
for X being set
for E being non empty set
for w being Element of E ^omega
for SA being non empty semiautomaton of (Lex E) \/ {(<%> E)} holds w -succ_of ({((<%> E) -succ_of (X,SA))},(_bool SA)) = {(w -succ_of (X,SA))}
proof end;

theorem Th34: :: FSM_3:34
for x being set
for E being non empty set
for A being non empty automaton of (Lex E) \/ {(<%> E)}
for P being Subset of A st x in the FinalS of A & x in P holds
P in the FinalS of (_bool A)
proof end;

theorem Th35: :: FSM_3:35
for X being set
for E being non empty set
for A being non empty automaton of (Lex E) \/ {(<%> E)} st X in the FinalS of (_bool A) holds
X meets the FinalS of A
proof end;

theorem Th36: :: FSM_3:36
for E being non empty set
for A being non empty automaton of (Lex E) \/ {(<%> E)} holds the InitS of (_bool A) = {((<%> E) -succ_of ( the InitS of A,A))}
proof end;

theorem Th37: :: FSM_3:37
for X being set
for E being non empty set
for w being Element of E ^omega
for A being non empty automaton of (Lex E) \/ {(<%> E)} holds w -succ_of ({((<%> E) -succ_of (X,A))},(_bool A)) = {(w -succ_of (X,A))}
proof end;

theorem Th38: :: FSM_3:38
for E being non empty set
for w being Element of E ^omega
for A being non empty automaton of (Lex E) \/ {(<%> E)} holds w -succ_of ( the InitS of (_bool A),(_bool A)) = {(w -succ_of ( the InitS of A,A))}
proof end;

theorem Th39: :: FSM_3:39
for E being non empty set
for A being non empty automaton of (Lex E) \/ {(<%> E)} holds Lang A = Lang (_bool A)
proof end;

theorem :: FSM_3:40
for E being non empty set
for A being non empty automaton of (Lex E) \/ {(<%> E)} ex DA being non empty deterministic automaton of Lex E st Lang A = Lang DA
proof end;

theorem :: FSM_3:41
for E being non empty set
for FA being non empty finite automaton of (Lex E) \/ {(<%> E)} ex DFA being non empty finite deterministic automaton of Lex E st Lang FA = Lang DFA
proof end;