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
  for s being 0-started State of SCMPDS,I being halt-free shiftable Program of
  SCMPDS, a be Int_position, i be Integer,n be Nat,X be set st s.
  DataLoc(s.a,i) < 0 & not DataLoc(s.a,i) in X & n > 0 & a <>
       DataLoc(s.a,i) &
  (for t be State of SCMPDS,Q
 st (for x be Int_position st x in X
holds t.x=s.x) & t.a=s.a holds IExec(I,Q,Initialize t).a=t.a
 & IExec(I,Q,Initialize t).DataLoc(s.a,i)=t.
  DataLoc(s.a,i) & I is_closed_on t,Q & I is_halting_on t,Q &
   for y be Int_position
st y in X holds IExec(I,Q,Initialize t).y=t.y)
 holds IExec(for-up(a,i,n,I),P,s)
 = IExec(for-up(a,i,n,I),P,
      Initialize IExec(I ';' AddTo(a,i,n),P,s))
proof
  let s be 0-started State of SCMPDS,
      I be halt-free shiftable Program of SCMPDS, a be
  Int_position, i be Integer,n be Nat,X be set;
  set b=DataLoc(s.a,i);
  set FOR=for-up(a,i,n,I),
  pFOR = stop FOR,
  s1= s, P1 = P +* pFOR;
  set i1=(a,i)>=0_goto (card I+3), i2=AddTo(a,i,n), i3=goto -(card I+2);
  assume
A1: s.b < 0;
  set s4 = Comput(P1,s1,1), P4 = P1;
A2: IC s1 = 0 by MEMSTR_0:def 11;
  set m0=LifeSpan(P1,s1);
  set l2= card I+2;
  set sI= s, PI = P +* stop I,
  m1=LifeSpan(PI,sI)+3,
  J=I ';' AddTo(a,i,n), sJ= s,
  PJ = P +* stop J,
  s2=Initialize IExec(J,P,s), P2 = P +* pFOR,
  m2=LifeSpan(P2,s2);
  set Es=IExec(J,P,s), bj=DataLoc(Es.a,i);
A3: stop I c= PI by FUNCT_4:25;
A4: FOR = i1 ';' (I ';' i2 ';' i3) by Th2;
  set mI=LifeSpan(PI,sI), s5= Comput(P4, s4,mI), P5 = P4,
      l1= card I + 1;
  set m3=mI +1;
  set s6= Comput(P1, s1,m3), P6 = P1;
  set s7= Comput(P1, s1,m3+1), P7 = P1;
A5: pFOR c= P1 by FUNCT_4:25;
  FOR c= pFOR by AFINSQ_1:74;
  then
A6: FOR c= P1 by A5,XBOOLE_1:1;
  Shift(I,1) c= FOR by Lm3;
  then
A7: Shift(I,1) c= P4 by A6,XBOOLE_1:1;
  card I + 2 < card I + 3 by XREAL_1:6;
  then
A8: l2 in dom FOR by Th31;
  set m5=m3+1+1, s8= Comput(P1, s1,m5);
  card I + 1 < card I + 3 by XREAL_1:6;
  then
A9: l1 in dom FOR by Th31;
  assume
A10: not b in X;
  assume
A11: n > 0;
  assume
A12: a <> b;
A13: Initialize s = s by MEMSTR_0:44;
  assume
A14: for t be State of SCMPDS,Q
 st (for x be Int_position st x in X holds t
.x=s.x) & t.a=s.a holds IExec(I,Q,Initialize t).a=t.a &
IExec(I,Q,Initialize t).b=t.b
 & I is_closed_on t,Q
  & I is_halting_on t,Q & for y be Int_position st y in X
   holds IExec(I,Q,Initialize t).y=t.y;
  then FOR is_halting_on s,P by A1,A10,A11,A12,Th37;
  then
A15: P1 halts_on s1 by A13,SCMPDS_6:def 3;
A16: for x be Int_position st x in X holds s.x=s.x;
  then
A17: IExec(I,P,s).b=s.b by A14,A13;
A18: IExec(I,P,s).a=s.a by A14,A16,A13;
A19: b=DataLoc(IExec(I,P,s).a,i) by A14,A16,A13;
A20: IExec(I,P,s).a=s.a by A14,A16,A13;
A21: Comput(P1, s1,(0 qua Nat)+1) = Following(P1,
Comput(P1,s1,0)) by EXTPRO_1:3
    .= Exec(i1,s1) by A4,A13,SCMPDS_6:11;
A22: IC s4 = 0+1 by A2,A1,A21,SCMPDS_2:57;
  for a holds sI.a = s4.a by A21,SCMPDS_2:57;
  then
A23: DataPart sI = DataPart s4 by SCMPDS_4:8;
A24: I is_halting_on s,P by A14,A16;
  then
A25: PI halts_on sI by A13,SCMPDS_6:def 3;
  PI +* stop I halts_on sI by A25;
  then
A26: I is_halting_on sI,PI by A13,SCMPDS_6:def 3;
A27: I is_closed_on s,P by A14,A16;
  then
A28: Es.b=Exec(i2, IExec(I,P,s)).b by A24,Th29
    .=IExec(I,P,s).b+n by A18,SCMPDS_2:48
    .=s.b+n by A14,A16,A13;
A29: I is_closed_on sI,PI by A14,A16;
  then
A30: IC s5=l1 by A3,A26,A22,A23,A7,Th16;
A31: P6/.IC s6 = P6.IC s6 by PBOOLE:143;
A32: s6=s5 by EXTPRO_1:4;
  then
