reserve m for Nat;
reserve P,PP,P1,P2 for Instruction-Sequence of SCM+FSA;

theorem Th21:
  for s being State of SCM+FSA, I being Program of SCM+FSA st
  Directed I is_pseudo-closed_on s,P
   holds I ";" Stop SCM+FSA is_halting_on s,P &
   LifeSpan(P +* (I ";" Stop SCM+FSA),
         Initialize s) =
   pseudo-LifeSpan(s,P,Directed I) &
  (for n being Nat st n < pseudo-LifeSpan(s,P,Directed I) holds
   IC Comput(P +* I, (Initialize s),n)
     = IC Comput(P +* (I ";" Stop SCM+FSA),
     (Initialize s),n)) &
for n being Nat st n <= pseudo-LifeSpan(s,P,Directed I)
 holds DataPart Comput(P +* I, (Initialize s),n)
   = DataPart Comput(P+* (I ";" Stop SCM+FSA),
    Initialize s,n)
proof
  let s be State of SCM+FSA;
  set D = Data-Locations SCM+FSA;
  let I be Program of SCM+FSA;
  set I0 = Directed I;
  set I1 = I ";" Stop SCM+FSA;
  set s00 = Initialize s,
      P00 = P+*I0;
  set s10 = Initialize s,
      P10 = P+*I1;
  reconsider k = pseudo-LifeSpan(s00,P00,I0) as Element of NAT
            by ORDINAL1:def 12;
  (Stop SCM+FSA).0 = halt SCM+FSA;
  then
