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;

theorem
  ex sfsmf st tfsmf is_similar_to sfsmf
proof
  set S = the carrier of tfsmf, T = the Tran of tfsmf;
  set tOF = the OFun of tfsmf, IS = the InitS of tfsmf;
  set sS = [: S, OAlphf :];
  deffunc F(Element of sS,Element of IAlph) = [ T.[$1`1, $2], tOF.[$1`1, $2]];
  consider sT being Function of [:sS, IAlph:], sS such that
A1: for q being Element of sS, s being Element of IAlph holds sT.(q, s)
  = F(q,s) from BINOP_1:sch 4;
  set sSs = sS, sTs = sT;
  set r0 = the Element of OAlphf;
  deffunc F(Element of S,Element of OAlphf) = $2;
  consider sOF being Function of sS, OAlphf such that
A2: for q being Element of S, r being Element of OAlphf holds sOF.(q, r)
  = F(q,r) from BINOP_1:sch 4;
  set sI = [IS, r0];
  reconsider sOFs = sOF as Function of sSs, OAlphf;
  reconsider sfsmf = Moore-FSM (# sSs, sTs, sOFs, sI #) as finite non empty
  Moore-FSM over IAlph, OAlphf;
  take sfsmf;
  reconsider SI = sI as Element of sfsmf;
  thus tfsmf is_similar_to sfsmf
  proof
    let tw be FinSequence of IAlph;
    set twa = (the InitS of tfsmf, tw)-admissible;
    set swa = (the InitS of sfsmf, tw)-admissible;
    defpred P[Nat] means $1 in Seg (len tw + 1) implies twa.$1 = (
    swa.$1)`1;
A3: for i being Nat st P[i] holds P[i+1]
    proof
      let i be Nat;
      assume
A4:   P[i];
      assume i+1 in Seg (len tw +1);
      then
A5:   i+1 <= len tw +1 by FINSEQ_1:1;
      per cases by A5,XREAL_1:6;
      suppose
A6:     i = 0;
        twa.1 = IS by Def2
          .= [IS, r0]`1
          .= (swa.1)`1 by Def2;
        hence thesis by A6;
      end;
      suppose
A7:     i > 0 & i <= len tw;
        then
A8:     i <= len tw + 1 by NAT_1:13;
A9:     0+1=1 implies 1 <= i & i <= len tw by A7,NAT_1:13;
        then
A10:    ex twi being Element of IAlph, tqi, tqi1 being Element of tfsmf st
        twi = tw.i & tqi = twa.i & tqi1 = twa.(i+1) & twi-succ_of tqi = tqi1
by Def2;
        consider swi being Element of IAlph, sqi, sqi1 being Element of sfsmf
        such that
A11:    swi = tw.i & sqi = swa.i & sqi1 = swa.(i+1) and
A12:    swi-succ_of sqi = sqi1 by A9,Def2;
        sqi1 = sT.(sqi, swi) by A12
          .= [T.[sqi`1, swi], tOF.[sqi`1, swi]] by A1;
        hence thesis by A4,A9,A8,A10,A11,FINSEQ_1:1;
      end;
    end;
A13: P[0] by FINSEQ_1:1;
A14: for i being Nat holds P[i] from NAT_1:sch 2 ( A13, A3 );
    now
      thus len (<*sOF.sI*>^((IS, tw)-response)) = len <*sOF.sI*> + len ((
      IS, tw)-response) by FINSEQ_1:22
        .= 1 + len ((IS, tw)-response) by FINSEQ_1:40
        .= len tw + 1 by Def6;
      then
A15:  dom (<*sOF.sI*>^((IS, tw)-response)) = Seg (len tw + 1) by FINSEQ_1:def 3
;
      thus len ((SI, tw)-response) = len tw + 1 by Def7;
      let i be Nat;
      assume
A16:  i in dom (<*sOF.sI*>^((IS, tw)-response));
      then
A17:  1 <= i by A15,FINSEQ_1:1;
A18:  i <= len tw + 1 by A15,A16,FINSEQ_1:1;
      per cases by A17,XXREAL_0:1;
      suppose
A19:    i = 1;
        then i in Seg 1 by FINSEQ_1:2,TARSKI:def 1;
        then i in dom <*sOF.sI*> by FINSEQ_1:38;
        hence (<*sOF.sI*>^((IS, tw)-response)).i = <*sOF.sI*>.i by
FINSEQ_1:def 7
          .= sOF.sI by A19
          .= ((SI, tw)-response).i by A19,Th10;
      end;
      suppose
        1 < i;
        then consider j being Element of NAT such that
A20:    j = i-1 and
A21:    1 <= j by INT_1:51;
A22:    i = j + 1 by A20;
        then
A23:    j <= len tw by A18,XREAL_1:6;
        then consider
        swj being Element of IAlph, swaj, swai being Element of sfsmf
        such that
A24:    swj = tw.j and
A25:    swaj = swa.j and
A26:    swai = swa.(j+1) & swj-succ_of swaj = swai by A21,Def2;
        j <= len tw + 1 by A23,NAT_1:12;
        then
A27:    j in Seg (len tw + 1) by A21,FINSEQ_1:1;
        reconsider swaj as Element of sS;
A28:    j in Seg len tw by A21,A23,FINSEQ_1:1;
        then
A29:    j in dom tw by FINSEQ_1:def 3;
        len ((IS, tw)-response) = len tw by Def6;
        then len <*sOF.sI*> = 1 & j in dom ((IS, tw)-response) by A28,
FINSEQ_1:40,def 3;
        hence
        (<*sOF.sI*>^((IS, tw)-response)).i = ((IS, tw)-response).j by A22,
FINSEQ_1:def 7
          .= tOF.((IS, tw)-admissible.j, tw.j) by A29,Def6
          .= tOF.(swaj`1, tw.j) by A14,A27,A25
          .= sOF.(T.(swaj`1, swj), tOF.(swaj`1, swj)) by A2,A24
          .= sOF.(sT.(swaj, swj)) by A1
          .= (SI, tw)-response.i by A15,A16,A20,A26,Def7;
      end;
    end;
    hence thesis by FINSEQ_2:9;
  end;
end;
