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 Th46:
  for s being 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 0-started 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,t).a=t.a &
     IExec(I,Q,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,t).y=t.y)
 holds for-down(a,i,n,I) is_closed_on s,P &
       for-down(a,i,n,I) is_halting_on s,P
proof
  let s be 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-down(a,i,n,I), pFOR=stop FOR,
  pI=stop I;
  set i1=(a,i)<=0_goto (card I+3), i2=AddTo(a,i,-n), i3=goto -(card I+2);
  assume
A1: s.b > 0;
  defpred P[Nat] means
   for t be State of SCMPDS,Q st t.b <= $1 &
    (for x be Int_position st x in X holds t.x=s.x) & t.a=s.a
     holds FOR is_closed_on t,Q & FOR is_halting_on t,Q;
  assume
A2: not b in X;
  assume
A3: n > 0;
  assume
A4: a <> b;
  assume
A5: for t be 0-started 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,t).a=t.a &
  IExec(I,Q,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,t).y=t.y;
A6: for k be Nat st P[k] holds P[k + 1]
  proof
    let k be Nat;
    assume
A7: P[k];
      let t be State of SCMPDS,Q;
      assume
A8:   t.b <= k+1;
      assume
A9:  for x be Int_position st x in X holds t.x=s.x;
A10:  for x be Int_position st x in X holds (Initialize t).x=s.x
       proof let x be Int_position;
        assume x in X;
         then t.x=s.x by A9;
        hence (Initialize t).x=s.x by SCMPDS_5:15;
       end;
      assume
A11:  t.a=s.a;
      then
A12:   (Initialize t).a=s.a by SCMPDS_5:15;
      per cases;
      suppose
        t.b <= 0;
        hence FOR is_closed_on t,Q & FOR is_halting_on t,Q by A11,Th42;
      end;
      suppose
A13:    t.b > 0;
        set t2 = Initialize t, t3 = Initialize t,
        Q2 = Q +* stop I, Q3 = Q +* pFOR,
        t4 = Comput(Q3,t3,1), Q4 = Q3;
A14:    stop I c= Q2 by FUNCT_4:25;
A15:    FOR = i1 ';' (I ';' i2 ';' i3) by Th2;
A16:    Comput(Q3, t3,(0 qua Nat)+1) = Following(Q3,
Comput(Q3,t3,0)) by EXTPRO_1:3
          .= Exec(i1,t3) by A15,SCMPDS_6:11;
        for a holds t2.a = t4.a by A16,SCMPDS_2:56;
        then
A17:    DataPart t2 = DataPart t4 by SCMPDS_4:8;
A18:    IExec(I,Q,Initialize t).b= (Initialize t).b by A5,A10,A12
          .= t.b by SCMPDS_5:15;
        -(-n) > 0 by A3;
        then -n < 0;
        then -n <= -1 by INT_1:8;
        then
A19:    -n+t.b <= -1+t.b by XREAL_1:6;
        t.b-1 <= k by A8,XREAL_1:20;
        then
A20:    -n+t.b <= k by A19,XXREAL_0:2;
        I is_closed_on Initialize t, Q by A5,A10,A12;
        then
A21:    I is_closed_on t,Q by SCMPDS_6:125;
        then
A22:    I is_closed_on t2,Q2 by SCMPDS_6:24;
A23:    not b in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
        set m2=LifeSpan(Q2,t2), t5= Comput(Q4, t4,m2), Q5 = Q4,
        l1= (card I +
1);
A24:    IC t3 = 0 by MEMSTR_0:def 11;
        set m3=m2 +1;
        set t6= Comput(Q3, t3,m3), Q6 = Q3;
        card I + 1 < card I + 3 by XREAL_1:6;
        then
A25:    l1 in dom FOR by Th40;
        set m5=m3+1+1, t8= Comput(Q3, t3,m5), Q8 = Q3;
        set t7= Comput(Q3, t3,m3+1), Q7 = Q3;
A26:    IExec(I,Q,Initialize t).a = (Initialize t).a by A5,A10,A12
           .=t.a by SCMPDS_5:15;
        set l2=(card I+2);
A27:     0 in dom pFOR by COMPOS_1:36;
        card I + 2 < card I + 3 by XREAL_1:6;
        then
A28:    l2 in dom FOR by Th40;
A29:    pFOR c= Q3 by FUNCT_4:25;
        FOR c= pFOR by AFINSQ_1:74;
        then
A30:    FOR c= Q3 by A29,XBOOLE_1:1;
        Shift(I,1) c= FOR by Lm5;
        then
A31:    Shift(I,1) c= Q4 by A30,XBOOLE_1:1;
        I is_halting_on Initialize t, Q by A5,A10,A12;
        then I is_halting_on t,Q by SCMPDS_6:126;
        then
A32:    Q2 halts_on t2 by SCMPDS_6:def 3;
        Q2 +* stop I halts_on Initialize t2 by A32;
        then
A33:    I is_halting_on t2,Q2 by SCMPDS_6:def 3;
        not a in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
        then t3.DataLoc(t3.a,i)= t3.b by A11,FUNCT_4:11
          .= t.b by A23,FUNCT_4:11;
        then
A34:    IC t4 = 0+1 by A24,A13,A16,SCMPDS_2:56;
        then
A35:    IC t5=l1 by A14,A33,A22,A17,A31,Th16;
A36: Q6/.IC t6 = Q6.IC t6 by PBOOLE:143;
A37:    t6=t5 by EXTPRO_1:4;
        then
A38:    CurInstr(Q6,t6)=Q5.l1 by A14,A33,A22,A34,A17,A31,Th16,A36
          .=FOR.l1 by A25,A30,GRFUNC_1:2
          .=i2 by Th41;
