reserve A for preIfWhileAlgebra;
reserve A for Euclidean preIfWhileAlgebra;
reserve X for non empty countable set;
reserve T for Subset of Funcs(X, INT);
reserve f for Euclidean ExecutionFunction of A, Funcs(X, INT), T;
reserve A for Euclidean preIfWhileAlgebra,
  X for non empty countable set,
   z for (Element of X),
  s,s9 for (Element of Funcs(X, INT)),
  T for Subset of Funcs(X, INT),
  f for Euclidean ExecutionFunction of A, Funcs(X, INT), T,
  v for INT-Variable of A,f,
  t for INT-Expression of A,f;
reserve i for Integer;
reserve b for (Element of X),
  g for Euclidean ExecutionFunction of A, Funcs(X, INT), Funcs(X, INT)\(b,0);

theorem Th53:
  for P being set for I being Element of A for i,n being Variable
of g st (ex d being Function st d.b = 0 & d.n = 1 & d.i = 2) & for s st s in P
holds g.(s,I).n = s.n & g.(s,I).i = s.i & g.(s, I) in P & g.(s, i leq n) in P &
  g.(s, i+=1) in P holds s in P implies g iteration_terminates_for I\; i+=1\; i
  leq n, g.(s, i leq n)
proof
  let P be set;
  let I be Element of A;
  let i,n be Variable of g;
  given d being Function such that
A1: d.b = 0 and
A2: d.n = 1 and
A3: d.i = 2;
  set J = i+=1;
  set C = i leq n;
  set S = Funcs(X, INT);
  set h = g;
  assume that
A4: for s st s in P holds g.(s,I).n = s.n & g.(s,I).i = s.i & g.(s, I)
  in P & g.(s, i leq n) in P & g.(s, i+=1) in P and
A5: s in P;
  defpred P[Element of S] means $1 in P;
  reconsider s1 = h.(s, C) as Element of S;
A6: P[s1] by A4,A5;
  deffunc F(Element of S) = In($1.n+1-$1.i, NAT);
  defpred R[Element of S] means $1.i <= $1.n;
  set T = S\(b,0);
A7: i <> n by A2,A3;
A8: for s being Element of S st P[s] & s in T & R[s] holds P[h.(s,I\;J\;C)
qua Element of S] & (R[h.(s,I\;J\;C) qua Element of S] iff h.(s,I\;J\;C) in T)
  & F(h.(s,I\;J\;C) qua Element of S) < F(s)
  proof
    let s be Element of S;
    assume that
A9: P[s] and
    s in T and
A10: R[s];
    set q = h.(s, I\;J);
    set s1 = h.(s, I);
    set q1 = h.(q, C);
A11: q = h.(s1, J) by AOFA_000:def 29;
    s1.i = s.i by A4,A9;
    then q.i = s.i+1 by A11,Th28;
    then
A12: q1.i = s.i+1 by A1,A3,Th35;
    reconsider ni = s.n-s.i as Element of NAT by A10,INT_1:3,XREAL_1:48;
A13: F(s) = ni+1;
A14: q.i <= q.n implies q1.b = 1 by Th35;
A15: q1 = h.(s, I\;J\;C) by AOFA_000:def 29;
    P[s1 qua Element of S] by A4,A9;
    then P[q qua Element of S] by A4,A11;
    hence P[h.(s,I\;J\;C) qua Element of S] by A4,A15;
A16: q.i > q.n implies q1.b = 0 by Th35;
    q1.i = q.i by A1,A3,Th35;
    hence
    R[h.(s,I\;J\;C) qua Element of S] iff h.(s,I\;J\;C) in T by A1,A2,A16,A14
,A15,Th2,Th35;
    s1.n = s.n by A4,A9;
    then q.n = s.n by A7,A11,Th28;
    then q1.n = s.n by A1,A2,Th35;
    then F(q1 qua Element of S) = ni by A12;
    hence thesis by A15,A13,NAT_1:13;
  end;
A17: s.i > s.n implies s1.b = 0 by Th35;
A18: s.i <= s.n implies s1.b = 1 by Th35;
  s1.i = s.i by A1,A3,Th35;
  then
A19: s1 in T iff R[s1] by A1,A2,A17,A18,Th2,Th35;
  h iteration_terminates_for I\;J\;C, s1 from AOFA_000:sch 4(A6,A19, A8);
  hence thesis;
end;
