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
  for s being 0-started State of SCMPDS,
   sp,cv,result,pp,pD be Nat, f be
FinSequence of NAT st s.intpos sp > sp & cv < result & s.intpos sp+result < pp
  & pp <pD & pD < s.intpos pD & len f = s.DataLoc(s.intpos sp,cv) & for k be
Nat st k < len f holds f.(k+1)=s.DataLoc(s.intpos pD,k)
 holds IExec(
  sum(sp,cv,result,pp,pD),P,s).DataLoc(s.intpos sp,result)=Sum f
proof
  let s be 0-started State of SCMPDS,
      sp,cv,fr,pp,pD be Nat, f be FinSequence
  of NAT;
  set BP=intpos sp, PD=intpos pD, PP=intpos pp;
  assume that
A1: s.BP > sp and
A2: cv < fr and
A3: s.BP+fr <pp and
A4: pp < pD and
A5: pD < s.PD and
A6: len f = s.DataLoc(s.BP,cv) and
A7: for k be Nat st k < len f holds f.(k+1)=s.DataLoc(s.PD,k);
  reconsider n=s.BP as Element of NAT by A1,INT_1:3;
A8: PD <> PP by A4,XTUPLE_0:1;
  set i0= (BP,fr):=0, i1= PP:=pD, Hi= i0 ';' i1, i2= AddTo(BP,fr,PD,0), i3=
AddTo(PP,0,1), FD= for-down(BP,cv,1,i2 ';' i3), s2=IExec(Hi,P,s),
  P2 = P,
  s0=s, s1=Exec(i0, s0), a =DataLoc(s.BP,fr), a1=DataLoc(s2.BP,fr);
A9: DataLoc(s0.BP,fr) =intpos(n+fr) by SCMP_GCD:1;
  then
A10: |.s0.BP+fr.| = n+fr by XTUPLE_0:1;
  then |.s0.BP+fr.| <> sp by A1,NAT_1:12;
  then
A11: DataLoc(s0.BP,fr) <> BP by XTUPLE_0:1;
A12: DataLoc(s0.BP,fr) <> PD by A3,A4,A9,XTUPLE_0:1;
A13: s2.PD=Exec(i1, s1).PD by SCMPDS_5:42
    .=s1.PD by A8,SCMPDS_2:45
    .=s.PD by A12,SCMPDS_2:46;
  n <= n+fr by NAT_1:12;
  then sp <> pp by A1,A3,XXREAL_0:2;
  then
A14: BP <> PP by XTUPLE_0:1;
A15: intpos(n+fr) <> PP by A3,XTUPLE_0:1;
A16: s2.BP=Exec(i1, s1).BP by SCMPDS_5:42
    .=s1.BP by A14,SCMPDS_2:45
    .=n by A11,SCMPDS_2:46;
  then
A17: s2.DataLoc(s2.BP,fr)=s2.intpos(n+fr) by SCMP_GCD:1
    .=Exec(i1, s1).intpos(n+fr) by SCMPDS_5:42
    .=s1.intpos(n+fr) by A15,SCMPDS_2:45
    .=0 by A9,SCMPDS_2:46;
A18: n+fr < pD by A3,A4,XXREAL_0:2;
A19: now
    reconsider m=s.PD as Element of NAT by A5,INT_1:3;
    let k be Nat;
    assume
A20: k < len f;
    pp < m by A4,A5,XXREAL_0:2;
    then m+k <> pp by NAT_1:11;
    then
A21: intpos(m+k) <> PP by XTUPLE_0:1;
    m <= m + k by NAT_1:11;
    then |.s0.BP+fr.| <> m+k by A5,A10,A18,XXREAL_0:2;
    then
A22: DataLoc(s0.BP,fr) <> intpos(m+k) by XTUPLE_0:1;
    thus (Initialize s2).DataLoc(s2.PD,k)
       = s2.DataLoc(s2.PD,k) by SCMPDS_5:15
      .=s2.intpos(m+k) by A13,SCMP_GCD:1
      .=Exec(i1, s1).intpos(m+k) by SCMPDS_5:42
      .=s1.intpos(m+k) by A21,SCMPDS_2:45
      .=s.intpos(m+k) by A22,SCMPDS_2:46
      .=s.DataLoc(s.PD,k) by SCMP_GCD:1
      .=f.(k+1) by A7,A20;
  end;
  |.s0.BP+fr.| <> n+cv by A2,A10;
  then
A23: DataLoc(s0.BP,fr) <> intpos(n+cv) by XTUPLE_0:1;
  n+cv <> pp by A2,A3,XREAL_1:6;
  then
A24: intpos(n+cv) <> PP by XTUPLE_0:1;
A25: Hi is_halting_on s,P by SCMPDS_6:21;
A26: Hi is_closed_on s,P by SCMPDS_6:20;
A27:  s2.PP = (Initialize s2).PP by SCMPDS_5:15;
A28:  s2.BP = (Initialize s2).BP by SCMPDS_5:15;
A29:  s2.PD = (Initialize s2).PD by SCMPDS_5:15;
A30: s2.PP=Exec(i1, s1).PP by SCMPDS_5:42
    .=pD by SCMPDS_2:45;
  then FD is_halting_on Initialize s2, P2
   by A1,A2,A3,A4,A5,A16,A13,Th51,A27,A28,A29;
  then
A31: FD is_halting_on s2,P2 by SCMPDS_6:126;
A32: s2.DataLoc(s2.BP,cv)=s2.intpos(n+cv) by A16,SCMP_GCD:1
    .=Exec(i1, s1).intpos(n+cv) by SCMPDS_5:42
    .=s1.intpos(n+cv) by A24,SCMPDS_2:45
    .=s.intpos(n+cv) by A23,SCMPDS_2:46
    .=len f by A6,SCMP_GCD:1;
A33:  s2.DataLoc(s2.BP,fr) = (Initialize s2).DataLoc(s2.BP,fr) by SCMPDS_5:15;
A34:  s2.DataLoc(s2.BP,cv) = (Initialize s2).DataLoc(s2.BP,cv) by SCMPDS_5:15;
  FD is_closed_on Initialize s2,P2
   by A1,A2,A3,A4,A5,A16,A30,A13,Th51,A27,A28,A29;
  then FD is_closed_on s2,P2 by SCMPDS_6:125;
  hence IExec(sum(sp,cv,fr,pp,pD),P,s).a
      = IExec(FD,P2,Initialize s2).a1 by A16,A26,A25,A31,Th28
    .= Sum f
     by A1,A2,A3,A4,A5,A16,A30,A13,A17,A32,A19,Th52,A27,A28,A29,A33,A34;
end;
