reserve x,a for Int_position,
  s for State of SCMPDS;
reserve P,Q for Instruction-Sequence of SCMPDS;

theorem Th22:
  for s being 0-started State of SCMPDS,I being halt-free shiftable
  Program of SCMPDS, a be Int_position,i,c be Integer,X,Y be set, f being
  Function of product the_Values_of SCMPDS,NAT st
  (for t be 0-started State of SCMPDS st f.t=0 holds t.DataLoc(s.a,i) <= 0) &
  (for x st x in X holds s.x >= c+s.DataLoc(s.a,i)) &
  (for t be 0-started State of SCMPDS,Q st
   (for x st x in X holds t.x >= c+t.DataLoc(s.a,i)) &
   (for x st x in Y holds t.x=s.x) & t.a=s.a & t.DataLoc(s.a,i) > 0
    holds IExec(I,Q,t).a=t.a &
     I is_closed_on t,Q & I is_halting_on t,Q &
     f.Initialize(IExec(I,Q,t)) < f.t
   & (for x st x in X holds IExec(I,Q,t).x >= c+IExec(I,Q,t).DataLoc(s.a,i))
 & for x st x in Y holds IExec(I,Q,t).x=t.x)
  holds while>0(a,i,I) is_closed_on s, P &
     while>0(a,i,I) is_halting_on s, P
proof
  let s be 0-started State of SCMPDS,
      I be halt-free shiftable Program of SCMPDS, a be
  Int_position,i,c be Integer,X,Y be set,
  f be Function of product the_Values_of SCMPDS,NAT;
  set b=DataLoc(s.a,i);
  set WHL=while>0(a,i,I), pWHL=stop WHL,
  pI=stop I;
  set i1=(a,i)<=0_goto (card I+2), i2=goto -(card I+1);
  defpred P[Nat] means
   for t be 0-started State of SCMPDS,Q st f.t <= $1 &
   (for x st x in X holds t.x >= c+t.b) &
   (for x st x in Y holds t.x=s.x) & t.a=s.a
    holds WHL is_closed_on t,Q & WHL is_halting_on t,Q;
  assume
A1: for t be 0-started State of SCMPDS st f.t=0 holds t.b <= 0;
  assume
A2: for x st x in X holds s.x >= c+s.b;
  assume
A3: for t be 0-started State of SCMPDS,Q
 st (for x st x in X holds t.x >= c+t.b) & (
  for x st x in Y holds t.x=s.x) & t.a=s.a & t.b > 0
   holds IExec(I,Q,t).a=t.a & I is_closed_on t,Q & I is_halting_on t,Q &
  f.Initialize(IExec(I,Q,t)) < f.t &
 (for x st x in X holds IExec(I,Q,t).x >= c+IExec(I,Q,t).b )
   & for x st x in Y holds IExec(I,Q,t).x=t.x;
A4: for k be Nat st P[k] holds P[k + 1]
  proof
    let k be Nat;
    assume
A5: P[k];
    now
      let t be 0-started State of SCMPDS, Q;
A6: Initialize t = t by MEMSTR_0:44;
      assume
A7:   f.t <= k+1;
      assume
A8:   for x st x in X holds t.x >= c+t.b;
      assume
A9:   for x st x in Y holds t.x=s.x;
      assume
A10:  t.a=s.a;
      per cases;
      suppose
        t.b <= 0;
        hence WHL is_closed_on t,Q & WHL is_halting_on t,Q by A10,Th18;
      end;
      suppose
A11:    t.b > 0;
A12:     0 in dom pWHL by COMPOS_1:36;
A13:    WHL = i1 ';' (I ';' i2) by SCMPDS_4:15;
        set Q2 = Q +* pI, Q3 = Q +* pWHL,
        t4 = Comput(Q3,t,1), Q4 = Q3;
A14:    pI c= Q2 by FUNCT_4:25;
A15:    Comput(Q3,t,0+1) = Following(Q3,
Comput(Q3,t,0)) by EXTPRO_1:3
          .= Following(Q3,t)
          .= Exec(i1,t) by A13,A6,SCMPDS_6:11;
        for a holds t.a = t4.a by A15,SCMPDS_2:56;
        then
