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 Th40:
 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 ex f being Function of product the_Values_of SCM+FSA, NAT
st f is on_data_only & for k being Nat
 holds f.(StepWhile>0(a,Ig,p,s).(k+1)) < f.(StepWhile>0(a,Ig,p,s).k) or
 StepWhile>0(a,Ig,p,s).k.a <= 0
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
  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),Initialize s)))
   = DataPart StepWhile>0(a,I,p,s).K by A2,A3,Def6;
  consider g being Function of product the_Values_of SCM+FSA, NAT such
  that
A6: for k being Nat holds g.(SW.(k+1)) < g.(SW.k) or SW.k.a
  <= 0 by A3;
  defpred P[State of SCM+FSA, set] means (ex k being Nat st k <= K
  & DataPart $1 = DataPart SW.k & $2 = g.(SW.k)) or
  not (ex k being Nat st k <= K & DataPart $1 = DataPart SW.k) & $2 = 0;
A7: for x being Element of product the_Values_of SCM+FSA
 ex y being Element of NAT st P[x,y]
  proof
    let x be  Element of product the_Values_of SCM+FSA;
    per cases;
    suppose
      ex k being Nat st k <= K & DataPart x = DataPart SW.k;
      then consider k being Nat such that
A8:   k <= K & DataPart x = DataPart SW.k;
      take g.(SW.k);
      thus thesis by A8;
    end;
    suppose
A9:   not ex k being Nat st k <= K & DataPart x = DataPart
      SW.k;
      take 0;
      thus thesis by A9;
    end;
  end;
  consider f being Function of product the_Values_of SCM+FSA, NAT such
  that
A10: for x being Element of product the_Values_of SCM+FSA
 holds P[x,f.x]
 from FUNCT_2:sch 3(A7);
  take f;
  hereby
    let s1, s2 such that
A11: DataPart s1 = DataPart s2;
     reconsider ss1=s1, ss2=s2 as
      Element of product the_Values_of SCM+FSA by CARD_3:107;
    ( P[ss1, f.ss1])& P[ss2, f.ss2] by A10;
    hence f.s1 = f.s2 by A1,A2,A3,A4,A11,Th39;
  end;
  let k be Nat;
  per cases;
  suppose
A12: k < K;
    then
A13: k+1 <= K by NAT_1:13;
    then consider kk1 being Nat such that
A14: kk1 <= K & DataPart SW.(k+1) = DataPart SW.kk1 and
A15: f.(SW.(k+1))=g.(SW.kk1) by A10;
A16: k+1 = kk1 by A1,A2,A3,A4,A13,A14,Th39;
    consider kk being Nat such that
A17: kk <= K & DataPart SW.k = DataPart SW.kk and
A18: f.(SW.k) = g.(SW.kk) by A10,A12;
    k = kk by A1,A2,A3,A4,A12,A17,Th39;
    hence thesis by A6,A18,A15,A16;
  end;
  suppose
    K <= k;
    then DataPart SW.K = DataPart SW.k by A5,Th37;
    hence thesis by A5,SCMFSA_M:2;
  end;
end;
