reserve A for preIfWhileAlgebra,
  C,I,J for Element of A;
reserve S for non empty set,
  T for Subset of S,
  s for Element of S;
reserve f for ExecutionFunction of A,S,T;

theorem Th99:
  A is free & [s, while(C,I)] in TerminatingPrograms(A,S,T,f)
  implies [s,C] in TerminatingPrograms(A,S,T,f) &
  ex r being non empty FinSequence of S st r.1 = f.(s,C) & r.len r nin T &
  for i being Nat st 1 <= i & i < len r
  holds r.i in T & [r.i, I\;C] in TerminatingPrograms(A,S,T,f) &
  r.(i+1) = f.(r.i, I\;C)
proof
  set TP = TerminatingPrograms(A,S,T,f);
  set rr = s, IJ = while(C,I);
  assume that
A1: A is free and
A2: [s, IJ] in TP;
  reconsider P = TP \ {[s, IJ]} as Subset of [:S, the carrier of A:];
A3: [:S, ElementaryInstructions A:] c= P
  proof
    let x,y be object;
    assume
A4: [x,y] in [:S, ElementaryInstructions A:];
    then y in ElementaryInstructions A by ZFMISC_1:87;
    then
A5: y <> IJ by Th52;
A6: [:S, ElementaryInstructions A:] c= TP by Def35;
    [x,y] <> [s, IJ] by A5,XTUPLE_0:1;
    then [x,y] nin {[s, IJ]} by TARSKI:def 1;
    hence thesis by A4,A6,XBOOLE_0:def 5;
  end;
A7: [:S, {EmptyIns A}:] c= P
  proof
    let x,y be object;
    assume
A8: [x,y] in [:S, {EmptyIns A}:];
    then y in {EmptyIns A} by ZFMISC_1:87;
    then y = EmptyIns A by TARSKI:def 1;
    then
A9: y <> IJ by A1,Th72;
A10: [:S, {EmptyIns A}:] c= TP by Def35;
    [x,y] <> [s, IJ] by A9,XTUPLE_0:1;
    then [x,y] nin {[s, IJ]} by TARSKI:def 1;
    hence thesis by A8,A10,XBOOLE_0:def 5;
  end;
A11: now
    let s be Element of S;
    let C,I,J be Element of A;
    hereby
      assume that
A12:  [s,I] in P and
A13:  [f.(s,I), J] in P;
A14:  [s,I] in TP by A12,ZFMISC_1:56;
A15:  [f.(s,I), J] in TP by A13,ZFMISC_1:56;
A16:  IJ <> I\;J by A1,Th73;
A17:  [s, I\;J] in TP by A14,A15,Def35;
      [rr,IJ] <> [s, I\;J] by A16,XTUPLE_0:1;
      hence [s, I\;J] in P by A17,ZFMISC_1:56;
    end;
    hereby
      assume that
A18:  [s,C] in P and
A19:  [f.(s,C), I] in P and
A20:  f.(s, C) in T;
A21:  [s,C] in TP by A18,ZFMISC_1:56;
A22:  [f.(s,C), I] in TP by A19,ZFMISC_1:56;
A23:  IJ <> if-then-else(C,I,J) by A1,Th74;
A24:  [s, if-then-else(C,I,J)] in TP by A20,A21,A22,Def35;
      [rr,IJ] <> [s, if-then-else(C,I, J)] by A23,XTUPLE_0:1;
      hence [s, if-then-else(C,I,J)] in P by A24,ZFMISC_1:56;
    end;
    hereby
      assume that
A25:  [s,C] in P and
A26:  [f.(s,C), J] in P and
A27:  f.(s, C) nin T;
A28:  [s,C] in TP by A25,ZFMISC_1:56;
A29:  [f.(s,C), J] in TP by A26,ZFMISC_1:56;
A30:  IJ <> if-then-else(C,I,J) by A1,Th74;
A31:  [s, if-then-else(C,I,J)] in TP by A27,A28,A29,Def35;
      [rr,IJ] <> [s, if-then-else(C,I, J)] by A30,XTUPLE_0:1;
      hence [s, if-then-else(C,I,J)] in P by A31,ZFMISC_1:56;
    end;
  end;
  hereby
    assume
A32: [s,C] nin TerminatingPrograms(A,S,T,f);
    now
      let s be Element of S;
      let C9,I9,J be Element of A;
      assume
A33:  [s,C9] in P;
      given r being non empty FinSequence of S such that
