reserve x for set,
  m,n for Nat,
  a,b for Int_position,
  i,j,k for Instruction of SCMPDS,
  s,s1,s2 for State of SCMPDS,
  k1,k2 for Integer,
  loc,l for Nat,
  I,J,K for Program of SCMPDS;
reserve P,P1,P2,Q for Instruction-Sequence of SCMPDS;

theorem Th51:
  for s being 0-started State of SCMPDS,sp,cv,result,pp,pD be Nat
st s.intpos sp > sp & cv < result & s.intpos pp=pD & s.intpos sp+result < pp &
pp <pD & pD < s.intpos pD
 holds for-down(intpos sp,cv,1, AddTo(intpos sp,result,intpos pD,0) ';'
  AddTo(intpos pp,0,1)) is_closed_on s,P &
   for-down(intpos sp,cv,1, AddTo(intpos sp,result,intpos pD,0) ';'
  AddTo(intpos pp,0,1)) is_halting_on s,P
proof
  let s be 0-started State of SCMPDS, sp,cv,fr,pp,pD be Nat;
  set BP=intpos sp, PD=intpos pD, PP=intpos pp;
  assume that
A1: s.BP > sp and
A2: cv < fr and
A3: s.PP=pD and
A4: s.BP+fr <pp and
A5: pp < pD and
A6: pD < s.PD;
  set i2= AddTo(BP,fr,PD,0), i3= AddTo(PP,0,1), I= i2 ';' i3;
  per cases;
  suppose
    s.DataLoc(s.BP,cv) <= 0;
    hence thesis by Th42;
  end;
  suppose
A7: s.DataLoc(s.BP,cv) > 0;
    reconsider n=s.BP as Element of NAT by A1,INT_1:3;
    n+cv <> sp by A1,NAT_1:11;
    then |.n+cv.| <> sp by ABSVALUE:def 1;
    then
A8: DataLoc(s.BP,cv) <> BP by XTUPLE_0:1;
A9: n+fr > n+cv by A2,XREAL_1:6;
A10: now
      set Dv=DataLoc(s.BP,cv);
      let t be 0-started State of SCMPDS;
      let Q;
A11:   Initialize t = t by MEMSTR_0:44;
      assume that
A12:  for x be Int_position st x in {BP,PP} holds t.x=s.x and
A13:  t.BP=s.BP;
      set t0=Initialize t, t1=Exec(i2, t0);
A14:  DataLoc(t0.BP,fr)=DataLoc(n,fr) by A13,SCMPDS_5:15
        .=intpos(n+fr) by SCMP_GCD:1;
      then DataLoc(t0.BP,fr) <> PP by A4,XTUPLE_0:1;
      then
A15:  t1.PP=t0.PP by SCMPDS_2:49
        .=t.PP by SCMPDS_5:15;
      n+fr <> sp by A1,NAT_1:11;
      then DataLoc(t0.BP,fr) <> BP by A14,XTUPLE_0:1;
      then
A16:  t1.BP=t0.BP by SCMPDS_2:49
        .=t.BP by SCMPDS_5:15;
      PP in {BP,PP} by TARSKI:def 2;
      then t1.PP=pD by A3,A12,A15;
      then
A17:  DataLoc(t1.PP,0)=intpos (pD+(0 qua Nat)) by SCMP_GCD:1;
      then
A18:  |.t1.PP+(0 qua Nat).| = pD by XTUPLE_0:1;
      n <= n+fr by NAT_1:11;
      then sp < n+fr by A1,XXREAL_0:2;
      then |.t1.PP+(0 qua Nat).| <> sp by A4,A5,A18,XXREAL_0:2;
      then
A19:  DataLoc(t1.PP,0) <> BP by XTUPLE_0:1;
      Dv=intpos(n+cv) by SCMP_GCD:1;
      then
A20:  |.s.BP+cv.| = n+cv by XTUPLE_0:1;
      then |.t1.PP+(0 qua Nat).| <> |.s.BP+cv.| by A4,A5,A9,A18,XXREAL_0:2;
      then
A21:  DataLoc(t1.PP,0) <> Dv by XTUPLE_0:1;
      |.t0.BP+fr.| = n+fr by A14,XTUPLE_0:1;
      then |.t0.BP+fr.| <> |.s.BP+cv.| by A2,A20;
      then
A22:  DataLoc(t0.BP,fr) <> Dv by XTUPLE_0:1;
      thus
A23:  IExec(I,Q,t).BP=Exec(i3, t1).BP by A11,SCMPDS_5:42
        .=t.BP by A16,A19,SCMPDS_2:48;
      thus IExec(I,Q,t).Dv=Exec(i3, t1).Dv by A11,SCMPDS_5:42
        .=t1.Dv by A21,SCMPDS_2:48
        .=t0.Dv by A22,SCMPDS_2:49
        .=t.Dv by SCMPDS_5:15;
      thus I is_closed_on t,Q & I is_halting_on t,Q by SCMPDS_6:20,21;
A24:  IExec(I,Q,Initialize t).PP=Exec(i3, t1).PP by SCMPDS_5:42
        .=t.PP by A3,A6,A15,A17,SCMPDS_2:48;
      hereby
        let y be Int_position;
        assume
A25:    y in {BP,PP};
        per cases by A25,TARSKI:def 2;
        suppose
          y=BP;
          hence IExec(I,Q,t).y=t.y by A23;
        end;
        suppose
          y=PP;
          hence IExec(I,Q,t).y=t.y by A24,MEMSTR_0:44;
        end;
      end;
    end;
    n+cv <> pp by A2,A4,XREAL_1:6;
    then |.n+cv.| <> pp by ABSVALUE:def 1;
    then DataLoc(s.BP,cv) <> PP by XTUPLE_0:1;
    then not DataLoc(s.BP,cv) in {BP,PP} by A8,TARSKI:def 2;
    hence thesis by A7,A8,A10,Th46;
  end;
end;
