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

theorem Th18:
  for s being State of SCMPDS,I being Program of SCMPDS,a being
  Int_position, i being Integer st s.DataLoc(s.a,i) <= 0 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 State of SCMPDS,I be Program of SCMPDS,a be Int_position, i be
  Integer;
  set d1=DataLoc(s.a,i);
  assume
A1: s.d1 <= 0;
  set i1=(a,i)<=0_goto (card I+2), i2=goto -(card I+1);
  set WHL=while>0(a,i,I), pWHL=stop WHL,
  s3 = Initialize s, P3 = P +* pWHL,
  s4 = Comput(P3,s3,1), P4 = P3;
A2: IC s3 = 0 by MEMSTR_0:def 11;
A3: not d1 in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
  not a in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
  then
A4: s3.DataLoc(s3.a,i)=s3.d1 by FUNCT_4:11
    .= s.d1 by A3,FUNCT_4:11;
A5: WHL = i1 ';' (I ';' i2 ) by SCMPDS_4:15;
  Comput(P3,s3,0+1) = Following(P3,
  Comput(P3,s3,0)) by EXTPRO_1:3
    .= Following(P3,s3)
    .= Exec(i1,s3) by A5,SCMPDS_6:11;
  then
A6: IC s4 = ICplusConst(s3,(card I+2)) by A1,A4,SCMPDS_2:56
    .= (0+(card I+2)) by A2,SCMPDS_6:12;
A7: card WHL=card I+2 by Th15;
  then
A8: (card I+2) in dom pWHL by COMPOS_1:64;
  pWHL c= P4 by FUNCT_4:25;
  then P4.(card I+2) = pWHL.(card I+2) by A8,GRFUNC_1:2
    .=halt SCMPDS by A7,COMPOS_1:64;
  then
A9: CurInstr(P4,s4) = halt SCMPDS by A6,PBOOLE:143;
  now
    let k be Nat;
    per cases;
    suppose
      0 < k;
      then 1+0 <= k by INT_1:7;
      hence IC Comput(P3,s3,k) in dom pWHL
      by A8,A6,A9,EXTPRO_1:5;
    end;
    suppose
      k = 0;
      then Comput(P3,s3,k) = s3;
      hence IC Comput(P3,s3,k) in dom pWHL by A2,COMPOS_1:36;
    end;
  end;
  hence WHL is_closed_on s, P by SCMPDS_6:def 2;
  P3 halts_on s3 by A9,EXTPRO_1:29;
  hence thesis by SCMPDS_6:def 3;
end;
