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

theorem Th29:
  for s being 0-started State of SCMPDS, I,J being shiftable Program of
  SCMPDS, a being Int_position,k1 being Integer st s.DataLoc(s.a,k1)= 0 & I
is_closed_on s,P & I is_halting_on s,P holds if=0(a,k1,I,J) is_closed_on s,P
 & if=0(a,k1,I,J) is_halting_on s,P
proof
  let s be 0-started State of SCMPDS, I,J be shiftable Program of SCMPDS, a be
  Int_position,k1 be Integer;
  set b=DataLoc(s.a,k1);
  assume
A1: s.b = 0;
  set i = (a,k1)<>0_goto (card I + 2);
  set G=Goto (card J+1);
  set I2 = I ';' G ';' J, IF=if=0(a,k1,I,J), pIF=stop IF,
   pI2=stop I2, P2 = P +* pI2, P3 = P +* pIF,
  s4 = Comput(P3,s,1),
  P4 = P3;
A2: Initialize s = s by MEMSTR_0:44;
   then
A3: IC s = 0 by MEMSTR_0:47;
A4: IF = i ';' (I ';' G) ';' J by SCMPDS_4:14
    .= i ';' I2 by SCMPDS_4:14;
  then
A5: Shift(pI2,1) c= P4 by Lm6;
A6: Comput(P3, s,0 + 1) = Following(P3,Comput(P3,s,0)) by EXTPRO_1:3
    .= Following(P3,s) by EXTPRO_1:2
    .= Exec(i,s) by A4,Th3,A2;
  for a holds s.a= s4.a by A6,SCMPDS_2:55;
  then
A7: DataPart s = DataPart s4 by SCMPDS_4:8;
  s.DataLoc(s.a,k1)=s.b
    .=0 by A1;
  then
A8: IC s4 = IC s + 1 by A6,SCMPDS_2:55
    .= (0+1) by A3;
A9:  0 in dom pIF by COMPOS_1:36;
  assume
A10: I is_closed_on s,P;
  assume
A11: I is_halting_on s,P;
  then I2 is_halting_on s,P by A10,Th21;
  then
A12: P2 halts_on s by A2;
A13: I2 is_closed_on s,P by A10,A11,Th21;
  then
A14: Start-At(0,SCMPDS) c= s & I2 is_closed_on s,P2 by A2,FUNCT_4:25;
A15: card pIF = card IF +1 by COMPOS_1:55
    .= card I2 +1+1 by A4,Th1;
A16:  stop I2 c= P2 by FUNCT_4:25;
  now
    let k be Nat;
    per cases;
    suppose
      0 < k;
      then consider k1 being Nat such that
A17:  k1 + 1 = k by NAT_1:6;
      reconsider k1 as Nat;
      reconsider m = IC Comput(P2, s,k1) as Nat;
A18:  card pIF = card pI2+1 by A15,COMPOS_1:55;
       m in dom pI2 by A13,A2;
      then m < card pI2 by AFINSQ_1:66;
      then
A19:  m+1 < card pIF by A18,XREAL_1:6;
     IC Comput(P3,s,k) = IC Comput(P3, s4,k1) by A17,EXTPRO_1:4
        .= m + 1 by A14,A5,A8,A7,Th22,A16;
      hence IC Comput(P3,s,k) in dom pIF by A19,AFINSQ_1:66;
    end;
    suppose
      k = 0;
      hence IC Comput(P3,s,k) in dom pIF by A9,A3,EXTPRO_1:2;
    end;
  end;
  hence IF is_closed_on s,P by A2;
A20: Comput(P3,s,LifeSpan(P2,s)+1)
 = Comput(P3,Comput(P3,s,1),LifeSpan(P2
,s))
by EXTPRO_1:4;
  CurInstr(P3,Comput(P3,s,LifeSpan(P2,s)+1))
   =CurInstr(P4,Comput(P4,s4,LifeSpan(P2,s))) by A20
    .=CurInstr(P2,Comput(P2,s,LifeSpan(P2,s))) by A14,A5,A8,A7,Th22,A16
    .= halt SCMPDS by A12,EXTPRO_1:def 15;
  then P3 halts_on s by EXTPRO_1:29;
  hence thesis by A2;
end;
