reserve
  S for (4,1) integer bool-correct non empty non void BoolSignature,
  X for non-empty ManySortedSet of the carrier of S,
  T for vf-free integer all_vars_including inheriting_operations free_in_itself
  (X,S)-terms VarMSAlgebra over S,
  C for (4,1) integer bool-correct non-empty image of T,
  G for basic GeneratorSystem over S,X,T,
  A for IfWhileAlgebra of the generators of G,
  I for integer SortSymbol of S,
  x,y,z,m for pure (Element of (the generators of G).I),
  b for pure (Element of (the generators of G).the bool-sort of S),
  t,t1,t2 for Element of T,I,
  P for Algorithm of A,
  s,s1,s2 for Element of C-States(the generators of G);
reserve
  f for ExecutionFunction of A, C-States(the generators of G),
  (\falseC)-States(the generators of G, b);
reserve u for ManySortedFunction of FreeGen T, the Sorts of C;
reserve
  S for 1-1-connectives (4,1) integer (11,1,1)-array 11 array-correct
  bool-correct non empty non void BoolSignature,
  X for non-empty ManySortedSet of the carrier of S,
  T for vf-free all_vars_including inheriting_operations free_in_itself
  (X,S)-terms integer-array non-empty VarMSAlgebra over S,
  C for (11,1,1)-array (4,1) integer bool-correct non-empty image of T,
  G for basic GeneratorSystem over S,X,T,
  A for IfWhileAlgebra of the generators of G,
  I for integer SortSymbol of S,
  x,y,m,i for pure (Element of (the generators of G).I),
  M,N for pure (Element of (the generators of G).the_array_sort_of S),
  b for pure (Element of (the generators of G).the bool-sort of S),
  s,s1 for (Element of C-States(the generators of G));
reserve u for ManySortedFunction of FreeGen T, the Sorts of C;

theorem
  for A being elementary IfWhileAlgebra of the generators of G
  for f being ExecutionFunction of A, C-States(the generators of G),
  (\falseC)-States(the generators of G,b) holds
  f in C-Execution(A,b,\falseC) & G is C-supported & i <> m implies
  m:=(\0(T,I),A)\;
  for-do(i:=(\1(T,I),A), b gt(length(@M,I),@i,A), i:=(@i+\1(T,I),A),
         if-then(b gt(@M.(@i), @M.(@m), A), m:=(@i,A)))
  is_terminating_wrt f, {s: s.(the_array_sort_of S).M <> {}}
  proof
    let A be elementary IfWhileAlgebra of the generators of G;
    let f be ExecutionFunction of A, C-States(the generators of G),
    (\falseC)-States(the generators of G,b);
    assume A1: f in C-Execution(A,b,\falseC);
    assume A2: G is C-supported;
    assume A3: i <> m;
    set J = m:=(\0(T,I),A);
    set K = i:=(\1(T,I),A);
    set W = b gt(length(@M,I),@i,A);
    set L = i:=(@i+\1(T,I),A);
    set N = b gt(@M.(@i), @M.(@m), A);
    set O = m:=(@i,A);
    set a = the_array_sort_of S;
    set P = {s: s.(a).M <> {}};
A4: (the Sorts of C).the bool-sort of S = BOOLEAN &
    (the Sorts of C).a = INT^omega by Th74,AOFA_A00:def 32;
    then
A5: the bool-sort of S <> a & I <> a & the bool-sort of S <> I
    by Th73,AOFA_A00:53;
A6: P is_invariant_wrt J, f
    proof
      let s; assume s in P;
      then consider s1 such that
A7:   s = s1 & s1.a.M <> {};
      f.(s,J).a.M = s.a.M by A1,A2,A5,Th65;
      hence thesis by A7;
    end;
A8: P is_invariant_wrt K,f
    proof
      let s; assume s in P;
      then consider s1 such that
A9:   s = s1 & s1.a.M <> {};
      f.(s,K).a.M = s.a.M by A1,A2,A5,Th65;
      hence thesis by A9;
    end;
A10: P is_invariant_wrt W,f
    proof
      let s; assume s in P;
      then consider s1 such that
A11:   s = s1 & s1.a.M <> {};
      f.(s,W).a.M = s.a.M by A1,A2,A4,Th65;
      hence thesis by A11;
    end;
A12: P is_invariant_wrt L,f
    proof
      let s; assume s in P;
      then consider s1 such that
A13:   s = s1 & s1.a.M <> {};
      f.(s,L).a.M = s.a.M by A1,A2,A5,Th65;
      hence thesis by A13;
    end;
