reserve m,n for Element of NAT,
  i,j for Instruction of SCMPDS,
  I for Program
  of SCMPDS,
  a for Int_position;
reserve Q,U,P for Instruction-Sequence of SCMPDS;

theorem Th16:
  for s being 0-started State of SCMPDS,I being halt-free shiftable
Program of SCMPDS, a,b,c be Int_position,i,d be Integer st card I > 0 & s.a=d &
s.b > 0 & s.c > 0 & s.DataLoc(d,i)=s.b-s.c &
 (for t be 0-started State of SCMPDS,Q st t.b >
0 & t.c > 0 & t.a=d & t.DataLoc(d,i)=t.b-t.c & t.b<>t.c
 holds IExec(I,Q,t).a=d &
I is_closed_on t,Q & I is_halting_on t,Q
 & (t.b > t.c implies IExec(I,Q,t).b=t.b-t.c
& IExec(I,Q,t).c = t.c) & (t.b <= t.c
 implies IExec(I,Q,t).c = t.c-t.b & IExec(I,Q,t)
.b=t.b) & IExec(I,Q,t).DataLoc(d,i)=
IExec(I,Q,t).b-IExec(I,Q,t).c)
 holds while<>0(a,i,I) is_closed_on s,P & while<>0(a,i,I) is_halting_on s,P
   & (s.DataLoc(s.a,i) <> 0
  implies IExec(while<>0(a,i,I),P,s) =
  IExec(while<>0(a,i,I),P,Initialize IExec(I,P,s)))
proof
  let s be 0-started State of SCMPDS,
      I be halt-free shiftable Program of SCMPDS, a,b,c
  be Int_position, i,d be Integer;
  set ci=DataLoc(s.a,i);
  assume
 card I > 0;
  consider f be Function of product the_Values_of SCMPDS,NAT such that
A1: for s be State of SCMPDS holds (s.b = s.c implies f.s =0) & (s.b <>
  s.c implies f.s=max(|.s.b.|,|.s.c.|)) by Th2;
  deffunc F(State of SCMPDS) = f.$1;
  defpred P[set] means ex t be State of SCMPDS st t=$1 & t.b > 0 & t.c > 0 & t
  .DataLoc(d,i)=t.b-t.c;
  assume that
A2: s.a=d and
A3: s.b > 0 and
A4: s.c > 0 and
A5: s.DataLoc(d,i)=s.b-s.c;
  assume
A6: for t be 0-started State of SCMPDS,Q
   st t.b > 0 & t.c > 0 & t.a=d & t.DataLoc(d,
i)=t.b-t.c & t.b<>t.c holds IExec(I,Q,t).a=d
 & I is_closed_on t,Q & I is_halting_on
t,Q & (t.b > t.c implies IExec(I,Q,t).b=t.b-t.c
 & IExec(I,Q,t).c = t.c) & (t.b <= t.c
  implies IExec(I,Q,t).c = t.c-t.b
   & IExec(I,Q,t).b=t.b) & IExec(I,Q,t).DataLoc(d,i)=
  IExec(I,Q,t).b-IExec(I,Q,t).c;
A7: now
    let t be 0-started State of SCMPDS, Q;
    assume that
A8: P[t] and
A9: t.a=s.a and
A10: t.ci <> 0;
    set It=IExec(I,Q,t), t2=Initialize It, t1=t;
    set x=IExec(I,Q,t).b, y=IExec(I,Q,t).c;
    consider v be State of SCMPDS such that
A11: v=t and
A12: v.b > 0 and
A13: v.c > 0 and
A14: v.DataLoc(d,i)=v.b-v.c by A8;
A15: t.b > 0 by A11,A12;
A16: t.c > 0 by A11,A13;
A17: t.DataLoc(d,i)=v.b-v.c by A11,A14
      .=t.b-v.c by A11
      .=t.b-t.c by A11;
    then
A18: t.b<>t.c by A2,A10;
    hence IExec(I,Q,t).a=t.a by A2,A6,A9,A15,A16,A17;
    thus I is_closed_on t,Q & I is_halting_on t,Q by A2,A6,A9,A15,A16,A17,A18;
A19: now
      per cases;
      suppose
A20:    t.b > t.c;
        then t.b-t.c > 0 by XREAL_1:50;
        hence x > 0 by A2,A6,A9,A16,A17,A20;
        thus y > 0 by A2,A6,A9,A16,A17,A20;
A21:    x=t.b-t.c by A2,A6,A9,A16,A17,A20;
        hereby
