reserve m, n, i, k for Nat;
reserve IAlph, OAlph for non empty set,
  fsm for non empty FSM over IAlph,
  s for Element of IAlph,
  w, w1, w2 for FinSequence of IAlph,
  q, q9, q1, q2 for State of fsm;
reserve tfsm, tfsm1, tfsm2, tfsm3 for non empty Mealy-FSM over IAlph, OAlph,
  sfsm for non empty Moore-FSM over IAlph, OAlph,
  qs for State of sfsm,
  q, q1, q2 , q3, qa, qb, qc, qa9, qt, q1t, q2t for State of tfsm,
  q11, q12 for State of tfsm1,
  q21, q22 for State of tfsm2;
reserve OAlphf for finite non empty set,
  tfsmf for finite non empty Mealy-FSM over IAlph, OAlphf,
  sfsmf for finite non empty Moore-FSM over IAlph, OAlphf;
reserve tfsm, rtfsm for finite non empty Mealy-FSM over IAlph, OAlph,
  q for State of tfsm;
reserve qr1, qr2 for State of rtfsm,
  Tf for Function of the carrier of tfsm1, the carrier of tfsm2;
reserve Rtfsm for reduced finite non empty Mealy-FSM over IAlph, OAlph;
reserve Ctfsm, Ctfsm1, Ctfsm2 for connected finite non empty Mealy-FSM over
  IAlph, OAlph;

theorem
  ex Ctfsm 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
  set M = tfsm;
  set I = the InitS of M;
  accessibleStates M c= the carrier of M by Th48;
  then [:accessibleStates M, IAlph:] c= [:the carrier of M, IAlph:] by
ZFMISC_1:96;
  then reconsider cOFun = (the OFun of M) | [:accessibleStates M, IAlph:] as
  Function of [:accessibleStates M, IAlph:], OAlph by FUNCT_2:32;
  I, <*>IAlph-leads_to I by Th2;
  then I is accessible;
  then reconsider cInitS = the InitS of M as Element of accessibleStates M by
Th48;
  reconsider cTran = (the Tran of M) | [:accessibleStates M, IAlph:] as
  Function of [:accessibleStates M,IAlph:],accessibleStates M by Th49;
  set cm = Mealy-FSM(#accessibleStates M, cTran, cOFun, cInitS#);
A1: now
    let w be FinSequence of IAlph;
    set ma= (the InitS of M,w)-admissible;
    set cma= (the InitS of cm,w)-admissible;
    now
      defpred P[Nat] means $1 in dom ma implies ma.$1 = cma.$1;
      thus len ma = len w + 1 & len cma = len w + 1 by Def2;
      then
A2:   dom ma = Seg (len w + 1) by FINSEQ_1:def 3;
A3:   for k being Nat st P[k] holds P[k + 1]
      proof
        let j be Nat such that
A4:     j in dom ma implies ma.j = cma.j;
A5:     0=j or 0<j & 0+1 = 1;
        assume j+1 in dom ma;
        then
A6:     j+1<=len w +1 by A2,FINSEQ_1:1;
        then
A7:     j<=len w by XREAL_1:6;
A8:     j<len w +1 by A6,NAT_1:13;
        per cases by A5,NAT_1:13;
        suppose
A9:       0 = j;
          hence ma.(j+1) = the InitS of M by Def2
            .= cma.(j+1) by A9,Def2;
        end;
        suppose
A10:      1 <= j;
          then (ex mwj being Element of IAlph, mqj,mqj1 being State of M st
mwj = w.j & mqj = ma.j & mqj1 = ma.(j+1) & mwj-succ_of mqj = mqj1 )& ex cmwj
being Element of IAlph, cmqj, cmqj1 being State of cm st cmwj = w.j & cmqj =
          cma.j & cmqj1 = cma.(j+1) & cmwj-succ_of cmqj=cmqj1 by A7,Def2;
          hence thesis by A2,A4,A8,A10,FINSEQ_1:1,FUNCT_1:49;
        end;
      end;
A11:  P[0] by A2,FINSEQ_1:1;
      thus for j be Nat holds P[j] from NAT_1:sch 2(A11, A3);
    end;
    hence ma = cma by FINSEQ_2:9;
  end;
  now
    let q be State of cm;
    q in accessibleStates M & accessibleStates M c= the carrier of M by Th48;
    then reconsider q9 = q as State of M;
    q9 is accessible by Th48;
    then consider w being FinSequence of IAlph such that
A12: the InitS of M, w-leads_to q9;
    (the InitS of M, w)-admissible.(len w + 1) = q9 by A12;
    then (the InitS of cm, w)-admissible.(len w + 1) = q by A1;
    then the InitS of cm, w-leads_to q;
    hence q is accessible;
  end;
  then reconsider
  cm as connected finite non empty Mealy-FSM over IAlph, OAlph by Def22;
  take cm;
  thus the Tran of cm = (the Tran of M) | [:accessibleStates M, IAlph:];
  thus the OFun of cm = (the OFun of M) | [:accessibleStates M, IAlph:];
  thus the InitS of cm = the InitS of M;
  let w be FinSequence of IAlph;
  set ma= (the InitS of M,w)-admissible;
  set cma= (the InitS of cm,w)-admissible;
  set mr = (the InitS of M, w)-response;
  set cmr = (the InitS of cm, w)-response;
A13: len cma = len w + 1 by Def2;
  now
    thus len mr = len w & len cmr = len w by Def6;
    then
A14: dom mr = Seg len w by FINSEQ_1:def 3;
    let j be Nat;
    assume
A15: j in dom mr;
    then
A16: j in dom w by A14,FINSEQ_1:def 3;
    j in Seg (len w + 1) by A14,A15,FINSEQ_2:8;
    then j in dom cma by A13,FINSEQ_1:def 3;
    then
A17: cma.j in accessibleStates M by FINSEQ_2:11;
    w.j in IAlph by A16,FINSEQ_2:11;
    then
A18: [cma.j, w.j] in [:accessibleStates M, IAlph:] by A17,ZFMISC_1:87;
A19: [ma.j, w.j] = [cma.j, w.j] by A1;
    thus mr.j = (the OFun of M).[ma.j, w.j] by A16,Def6
      .= cOFun.[cma.j, w.j] by A19,A18,FUNCT_1:49
      .= cmr.j by A16,Def6;
  end;
  hence thesis by FINSEQ_2:9;
end;
