reserve p,p1,p2,h for Instruction-Sequence of SCM+FSA;
reserve k, l, n for Nat,
  j for Integer,
  i,i1 for Instruction of SCM+FSA;
reserve s, s1, s2 for State of SCM+FSA,
  a for read-write Int-Location,
  b for Int-Location,
  I, J for MacroInstruction of SCM+FSA,
  Ig for good MacroInstruction of SCM+FSA,
  i, j, k, m, n for Nat;

theorem Th39:
 for Ig being good really-closed MacroInstruction of SCM+FSA holds
  s.intloc 0 = 1 & ProperBodyWhile>0 a,Ig,s,p &
   WithVariantWhile>0 a, Ig, s, p
    implies for i, j st i <> j & i <= ExitsAtWhile>0(a,Ig,p,s) & j <=
ExitsAtWhile>0(a,Ig,p,s) holds StepWhile>0(a,Ig,p,s).i <> StepWhile>0(a,Ig,p,s)
  .j & DataPart StepWhile>0(a,Ig,p,s).i <> DataPart StepWhile>0(a,Ig,p,s).j
proof let Ig be good really-closed MacroInstruction of SCM+FSA;
  set I = Ig;
  assume that
A1: s.intloc 0 = 1 and
A2: ProperBodyWhile>0 a,I,s,p and
A3: WithVariantWhile>0 a,I,s,p;
  set SW = StepWhile>0(a,I,p,s),
      PW = p +* while>0(a,I);
  consider K being Nat such that
A4: ExitsAtWhile>0(a,I,p,s) = K and
A5: SW.K.a <= 0 and
A6: for i being Nat st SW.i.a <= 0 holds K <= i and
  DataPart Comput(p +* while>0(a,I),(Initialize s),
  (LifeSpan(p +* while>0(a,I),s +* (
  Start-At(0,SCM+FSA))))) = DataPart SW.K by A2,A3,Def6;
  consider f being Function of product the_Values_of SCM+FSA, NAT such
  that
A7: for k being Nat holds f.(SW.(k+1)) < f.(SW.k) or SW.k.a
  <= 0 by A3;
A8: for i, j being Nat st i < j & i <= K & j <= K holds DataPart
  SW.i <> DataPart SW.j
  proof
    let i, j be Nat such that
A9: i < j and
    i <= K and
A10: j <= K;
    per cases by A10,XXREAL_0:1;
    suppose
A11:  j = K;
      assume DataPart SW.i = DataPart SW.j;
      then SW.i.a <= 0 by A5,A11,SCMFSA_M:2;
      hence contradiction by A6,A9,A11;
    end;
    suppose
A12:  j < K;
      defpred X[Nat] means j+$1 <= K implies DataPart SW.(i+$1) =
      DataPart SW.(j+$1);
A13:  for k being Nat st X[k] holds X[k+1]
      proof
        let k be Nat such that
A14:    j+k <= K implies DataPart SW.(i+k) = DataPart SW.(j+k) and
A15:    j+(k+1) <= K;
A16:    SW.(j+k).intloc 0 = 1 by A1,A2,Th33;
A17:    j+k < (j+k)+1 by XREAL_1:29;
        then
A18:    j+k < K by A15,XXREAL_0:2;
        then
A19:    SW.(j+k).a > 0 by A6;
A20:    I is_halting_on SW.(j+k), PW by A2,A19;
        then
A21:    I is_halting_on Initialized SW.(j+k), PW by A16,Lm7;
A22:    SW.(i+k).intloc 0 = 1 by A1,A2,Th33;
A23:    SW.(i+k).a > 0
        proof
          assume not thesis;
          then
A24:      K <= i+k by A6;
          i+k < j+k by A9,XREAL_1:6;
          hence contradiction by A18,A24,XXREAL_0:2;
        end;
        I is_halting_on SW.(i+k),PW by A2,A23;
        then
A25:    I is_halting_on Initialized SW.(i+k),PW by A22,Lm7;
        thus DataPart SW.(i+(k+1)) = DataPart SW.(i+k+1)
          .= DataPart IExec(I,PW,SW.(i+k)) by A22,A23,A25,Th32
          .= DataPart IExec(I,PW,SW.(j+k))
           by A14,A15,A17,A16,A20,SCMFSA8C:20,XXREAL_0:2
          .= DataPart SW.(j+k+1) by A16,A19,A21,Th32
          .= DataPart SW.(j+(k+1));
      end;
      consider p being Element of NAT such that
A26:  K = j+p and
      1 <= p by A12,FINSEQ_4:84;
      assume DataPart SW.i = DataPart SW.j;
      then
A27:  X[0];
      for k being Nat holds X[k] from NAT_1:sch 2(A27, A13);
      then DataPart SW.(i+p) = DataPart SW.K by A26;
      then
A28:  SW.(i+p).a <= 0 by A5,SCMFSA_M:2;
      i+p < K by A9,A26,XREAL_1:6;
      hence contradiction by A6,A28;
    end;
  end;
A29: for i, j being Nat st i < j & i <= K & j <= K holds SW.i <>
  SW.j
  proof
    let i, j be Nat;
    assume that
A30: i < j and
    i <= K and
A31: j <= K;
    defpred X[Nat] means i < $1 & $1 <= j implies f.(SW.$1) < f.(SW.i);
A32: i < K by A30,A31,XXREAL_0:2;
A33: for k being Nat st X[k] holds X[k+1]
    proof
      let k be Nat such that
A34:  i < k & k <= j implies f.(SW.k) < f.(SW.i) and
A35:  i < k+1 and
A36:  k+1 <= j;
A37:  i <= k by A35,NAT_1:13;
      per cases by A37,XXREAL_0:1;
      suppose
A38:    i = k;
        not SW.i.a <= 0 by A6,A32;
        hence thesis by A7,A38;
      end;
      suppose
A39:    i < k;
A40:    k < j by A36,NAT_1:13;
        now
          assume SW.k.a <= 0;
          then K <= k by A6;
          hence contradiction by A31,A40,XXREAL_0:2;
        end;
        then f.(SW.(k+1)) < f.(SW.k) by A7;
        hence thesis by A34,A36,A39,NAT_1:13,XXREAL_0:2;
      end;
    end;
    assume
A41: SW.i = SW.j;
A42: X[0];
    for k being Nat holds X[k] from NAT_1:sch 2(A42, A33 );
    hence contradiction by A30,A41;
  end;
  given i, j being Nat such that
A43: i <> j and
A44: i <= ExitsAtWhile>0(a,I,p,s) & j <= ExitsAtWhile>0(a,I,p,s) &( SW.i
  = SW. j or DataPart SW.i = DataPart SW.j);
  i < j or j < i by A43,XXREAL_0:1;
  hence contradiction by A4,A29,A8,A44;
end;
