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 Th55:
 for J being good really-closed MacroInstruction of SCM+FSA holds
  J does not destroy a &
  s.intloc 0 = 1 & (ProperTimesBody a,J,s,p or J is parahalting)
  implies Times(a, J) is_halting_on s,p
proof let J be good really-closed MacroInstruction of SCM+FSA;
  set I = J;
  assume
A1: J does not destroy a;
  assume
A2: s.intloc 0 = 1;
  set taI = Times(a, I);
  set ST = StepTimes(a,I,p,s);
  set ISu = I ";" SubFrom(a, intloc 0);
  set WH = while>0 ( a, ISu );
  set s1 = Initialized s;
  set Is1 = Initialized s1;
  set SW = StepWhile>0(a, ISu, p, s1);
  set ISW = StepWhile>0(a, ISu, p, Is1);
  assume
A3: ProperTimesBody a,I,s,p or I is parahalting;
  then
A4: ProperTimesBody a,I,s,p by Th50;
  per cases;
  suppose
A5: s.a < 0;
A6: s1.a = s.a by SCMFSA_M:37;
    WH is_halting_on s1,p by A5,A6,SCMFSA_9:38;
    then taI is_halting_on Initialized s,p;
    hence thesis by A2,SCMFSA8B:42;
  end;
  suppose
A7: 0 <= s.a;
A8: ProperBodyWhile>0 a, ISu, s1, p
    proof
      let k be Nat;
      assume SW.k.a > 0;
      then
A9:  k < s.a by A4,A7,Th53,A1;
      then
A10:  ST.k.intloc 0 = 1 by A3,Th50,Th51,A1;
      then
A11:  DataPart ST.k = DataPart Initialized (ST.k) by SCMFSA_M:19;
      I is_halting_on ST.k,p+*Times(a,I) by A4,A9;
      then
A12:  I is_halting_on Initialized ST.k,p+*Times(a,I) by A10,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 A12,SFMASTR1:3;
      hence thesis by A11,SCMFSA8B:5;
    end;
A13: WithVariantWhile>0 a, ISu, Is1, p
    proof
      reconsider sa = s.a as Element of NAT by A7,INT_1:3;
      deffunc U(State of SCM+FSA) = |.$1.a.|;
      consider f being Function of product the_Values_of SCM+FSA,NAT such
      that
A14:  for x being Element of product the_Values_of SCM+FSA holds
      f.x = U(x) from FUNCT_2:sch 4;
A15: 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 A14;
      hence thesis;
     end;
      take f;
      let k be Nat;
      per cases;
      suppose
A16:    k < s.a;
        then
A17:    k-k < s.a-k by XREAL_1:9;
A18:    ST.k.a+k = s.a by A4,A16,Th52,A1;
A19:    k+1 <= sa by A16,NAT_1:13;
        then
A20:    (k+1)-(k+1) <= s.a-(k+1) by XREAL_1:9;
A21:    ST.(k+1).a+(k+1) = s.a by A4,A19,Th52,A1;
        then
A22:    s.a = (ST.(k+1).a+1)+k;
A23:    f.(ISW.(k+1)) = |. ISW.(k+1).a .| by A15
          .= SW.(k+1).a by A21,A20,ABSVALUE:def 1;
        f.(ISW.k) = |. ISW.k.a .| by A15
          .= SW.k.a by A18,A17,ABSVALUE:def 1;
        hence thesis by A18,A22,A23,NAT_1:13;
      end;
      suppose
        k >= s.a;
        hence thesis by A4,A7,Th53,A1;
      end;
    end;
A24: ProperBodyWhile>0 a, ISu, Is1, p by A8;
    WH is_halting_on Is1,p by A24,A13,Th27;
    then WH is_halting_on s1,p;
    then taI is_halting_on Initialized s,p;
    hence thesis by A2,SCMFSA8B:42;
  end;
end;