A16:    DataPart t = DataPart t4 by SCMPDS_4:8;
A17:     WHL c= pWHL by AFINSQ_1:74;
        pWHL c= Q3 by FUNCT_4:25;
        then
A18:    WHL c= Q3 by A17,XBOOLE_1:1;
        Shift(I,1) c= WHL by Lm4;
        then
A19:    Shift(I,1) c= Q4 by A18,XBOOLE_1:1;
A20:    IExec(I,Q,t) = Result(Q2,t) by SCMPDS_4:def 5;
        set m2=LifeSpan(Q2,t), t5=Comput(Q4,t4,m2), Q5 = Q4,
l1= (card I + 1);
A21:    IC t = 0 by MEMSTR_0:def 11;
        set m3=m2 +1;
        set t6=Comput(Q3,t,m3), Q6 = Q3;
        set t7=Comput(Q3,t,m3+1), Q7 = Q3;
        card I + 1 < card I + 2 by XREAL_1:6;
        then
A22:    l1 in dom WHL by Th16;
A23:    I is_closed_on t,Q by A3,A8,A9,A10,A11;
A24:    I is_closed_on t,Q2 by A3,A8,A9,A10,A11;
        I is_halting_on t,Q by A3,A8,A9,A10,A11;
        then
A25:    Q2 halts_on t by A6,SCMPDS_6:def 3;
        Q2+*pI halts_on t by A25;
        then
A26:    I is_halting_on t,Q2 by A6,SCMPDS_6:def 3;
A27:    IC t4 = IC t + 1 by A11,A15,A10,SCMPDS_2:56
          .= 0+1 by A21;
        then
A28:    IC t5=l1 by A14,A26,A24,A16,A19,SCMPDS_7:18;
A29: Q6/.IC t6 = Q6.IC t6 by PBOOLE:143;
A30:    t6=t5 by EXTPRO_1:4;
        then
A31:    CurInstr(Q6,t6) =Q4.l1 by A14,A26,A24,A27,A16,A19,A29,SCMPDS_7:18
          .=WHL.l1 by A22,A18,GRFUNC_1:2
          .=i2 by Th17;
A32:    t7 = Following(Q3,t6) by EXTPRO_1:3
          .= Exec(i2,t6) by A31;
        then IC t7=ICplusConst(t6,0-(card I+1)) by SCMPDS_2:54
          .= 0 by A28,A30,SCMPDS_7:1;
        then
A33:    Initialize t7=t7 by MEMSTR_0:46;
A34:    DataPart Comput(Q2,t,m2) = DataPart t5 by A14,A26,A24,A27,A16,A19,
SCMPDS_7:18;
        then
A35:    DataPart t5 =DataPart Result(Q2,t) by A25,EXTPRO_1:23
          .=DataPart IExec(I,Q,t) by SCMPDS_4:def 5;
A36:    now
          let x be Int_position;
          assume
A37:      x in Y;
          thus t7.x=t5.x by A30,A32,SCMPDS_2:54
            .=IExec(I,Q,t).x by A35,SCMPDS_3:3
            .=t.x by A3,A8,A9,A10,A11,A37
            .=s.x by A9,A37;
        end;
        InsCode i2=14 by SCMPDS_2:12;
        then InsCode i2 in {0,4,5,6,14} by ENUMSET1:def 3;
        then
A38:    Initialize(t7)=Initialize(t6) by A32,Th2
          .=Initialize(IExec(I,Q,t)) by A35,A30,MEMSTR_0:80;
A39:    now
          f.Initialize(IExec(I,Q,t)) < f.Initialize(t)
           by A3,A8,A9,A10,A11,A6;
          then
A40:      f.t7 < k+1 by A7,A38,A33,A6,XXREAL_0:2;
          assume f.Initialize(t7) > k;
          hence contradiction by A40,A33,INT_1:7;
        end;
A41:    t7.b=t5.b by A30,A32,SCMPDS_2:54
          .=IExec(I,Q,t).b by A35,SCMPDS_3:3;
A42:    now
          let x be Int_position;
          assume
