reserve s for State of SCM+FSA,
  I for MacroInstruction of SCM+FSA,
  a for read-write Int-Location;
reserve i,j,k,n for Nat;
reserve P,P1,P2,Q for Instruction-Sequence of SCM+FSA;

theorem
  for I be really-closed MacroInstruction of SCM+FSA,
      a be read-write Int-Location, s be State
of SCM+FSA st ex f being Function of product the_Values_of SCM+FSA,NAT st
  (for k being Nat holds ( f.(StepWhile>0(a,P,s,I).k) <> 0
   implies f.(StepWhile>0(a,P,s,I).(k+1)) < f.(StepWhile>0(a,P,s,I).k) &
  I is_halting_onInit StepWhile>0(a,P,s,I).k,P+*while>0(a,I)) &
  (StepWhile>0(a,P,s,I).(k+1)).intloc 0=1 &
   ( f.(StepWhile>0(a,P,s,I).k)=0 iff (StepWhile>0(a,P,s,I).k).a <= 0 ) )
    holds while>0(a,I) is_halting_onInit s,P
proof
  let I be really-closed MacroInstruction of SCM+FSA,
      a be read-write Int-Location,s be State of
  SCM+FSA;
  set D = Data-Locations SCM+FSA;
  given f be Function of product the_Values_of SCM+FSA,NAT such that
A1: for k be Nat holds (f.(StepWhile>0(a,P,s,I).k) <> 0 implies
  f.(StepWhile>0(a,P,s,I).(k+1)) < f.(StepWhile>0(a,P,s,I).k) &
  I is_halting_onInit StepWhile>0(a,P,s,I).k,P+*while>0(a,I)) &
  (StepWhile>0(a,P,s,I).(k+1)).intloc 0=1 &
  (f.(StepWhile>0(a,P,s,I).k)=0 iff (StepWhile>0(a,P,s,I).k).a <= 0);
  set
      s1 = Initialized s, P1 = P +* while>0(a,I);
A2:  P1 +* while>0(a,I) = P1;
  deffunc F(Nat) = f.(StepWhile>0(a,P,s,I).$1);
A3: for k being Nat holds F(k+1) < F(k) or F(k) = 0
  by A1;
  consider m being Nat such that
A4: F(m)=0 and
A5: for n being Nat st F(n) =0 holds m <= n from NAT_1:sch 17(A3);
  reconsider m as Nat;
  defpred P[Nat] means $1+1 <= m implies
   ex k st StepWhile>0(a,P,s,I).($1+1)= Comput(P1, s1,k);
A6: P[ 0]
  proof
    assume 0+1 <= m;
    take n=LifeSpan(P +* while>0(a,I)+* I,Initialized s) + 2;
    thus thesis by Th8;
  end;
A7: now
    let i be Nat;
    assume i<m;
    then F(i)<>0 by A5;
    hence I is_halting_onInit StepWhile>0(a,P,s,I).i,P+*while>0(a,I) by A1;
  end;
A8: now
    let k be Nat;
    assume
A9: P[k];
    now
      set sk=StepWhile>0(a,P,s,I).k, sk1=StepWhile>0(a,P,s,I).(k+1);
      assume
A10:  (k+1)+ 1 <= m;
      (k+1)+ 0 < (k+ 1)+ 1 by XREAL_1:6;
      then consider n be Nat such that
A11:  sk1 = Comput(P1,s1,n) by A9,A10,XXREAL_0:2;
A12:  sk1.intloc 0=1 by A1;
      k + 0 < k+ (1+ 1) by XREAL_1:6;
      then
A13:  k < m by A10,XXREAL_0:2;
      then
A14:  I is_halting_onInit sk,P1 by A7;
      F(k) <> 0 by A5,A13;
      then
A15:  sk.a > 0 by A1;
      take m=n +(LifeSpan(P +* while>0(a,I) +* I,Initialized sk1) + 2);
A16:  P+*while>0(a,I) +* while>0(a,I) = P+*while>0(a,I);
A17:  sk1= Comput(P +* while>0(a,I),Initialized sk,
           LifeSpan(P +* while>0(a,I) +* I,Initialized sk) + 2) by Def1;
      IC sk1 = 0 by A17,A14,A15,Th4,A16;
      then
        StepWhile>0(a,P,s,I).(k+1+1)= Comput(P1, Initialized s,
          n +(LifeSpan(P +* while>0(a,I) +* I,
          Initialized StepWhile>0(a,P,s,I).(k+1)) + 2))
                by A11,A12,Th9;
  hence StepWhile>0(a,P,s,I).(k+1+1)= Comput(P1, s1,m);
    end;
    hence P[k+1];
  end;
A18: for k being Nat holds P[k] from NAT_1:sch 2(A6,A8);
    per cases;
    suppose
      m=0;
      then (StepWhile>0(a,P,s,I).0).a <= 0 by A1,A4;
      then s.a <= 0 by Def1;
      hence thesis by SCM_HALT:73;
    end;
    suppose m<>0;
      then consider i being Nat such that
A19:  m=i+1 by NAT_1:6;
      reconsider i as Nat;
      set si=StepWhile>0(a,P,s,I).i, sm=StepWhile>0(a,P,s,I).m,
      sm1=Initialized sm, sm2=Initialize sm;
A20:  i<m by A19,XREAL_1:29;
      i < m by A19,NAT_1:13;
      then F(i) <> 0 by A5;
      then
A21:  si.a > 0 by A1;
A22:  I is_halting_onInit si,P+*while>0(a,I) by A7,A20;
      sm= Comput(P +* while>0(a,I), Initialized si,
      (LifeSpan(P +* while>0(a,I) +* I,Initialized si)) + 2)
               by A19,Def1;
      then IC sm = 0 by A22,A21,Th4,A2;
      then
A23:  Start-At(0,SCM+FSA) c= sm by MEMSTR_0:30;
      StepWhile>0(a,P,s,I).(i+1).intloc 0 = 1 by A1;
      then
A24:  sm1=sm2 by A19,SCMFSA_M:18;
      set p=(LifeSpan(P+*while>0(a,I) +* I,Initialized s) + 3);
      m=i+1 by A19;
      then consider n being Nat such that
A25:  sm = Comput(P1,s1,n) by A18;
A26:  sm1=sm by A24,A23,FUNCT_4:98;
      sm.a <= 0 by A1,A4;
      then while>0(a,I) is_halting_onInit sm,P+*while>0(a,I) by SCM_HALT:73;
      then P+*while>0(a,I) halts_on sm1;
      then consider j being Nat such that
A27:  CurInstr(P+*while>0(a,I),Comput(P+*while>0(a,I),sm,j))
          = halt SCM+FSA by A26;
A28: Comput(P1,s1,j+n) = Comput(P1,Comput(P1,s1,n),j) by EXTPRO_1:4;
      P1 halts_on s1 by A25,A27,A28,EXTPRO_1:29;
      hence while>0(a,I) is_halting_onInit s,P;
    end;
end;
