reserve x for set,
  m,n for Nat,
  a,b for Int_position,
  i,j,k for Instruction of SCMPDS,
  s,s1,s2 for State of SCMPDS,
  k1,k2 for Integer,
  loc,l for Nat,
  I,J,K for Program of SCMPDS;
reserve P,P1,P2,Q for Instruction-Sequence of SCMPDS;

theorem Th20: ::SCMPDS_5:31
  for I,J being Program of SCMPDS st I c= J & I is_closed_on s,P & I
is_halting_on s,P
 holds CurInstr(P +* J,Comput(P +* J, Initialize s,
 LifeSpan(P +* stop I,Initialize s))) = halt SCMPDS
  or IC Comput(P +* J,Initialize s,
   LifeSpan(P +* stop I,Initialize s)) = card I
proof
  let I,J be Program of SCMPDS;
  set ss = Initialize s, PP = P +* stop I,
  m=LifeSpan(PP,ss);
  set s0=Initialize s, P0 = P +* J,
  s1= Comput(P0, s0,m), s2= Comput(PP, ss,m),
  P1 = P0, P2 = PP,
  Ik = IC s2;
  assume that
A1: I c= J and
A2: I is_closed_on s,P and
A3: I is_halting_on s,P;
A4: dom I c= dom J by A1,GRFUNC_1:2;
  reconsider n = Ik as Nat;
A5: stop I c= P2 by FUNCT_4:25;
A6: PP halts_on ss by A3,SCMPDS_6:def 3;
A7: Ik in dom stop(I) by A2,SCMPDS_6:def 2;
  card stop I = card I + 1 by COMPOS_1:55;
  then n < card I + 1 by A7,AFINSQ_1:66;
  then
A8: n <= card I by INT_1:7;
A9: IC s1 = Ik by A1,A2,A3,Th18;
  now
    per cases by A8,XXREAL_0:1;
    case
      n < card I;
      then
A10:   n in dom I by AFINSQ_1:66;
      thus halt SCMPDS = CurInstr(P2,s2) by A6,EXTPRO_1:def 15
        .= PP.Ik by PBOOLE:143
        .= (stop I).Ik by A7,A5,GRFUNC_1:2
        .= I.Ik by A10,AFINSQ_1:def 3
        .= J.Ik by A1,A10,GRFUNC_1:2
        .= P0.IC s1 by A4,A9,A10,FUNCT_4:13
        .=CurInstr(P1,s1) by PBOOLE:143;
    end;
    case
    n = card I;
      hence IC s1=  card I by A1,A2,A3,Th18;
    end;
  end;
  hence thesis;
end;