A43:      x in X;
          t7.x=t5.x by A30,A32,SCMPDS_2:54
            .=IExec(I,Q,t).x by A35,SCMPDS_3:3;
          hence t7.x >= c+t7.b by A3,A8,A9,A10,A11,A41,A43;
        end;
A44:    t5.a=Comput(Q2,t,m2).a by A34,SCMPDS_4:8
          .=(Result(Q2,t)).a by A25,EXTPRO_1:23
          .=s.a by A10,A3,A8,A9,A11,A20;
A45:    t7.a=t6.a by A32,SCMPDS_2:54
          .=s.a by A44,EXTPRO_1:4;
        then
A46:    WHL is_closed_on t7,Q7 by A5,A42,A36,A39,A33;
        now
          let k be Nat;
          per cases;
          suppose
            k < m3+1;
            then
A47:        k <= m3 by INT_1:7;
            hereby
              per cases by A47,NAT_1:8;
              suppose
A48:            k <= m2;
                hereby
                  per cases;
                  suppose
                    k=0;
                    hence IC Comput(Q3,t,k) in dom pWHL by A12,A21;
                  end;
                  suppose
                    k<>0;
                    then consider kn be Nat such that
A49:                k=kn+1 by NAT_1:6;
                    reconsider kn as Nat;
                    reconsider lm = IC Comput(Q2,t,kn) as Element
of NAT;
                    kn < k by A49,XREAL_1:29;
                    then kn < m2 by A48,XXREAL_0:2;
                    then IC Comput(Q2,t,kn) + 1 = IC Comput(
Q4,t4,kn) by A14,A26,A24,A27,A16,A19,SCMPDS_7:16;
                    then
A50:                IC Comput(Q3,t,k) = (lm+1) by A49,EXTPRO_1:4;
                    IC Comput(Q2,t,kn) in dom pI by A23,A6,SCMPDS_6:def 2;
                    then lm < card pI by AFINSQ_1:66;
                    then lm < card I+1 by COMPOS_1:55;
                    then
A51:                lm+1 <= card I +1 by INT_1:7;
                    card I + 1 < card I + 3 by XREAL_1:6;
                    then lm+1 < card I +3 by A51,XXREAL_0:2;
                    then lm+1 < card pWHL by Lm3;
                    hence IC Comput(Q3,t,k) in dom pWHL by A50,AFINSQ_1:66;
                  end;
                end;
              end;
              suppose
A52:            k=m3;
                l1 in dom pWHL by A22,COMPOS_1:62;
                hence IC Comput(Q3,t,k) in dom pWHL by A14,A26,A24,A27,A16,A19
,A30,A52,SCMPDS_7:18;
              end;
            end;
          end;
          suppose
            k >= m3+1;
            then consider nn be Nat such that
A53:        k=m3+1+nn by NAT_1:10;
            Comput(Q3,t,k)=
            Comput(Q7+*pWHL,t7,nn) by A53,EXTPRO_1:4;
            hence IC Comput(Q3,t,k) in dom pWHL
             by A46,A33,SCMPDS_6:def 2;
          end;
        end;
        hence WHL is_closed_on t,Q by A6,SCMPDS_6:def 2;
A54:     Q7 +* pWHL = Q7;
        WHL is_halting_on t7, Q7 by A5,A45,A42,A36,A39,A33;
        then Q3 halts_on t7 by A33,A54,SCMPDS_6:def 3;
        then Q3 halts_on t by EXTPRO_1:22;
        hence WHL is_halting_on t,Q by A6,SCMPDS_6:def 3;
      end;
    end;
    hence thesis;
  end;
  set n=f.s;
A55: for x st x in Y holds s.x=s.x;
A56: P[0]
  proof
    let t be 0-started State of SCMPDS,Q;
    assume f.t <= 0;
    then f.t=0;
    then
A57: t.b <= 0 by A1;
    assume for x be Int_position st x in X holds t.x >= c+t.b;
    assume for x st x in Y holds t.x=s.x;
    assume t.a=s.a;
    hence thesis by A57,Th18;
  end;
  for k being Nat holds P[k] from NAT_1:sch 2(A56,A4);
  then P[n];
  hence thesis by A2,A55;
end;
