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;
reserve s, s1, s2 for State of SCM+FSA,
  p, p1 for Instruction-Sequence of SCM+FSA,
  a, b for Int-Location,
  d for read-write Int-Location,
  f for FinSeq-Location,
  I for MacroInstruction of SCM+FSA,
  J for good MacroInstruction of SCM+FSA,
  k, m, n for Nat;
reserve a for read-write Int-Location;

theorem
 for J being good really-closed MacroInstruction of SCM+FSA holds
  J does not destroy a &
  s.a = k & (ProperTimesBody a,J,s,p or J is parahalting)
implies
   DataPart IExec(Times(a,J),p,s) = DataPart StepTimes(a,J,p,s).k
proof let J be good really-closed MacroInstruction of SCM+FSA;
  set I = J;
  assume
A1: J does not destroy a;
  assume
A2: s.a = k;
  set ST = StepTimes(a,I,p,s);
  reconsider ISu = I ";" SubFrom(a, intloc 0)
      as really-closed MacroInstruction of SCM+FSA;
:: !!!
  set s1 = Initialized s;
  set Is1 = Initialized s1;
  set SW = StepWhile>0(a, ISu, p, s1);
  set ISW = StepWhile>0(a, ISu, p, Is1);
  set WH = while>0 ( a, ISu );
  assume
A3: ProperTimesBody a,I,s,p or I is parahalting;
  then
A4: ProperTimesBody a,I,s,p by Th50;
A5: ProperBodyWhile>0 a, ISu, s1, p
  proof
    let k be Nat;
    assume SW.k.a > 0;
    then
A6: k < s.a by A2,A4,Th53,A1;
    then
A7: ST.k.intloc 0 = 1 by A3,Th50,Th51,A1;
    then
A8: DataPart ST.k = DataPart Initialized (ST.k) by SCMFSA_M:19;
    I is_halting_on ST.k,p+*Times(a,I) by A4,A6;
    then
A9: I is_halting_on Initialized ST.k,p+*Times(a,I) by A7,SCMFSA8B:42;
    Macro SubFrom(a, intloc 0)
     is_halting_on IExec(I,p+*Times(a,I),ST.k),p+*Times(a,I) by SCMFSA7B:19;
    then ISu is_halting_on
     Initialized ST.k,p+*Times(a,I) by A9,SFMASTR1:3;
    hence thesis by A8,SCMFSA8B:5;
  end;
A10: WithVariantWhile>0 a, ISu, Is1, p
  proof
    reconsider sa = s.a as Element of NAT by A2,ORDINAL1:def 12;
    deffunc U(State of SCM+FSA) = |.$1.a.|;
    consider f being Function of product the_Values_of SCM+FSA,NAT such
    that
A11: for x being Element of product the_Values_of SCM+FSA holds f
    .x = U(x) from FUNCT_2:sch 4;
A12: for x being State of SCM+FSA holds f.x = U(x)
     proof let x be State of SCM+FSA;
      reconsider x as Element of product the_Values_of SCM+FSA
        by CARD_3:107;
       f.x = U(x) by A11;
      hence thesis;
     end;
    take f;
    let k be Nat;
    per cases;
    suppose
A13:  k < s.a;
      then
A14:  k-k < s.a-k by XREAL_1:9;
A15:  ST.k.a+k = s.a by A4,A13,Th52,A1;
A16:  k+1 <= sa by A13,NAT_1:13;
      then
A17:  (k+1)-(k+1) <= s.a-(k+1) by XREAL_1:9;
A18:  ST.(k+1).a+(k+1) = s.a by A4,A16,Th52,A1;
      then
A19:  s.a = (ST.(k+1).a+1)+k;
A20:  f.(ISW.(k+1)) = |. ISW.(k+1).a .| by A12
        .= SW.(k+1).a by A18,A17,ABSVALUE:def 1;
      f.(ISW.k) = |. ISW.k.a .| by A12
        .= SW.k.a by A15,A14,ABSVALUE:def 1;
      hence thesis by A15,A19,A20,NAT_1:13;
    end;
    suppose
      k >= s.a;
      hence thesis by A2,A4,Th53,A1;
    end;
  end;
A21: ProperBodyWhile>0 a, ISu, Is1, p by A5;
  then consider K being Nat such that
A22: ExitsAtWhile>0(a, ISu, p, Is1) = K and
A23: ISW.K.a <= 0 and
A24: for i being Nat st ISW.i.a <= 0 holds K <= i and
  DataPart Comput(p+*WH,(Initialize Is1),(
LifeSpan(p+*WH,Initialize Is1)
  )) = DataPart ISW.K by A10,Def6;
A25: DataPart IExec(WH,p,s1)
 = DataPart ISW.ExitsAtWhile>0(a, ISu, p, Is1) by A21,A10,Th36;
  SW.k.a = 0 by A2,A4,Th53,A1;
  then ISW.k.a = 0;
  then
A26: K <= k by A24;
  then
A27: SW.K.a+K = k by A2,A4,Th52,A1;
  K-K <= k-K by A26,XREAL_1:9;
  then
A28: ISW.K.a = 0 by A23,A27;
A29: ISW.K.a+K = k by A27;
A30:  now
      let x be Int-Location;
      thus IExec(Times(a,I),p,s).x
         = IExec(WH,p,s1).x by SCMFSA8C:3
        .= ST.k.x by A25,A22,A29,A28,SCMFSA_M:2;
    end;
  now
    let x be FinSeq-Location;
    thus IExec(Times(a,I),p,s).x
     = IExec(WH,p,s1).x by SCMFSA8C:3
      .= ST.k.x by A25,A22,A29,A28,SCMFSA_M:2;
  end;
  hence thesis by A30,SCMFSA_M:2;
end;
