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 Th39:
  for s being State of SCMPDS, I 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) is_closed_on s,P
 & if=0(a,k1,I) is_halting_on s,P
proof
  let s be State of SCMPDS, I 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 + 1);
  set IF=if=0(a,k1,I), pIF=stop IF, pI=stop I,
  s2 = Initialize s, s3 = Initialize s,
  P2 = P +* pI, P3 = P +* pIF,
  s4 = Comput(P3,s3,1), P4 = P3;
A2: IC s3 = 0 by MEMSTR_0:47;
A3: not b in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
A4: Comput(P3, s3,0 + 1) = Following(P3,Comput(P3,s3,0)) by EXTPRO_1:3
    .= Following(P3,s3) by EXTPRO_1:2
    .= Exec(i,s3) by Th3;
  for a holds s2.a = s4.a by A4,SCMPDS_2:55;
  then
A5: DataPart s2 = DataPart s4 by SCMPDS_4:8;
  not a in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
  then s3.DataLoc(s3.a,k1)=s3.b by FUNCT_4:11
    .=0 by A1,A3,FUNCT_4:11;
  then
A6: IC s4 = IC s3 + 1 by A4,SCMPDS_2:55
    .= (0+1) by A2;
  assume
A7: I is_closed_on s,P;
  then
A8: I is_closed_on s2,P2;
  assume
  I is_halting_on s,P;
  then
A9: P2 halts_on s2;
A10:  0 in dom pIF by COMPOS_1:36;
A11: Start-At(0,SCMPDS) c= s2 & Shift(pI,1) c= P4 by Lm6,FUNCT_4:25;
A12:  stop I c= P2 by FUNCT_4:25;
A13: card pIF = card IF +1 by COMPOS_1:55
    .= card I +1+1 by Th1;
  now
    let k be Nat;
    per cases;
    suppose
      0 < k;
      then consider k1 being Nat such that
A14:  k1 + 1 = k by NAT_1:6;
      reconsider k1 as Nat;
      reconsider m = IC Comput(P2, s2,k1) as Nat;
A15:  card pIF = card pI+1 by A13,COMPOS_1:55;
       m in dom pI by A7;
      then m < card pI by AFINSQ_1:66;
      then
A16:  m+1 < card pIF by A15,XREAL_1:6;
      IC Comput(P3,s3,k) = IC Comput(P3, s4,k1) by A14,EXTPRO_1:4
        .=  (m + 1) by A8,A11,A6,A5,Th22,A12;
      hence IC Comput(P3,s3,k) in dom pIF by A16,AFINSQ_1:66;
    end;
    suppose
      k = 0;
      hence IC Comput(P3,s3,k) in dom pIF by A10,A2,EXTPRO_1:2;
    end;
  end;
  hence IF is_closed_on s,P;
A17: Comput(P3,s3,LifeSpan(P2,s2)+1)
 = Comput(P3,Comput(P3,s3,1),LifeSpan(P2
,s2))
 by EXTPRO_1:4;
  CurInstr(P3,
  Comput(P3,s3,LifeSpan(P2,s2)+1))
   =CurInstr(P3,
   Comput(P3,s4,LifeSpan(P2,s2))) by A17
    .=CurInstr(P2,
    Comput(P2,s2,LifeSpan(P2,s2))) by A8,A11,A6,A5,Th22,A12
    .= halt SCMPDS by A9,EXTPRO_1:def 15;
  then P3 halts_on s3 by EXTPRO_1:29;
  hence thesis;
end;