A39:    t7 = Following(Q3,t6) by EXTPRO_1:3
          .= Exec(i2,t6) by A38;
        then
A40:    IC t7= IC t6 + 1 by SCMPDS_2:48
          .= card I+(1+1) by A35,A37;
        then
A41:    CurInstr(Q7,t7)=Q3.l2 by PBOOLE:143
          .=FOR.l2 by A30,A28,GRFUNC_1:2
          .=i3 by Th41;
A42:    t8 = Following(Q3,t7) by EXTPRO_1:3
          .= Exec(i3,t7) by A41;
        then IC t8=ICplusConst(t7,(0 qua Nat)-(card I+2)) by SCMPDS_2:54
          .= 0 by A40,Th1;
        then
A43:    Initialize t8=t8 by MEMSTR_0:46;
A44:    DataPart Comput(Q2, t2,m2) = DataPart t5 by A14,A33,A22,A34,A17,A31
,Th16;
        then
A45:    t5.a= Comput(Q2, t2,m2).a by SCMPDS_4:8
          .=s.a by A11,A26,A32,EXTPRO_1:23;
        then DataLoc(t6.a,i)=b by EXTPRO_1:4;
        then t7.a=t6.a by A4,A39,SCMPDS_2:48
          .=s.a by A45,EXTPRO_1:4;
        then
A46:    t8.a=s.a by A42,SCMPDS_2:54;
A47:    now
          let x be Int_position;
          assume
A48:      x in X;
          t5.x= Comput(Q2, t2,m2).x by A44,SCMPDS_4:8
            .=IExec(I,Q,Initialize t).x by A32,EXTPRO_1:23
            .=(Initialize t).x by A5,A48,A10,A12
            .=t.x by SCMPDS_5:15
            .=s.x by A9,A48;
          then t7.x=s.x by A2,A45,A37,A39,A48,SCMPDS_2:48;
          hence t8.x=s.x by A42,SCMPDS_2:54;
        end;
A49:    t5.b= Comput(Q2, t2,m2).b by A44,SCMPDS_4:8
          .=t.b by A18,A32,EXTPRO_1:23;
A50:    t8.b=t7.b by A42,SCMPDS_2:54
          .=t.b+ -n by A45,A49,A37,A39,SCMPDS_2:48;
        then
A51:    FOR is_closed_on t8, Q8 by A7,A46,A47,A20;
        now
          let k be Nat;
          per cases;
          suppose
            k < m5;
            then k <= m3+1 by INT_1:7;
            then
A52:        k <= m3 or k=m3+1 by NAT_1:8;
            hereby
              per cases by A52,NAT_1:8;
              suppose
A53:            k <= m2;
                hereby
                  per cases;
                  suppose
                    k=0;
                    hence IC Comput(Q3, t3,k) in dom pFOR by A27,A24;
                  end;
                  suppose
                    k<>0;
                    then consider kn be Nat such that
A54:                k=kn+1 by NAT_1:6;
                    reconsider kn as Nat;
                    reconsider lm = IC Comput(Q2, t2,kn) as
Nat;
                    kn < k by A54,XREAL_1:29;
                    then kn < m2 by A53,XXREAL_0:2;
                    then IC Comput(Q2, t2,kn) + 1 = IC Comput(
Q4,t4,kn)
                    by A14,A33,A22,A34,A17,A31,Th14;
                    then
A55:                IC Comput(Q3, t3,k)= lm +1 by A54,EXTPRO_1:4;
                    IC Comput(Q2, t2,kn) in dom pI by A21,SCMPDS_6:def 2;
                    then lm < card pI by AFINSQ_1:66;
                    then lm < card I+1 by COMPOS_1:55;
                    then
A56:                lm+1 <= card I +1 by INT_1:7;
                    card I + 1 < card I + 4 by XREAL_1:6;
                    then lm+1 < card I +4 by A56,XXREAL_0:2;
                    then lm+1 < card pFOR by Lm4;
                    hence IC Comput(Q3, t3,k) in dom pFOR by A55,AFINSQ_1:66;
                  end;
                end;
              end;
              suppose
A57:            k=m3;
                l1 in dom pFOR by A25,COMPOS_1:62;
                hence
                IC Comput(Q3, t3,k) in dom pFOR by A14,A33,A22,A34,A17,A31,A37
,A57,Th16;
              end;
              suppose
                k=m3+1;
                hence IC Comput(Q3, t3,k) in dom pFOR by A40,A28,COMPOS_1:62;
              end;
            end;
          end;
          suppose
            k >= m5;
            then consider nn be Nat such that
A58:        k=m5+nn by NAT_1:10;
            reconsider nn as Nat;
            Comput(Q3,t3,k)=
            Comput(Q8 +* pFOR, Initialize t8,nn)
                by A43,A58,EXTPRO_1:4;
            hence IC Comput(Q3, t3,k) in dom pFOR by A51,SCMPDS_6:def 2;
          end;
        end;
        hence FOR is_closed_on t,Q by SCMPDS_6:def 2;
A59: Q3 = Q8 +* pFOR;
        FOR is_halting_on t8, Q8 by A7,A46,A47,A50,A20;
        then Q8 halts_on t8 by A43,A59,SCMPDS_6:def 3;
        then Q3 halts_on t3 by EXTPRO_1:22;
        hence FOR is_halting_on t,Q by SCMPDS_6:def 3;
      end;
  end;
  reconsider n=s.b as Element of NAT by A1,INT_1:3;
A60: P[0] by Th42;
  for k being Nat holds P[k] from NAT_1:sch 2(A60,A6);
  then
A61: P[n];
  for x be Int_position st x in X holds s.x=s.x;
  hence thesis by A61;
end;
