:: Minimization of finite state machines
:: by Miroslava Kaloper and Piotr Rudnicki
::
:: Received November 18, 1994
:: Copyright (c) 1994-2011 Association of Mizar Users


begin

definition
let IAlph be set ;
attr c2 is strict ;
struct FSM of IAlph -> 1-sorted ;
aggr FSM(# carrier, Tran, InitS #) -> FSM of IAlph;
sel Tran c2 -> Function of [: the carrier of c2,IAlph:], the carrier of c2;
sel InitS c2 -> Element of the carrier of c2;
end;

definition
let IAlph be set ;
let fsm be FSM of IAlph;
mode State of fsm is Element of fsm;
end;

registration
let X be set ;
cluster non empty finite FSM of X;
existence
ex b1 being FSM of X st
( not b1 is empty & b1 is finite )
proof end;
end;

definition
let IAlph be non empty set ;
let fsm be non empty FSM of IAlph;
let s be Element of IAlph;
let q be State of fsm;
func s -succ_of q -> State of fsm equals :: FSM_1:def 1
the Tran of fsm . [q,s];
correctness
coherence
the Tran of fsm . [q,s] is State of fsm
;
;
end;

:: deftheorem defines -succ_of FSM_1:def 1 :
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for s being Element of IAlph
for q being State of fsm holds s -succ_of q = the Tran of fsm . [q,s];

definition
let IAlph be non empty set ;
let fsm be non empty FSM of IAlph;
let q be State of fsm;
let w be FinSequence of IAlph;
func (q,w) -admissible -> FinSequence of the carrier of fsm means :Def2: :: FSM_1:def 2
( it . 1 = q & len it = (len w) + 1 & ( for i being Nat st 1 <= i & i <= len w holds
ex wi being Element of IAlph ex qi, qi1 being State of fsm st
( wi = w . i & qi = it . i & qi1 = it . (i + 1) & wi -succ_of qi = qi1 ) ) );
existence
ex b1 being FinSequence of the carrier of fsm st
( b1 . 1 = q & len b1 = (len w) + 1 & ( for i being Nat st 1 <= i & i <= len w holds
ex wi being Element of IAlph ex qi, qi1 being State of fsm st
( wi = w . i & qi = b1 . i & qi1 = b1 . (i + 1) & wi -succ_of qi = qi1 ) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of the carrier of fsm st b1 . 1 = q & len b1 = (len w) + 1 & ( for i being Nat st 1 <= i & i <= len w holds
ex wi being Element of IAlph ex qi, qi1 being State of fsm st
( wi = w . i & qi = b1 . i & qi1 = b1 . (i + 1) & wi -succ_of qi = qi1 ) ) & b2 . 1 = q & len b2 = (len w) + 1 & ( for i being Nat st 1 <= i & i <= len w holds
ex wi being Element of IAlph ex qi, qi1 being State of fsm st
( wi = w . i & qi = b2 . i & qi1 = b2 . (i + 1) & wi -succ_of qi = qi1 ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines -admissible FSM_1:def 2 :
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for q being State of fsm
for w being FinSequence of IAlph
for b5 being FinSequence of the carrier of fsm holds
( b5 = (q,w) -admissible iff ( b5 . 1 = q & len b5 = (len w) + 1 & ( for i being Nat st 1 <= i & i <= len w holds
ex wi being Element of IAlph ex qi, qi1 being State of fsm st
( wi = w . i & qi = b5 . i & qi1 = b5 . (i + 1) & wi -succ_of qi = qi1 ) ) ) );

theorem :: FSM_1:1
canceled;

theorem :: FSM_1:2
canceled;

theorem :: FSM_1:3
canceled;

theorem :: FSM_1:4
canceled;

theorem :: FSM_1:5
canceled;

theorem :: FSM_1:6
canceled;

theorem :: FSM_1:7
canceled;

theorem :: FSM_1:8
canceled;

theorem :: FSM_1:9
canceled;

theorem :: FSM_1:10
canceled;

theorem :: FSM_1:11
canceled;

theorem :: FSM_1:12
canceled;

theorem :: FSM_1:13
canceled;

theorem :: FSM_1:14
canceled;

theorem :: FSM_1:15
canceled;

theorem Th16: :: FSM_1:16
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for q being State of fsm holds (q,(<*> IAlph)) -admissible = <*q*>
proof end;

definition
let IAlph be non empty set ;
let fsm be non empty FSM of IAlph;
let w be FinSequence of IAlph;
let q1, q2 be State of fsm;
pred q1,w -leads_to q2 means :Def3: :: FSM_1:def 3
((q1,w) -admissible) . ((len w) + 1) = q2;
end;

:: deftheorem Def3 defines -leads_to FSM_1:def 3 :
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w being FinSequence of IAlph
for q1, q2 being State of fsm holds
( q1,w -leads_to q2 iff ((q1,w) -admissible) . ((len w) + 1) = q2 );

theorem Th17: :: FSM_1:17
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for q being State of fsm holds q, <*> IAlph -leads_to q
proof end;

definition
let IAlph be non empty set ;
let fsm be non empty FSM of IAlph;
let w be FinSequence of IAlph;
let qseq be FinSequence of the carrier of fsm;
pred qseq is_admissible_for w means :Def4: :: FSM_1:def 4
ex q1 being State of fsm st
( q1 = qseq . 1 & (q1,w) -admissible = qseq );
end;

:: deftheorem Def4 defines is_admissible_for FSM_1:def 4 :
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w being FinSequence of IAlph
for qseq being FinSequence of the carrier of fsm holds
( qseq is_admissible_for w iff ex q1 being State of fsm st
( q1 = qseq . 1 & (q1,w) -admissible = qseq ) );

theorem :: FSM_1:18
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for q being State of fsm holds <*q*> is_admissible_for <*> IAlph
proof end;

definition
let IAlph be non empty set ;
let fsm be non empty FSM of IAlph;
let q be State of fsm;
let w be FinSequence of IAlph;
func q leads_to_under w -> State of fsm means :Def5: :: FSM_1:def 5
q,w -leads_to it;
existence
ex b1 being State of fsm st q,w -leads_to b1
proof end;
uniqueness
for b1, b2 being State of fsm st q,w -leads_to b1 & q,w -leads_to b2 holds
b1 = b2
proof end;
end;

:: deftheorem Def5 defines leads_to_under FSM_1:def 5 :
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for q being State of fsm
for w being FinSequence of IAlph
for b5 being State of fsm holds
( b5 = q leads_to_under w iff q,w -leads_to b5 );

theorem Th19: :: FSM_1:19
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w being FinSequence of IAlph
for q, q9 being State of fsm holds
( ((q,w) -admissible) . (len ((q,w) -admissible)) = q9 iff q,w -leads_to q9 )
proof end;

theorem Th20: :: FSM_1:20
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w1, w2 being FinSequence of IAlph
for q1 being State of fsm
for k being Element of NAT st 1 <= k & k <= len w1 holds
((q1,(w1 ^ w2)) -admissible) . k = ((q1,w1) -admissible) . k
proof end;

theorem Th21: :: FSM_1:21
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w1, w2 being FinSequence of IAlph
for q1, q2 being State of fsm st q1,w1 -leads_to q2 holds
((q1,(w1 ^ w2)) -admissible) . ((len w1) + 1) = q2
proof end;

theorem Th22: :: FSM_1:22
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w1, w2 being FinSequence of IAlph
for q1, q2 being State of fsm st q1,w1 -leads_to q2 holds
for k being Element of NAT st 1 <= k & k <= (len w2) + 1 holds
((q1,(w1 ^ w2)) -admissible) . ((len w1) + k) = ((q2,w2) -admissible) . k
proof end;

theorem Th23: :: FSM_1:23
for IAlph being non empty set
for fsm being non empty FSM of IAlph
for w1, w2 being FinSequence of IAlph
for q1, q2 being State of fsm st q1,w1 -leads_to q2 holds
(q1,(w1 ^ w2)) -admissible = (Del (((q1,w1) -admissible),((len w1) + 1))) ^ ((q2,w2) -admissible)
proof end;

begin

definition
let IAlph be set ;
let OAlph be non empty set ;
attr c3 is strict ;
struct Mealy-FSM of IAlph,OAlph -> FSM of IAlph;
aggr Mealy-FSM(# carrier, Tran, OFun, InitS #) -> Mealy-FSM of IAlph,OAlph;
sel OFun c3 -> Function of [: the carrier of c3,IAlph:],OAlph;
attr c3 is strict ;
struct Moore-FSM of IAlph,OAlph -> FSM of IAlph;
aggr Moore-FSM(# carrier, Tran, OFun, InitS #) -> Moore-FSM of IAlph,OAlph;
sel OFun c3 -> Function of the carrier of c3,OAlph;
end;

registration
let IAlph be set ;
let X be non empty finite set ;
let T be Function of [:X,IAlph:],X;
let I be Element of X;
cluster FSM(# X,T,I #) -> non empty finite ;
coherence
( FSM(# X,T,I #) is finite & not FSM(# X,T,I #) is empty )
;
end;

registration
let IAlph be set ;
let OAlph be non empty set ;
let X be non empty finite set ;
let T be Function of [:X,IAlph:],X;
let O be Function of [:X,IAlph:],OAlph;
let I be Element of X;
cluster Mealy-FSM(# X,T,O,I #) -> non empty finite ;
coherence
( Mealy-FSM(# X,T,O,I #) is finite & not Mealy-FSM(# X,T,O,I #) is empty )
;
end;

registration
let IAlph be set ;
let OAlph be non empty set ;
let X be non empty finite set ;
let T be Function of [:X,IAlph:],X;
let O be Function of X,OAlph;
let I be Element of X;
cluster Moore-FSM(# X,T,O,I #) -> non empty finite ;
coherence
( Moore-FSM(# X,T,O,I #) is finite & not Moore-FSM(# X,T,O,I #) is empty )
;
end;

registration
let IAlph be set ;
let OAlph be non empty set ;
cluster non empty finite Mealy-FSM of IAlph,OAlph;
existence
ex b1 being Mealy-FSM of IAlph,OAlph st
( b1 is finite & not b1 is empty )
proof end;
cluster non empty finite Moore-FSM of IAlph,OAlph;
existence
ex b1 being Moore-FSM of IAlph,OAlph st
( b1 is finite & not b1 is empty )
proof end;
end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let qt be State of tfsm;
let w be FinSequence of IAlph;
func (qt,w) -response -> FinSequence of OAlph means :Def6: :: FSM_1:def 6
( len it = len w & ( for i being Element of NAT st i in dom w holds
it . i = the OFun of tfsm . [(((qt,w) -admissible) . i),(w . i)] ) );
existence
ex b1 being FinSequence of OAlph st
( len b1 = len w & ( for i being Element of NAT st i in dom w holds
b1 . i = the OFun of tfsm . [(((qt,w) -admissible) . i),(w . i)] ) )
proof end;
uniqueness
for b1, b2 being FinSequence of OAlph st len b1 = len w & ( for i being Element of NAT st i in dom w holds
b1 . i = the OFun of tfsm . [(((qt,w) -admissible) . i),(w . i)] ) & len b2 = len w & ( for i being Element of NAT st i in dom w holds
b2 . i = the OFun of tfsm . [(((qt,w) -admissible) . i),(w . i)] ) holds
b1 = b2
proof end;
end;

:: deftheorem Def6 defines -response FSM_1:def 6 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qt being State of tfsm
for w being FinSequence of IAlph
for b6 being FinSequence of OAlph holds
( b6 = (qt,w) -response iff ( len b6 = len w & ( for i being Element of NAT st i in dom w holds
b6 . i = the OFun of tfsm . [(((qt,w) -admissible) . i),(w . i)] ) ) );

theorem Th24: :: FSM_1:24
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qt being State of tfsm holds (qt,(<*> IAlph)) -response = <*> OAlph
proof end;

definition
let IAlph, OAlph be non empty set ;
let sfsm be non empty Moore-FSM of IAlph,OAlph;
let qs be State of sfsm;
let w be FinSequence of IAlph;
func (qs,w) -response -> FinSequence of OAlph means :Def7: :: FSM_1:def 7
( len it = (len w) + 1 & ( for i being Element of NAT st i in Seg ((len w) + 1) holds
it . i = the OFun of sfsm . (((qs,w) -admissible) . i) ) );
existence
ex b1 being FinSequence of OAlph st
( len b1 = (len w) + 1 & ( for i being Element of NAT st i in Seg ((len w) + 1) holds
b1 . i = the OFun of sfsm . (((qs,w) -admissible) . i) ) )
proof end;
uniqueness
for b1, b2 being FinSequence of OAlph st len b1 = (len w) + 1 & ( for i being Element of NAT st i in Seg ((len w) + 1) holds
b1 . i = the OFun of sfsm . (((qs,w) -admissible) . i) ) & len b2 = (len w) + 1 & ( for i being Element of NAT st i in Seg ((len w) + 1) holds
b2 . i = the OFun of sfsm . (((qs,w) -admissible) . i) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def7 defines -response FSM_1:def 7 :
for IAlph, OAlph being non empty set
for sfsm being non empty Moore-FSM of IAlph,OAlph
for qs being State of sfsm
for w being FinSequence of IAlph
for b6 being FinSequence of OAlph holds
( b6 = (qs,w) -response iff ( len b6 = (len w) + 1 & ( for i being Element of NAT st i in Seg ((len w) + 1) holds
b6 . i = the OFun of sfsm . (((qs,w) -admissible) . i) ) ) );

theorem Th25: :: FSM_1:25
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for sfsm being non empty Moore-FSM of IAlph,OAlph
for qs being State of sfsm holds ((qs,w) -response) . 1 = the OFun of sfsm . qs
proof end;

theorem Th26: :: FSM_1:26
for IAlph, OAlph being non empty set
for w1, w2 being FinSequence of IAlph
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for q1t, q2t being State of tfsm st q1t,w1 -leads_to q2t holds
(q1t,(w1 ^ w2)) -response = ((q1t,w1) -response) ^ ((q2t,w2) -response)
proof end;

theorem Th27: :: FSM_1:27
for IAlph, OAlph being non empty set
for w1, w2 being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q11, q12 being State of tfsm1
for q21, q22 being State of tfsm2 st q11,w1 -leads_to q12 & q21,w1 -leads_to q22 & (q12,w2) -response <> (q22,w2) -response holds
(q11,(w1 ^ w2)) -response <> (q21,(w1 ^ w2)) -response
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let sfsm be non empty Moore-FSM of IAlph,OAlph;
pred tfsm is_similar_to sfsm means :: FSM_1:def 8
for tw being FinSequence of IAlph holds <*( the OFun of sfsm . the InitS of sfsm)*> ^ (( the InitS of tfsm,tw) -response) = ( the InitS of sfsm,tw) -response ;
end;

:: deftheorem defines is_similar_to FSM_1:def 8 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for sfsm being non empty Moore-FSM of IAlph,OAlph holds
( tfsm is_similar_to sfsm iff for tw being FinSequence of IAlph holds <*( the OFun of sfsm . the InitS of sfsm)*> ^ (( the InitS of tfsm,tw) -response) = ( the InitS of sfsm,tw) -response );

theorem :: FSM_1:28
for IAlph, OAlph being non empty set
for sfsm being non empty finite Moore-FSM of IAlph,OAlph ex tfsm being non empty finite Mealy-FSM of IAlph,OAlph st tfsm is_similar_to sfsm
proof end;

theorem :: FSM_1:29
for IAlph being non empty set
for OAlphf being non empty finite set
for tfsmf being non empty finite Mealy-FSM of IAlph,OAlphf ex sfsmf being non empty finite Moore-FSM of IAlph,OAlphf st tfsmf is_similar_to sfsmf
proof end;

begin

definition
let IAlph, OAlph be non empty set ;
let tfsm1, tfsm2 be non empty Mealy-FSM of IAlph,OAlph;
pred tfsm1,tfsm2 -are_equivalent means :Def9: :: FSM_1:def 9
for w being FinSequence of IAlph holds ( the InitS of tfsm1,w) -response = ( the InitS of tfsm2,w) -response ;
reflexivity
for tfsm1 being non empty Mealy-FSM of IAlph,OAlph
for w being FinSequence of IAlph holds ( the InitS of tfsm1,w) -response = ( the InitS of tfsm1,w) -response
;
symmetry
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph st ( for w being FinSequence of IAlph holds ( the InitS of tfsm1,w) -response = ( the InitS of tfsm2,w) -response ) holds
for w being FinSequence of IAlph holds ( the InitS of tfsm2,w) -response = ( the InitS of tfsm1,w) -response
;
end;

:: deftheorem Def9 defines -are_equivalent FSM_1:def 9 :
for IAlph, OAlph being non empty set
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph holds
( tfsm1,tfsm2 -are_equivalent iff for w being FinSequence of IAlph holds ( the InitS of tfsm1,w) -response = ( the InitS of tfsm2,w) -response );

theorem Th30: :: FSM_1:30
for IAlph, OAlph being non empty set
for tfsm1, tfsm2, tfsm3 being non empty Mealy-FSM of IAlph,OAlph st tfsm1,tfsm2 -are_equivalent & tfsm2,tfsm3 -are_equivalent holds
tfsm1,tfsm3 -are_equivalent
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let qa, qb be State of tfsm;
pred qa,qb -are_equivalent means :Def10: :: FSM_1:def 10
for w being FinSequence of IAlph holds (qa,w) -response = (qb,w) -response ;
reflexivity
for qa being State of tfsm
for w being FinSequence of IAlph holds (qa,w) -response = (qa,w) -response
;
symmetry
for qa, qb being State of tfsm st ( for w being FinSequence of IAlph holds (qa,w) -response = (qb,w) -response ) holds
for w being FinSequence of IAlph holds (qb,w) -response = (qa,w) -response
;
end;

:: deftheorem Def10 defines -are_equivalent FSM_1:def 10 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm holds
( qa,qb -are_equivalent iff for w being FinSequence of IAlph holds (qa,w) -response = (qb,w) -response );

theorem :: FSM_1:31
canceled;

theorem :: FSM_1:32
canceled;

theorem :: FSM_1:33
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for q1, q2, q3 being State of tfsm st q1,q2 -are_equivalent & q2,q3 -are_equivalent holds
q1,q3 -are_equivalent
proof end;

theorem Th34: :: FSM_1:34
for IAlph, OAlph being non empty set
for s being Element of IAlph
for w being FinSequence of IAlph
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa9, qa being State of tfsm st qa9 = the Tran of tfsm . [qa,s] holds
for i being Element of NAT st i in Seg ((len w) + 1) holds
((qa,(<*s*> ^ w)) -admissible) . (i + 1) = ((qa9,w) -admissible) . i
proof end;

theorem Th35: :: FSM_1:35
for IAlph, OAlph being non empty set
for s being Element of IAlph
for w being FinSequence of IAlph
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa9, qa being State of tfsm st qa9 = the Tran of tfsm . [qa,s] holds
(qa,(<*s*> ^ w)) -response = <*( the OFun of tfsm . [qa,s])*> ^ ((qa9,w) -response)
proof end;

theorem Th36: :: FSM_1:36
for OAlph, IAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm holds
( qa,qb -are_equivalent iff for s being Element of IAlph holds
( the OFun of tfsm . [qa,s] = the OFun of tfsm . [qb,s] & the Tran of tfsm . [qa,s], the Tran of tfsm . [qb,s] -are_equivalent ) )
proof end;

theorem :: FSM_1:37
for OAlph, IAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm st qa,qb -are_equivalent holds
for w being FinSequence of IAlph
for i being Element of NAT st i in dom w holds
ex qai, qbi being State of tfsm st
( qai = ((qa,w) -admissible) . i & qbi = ((qb,w) -admissible) . i & qai,qbi -are_equivalent )
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let qa, qb be State of tfsm;
let k be Nat;
pred k -equivalent qa,qb means :Def11: :: FSM_1:def 11
for w being FinSequence of IAlph st len w <= k holds
(qa,w) -response = (qb,w) -response ;
end;

:: deftheorem Def11 defines -equivalent FSM_1:def 11 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm
for k being Nat holds
( k -equivalent qa,qb iff for w being FinSequence of IAlph st len w <= k holds
(qa,w) -response = (qb,w) -response );

theorem Th38: :: FSM_1:38
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa being State of tfsm
for k being Nat holds k -equivalent qa,qa
proof end;

theorem Th39: :: FSM_1:39
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm
for k being Nat st k -equivalent qa,qb holds
k -equivalent qb,qa
proof end;

theorem Th40: :: FSM_1:40
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb, qc being State of tfsm
for k being Nat st k -equivalent qa,qb & k -equivalent qb,qc holds
k -equivalent qa,qc
proof end;

theorem Th41: :: FSM_1:41
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm st qa,qb -are_equivalent holds
k -equivalent qa,qb
proof end;

theorem Th42: :: FSM_1:42
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm holds 0 -equivalent qa,qb
proof end;

theorem Th43: :: FSM_1:43
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm
for k, m being Nat st k + m -equivalent qa,qb holds
k -equivalent qa,qb
proof end;

theorem Th44: :: FSM_1:44
for OAlph, IAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for qa, qb being State of tfsm
for k being Nat st 1 <= k holds
( k -equivalent qa,qb iff ( 1 -equivalent qa,qb & ( for s being Element of IAlph
for k1 being Element of NAT st k1 = k - 1 holds
k1 -equivalent the Tran of tfsm . [qa,s], the Tran of tfsm . [qb,s] ) ) )
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let i be Nat;
func i -eq_states_EqR tfsm -> Equivalence_Relation of the carrier of tfsm means :Def12: :: FSM_1:def 12
for qa, qb being State of tfsm holds
( [qa,qb] in it iff i -equivalent qa,qb );
existence
ex b1 being Equivalence_Relation of the carrier of tfsm st
for qa, qb being State of tfsm holds
( [qa,qb] in b1 iff i -equivalent qa,qb )
proof end;
uniqueness
for b1, b2 being Equivalence_Relation of the carrier of tfsm st ( for qa, qb being State of tfsm holds
( [qa,qb] in b1 iff i -equivalent qa,qb ) ) & ( for qa, qb being State of tfsm holds
( [qa,qb] in b2 iff i -equivalent qa,qb ) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def12 defines -eq_states_EqR FSM_1:def 12 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for i being Nat
for b5 being Equivalence_Relation of the carrier of tfsm holds
( b5 = i -eq_states_EqR tfsm iff for qa, qb being State of tfsm holds
( [qa,qb] in b5 iff i -equivalent qa,qb ) );

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let i be Nat;
func i -eq_states_partition tfsm -> non empty a_partition of the carrier of tfsm equals :: FSM_1:def 13
Class (i -eq_states_EqR tfsm);
coherence
Class (i -eq_states_EqR tfsm) is non empty a_partition of the carrier of tfsm
;
end;

:: deftheorem defines -eq_states_partition FSM_1:def 13 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for i being Nat holds i -eq_states_partition tfsm = Class (i -eq_states_EqR tfsm);

theorem Th45: :: FSM_1:45
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph holds (k + 1) -eq_states_partition tfsm is_finer_than k -eq_states_partition tfsm
proof end;

theorem Th46: :: FSM_1:46
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for k being Nat st Class (k -eq_states_EqR tfsm) = Class ((k + 1) -eq_states_EqR tfsm) holds
for m being Nat holds Class ((k + m) -eq_states_EqR tfsm) = Class (k -eq_states_EqR tfsm)
proof end;

theorem :: FSM_1:47
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph st k -eq_states_partition tfsm = (k + 1) -eq_states_partition tfsm holds
for m being Element of NAT holds (k + m) -eq_states_partition tfsm = k -eq_states_partition tfsm by Th46;

theorem Th48: :: FSM_1:48
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph st (k + 1) -eq_states_partition tfsm <> k -eq_states_partition tfsm holds
for i being Element of NAT st i <= k holds
(i + 1) -eq_states_partition tfsm <> i -eq_states_partition tfsm
proof end;

theorem Th49: :: FSM_1:49
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph holds
( k -eq_states_partition tfsm = (k + 1) -eq_states_partition tfsm or card (k -eq_states_partition tfsm) < card ((k + 1) -eq_states_partition tfsm) )
proof end;

theorem Th50: :: FSM_1:50
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for q being State of tfsm holds Class ((0 -eq_states_EqR tfsm),q) = the carrier of tfsm
proof end;

theorem :: FSM_1:51
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph holds 0 -eq_states_partition tfsm = { the carrier of tfsm}
proof end;

theorem Th52: :: FSM_1:52
for n being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph st n + 1 = card the carrier of tfsm holds
(n + 1) -eq_states_partition tfsm = n -eq_states_partition tfsm
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let IT be a_partition of the carrier of tfsm;
attr IT is final means :Def14: :: FSM_1:def 14
for qa, qb being State of tfsm holds
( qa,qb -are_equivalent iff ex X being Element of IT st
( qa in X & qb in X ) );
end;

:: deftheorem Def14 defines final FSM_1:def 14 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for IT being a_partition of the carrier of tfsm holds
( IT is final iff for qa, qb being State of tfsm holds
( qa,qb -are_equivalent iff ex X being Element of IT st
( qa in X & qb in X ) ) );

theorem :: FSM_1:53
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph st k -eq_states_partition tfsm is final holds
(k + 1) -eq_states_EqR tfsm = k -eq_states_EqR tfsm
proof end;

theorem Th54: :: FSM_1:54
for k being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph st k -eq_states_partition tfsm = (k + 1) -eq_states_partition tfsm holds
k -eq_states_partition tfsm is final
proof end;

theorem :: FSM_1:55
for n being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph st n + 1 = card the carrier of tfsm holds
ex k being Element of NAT st
( k <= n & k -eq_states_partition tfsm is final )
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
func final_states_partition tfsm -> a_partition of the carrier of tfsm means :Def15: :: FSM_1:def 15
it is final ;
existence
ex b1 being a_partition of the carrier of tfsm st b1 is final
proof end;
uniqueness
for b1, b2 being a_partition of the carrier of tfsm st b1 is final & b2 is final holds
b1 = b2
proof end;
end;

:: deftheorem Def15 defines final_states_partition FSM_1:def 15 :
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for b4 being a_partition of the carrier of tfsm holds
( b4 = final_states_partition tfsm iff b4 is final );

theorem Th56: :: FSM_1:56
for n being Element of NAT
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph st n + 1 = card the carrier of tfsm holds
final_states_partition tfsm = n -eq_states_partition tfsm
proof end;

begin

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
let qf be Element of final_states_partition tfsm;
let s be Element of IAlph;
func (s,qf) -succ_class -> Element of final_states_partition tfsm means :Def16: :: FSM_1:def 16
ex q being State of tfsm ex n being Element of NAT st
( q in qf & n + 1 = card the carrier of tfsm & it = Class ((n -eq_states_EqR tfsm),( the Tran of tfsm . [q,s])) );
existence
ex b1 being Element of final_states_partition tfsm ex q being State of tfsm ex n being Element of NAT st
( q in qf & n + 1 = card the carrier of tfsm & b1 = Class ((n -eq_states_EqR tfsm),( the Tran of tfsm . [q,s])) )
proof end;
uniqueness
for b1, b2 being Element of final_states_partition tfsm st ex q being State of tfsm ex n being Element of NAT st
( q in qf & n + 1 = card the carrier of tfsm & b1 = Class ((n -eq_states_EqR tfsm),( the Tran of tfsm . [q,s])) ) & ex q being State of tfsm ex n being Element of NAT st
( q in qf & n + 1 = card the carrier of tfsm & b2 = Class ((n -eq_states_EqR tfsm),( the Tran of tfsm . [q,s])) ) holds
b1 = b2
proof end;
end;

:: deftheorem Def16 defines -succ_class FSM_1:def 16 :
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for qf being Element of final_states_partition tfsm
for s being Element of IAlph
for b6 being Element of final_states_partition tfsm holds
( b6 = (s,qf) -succ_class iff ex q being State of tfsm ex n being Element of NAT st
( q in qf & n + 1 = card the carrier of tfsm & b6 = Class ((n -eq_states_EqR tfsm),( the Tran of tfsm . [q,s])) ) );

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
let qf be Element of final_states_partition tfsm;
let s be Element of IAlph;
func (qf,s) -class_response -> Element of OAlph means :Def17: :: FSM_1:def 17
ex q being State of tfsm st
( q in qf & it = the OFun of tfsm . [q,s] );
existence
ex b1 being Element of OAlph ex q being State of tfsm st
( q in qf & b1 = the OFun of tfsm . [q,s] )
proof end;
uniqueness
for b1, b2 being Element of OAlph st ex q being State of tfsm st
( q in qf & b1 = the OFun of tfsm . [q,s] ) & ex q being State of tfsm st
( q in qf & b2 = the OFun of tfsm . [q,s] ) holds
b1 = b2
proof end;
end;

:: deftheorem Def17 defines -class_response FSM_1:def 17 :
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for qf being Element of final_states_partition tfsm
for s being Element of IAlph
for b6 being Element of OAlph holds
( b6 = (qf,s) -class_response iff ex q being State of tfsm st
( q in qf & b6 = the OFun of tfsm . [q,s] ) );

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
func the_reduction_of tfsm -> strict Mealy-FSM of IAlph,OAlph means :Def18: :: FSM_1:def 18
( the carrier of it = final_states_partition tfsm & ( for Q being State of it
for s being Element of IAlph
for q being State of tfsm st q in Q holds
( the Tran of tfsm . (q,s) in the Tran of it . (Q,s) & the OFun of tfsm . (q,s) = the OFun of it . (Q,s) ) ) & the InitS of tfsm in the InitS of it );
existence
ex b1 being strict Mealy-FSM of IAlph,OAlph st
( the carrier of b1 = final_states_partition tfsm & ( for Q being State of b1
for s being Element of IAlph
for q being State of tfsm st q in Q holds
( the Tran of tfsm . (q,s) in the Tran of b1 . (Q,s) & the OFun of tfsm . (q,s) = the OFun of b1 . (Q,s) ) ) & the InitS of tfsm in the InitS of b1 )
proof end;
uniqueness
for b1, b2 being strict Mealy-FSM of IAlph,OAlph st the carrier of b1 = final_states_partition tfsm & ( for Q being State of b1
for s being Element of IAlph
for q being State of tfsm st q in Q holds
( the Tran of tfsm . (q,s) in the Tran of b1 . (Q,s) & the OFun of tfsm . (q,s) = the OFun of b1 . (Q,s) ) ) & the InitS of tfsm in the InitS of b1 & the carrier of b2 = final_states_partition tfsm & ( for Q being State of b2
for s being Element of IAlph
for q being State of tfsm st q in Q holds
( the Tran of tfsm . (q,s) in the Tran of b2 . (Q,s) & the OFun of tfsm . (q,s) = the OFun of b2 . (Q,s) ) ) & the InitS of tfsm in the InitS of b2 holds
b1 = b2
proof end;
end;

:: deftheorem Def18 defines the_reduction_of FSM_1:def 18 :
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for b4 being strict Mealy-FSM of IAlph,OAlph holds
( b4 = the_reduction_of tfsm iff ( the carrier of b4 = final_states_partition tfsm & ( for Q being State of b4
for s being Element of IAlph
for q being State of tfsm st q in Q holds
( the Tran of tfsm . (q,s) in the Tran of b4 . (Q,s) & the OFun of tfsm . (q,s) = the OFun of b4 . (Q,s) ) ) & the InitS of tfsm in the InitS of b4 ) );

registration
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
cluster the_reduction_of tfsm -> non empty finite strict ;
coherence
( not the_reduction_of tfsm is empty & the_reduction_of tfsm is finite )
proof end;
end;

theorem Th57: :: FSM_1:57
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for rtfsm, tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for q being State of tfsm
for qr being State of rtfsm st rtfsm = the_reduction_of tfsm & q in qr holds
for k being Element of NAT st k in Seg ((len w) + 1) holds
((q,w) -admissible) . k in ((qr,w) -admissible) . k
proof end;

theorem Th58: :: FSM_1:58
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph holds tfsm, the_reduction_of tfsm -are_equivalent
proof end;

begin

definition
let IAlph, OAlph be non empty set ;
let tfsm1, tfsm2 be non empty Mealy-FSM of IAlph,OAlph;
pred tfsm1,tfsm2 -are_isomorphic means :Def19: :: FSM_1:def 19
ex Tf being Function of the carrier of tfsm1, the carrier of tfsm2 st
( Tf is bijective & Tf . the InitS of tfsm1 = the InitS of tfsm2 & ( for q11 being State of tfsm1
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm1 . (q11,s)) = the Tran of tfsm2 . ((Tf . q11),s) & the OFun of tfsm1 . (q11,s) = the OFun of tfsm2 . ((Tf . q11),s) ) ) );
reflexivity
for tfsm1 being non empty Mealy-FSM of IAlph,OAlph ex Tf being Function of the carrier of tfsm1, the carrier of tfsm1 st
( Tf is bijective & Tf . the InitS of tfsm1 = the InitS of tfsm1 & ( for q11 being State of tfsm1
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm1 . (q11,s)) = the Tran of tfsm1 . ((Tf . q11),s) & the OFun of tfsm1 . (q11,s) = the OFun of tfsm1 . ((Tf . q11),s) ) ) )
proof end;
symmetry
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph st ex Tf being Function of the carrier of tfsm1, the carrier of tfsm2 st
( Tf is bijective & Tf . the InitS of tfsm1 = the InitS of tfsm2 & ( for q11 being State of tfsm1
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm1 . (q11,s)) = the Tran of tfsm2 . ((Tf . q11),s) & the OFun of tfsm1 . (q11,s) = the OFun of tfsm2 . ((Tf . q11),s) ) ) ) holds
ex Tf being Function of the carrier of tfsm2, the carrier of tfsm1 st
( Tf is bijective & Tf . the InitS of tfsm2 = the InitS of tfsm1 & ( for q11 being State of tfsm2
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm2 . (q11,s)) = the Tran of tfsm1 . ((Tf . q11),s) & the OFun of tfsm2 . (q11,s) = the OFun of tfsm1 . ((Tf . q11),s) ) ) )
proof end;
end;

:: deftheorem Def19 defines -are_isomorphic FSM_1:def 19 :
for IAlph, OAlph being non empty set
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph holds
( tfsm1,tfsm2 -are_isomorphic iff ex Tf being Function of the carrier of tfsm1, the carrier of tfsm2 st
( Tf is bijective & Tf . the InitS of tfsm1 = the InitS of tfsm2 & ( for q11 being State of tfsm1
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm1 . (q11,s)) = the Tran of tfsm2 . ((Tf . q11),s) & the OFun of tfsm1 . (q11,s) = the OFun of tfsm2 . ((Tf . q11),s) ) ) ) );

theorem Th59: :: FSM_1:59
for IAlph, OAlph being non empty set
for tfsm1, tfsm2, tfsm3 being non empty Mealy-FSM of IAlph,OAlph st tfsm1,tfsm2 -are_isomorphic & tfsm2,tfsm3 -are_isomorphic holds
tfsm1,tfsm3 -are_isomorphic
proof end;

theorem Th60: :: FSM_1:60
for OAlph, IAlph being non empty set
for w being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q11 being State of tfsm1
for Tf being Function of the carrier of tfsm1, the carrier of tfsm2 st ( for q being State of tfsm1
for s being Element of IAlph holds Tf . ( the Tran of tfsm1 . (q,s)) = the Tran of tfsm2 . ((Tf . q),s) ) holds
for k being Element of NAT st 1 <= k & k <= (len w) + 1 holds
Tf . (((q11,w) -admissible) . k) = (((Tf . q11),w) -admissible) . k
proof end;

theorem Th61: :: FSM_1:61
for OAlph, IAlph being non empty set
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q11, q12 being State of tfsm1
for Tf being Function of the carrier of tfsm1, the carrier of tfsm2 st ( for q being State of tfsm1
for s being Element of IAlph holds
( Tf . ( the Tran of tfsm1 . (q,s)) = the Tran of tfsm2 . ((Tf . q),s) & the OFun of tfsm1 . (q,s) = the OFun of tfsm2 . ((Tf . q),s) ) ) holds
( q11,q12 -are_equivalent iff Tf . q11,Tf . q12 -are_equivalent )
proof end;

theorem Th62: :: FSM_1:62
for IAlph, OAlph being non empty set
for rtfsm, tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for qr1, qr2 being State of rtfsm st rtfsm = the_reduction_of tfsm & qr1 <> qr2 holds
not qr1,qr2 -are_equivalent
proof end;

begin

definition
let IAlph, OAlph be non empty set ;
let IT be non empty Mealy-FSM of IAlph,OAlph;
attr IT is reduced means :Def20: :: FSM_1:def 20
for qa, qb being State of IT st qa <> qb holds
not qa,qb -are_equivalent ;
end;

:: deftheorem Def20 defines reduced FSM_1:def 20 :
for IAlph, OAlph being non empty set
for IT being non empty Mealy-FSM of IAlph,OAlph holds
( IT is reduced iff for qa, qb being State of IT st qa <> qb holds
not qa,qb -are_equivalent );

theorem :: FSM_1:63
canceled;

registration
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
cluster the_reduction_of tfsm -> strict reduced ;
coherence
the_reduction_of tfsm is reduced
proof end;
end;

registration
let IAlph, OAlph be non empty set ;
cluster non empty finite reduced Mealy-FSM of IAlph,OAlph;
existence
ex b1 being non empty Mealy-FSM of IAlph,OAlph st
( b1 is reduced & b1 is finite )
proof end;
end;

theorem Th64: :: FSM_1:64
for IAlph, OAlph being non empty set
for Rtfsm being non empty finite reduced Mealy-FSM of IAlph,OAlph holds Rtfsm, the_reduction_of Rtfsm -are_isomorphic
proof end;

theorem Th65: :: FSM_1:65
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph holds
( tfsm is reduced iff ex M being non empty finite Mealy-FSM of IAlph,OAlph st tfsm, the_reduction_of M -are_isomorphic )
proof end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
let IT be State of tfsm;
attr IT is accessible means :Def21: :: FSM_1:def 21
ex w being FinSequence of IAlph st the InitS of tfsm,w -leads_to IT;
end;

:: deftheorem Def21 defines accessible FSM_1:def 21 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph
for IT being State of tfsm holds
( IT is accessible iff ex w being FinSequence of IAlph st the InitS of tfsm,w -leads_to IT );

definition
let IAlph, OAlph be non empty set ;
let IT be non empty Mealy-FSM of IAlph,OAlph;
attr IT is connected means :Def22: :: FSM_1:def 22
for q being State of IT holds q is accessible ;
end;

:: deftheorem Def22 defines connected FSM_1:def 22 :
for IAlph, OAlph being non empty set
for IT being non empty Mealy-FSM of IAlph,OAlph holds
( IT is connected iff for q being State of IT holds q is accessible );

registration
let IAlph, OAlph be non empty set ;
cluster non empty finite connected Mealy-FSM of IAlph,OAlph;
existence
ex b1 being non empty finite Mealy-FSM of IAlph,OAlph st b1 is connected
proof end;
end;

theorem :: FSM_1:66
canceled;

registration
let IAlph, OAlph be non empty set ;
let Ctfsm be non empty finite connected Mealy-FSM of IAlph,OAlph;
cluster the_reduction_of Ctfsm -> strict connected ;
coherence
the_reduction_of Ctfsm is connected
proof end;
end;

registration
let IAlph, OAlph be non empty set ;
cluster non empty finite reduced connected Mealy-FSM of IAlph,OAlph;
existence
ex b1 being non empty Mealy-FSM of IAlph,OAlph st
( b1 is connected & b1 is reduced & b1 is finite )
proof end;
end;

definition
let IAlph, OAlph be non empty set ;
let tfsm be non empty Mealy-FSM of IAlph,OAlph;
func accessibleStates tfsm -> set equals :: FSM_1:def 23
{ q where q is State of tfsm : q is accessible } ;
coherence
{ q where q is State of tfsm : q is accessible } is set
;
end;

:: deftheorem defines accessibleStates FSM_1:def 23 :
for IAlph, OAlph being non empty set
for tfsm being non empty Mealy-FSM of IAlph,OAlph holds accessibleStates tfsm = { q where q is State of tfsm : q is accessible } ;

registration
let IAlph, OAlph be non empty set ;
let tfsm be non empty finite Mealy-FSM of IAlph,OAlph;
cluster accessibleStates tfsm -> non empty finite ;
coherence
( accessibleStates tfsm is finite & not accessibleStates tfsm is empty )
proof end;
end;

theorem Th67: :: FSM_1:67
for OAlph, IAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph holds
( accessibleStates tfsm c= the carrier of tfsm & ( for q being State of tfsm holds
( q in accessibleStates tfsm iff q is accessible ) ) )
proof end;

theorem Th68: :: FSM_1:68
for OAlph, IAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph holds the Tran of tfsm | [:(accessibleStates tfsm),IAlph:] is Function of [:(accessibleStates tfsm),IAlph:],(accessibleStates tfsm)
proof end;

theorem :: FSM_1:69
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for cTran being Function of [:(accessibleStates tfsm),IAlph:],(accessibleStates tfsm)
for cOFun being Function of [:(accessibleStates tfsm),IAlph:],OAlph
for cInitS being Element of accessibleStates tfsm st cTran = the Tran of tfsm | [:(accessibleStates tfsm),IAlph:] & cOFun = the OFun of tfsm | [:(accessibleStates tfsm),IAlph:] & cInitS = the InitS of tfsm holds
tfsm, Mealy-FSM(# (accessibleStates tfsm),cTran,cOFun,cInitS #) -are_equivalent
proof end;

theorem :: FSM_1:70
for OAlph, IAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph ex Ctfsm being non empty finite connected Mealy-FSM of IAlph,OAlph st
( the Tran of Ctfsm = the Tran of tfsm | [:(accessibleStates tfsm),IAlph:] & the OFun of Ctfsm = the OFun of tfsm | [:(accessibleStates tfsm),IAlph:] & the InitS of Ctfsm = the InitS of tfsm & tfsm,Ctfsm -are_equivalent )
proof end;

begin

definition
let IAlph be set ;
let OAlph be non empty set ;
let tfsm1, tfsm2 be non empty Mealy-FSM of IAlph,OAlph;
func tfsm1 -Mealy_union tfsm2 -> strict Mealy-FSM of IAlph,OAlph means :Def24: :: FSM_1:def 24
( the carrier of it = the carrier of tfsm1 \/ the carrier of tfsm2 & the Tran of it = the Tran of tfsm1 +* the Tran of tfsm2 & the OFun of it = the OFun of tfsm1 +* the OFun of tfsm2 & the InitS of it = the InitS of tfsm1 );
existence
ex b1 being strict Mealy-FSM of IAlph,OAlph st
( the carrier of b1 = the carrier of tfsm1 \/ the carrier of tfsm2 & the Tran of b1 = the Tran of tfsm1 +* the Tran of tfsm2 & the OFun of b1 = the OFun of tfsm1 +* the OFun of tfsm2 & the InitS of b1 = the InitS of tfsm1 )
proof end;
uniqueness
for b1, b2 being strict Mealy-FSM of IAlph,OAlph st the carrier of b1 = the carrier of tfsm1 \/ the carrier of tfsm2 & the Tran of b1 = the Tran of tfsm1 +* the Tran of tfsm2 & the OFun of b1 = the OFun of tfsm1 +* the OFun of tfsm2 & the InitS of b1 = the InitS of tfsm1 & the carrier of b2 = the carrier of tfsm1 \/ the carrier of tfsm2 & the Tran of b2 = the Tran of tfsm1 +* the Tran of tfsm2 & the OFun of b2 = the OFun of tfsm1 +* the OFun of tfsm2 & the InitS of b2 = the InitS of tfsm1 holds
b1 = b2
;
end;

:: deftheorem Def24 defines -Mealy_union FSM_1:def 24 :
for IAlph being set
for OAlph being non empty set
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for b5 being strict Mealy-FSM of IAlph,OAlph holds
( b5 = tfsm1 -Mealy_union tfsm2 iff ( the carrier of b5 = the carrier of tfsm1 \/ the carrier of tfsm2 & the Tran of b5 = the Tran of tfsm1 +* the Tran of tfsm2 & the OFun of b5 = the OFun of tfsm1 +* the OFun of tfsm2 & the InitS of b5 = the InitS of tfsm1 ) );

registration
let IAlph be set ;
let OAlph be non empty set ;
let tfsm1, tfsm2 be non empty finite Mealy-FSM of IAlph,OAlph;
cluster tfsm1 -Mealy_union tfsm2 -> non empty finite strict ;
coherence
( not tfsm1 -Mealy_union tfsm2 is empty & tfsm1 -Mealy_union tfsm2 is finite )
proof end;
end;

theorem Th71: :: FSM_1:71
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q11 being State of tfsm1
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for q being State of tfsm st tfsm = tfsm1 -Mealy_union tfsm2 & the carrier of tfsm1 misses the carrier of tfsm2 & q11 = q holds
(q11,w) -admissible = (q,w) -admissible
proof end;

theorem Th72: :: FSM_1:72
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q11 being State of tfsm1
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for q being State of tfsm st tfsm = tfsm1 -Mealy_union tfsm2 & the carrier of tfsm1 misses the carrier of tfsm2 & q11 = q holds
(q11,w) -response = (q,w) -response
proof end;

theorem Th73: :: FSM_1:73
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q21 being State of tfsm2
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for q being State of tfsm st tfsm = tfsm1 -Mealy_union tfsm2 & q21 = q holds
(q21,w) -admissible = (q,w) -admissible
proof end;

theorem Th74: :: FSM_1:74
for IAlph, OAlph being non empty set
for w being FinSequence of IAlph
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph
for q21 being State of tfsm2
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for q being State of tfsm st tfsm = tfsm1 -Mealy_union tfsm2 & q21 = q holds
(q21,w) -response = (q,w) -response
proof end;

theorem Th75: :: FSM_1:75
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for Rtfsm1, Rtfsm2 being non empty reduced Mealy-FSM of IAlph,OAlph st tfsm = Rtfsm1 -Mealy_union Rtfsm2 & the carrier of Rtfsm1 misses the carrier of Rtfsm2 & Rtfsm1,Rtfsm2 -are_equivalent holds
ex Q being State of (the_reduction_of tfsm) st
( the InitS of Rtfsm1 in Q & the InitS of Rtfsm2 in Q & Q = the InitS of (the_reduction_of tfsm) )
proof end;

theorem Th76: :: FSM_1:76
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for CRtfsm1, CRtfsm2 being non empty reduced connected Mealy-FSM of IAlph,OAlph
for q1u, q2u being State of tfsm
for crq11, crq12 being State of CRtfsm1 st crq11 = q1u & crq12 = q2u & the carrier of CRtfsm1 misses the carrier of CRtfsm2 & tfsm = CRtfsm1 -Mealy_union CRtfsm2 & not crq11,crq12 -are_equivalent holds
not q1u,q2u -are_equivalent
proof end;

theorem Th77: :: FSM_1:77
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for CRtfsm2, CRtfsm1 being non empty reduced connected Mealy-FSM of IAlph,OAlph
for q1u, q2u being State of tfsm
for crq21, crq22 being State of CRtfsm2 st crq21 = q1u & crq22 = q2u & tfsm = CRtfsm1 -Mealy_union CRtfsm2 & not crq21,crq22 -are_equivalent holds
not q1u,q2u -are_equivalent
proof end;

theorem Th78: :: FSM_1:78
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for CRtfsm1, CRtfsm2 being non empty finite reduced connected Mealy-FSM of IAlph,OAlph st the carrier of CRtfsm1 misses the carrier of CRtfsm2 & tfsm = CRtfsm1 -Mealy_union CRtfsm2 holds
for Q being State of (the_reduction_of tfsm)
for q1, q2 being Element of Q holds
( not q1 in the carrier of CRtfsm1 or not q2 in the carrier of CRtfsm1 or not q1 <> q2 )
proof end;

theorem Th79: :: FSM_1:79
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for CRtfsm1, CRtfsm2 being non empty finite reduced connected Mealy-FSM of IAlph,OAlph st tfsm = CRtfsm1 -Mealy_union CRtfsm2 holds
for Q being State of (the_reduction_of tfsm)
for q1, q2 being Element of Q holds
( not q1 in the carrier of CRtfsm2 or not q2 in the carrier of CRtfsm2 or not q1 <> q2 )
proof end;

theorem Th80: :: FSM_1:80
for IAlph, OAlph being non empty set
for tfsm being non empty finite Mealy-FSM of IAlph,OAlph
for CRtfsm1, CRtfsm2 being non empty finite reduced connected Mealy-FSM of IAlph,OAlph st the carrier of CRtfsm1 misses the carrier of CRtfsm2 & CRtfsm1,CRtfsm2 -are_equivalent & tfsm = CRtfsm1 -Mealy_union CRtfsm2 holds
for Q being State of (the_reduction_of tfsm) ex q1, q2 being Element of Q st
( q1 in the carrier of CRtfsm1 & q2 in the carrier of CRtfsm2 & ( for q being Element of Q holds
( q = q1 or q = q2 ) ) )
proof end;

begin

theorem Th81: :: FSM_1:81
for IAlph, OAlph being non empty set
for tfsm1, tfsm2 being non empty finite Mealy-FSM of IAlph,OAlph ex fsm1, fsm2 being non empty finite Mealy-FSM of IAlph,OAlph st
( the carrier of fsm1 misses the carrier of fsm2 & fsm1,tfsm1 -are_isomorphic & fsm2,tfsm2 -are_isomorphic )
proof end;

theorem Th82: :: FSM_1:82
for IAlph, OAlph being non empty set
for tfsm1, tfsm2 being non empty Mealy-FSM of IAlph,OAlph st tfsm1,tfsm2 -are_isomorphic holds
tfsm1,tfsm2 -are_equivalent
proof end;

theorem Th83: :: FSM_1:83
for IAlph, OAlph being non empty set
for CRtfsm1, CRtfsm2 being non empty finite reduced connected Mealy-FSM of IAlph,OAlph st the carrier of CRtfsm1 misses the carrier of CRtfsm2 & CRtfsm1,CRtfsm2 -are_equivalent holds
CRtfsm1,CRtfsm2 -are_isomorphic
proof end;

theorem Th84: :: FSM_1:84
for IAlph, OAlph being non empty set
for Ctfsm1, Ctfsm2 being non empty finite connected Mealy-FSM of IAlph,OAlph st Ctfsm1,Ctfsm2 -are_equivalent holds
the_reduction_of Ctfsm1, the_reduction_of Ctfsm2 -are_isomorphic
proof end;

theorem :: FSM_1:85
for IAlph, OAlph being non empty set
for M1, M2 being non empty finite reduced connected Mealy-FSM of IAlph,OAlph holds
( M1,M2 -are_isomorphic iff M1,M2 -are_equivalent )
proof end;