A1: halt SCM+FSA = (Stop SCM+FSA). (card I -' card I) by XREAL_1:232;
A2: DataPart s00 = DataPart s10;
  assume
A3: I0 is_pseudo-closed_on s,P;
  then
A4: I0 is_pseudo-closed_on s00,P00;
  defpred P[Nat] means k <= $1 implies
   IC Comput(P10, s10,$1) = card I &
   CurInstr(P10,Comput(P10,s10,$1)) = halt SCM+FSA;
A5: I1 c= P10 by FUNCT_4:25;
A6: I1 c= P10 by FUNCT_4:25;
A7: I0 c= I1 by SCMFSA6A:16;
A8: I0 c= P10 by A7,A5,XBOOLE_1:1;
  Reloc(I0,0) c= I1 by A7;
  then
A9: Reloc(I0,0) c= P10 by A6,XBOOLE_1:1;
A10: IC s10 =  0 by FUNCT_4:113;
A11: I0 c= P00 by FUNCT_4:25;
A12: now
    let n be Nat;
    assume
A13: n <= pseudo-LifeSpan(s00,P00,I0);
    then IC Comput(P00, s00,n) + 0 = IC Comput(P10,s10,n)
     by A4,A9,A10,A2,Th14,A11;
    hence IC Comput(P00, s00,n) = IC Comput(P10,s10,n);
    thus DataPart Comput(P00, s00,n) = DataPart Comput(P10, s10,n)
     by A4,A9,A10,A2,A13,Th14,A11;
  end;
A14: k = pseudo-LifeSpan(s,P,I0) by A3,Th13;
A15: now
    let n be Nat;
    assume
A16: n < pseudo-LifeSpan(s00,P00,I0);
    then
    IncAddr(CurInstr(P00,Comput(P00,s00,n)),0)
     = CurInstr(P10,Comput(P10,s10,n))
      by A4,A9,A10,A2,Th14,A11;
    hence CurInstr(P00,Comput(P00,s00,n))
     = CurInstr(P10,Comput(P10,s10,n))
      by COMPOS_0:3;
    thus IC Comput(P00, s00,n) in dom I0 by A4,A16,SCMFSA8A:17;
    thus CurInstr(P00,Comput(P00,s00,n))
     <> halt SCM+FSA by A4,A16,SCMFSA8A:17;
  end;
A17: now
    let n be Nat;
    assume
A18: CurInstr(P10,Comput(P10,s10,n)) = halt SCM+FSA;
    reconsider l = IC Comput(P00, s00,n) as Element of NAT;
    assume
A19: k > n;
    then
A20: l in dom I0 by A3,A14,SCMFSA8A:def 4;
    CurInstr(P10,Comput(P10,s10,n)) =
     CurInstr(P00,Comput(P00,s00,n)) by A15,A19
      .= P00.l by PBOOLE:143
      .= I0.l by A20,A11,GRFUNC_1:2;
    then halt SCM+FSA in rng I0 by A18,A20,FUNCT_1:def 3;
    hence contradiction by COMPOS_1:def 11;
  end;
A21: card Stop SCM+FSA = 1 by AFINSQ_1:34;
  then card I1 = card I + 1 by SCMFSA6A:21;
  then card I < card I1 by NAT_1:13;
  then
A22:  card I in dom I1 by AFINSQ_1:66;
  card I < card I + card Stop SCM+FSA by A21,NAT_1:13;
  then
A23: I1. card I = IncAddr(halt SCM+FSA,card I) by A1,Th2
    .= halt SCM+FSA by COMPOS_0:4;
  then
A24: P10. card I = halt SCM+FSA by A22,A5,GRFUNC_1:2;
A25: for n being Nat st P[n] holds P[n + 1]
  proof
    let n be Nat;
    assume
A26: P[n];
    assume
A27: k <= n + 1;
    hereby
      per cases by A27,NAT_1:8;
      suppose
        k = n + 1;
        hence IC Comput(P10, s10,n+1)
            = IC Comput(P00, s00,k) by A12
          .=  card I0 by A3,A14,SCMFSA8A:def 4
          .=  card I by SCMFSA6A:36;
      end;
      suppose
A28:    k <= n;
        Comput(P10, s10,n+1) = Following(P10,Comput(P10,s10,n)) by EXTPRO_1:3;
        hence IC Comput(P10, s10,n+1) =  card I by A26,A28,EXTPRO_1:def 3;
      end;
    end;
    hence thesis by A24,PBOOLE:143;
  end;
A29: P[0]
  proof
    assume k <= 0;
    then k = 0;
    hence IC Comput(P10, s10,0) = IC Comput(P00,s00,k)
      .=  card I0 by A3,A14,SCMFSA8A:def 4
      .=  card I by SCMFSA6A:36;
    hence CurInstr(P10,Comput(P10,s10,0))
           = P10.card I by PBOOLE:143
          .= halt SCM+FSA by A23,A22,A5,GRFUNC_1:2;
  end;
A30: for n being Nat holds P[n] from NAT_1:sch 2(A29,A25);
  set s1 = Initialize s,
      P1 = P +* I;
A31: I c= P1 by FUNCT_4:25;
A32: card I0 = card I by SCMFSA6A:36;
  P[k] by A30;
  then
A33: P10 halts_on s10 by EXTPRO_1:29;
  hence I1 is_halting_on s,P;
  CurInstr(P10,Comput(P10,s10,k)) = halt SCM+FSA by A30;
  then
A34: LifeSpan(P10,s10) = k by A33,A17,EXTPRO_1:def 15;
  defpred P[Nat] means $1 < pseudo-LifeSpan(s,P,I0) implies
    IC Comput(P1, s1,$1) in dom I &
    IC Comput(P1, s1,$1) = IC Comput(P10, s10,$1) &
    DataPart Comput(P1, s1,$1) = DataPart Comput(P10, s10,$1);
A35: for n being Nat st P[n] holds P[n + 1]
  proof
    let n be Nat;
    set l = IC Comput(P1, s1,n);
    set l0 = IC Comput(P10, s10,n);
    assume
A36: P[n];
    assume
A37: n + 1 < pseudo-LifeSpan(s,P,I0);
    then
A38: l0 in dom I0 by A36,FUNCT_4:99,NAT_1:12;
A39: for f being FinSeq-Location
      holds Comput(P1, s1,n).f = Comput(P10,s10,n).f
       by A36,A37,NAT_1:12,SCMFSA_M:2;
    for a being Int-Location
     holds Comput(P1, s1,n).a = Comput(P10, s10,n).a
      by A36,A37,NAT_1:12,SCMFSA_M:2;
    then
A40:  Comput(P1, s1,n) =  Comput(P10, s10,n)
              by A36,A37,A39,NAT_1:12,SCMFSA_2:61;
A41: now
      assume
A42:  I.l = halt SCM+FSA;
A43:  P00/.IC Comput(P00,s00,n)
 = P00.IC Comput(P00,s00,n) by PBOOLE:143;
      n < k by A14,A37,NAT_1:12;
      then
A44:  CurInstr(P00,Comput(P00,s00,n))
       = P00.l0 by A12,A43
        .= I0.l0 by A38,A11,GRFUNC_1:2
        .= goto  card I by A36,A37,A42,NAT_1:12,SCMFSA8A:16;
A45:  IC Comput(P00, s00,n+1) = IC Following(P00,Comput(P00,s00,n))
                by EXTPRO_1:3
        .=  card I by A44,SCMFSA_2:69
        .=  card I0 by SCMFSA6A:36;
      IC Comput(P00, s00,n+1) in dom I0 by A3,A37,SCMFSA8A:17;
      hence contradiction by A45;
    end;
A46: CurInstr(P1,Comput(P1,s1,n)) = P1.l by PBOOLE:143
      .= I.l by A31,A36,A37,GRFUNC_1:2,NAT_1:12
      .= I0.l0 by A36,A37,A41,NAT_1:12,SCMFSA8A:16
      .= P10.l0 by A38,A8,GRFUNC_1:2
      .= CurInstr(P10,Comput(P10,s10,n)) by PBOOLE:143;
A47: Comput(P10, s10,n+1) = Following(P10,Comput(P10,s10,n)) by EXTPRO_1:3
      .= Exec(CurInstr(P1,Comput(P1,s1,n)),Comput(P10, s10,n)) by A46;
    pseudo-LifeSpan(s,P,I0) = k by A3,Th13;
    then
A48: IC Comput(P00, s00,n+1) = IC Comput(P10, s10,n+1) by A12,A37;
A49: dom I0 = dom I by FUNCT_4:99;
 Comput(P1, s1,n+1) = Following(P1,Comput(P1,s1,n)) by EXTPRO_1:3;
    then
A50:  Comput(P1, s1,n+1) =  Comput(P10, s10,n+1) by A47,A40;
A51: for f being FinSeq-Location
       holds Comput(P1, s1,n+1).f = Comput(P10, s10,n+1).f
     by A50;
    IC Comput(P00, s00,n+1) in dom I0 by A3,A37,SCMFSA8A:17;
    hence IC Comput(P1, s1,n+1) in dom I by A48,A49,A50;
    thus IC Comput(P1, s1,n+1) = IC Comput(P10, s10,n+1) by A50;
    for a being Int-Location holds Comput(P1, s1,n+1).a
       = Comput(P10,s10,n+1).a by A50;
    hence thesis by A51,SCMFSA_M:2;
  end;
  IC Comput(P10, s10,k) =  card I by A30;
  then
A52: IC Comput(P00, s00,LifeSpan(P10,s10)) =  card I
by A12,A34;
  for n be Nat st not IC Comput(P00, s00,n) in dom I0
    holds LifeSpan(P10,s10) <= n by A15,A34;
  hence LifeSpan(P10,s10) = pseudo-LifeSpan(s,P,I0)
    by A3,A52,A32,SCMFSA8A:def 4;
A53: P[0]
  proof
A54: IC Comput(P1, s1,0) = IC s1
      .= IC Initialize s
      .=  0 by FUNCT_4:113;
    assume 0 < pseudo-LifeSpan(s,P,I0);
    then IC Comput(P +* I0, (Initialize s),0)
     in dom I0 by A3,SCMFSA8A:17;
    then IC (Initialize s) in dom I0;
    then  0 in dom I0 by MEMSTR_0:16;
    hence IC Comput(P1, s1,0) in dom I by A54,FUNCT_4:99;
    thus IC Comput(P1, s1,0) = IC Comput(P10, s10,0);
    thus DataPart Comput(P1, s1,0) = DataPart s1
      .= DataPart s10
      .= DataPart Comput(P10, s10,0);
  end;
A55: for n being Nat holds P[n] from NAT_1:sch 2(A53,A35);
  hence for n be Nat st n < pseudo-LifeSpan(s,P,I0)
    holds IC Comput(P1, s1,n) = IC Comput(P10, s10,n);
  let n be Nat;
  assume
A56: n <= pseudo-LifeSpan(s,P,Directed I);
  per cases by A56,XXREAL_0:1;
  suppose
    n < pseudo-LifeSpan(s,P,I0);
    hence thesis by A55;
  end;
  suppose
A57: n = pseudo-LifeSpan(s,P,I0);
      per cases by NAT_1:6;
      suppose
A58:    n = 0;
        hence DataPart Comput(P1, s1,n) = DataPart s1
          .= DataPart s10
          .= DataPart Comput(P10, s10,n) by A58;
      end;
      suppose
        ex m be Nat st n = m + 1;
        then consider m being Nat such that
A59:    n = m + 1;
        reconsider m as Element of NAT by ORDINAL1:def 12;
A60:    Comput(P10, s10,n) = Following(P10,Comput(P10,s10,m))
              by A59,EXTPRO_1:3;
        set i = CurInstr(P1,Comput(P1,s1,m));
A61:    Comput(P1, s1,n) = Following(P1,Comput(P1,s1,m)) by A59,EXTPRO_1:3;
        set l0 = IC Comput(P10, s10,m);
        set l = IC Comput(P1, s1,m);
A62:    m + 0 < pseudo-LifeSpan(s,P,I0) by A57,A59,XREAL_1:6;
        then
A63:    l = l0 by A55;
A64:    l in dom I by A55,A62;
        then
A65:    l0 in dom I0 by A63,FUNCT_4:99;
A66:    i = P1.l by PBOOLE:143
          .= I.l by A31,A64,GRFUNC_1:2;
A67:     I0 c= I1 by SCMFSA6A:16;
        then
A68:    dom I0 c= dom I1 by RELAT_1:11;
A69:    I0.l0 = I1.l0 by A65,A67,GRFUNC_1:2
          .= P10.l0 by A5,A68,A65,GRFUNC_1:2
          .= CurInstr(P10,Comput(P10,s10,m)) by PBOOLE:143;
A70:    DataPart Comput(P1, s1,m) = DataPart Comput(P10, s10,m) by A55,A62;
          per cases;
          suppose
A71:        i = halt SCM+FSA;
            then CurInstr(P10,Comput(P10,s10,m))
             = goto  card I by A64,A63,A66,A69,SCMFSA8A:16;
            then InsCode CurInstr(P10,
            Comput(P10,s10,m)) = 6 by SCMFSA_2:23;
            then
A72:        InsCode CurInstr(P10,Comput(P10,s10,m)) in {0,6,7,8}
              by ENUMSET1:def 2;
            thus DataPart Comput(P1, s1,n)
             = DataPart Comput(P1, s1,m) by A61,A71,EXTPRO_1:def 3
              .= DataPart Comput(P10, s10,m) by A55,A62
              .= DataPart Comput(P10, s10,n) by A60,A72,Th6;
          end;
          suppose
            i <> halt SCM+FSA;
            then
            CurInstr(P10,Comput(P10,s10,m))
             = i by A64,A63,A66,A69,SCMFSA8A:16;
            hence thesis by A61,A60,A70,SCMFSA6C:4;
          end;
      end;
  end;
end;
