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 Th22:
  for I being Program of SCMPDS,J being shiftable Program of
SCMPDS st I is_closed_on s,P & I is_halting_on s,P
 & J is_closed_on IExec(I,P,Initialize s),P
 & J is_halting_on IExec(I,P,Initialize s),P
  holds I ';'J is_closed_on s,P & I ';' J is_halting_on s,P
proof
  let I be Program of SCMPDS,J be shiftable Program of SCMPDS;
  set sE=IExec(I,P,Initialize s);
  assume that
A1: I is_closed_on s,P and
A2: I is_halting_on s,P and
A3: J is_closed_on sE,P and
A4: J is_halting_on sE, P;
  set IJ =I ';' J, sIJ = stop IJ, spI = stop I,
  ss=Initialize s, PP = P +* stop IJ;
  set spJ = stop J,
  s1 = Initialize s, P1 = P +* stop I,
  m1 = LifeSpan(P1,s1), sm
  = Comput(P1, s1,m1), s3 = Initialize sm,
  P3 = P1 +* spJ,
  m3 = LifeSpan(P3,s3);
  J is_halting_on sm,P1 by A2,A3,A4,Th21;
  then
A5: P3 halts_on s3 by SCMPDS_6:def 3;
A6: J is_closed_on sm,P1 by A2,A3,A4,Th21;
  then
A7: J is_closed_on s3,P3 by SCMPDS_6:24;
  set s4 = Comput(PP, ss,m1), P4 = PP;
A8: spJ c= P3 by FUNCT_4:25;
A9: DataPart sm = DataPart s3 by MEMSTR_0:45;
A10: (I ';' (J ';' Stop SCMPDS)) = stop IJ by AFINSQ_1:27;
A11: sm =  s4 by A1,A2,Th17,A10;
  sIJ = I ';' (J ';' Stop SCMPDS) by AFINSQ_1:27
    .= I +* Shift(spJ, card I);
  then
A12: Shift(spJ, card I) c= sIJ by FUNCT_4:25;
  sIJ c= PP by FUNCT_4:25;
  then
A13: Shift(spJ, card I) c= P4 by A12,XBOOLE_1:1;
A14: dom stop I c= dom sIJ by SCMPDS_5:13;
  now
    let k be Nat;
    per cases;
    suppose
      k <= m1;
      then IC Comput(PP, ss,k) in dom stop I by A1,A2,Th4,Th19;
      hence IC Comput(PP, ss,k) in dom sIJ by A14;
    end;
    suppose
A15:  k > m1;
A16:  IC s4 in dom spI by A1,A2,Th4,Th19;
      hereby
        per cases by A1,A2,Th4,Th20;
        suppose
A17:      IC s4 =  card I;
          consider ii be Nat such that
A18:      k=m1+ii by A15,NAT_1:10;
          reconsider ii as Nat;
          reconsider nn = IC Comput(P3, s3,ii) as Nat;
          IC Comput(P3, s3,ii) + card I = IC Comput(P4, s4,ii)
           by A8,A11,A9,A7,A13,A17,SCMPDS_6:31;
          then
A19:      IC Comput(P4, ss,k)= nn+card I by A18,EXTPRO_1:4;
           nn in dom spJ by A6,SCMPDS_6:def 2;
          then nn < card spJ by AFINSQ_1:66;
          then nn < card J+1 by COMPOS_1:55;
          then
A20:      card I +nn < card I +(card J+1) by XREAL_1:6;
          card sIJ=card IJ+1 by COMPOS_1:55
            .=card I + card J+1 by AFINSQ_1:17;
          hence IC Comput(PP, ss,k) in dom sIJ by A20,A19,AFINSQ_1:66;
        end;
        suppose
          CurInstr(P4,s4) = halt SCMPDS;
          then IC Comput(PP, ss,k)=IC s4 by A15,EXTPRO_1:5;
          hence IC Comput(PP, ss,k) in dom sIJ by A14,A16;
        end;
      end;
    end;
  end;
  hence (I ';'J) is_closed_on s,P by SCMPDS_6:def 2;
A21: Comput(PP,ss,m1+m3)
 = Comput(PP,Comput(PP,ss,m1),m3) by EXTPRO_1:4;
  per cases by A1,A2,Th4,Th20;
  suppose
    CurInstr(P4,s4) = halt SCMPDS;
    then PP halts_on ss by EXTPRO_1:29;
    hence thesis by SCMPDS_6:def 3;
  end;
  suppose
    IC s4 =  card I;
    then
    CurInstr(PP,Comput(PP,ss,m1+m3)) =
    CurInstr(P3,Comput(P3,s3,m3)) by A21,A8,A11,A9,A7,A13,SCMPDS_6:31
      .= halt SCMPDS by A5,EXTPRO_1:def 15;
    then PP halts_on ss by EXTPRO_1:29;
    hence thesis by SCMPDS_6:def 3;
  end;
end;
