reserve m,n for Element of NAT,
  i,j for Instruction of SCMPDS,
  I for Program
  of SCMPDS,
  a for Int_position;
reserve Q,U,P for Instruction-Sequence of SCMPDS;

theorem Th12:
  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 b=DataLoc(s.a,i);
  assume
A1: s.b = 0;
  set WHL=while<>0(a,i,I), pWH=stop WHL, iWH=pWH,
  s3 = Initialize s, P3 = P +* pWH,
  s4 = Comput(P3,s3,1), s5 = Comput(P3,s3,2), P4 = P3, P5 = P3;
A2: not b in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
  not a in dom Start-At(0,SCMPDS) by SCMPDS_4:18;
  then
A3: s3.DataLoc(s3.a,i)=s3.b by FUNCT_4:11
    .= 0 by A1,A2,FUNCT_4:11;
  set i1=(a,i)<>0_goto 2, i2=goto (card I+2), i3=goto -(card I+2);
A4: IC s3 = 0 by MEMSTR_0:47;
A5: WHL = i1 ';' (i2 ';' I ';' i3 ) by Lm8;
  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 = IC s3 + 1 by A3,SCMPDS_2:55
    .= (0+1) by A4;
A7: iWH c= P3 by FUNCT_4:25;
  then
A8: pWH c= P4;
A9:  1 in dom WHL by Th10;
  then  1 in dom pWH by COMPOS_1:62;
  then
A10: P4. 1 = pWH. 1 by A8,GRFUNC_1:2
    .=WHL. 1 by A9,COMPOS_1:63
    .=i2 by Th11;
A11: card WHL=card I+3 by Th8;
  then
A12: (card I+3) in dom pWH by COMPOS_1:64;
A13: P4/.IC s4 = P4.IC s4 by PBOOLE:143;
  Comput(P3,s3,1+1) = Following(P3,s4) by EXTPRO_1:3
    .= Exec(i2,s4) by A6,A10,A13;
  then
A14: IC s5 = ICplusConst(s4,card I+2) by SCMPDS_2:54
    .= (card I+2+1) by A6,SCMPDS_6:12
    .= (card I+(2+1));
A15: P5/.IC s5 = P5.IC s5 by PBOOLE:143;
  pWH c= P5 by A7;
  then P5.(card I+3) = pWH.(card I+3) by A12,GRFUNC_1:2
    .=halt SCMPDS by A11,COMPOS_1:64;
  then
A16: CurInstr(P5,s5) = halt SCMPDS by A14,A15;
  now
    let k be Nat;
    k = 0 or 0 < k;
    then
A17: k = 0 or 0 + 1 <= k by INT_1:7;
    per cases by A17,XXREAL_0:1;
    suppose
      k = 0;
      then Comput(P3,s3,k) = s3;
      hence IC Comput(P3,s3,k) in dom pWH by A4,COMPOS_1:36;
    end;
    suppose
      k = 1;
      hence IC Comput(P3,s3,k) in dom pWH by A9,A6,COMPOS_1:62;
    end;
    suppose
      1 < k;
      then 1+1 <= k by INT_1:7;
      hence IC Comput(P3,s3,k) in dom pWH
      by A12,A14,A16,EXTPRO_1:5;
    end;
  end;
  hence WHL is_closed_on s,P by SCMPDS_6:def 2;
  P3 halts_on s3 by A16,EXTPRO_1:29;
  hence thesis by SCMPDS_6:def 3;
end;