A33: CurInstr(P6,s6)
     =P1.l1 by A3,A26,A29,A22,A23,A7,Th16,A31
    .=FOR.l1 by A9,A6,GRFUNC_1:2
    .=i2 by Th32;
A34: DataPart Comput(PI, sI,mI) = DataPart s5 by A3,A26,A29,A22,A23,A7,Th16;
  then
A35: s5.a= Comput(PI, sI,mI).a by SCMPDS_4:8
    .=s.a by A20,A25,EXTPRO_1:23;
A36: Es.a=Exec(i2, IExec(I,P,s)).a by A27,A24,Th29
    .=s.a by A12,A18,SCMPDS_2:48;
  now
    per cases;
    suppose
      Es.bj >= 0;
      hence FOR is_halting_on Es,P by Th33;
    end;
    suppose
A37:  Es.bj<0;
      now
        let t be State of SCMPDS,Q;
        assume that
A38:    for x be Int_position st x in X holds t.x=Es.x and
A39:    t.a=Es.a;
A40:    now
          let x be Int_position;
          assume
A41:      x in X;
          hence t.x=Es.x by A38
            .=Exec(i2, IExec(I,P,s)).x by A27,A24,Th29
            .=IExec(I,P,s).x by A10,A18,A41,SCMPDS_2:48
            .=s.x by A14,A16,A41,A13;
        end;
        hence IExec(I,Q,Initialize t).a=t.a by A14,A36,A39;
        thus IExec(I,Q,Initialize t).bj= t.bj by A14,A36,A39,A40;
        thus I is_closed_on t,Q & I is_halting_on t,Q &
         for y be Int_position st y
        in X holds IExec(I,Q,Initialize t).y=t.y by A14,A36,A39,A40;
      end;
      hence FOR is_halting_on Es,P by A10,A11,A12,A36,A37,Th37;
    end;
  end;
  then
A42: P2 halts_on s2 by SCMPDS_6:def 3;
A43: s7 = Following(P1,s6) by EXTPRO_1:3
    .= Exec(i2,s6) by A33;
  then
A44: IC s7= IC s6 + 1 by SCMPDS_2:48
    .= card I+(1+1) by A30,A32;
  then
A45: CurInstr(P7,s7)=P1.l2 by PBOOLE:143
    .=FOR.l2 by A6,A8,GRFUNC_1:2
    .=i3 by Th32;
A46: s8 = Following(P1,s7) by EXTPRO_1:3
    .= Exec(i3,s7) by A45;
  then IC s8=ICplusConst(s7,(0 qua Nat)-(card I+2)) by SCMPDS_2:54
    .= 0 by A44,Th1;
  then
A47: IC s2 =IC Comput(P1,s1,m1) by MEMSTR_0:def 11;
A48: s5.b= Comput(PI, sI,mI).b by A34,SCMPDS_4:8
    .=s.b by A17,A25,EXTPRO_1:23;
A49: s8.b=s7.b by A46,SCMPDS_2:54
    .=s.b+n by A35,A48,A32,A43,SCMPDS_2:48;
  now
    let x be Int_position;
A50: not x in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
    then
A51: s2.x=IExec(J,P,s).x by FUNCT_4:11;
    per cases;
    suppose
      x=b;
      hence s8.x=s2.x by A49,A28,A50,FUNCT_4:11;
    end;
    suppose
A52:  x<>b;
A53:  s5.x= Comput(PI, sI,mI).x by A34,SCMPDS_4:8
        .=IExec(I,P,s).x by A25,EXTPRO_1:23;
A54:  s7.x=s5.x by A35,A32,A43,A52,SCMPDS_2:48;
      Es.x=Exec(i2, IExec(I,P,s)).x by A27,A24,Th29
        .=IExec(I,P,s).x by A19,A52,SCMPDS_2:48;
      hence s8.x=s2.x by A46,A51,A53,A54,SCMPDS_2:54;
    end;
  end;
  then
A55: DataPart s8 = DataPart s2 by SCMPDS_4:8;
A56: Comput(P1,s1,m1)= Initialize IExec(J,P,s)
  by A55,A47,MEMSTR_0:78;
  then CurInstr(P1,Comput(P1,s1,m1))=i1
   by A4,SCMPDS_6:11;
  then m0 > m1 by A15,EXTPRO_1:36;
  then consider nn be Nat such that
A57: m0=m1+nn by NAT_1:10;
  reconsider nn as Nat;
  Comput(P1,s1,m1+m2) = Comput(P2,s2,m2) by A56,EXTPRO_1:4;
  then CurInstr(P1,Comput(P1,s1,m1+m2))
   = halt SCMPDS by A42,EXTPRO_1:def 15;
  then m1 + m2 >= m0 by A15,EXTPRO_1:def 15;
  then
A58: m2 >= nn by A57,XREAL_1:6;
A59: Comput(P1,s1,m0) = Comput(P2,s2,nn) by A56,A57,EXTPRO_1:4;
  then CurInstr(P2,Comput(P2,s2,nn))
   =halt SCMPDS by A15,EXTPRO_1:def 15;
  then nn >= m2 by A42,EXTPRO_1:def 15;
  then nn=m2 by A58,XXREAL_0:1;
  then Result(P1,s1) = Comput(P2,s2,m2) by A15,A59,EXTPRO_1:23;
  hence thesis by A42,EXTPRO_1:23;
end;