A14: P is_invariant_wrt N,f
    proof
      let s; assume s in P;
      then consider s1 such that
A15:   s = s1 & s1.a.M <> {};
      f.(s,N).a.M = s.a.M by A1,A2,A4,Th65;
      hence thesis by A15;
    end;
A16: P is_invariant_wrt O,f
    proof
      let s; assume s in P;
      then consider s1 such that
A17:   s = s1 & s1.a.M <> {};
      f.(s,O).a.M = s.a.M by A1,A2,A5,Th65;
      hence thesis by A17;
    end;
    set ST = C-States(the generators of G);
    set TV = (\falseC)-States(the generators of G, b);
A18: f complies_with_if_wrt TV by AOFA_000:def 32;
A19: P is_invariant_wrt if-then(N,O), f
    proof
      let s; assume s in P;
      then
A20:   f.(s,N) in P by A14;
      per cases;
      suppose f.(s, N) in TV;
        then f.(s,if-then(N,O)) = f.(f.(s,N),O) by A18;
        hence thesis by A20,A16;
      end;
      suppose f.(s, N) nin TV;
        then f.(s,if-then(N,O)) = f.(f.(s,N),EmptyIns A) by A18;
        hence thesis by A20,AOFA_000:def 28;
      end;
    end;
A21: J is_terminating_wrt f,P by AOFA_000:107;
    for s holds f.(s,if-then(N,O)).I.i = s.I.i & f.(s,W).I.i = s.I.i &
    length(@M,I) value_at(C,f.(s,W)) = length(@M,I) value_at(C,s) &
    length(@M,I) value_at(C,f.(s,if-then(N,O)\;L)) =
    length(@M,I) value_at(C,s)
    proof
      let s;
      hereby
        per cases;
        suppose f.(s,N) in TV;
          then f.(s,if-then(N,O)) = f.(f.(s,N),O) by A18;
          hence f.(s,if-then(N,O)).I.i = f.(s,N).I.i by A1,A2,A3,Th65
          .= s.I.i by A1,A2,A5,Th65;
        end;
        suppose f.(s,N) nin TV;
          then f.(s,if-then(N,O)) = f.(f.(s,N),EmptyIns A)
          by A18;
          hence f.(s,if-then(N,O)).I.i = f.(s,N).I.i by AOFA_000:def 28
          .= s.I.i by A1,A2,A5,Th65;
        end;
      end;
A22:   now
        per cases;
        suppose f.(s,N) in TV;
          then f.(s,if-then(N,O)) = f.(f.(s,N),O) by A18;
          hence f.(s,if-then(N,O)).a.M = f.(s,N).a.M by A1,A2,A5,Th65
          .= s.a.M by A1,A2,A4,Th65;
        end;
        suppose f.(s,N) nin TV;
          then f.(s,if-then(N,O)) = f.(f.(s,N),EmptyIns A)
          by A18;
          hence f.(s,if-then(N,O)).a.M = f.(s,N).a.M by AOFA_000:def 28
          .= s.a.M by A1,A2,A4,Th65;
        end;
      end;
      thus f.(s,W).I.i = s.I.i by A1,A2,A5,Th65;
A23:   @M value_at(C,f.(s,if-then(N,O)\;L))
      = f.(s,if-then(N,O)\;L).a.M &
      @M value_at(C,f.(s,W)) = f.(s,W).a.M & @M value_at(C,s) = s.a.M by Th61;
      thus length(@M,I) value_at(C,f.(s,W))
      = length(@M value_at(C,f.(s,W)),I) by Th81
      .= len(f.(s,W).a.M) by A23,Th74
      .= len(s.a.M) by A1,A2,A4,Th65
      .= length(@M value_at(C,s),I) by A23,Th74
      .= length(@M,I) value_at(C,s) by Th81;
      thus length(@M,I) value_at(C,f.(s,if-then(N,O)\;L))
      = length(@M value_at(C,f.(s,if-then(N,O)\;L)),I) by Th81
      .= len(f.(s,if-then(N,O)\;L).a.M) by A23,Th74
      .= len(f.(f.(s,if-then(N,O)),L).a.M) by AOFA_000:def 29
      .= len(f.(s,if-then(N,O)).a.M) by A1,A2,A5,Th65
      .= length(@M value_at(C,s),I) by A23,A22,Th74
      .= length(@M,I) value_at(C,s) by Th81;
   end;
   then for-do(K,W,L,if-then(N,O)) is_terminating_wrt f, P
   by A1,A2,A8,A10,A12,A19,Th94,AOFA_000:107;
   hence thesis by A6,A21,AOFA_000:111;
 end;
