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 Th27:
  for k be Nat st 1 <= k holds (k-equivalent qa, qb iff 1
  -equivalent qa, qb & for s being Element of IAlph, k1 being Nat st
k1 = k - 1 holds k1-equivalent (the Tran of tfsm).[qa, s], (the Tran of tfsm).[
  qb, s])
proof
  let k be Nat;
  set OF = the OFun of tfsm;
  assume
A1: 1 <= k;
  hereby
    assume
A2: k-equivalent qa, qb;
    thus
A3: 1-equivalent qa, qb
    by A1,XXREAL_0:2,A2;
    let s be Element of IAlph, k1 be Nat such that
A4: k1 = k - 1;
    set qb9 = (the Tran of tfsm).[qb, s];
    set qa9 = (the Tran of tfsm).[qa, s];
    thus k1-equivalent qa9, qb9
    proof
      let w be FinSequence of IAlph;
      set sw = <*s*>^w;
A5:   len <*s*> = 1 by FINSEQ_1:40;
      assume len w <= k1;
      then
A6:   len w + 1 <= k1 + 1 by XREAL_1:7;
      len (<*s*>^w) = len <*s*> + len w by FINSEQ_1:22
        .=1+ len w by FINSEQ_1:40;
      then
A7:   (qa, sw)-response = (qb, sw)-response by A2,A4,A6;
A8:   (qa, sw)-response = <*OF.[qa, s]*>^(qa9, w)-response & (qb, sw)
      -response = <*OF.[qb, s]*>^(qb9, w)-response by Th18;
      0+1 in Seg (0+1) by FINSEQ_1:4;
      then
A9:   1 in dom <*s*> by A5,FINSEQ_1:def 3;
      OF.[qa, s] = OF.[(qa, <*s*>)-admissible.1, s] by Def2
        .= OF.[(qa, <*s*>)-admissible.1, <*s*>.1]
        .= (qa, <*s*>)-response.1 by A9,Def6
        .= (qb, <*s*>)-response.1 by A3,A5
        .= OF.[(qb, <*s*>)-admissible.1, <*s*>.1] by A9,Def6
        .= OF.[(qb, <*s*>)-admissible.1, s]
        .= OF.[qb, s] by Def2;
      hence thesis by A8,A7,FINSEQ_1:33;
    end;
  end;
  assume that
A10: 1-equivalent qa, qb and
A11: for s being Element of IAlph, k1 being Nat st k1 = k - 1
  holds k1-equivalent (the Tran of tfsm).[qa, s],(the Tran of tfsm).[qb, s];
  thus k-equivalent qa, qb
  proof
    let w be FinSequence of IAlph such that
A12: len w <= k;
    per cases;
    suppose
A13:  w = <*>IAlph;
      hence (qa,w)-response=<*>OAlph by Th9
        .=(qb,w)-response by A13,Th9;
    end;
    suppose
      w is non empty;
      then consider
      s being Element of IAlph, w9 being FinSequence of IAlph such
      that
      s = w.1 and
A14:  w = <*s*>^w9 by FINSEQ_3:102;
      reconsider k1 = k-1 as Element of NAT by A1,INT_1:5;
A15:  len <*s*> = 1 by FINSEQ_1:40;
      len w = len <*s*> + len w9 by A14,FINSEQ_1:22
        .= len w9 + 1 by FINSEQ_1:40;
      then
A16:  len w9 + 1 - 1 <= k1 by A12,XREAL_1:9;
      0+1 in Seg (0+1) by FINSEQ_1:4;
      then
A17:  1 in dom <*s*> by A15,FINSEQ_1:def 3;
      set qa9 = (the Tran of tfsm).[qa, s], qb9 = (the Tran of tfsm).[qb, s];
A18:  (qa, w)-response = <*OF.[qa, s]*>^(qa9, w9)-response & (qb, w)
      -response = <* OF.[qb, s]*>^(qb9, w9)-response by A14,Th18;
A19:  k1-equivalent qa9, qb9 by A11;
      OF.[qa, s] = OF.[(qa, <*s*>)-admissible.1, s] by Def2
        .= OF.[(qa, <*s*>)-admissible.1, <*s*>.1]
        .= (qa, <*s*>)-response.1 by A17,Def6
        .= (qb, <*s*>)-response.1 by A10,A15
        .= OF.[(qb, <*s*>)-admissible.1, <*s*>.1] by A17,Def6
        .= OF.[(qb, <*s*>)-admissible.1, s]
        .= OF.[qb, s] by Def2;
      hence thesis by A18,A19,A16;
    end;
  end;
end;