A34:  r.1 = f.(s,C9) and
A35:  r.len r nin T and
A36:  for i being Nat st 1 <= i & i < len r
      holds r.i in T & [r.i, I9\;C9] in P & r.(i+1) = f.(r.i, I9\;C9);
A37:  now
        let i be Nat;
        assume that
A38:    1 <= i and
A39:    i < len r;
        [r.i, I9\;C9] in P by A36,A38,A39;
        hence r.i in T & [r.i, I9\;C9] in TP & r.(i+1) = f.(r.i, I9\;C9)
        by A36,A38,A39,ZFMISC_1:56;
      end;
A40:  [s,C9] in TP by A33,ZFMISC_1:56;
      then
A41:  while(C9,I9) <> IJ or s <> rr by A1,A32,Th75;
A42:  [s, while(C9,I9)] in TP by A34,A35,A37,A40,Def35;
      [s, while(C9,I9)] <> [rr,IJ] by A41,XTUPLE_0:1;
      hence [s, while(C9,I9)] in P by A42,ZFMISC_1:56;
    end;
    then for s being Element of S for C,I,J being Element of A holds
    ([s,I] in P & [f.(s,I), J] in P implies [s, I\;J] in P) &
    ([s,C] in P & [f.(s,C), I] in P & f.(s, C) in T
    implies [s, if-then-else(C,I,J)] in P) &
    ([s,C] in P & [f.(s,C), J] in P & f.(s, C) nin T
    implies [s, if-then-else(C,I,J)] in P) & ([s,C] in P &
    (ex r being non empty FinSequence of S st r.1 = f.(s,C) & r.len r nin T &
    for i being Nat st 1 <= i & i < len r
    holds r.i in T & [r.i, I\;C] in P & r.(i+1) = f.(r.i, I\;C))
    implies [s, while(C,I)] in P) by A11;
    then TP c= P by A3,A7,Def35;
    hence contradiction by A2,ZFMISC_1:56;
  end;
  assume
A43: not ex r being non empty FinSequence of S st
  r.1 = f.(rr,C) & r.len r nin T & for i being Nat st 1 <= i & i < len r
  holds r.i in T & [r.i, I\;C] in TP & r.(i+1) = f.(r.i, I\;C);
  now
    let s be Element of S;
    let C9,I9,J be Element of A;
    assume
A44: [s,C9] in P;
    given r being non empty FinSequence of S such that
A45: r.1 = f.(s,C9) and
A46: r.len r nin T and
A47: for i being Nat st 1 <= i & i < len r
    holds r.i in T & [r.i, I9\;C9] in P & r.(i+1) = f.(r.i, I9\;C9);
A48: now
      let i be Nat;
      assume that
A49:  1 <= i and
A50:  i < len r;
      [r.i, I9\;C9] in P by A47,A49,A50;
      hence r.i in T & [r.i, I9\;C9] in TP & r.(i+1) = f.(r.i, I9\;C9)
      by A47,A49,A50,ZFMISC_1:56;
    end;
A51: [s,C9] in TP by A44,ZFMISC_1:56;
    I <> I9 or C <> C9 or s <> rr by A43,A45,A46,A48;
    then
A52: while(C9,I9) <> IJ or s <> rr by A1,Th75;
A53: [s, while(C9,I9)] in TP by A45,A46,A48,A51,Def35;
    [s, while(C9,I9)] <> [rr,IJ] by A52,XTUPLE_0:1;
    hence [s, while(C9,I9)] in P by A53,ZFMISC_1:56;
  end;
  then for s being Element of S for C,I,J being Element of A holds
  ([s,I] in P & [f.(s,I), J] in P implies [s, I\;J] in P) &
  ([s,C] in P & [f.(s,C), I] in P & f.(s, C) in T
  implies [s, if-then-else(C,I,J)] in P) &
  ([s,C] in P & [f.(s,C), J] in P & f.(s, C) nin T
  implies [s, if-then-else(C,I,J)] in P) & ([s,C] in P &
  (ex r being non empty FinSequence of S st r.1 = f.(s,C) & r.len r nin T &
  for i being Nat st 1 <= i & i < len r
  holds r.i in T & [r.i, I\;C] in P & r.(i+1) = f.(r.i, I\;C))
  implies [s, while(C,I)] in P) by A11;
  then TP c= P by A3,A7,Def35;
  hence contradiction by A2,ZFMISC_1:56;
end;