A22:      max(t.b,t.c)=t.b by A20,XXREAL_0:def 10;
          per cases by XXREAL_0:16;
          suppose
            max(x,y) = x;
            hence max(x,y) < max(t.b,t.c) by A16,A21,A22,XREAL_1:44;
          end;
          suppose
            max(x,y) = y;
            hence max(x,y) < max(t.b,t.c) by A2,A6,A9,A16,A17,A20,A22;
          end;
        end;
      end;
      suppose
A23:    t.b <= t.c;
        hence x > 0 by A2,A6,A9,A15,A17,A18;
        t.b < t.c by A18,A23,XXREAL_0:1;
        then t.c-t.b > 0 by XREAL_1:50;
        hence y > 0 by A2,A6,A9,A15,A17,A18,A23;
A24:    y=t.c-t.b by A2,A6,A9,A15,A17,A18,A23;
A25:    x=t.b by A2,A6,A9,A15,A17,A18,A23;
        hereby
A26:      max(t.b,t.c)=t.c by A23,XXREAL_0:def 10;
          per cases by XXREAL_0:16;
          suppose
            max(x,y) = y;
            hence max(x,y) < max(t.b,t.c) by A15,A24,A26,XREAL_1:44;
          end;
          suppose
            max(x,y) = x;
            hence max(x,y) < max(t.b,t.c) by A18,A23,A25,A26,XXREAL_0:1;
          end;
        end;
      end;
    end;
    thus F(t2) < F(t1)
    proof
      t1.b <> t.c by A18;
      then t1.b <> t1.c;
      then
A27:  F(t1)=max(|.t1.b.|,|.t1.c.|) by A1
        .=max(|.t.b.|,|.t1.c.|)
        .=max(|.t.b.|,|.t.c.|)
        .=max( t.b,|.t.c.|) by A15,ABSVALUE:def 1
        .=max(t.b,t.c) by A16,ABSVALUE:def 1;
      then F(t1) >= t.b by XXREAL_0:25;
      then
A28:  F(t1) > 0 by A15;
      per cases;
      suppose
        t2.b=t2.c;
        hence thesis by A1,A28;
      end;
      suppose
        t2.b<>t2.c;
        then F(t2)=max(|.t2.b.|,|.t2.c.|) by A1
          .=max(|.x.|,|.t2.c.|) by SCMPDS_5:15
          .=max(|.x.|,|.y.|) by SCMPDS_5:15
          .=max( x,|.y.|) by A19,ABSVALUE:def 1
          .=max(x,y) by A19,ABSVALUE:def 1;
        hence thesis by A19,A27;
      end;
    end;
A29: IExec(I,Q,t).DataLoc(d,i)=
     IExec(I,Q,t).b-IExec(I,Q,t).c
 by A2,A6,A9,A15,A16,A17,A18;
    thus P[Initialize It]
    proof
      take v=Initialize It;
      thus v=Initialize It;
      thus v.b > 0 & v.c > 0 by A19,SCMPDS_5:15;
      thus v.DataLoc(d,i)=x-y by A29,SCMPDS_5:15
        .=v.b-y by SCMPDS_5:15
        .=v.b-v.c by SCMPDS_5:15;
    end;
  end;
A30: for t be 0-started State of SCMPDS st P[t] &
F(t)=0 holds t.ci = 0
  proof
    let t be 0-started State of SCMPDS;
    assume that
A31: P[t] and
A32: F(t)=0;
    consider v be State of SCMPDS such that
A33: v=t and
A34: v.b > 0 and
    v.c > 0 and
A35: v.DataLoc(d,i)=v.b-v.c by A31;
A36: now
      assume t.b <> t.c;
      then (t).b <> t.c;
      then (t).b <> (t).c;
      then
A37:  F(t)=max(|.t.b.|,|.t.c .|) by A1
        .=max(|.t.b.|,|.t.c.|)
        .=max(|.t.b.|,|.t.c.|);
      t.b > 0 by A33,A34;
      then |.t.b.| > 0 by COMPLEX1:47;
      hence contradiction by A32,A37,XXREAL_0:25;
    end;
    thus t.ci=v.b-v.c by A2,A33,A35
      .=t.b-v.c by A33
      .=t.b-t.c by A33
      .=0 by A36;
  end;
A38: P[s] by A3,A4,A5;
  while<>0(a,i,I) is_closed_on s,P & while<>0(a,i,I) is_halting_on s,P
   from WhileNHalt(A30,A38,A7);
  hence while<>0(a,i,I) is_closed_on s,P & while<>0(a,i,I) is_halting_on s,P;
  assume
A39: s.DataLoc(s.a,i) <> 0;
  IExec(while<>0(a,i,I),P,s) =
  IExec(while<>0(a,i,I),P,Initialize IExec(I,P,s))
   from WhileNExec(A39,A30,A38,A7);
  hence thesis;
end;
