reserve x for Int_position,
  n,p0 for Nat;
reserve P,Q,U,V for Instruction-Sequence of SCMPDS;

theorem Th16:
  for s being 0-started State of SCMPDS,
  f,g be FinSequence of INT, k0,k being Nat
   st s.(intpos 4) >= 7+s.(intpos 6) & s.GBP=0 & k=s.(intpos
  6) & k0=s.(intpos 4)-s.(intpos 6)-1 & f is_FinSequence_on s,k0 & g
is_FinSequence_on IExec(while>0(GBP,6,((GBP,5):=(intpos 4,-1)) ';' (SubFrom(GBP
,5,intpos 4,0)) ';' (if>0(GBP,5, ((GBP,5):=(intpos 4,-1)) ';' ((intpos 4,-1):=(
intpos 4,0)) ';' ((intpos 4,0 ):=(GBP,5)) ';' (AddTo(GBP,4,-1)) ';' (AddTo(GBP,
  6,-1)),Load ((GBP,6):=0)))),P,s),k0 &
   len f=len g & len f > k & f
  is_non_decreasing_on 1,k holds f,g are_fiberwise_equipotent & g
  is_non_decreasing_on 1,k+1 & (for i be Nat st i>k+1 & i <= len f
  holds f.i=g.i) & for i be Nat st 1 <= i & i <= k+1 holds ex j be
  Nat st 1 <= j & j <= k+1 & g.i=f.j
proof
  set a=GBP;
  let s be 0-started State of SCMPDS,
      f,g be FinSequence of INT,m,n be Nat;
  assume
A1: s.a4 >= 7+s.a6 & s.a=0 & n=s.a6 & m=s.a4-s.a6-1;
  defpred P[Nat] means for t be 0-started State of SCMPDS,Q
   for f1,f2 be
  FinSequence of INT st t.a4 >= 7+t.a6 & t.a=0 & $1=t.a6 & m=t.a4-t.a6-1 & f1
  is_FinSequence_on t,m & f2 is_FinSequence_on IExec(WH,Q,t),m
   & len f1=len f2 &
len f1 > $1 & f1 is_non_decreasing_on 1,$1 holds f1,f2 are_fiberwise_equipotent
  & f2 is_non_decreasing_on 1,$1+1 & (for i be Nat st i>$1+1 & i <=
  len f1 holds f1.i=f2.i) & (for i be Nat st 1 <= i & i <= $1+1 ex j
  be Nat st 1 <= j & j <= $1+1 & f2.i=f1.j);
  assume
A2: f is_FinSequence_on s,m & g is_FinSequence_on IExec(WH,P,s),m;
A3: now
    let k be Nat;
    assume
A4: P[k];
    thus P[k+1 qua Nat]
    proof
      let t be 0-started State of SCMPDS,Q;
      let f1,f2 be FinSequence of INT;
A5: Initialize t = t by MEMSTR_0:44;
      assume that
A6:   t.a4 >= 7+t.a6 and
A7:   t.a=0 and
A8:   k+1=t.a6 and
A9:   m=t.a4-t.a6-1 and
A10:   f1 is_FinSequence_on t,m and
A11:  f2 is_FinSequence_on IExec(WH,Q,t),m and
A12:  len f1=len f2 and
A13:  len f1 > k+1 and
A14:  f1 is_non_decreasing_on 1,k+1;
      set Bt=IExec(B1,Q,t), x=DataLoc(t.a4,-1), y=DataLoc(t.a4,0);
A15:  Bt.a=0 by A6,A7,A8,Lm6;
      m+1+(k+1) >= 7+t.a6 by A6,A8,A9;
      then
A16:  m+1 >= 7 by A8,XREAL_1:6;
A17:  x=DataLoc(m,k+1) by A8,A9
        .=intpos(m+(k+1)) by SCMP_GCD:1;
A18:  Bt.a6 = (Initialize Bt).a6 by SCMPDS_5:15;
A19:  Bt.a4 = (Initialize Bt).a4 by SCMPDS_5:15;
A20: (Initialize Bt).a = Bt.a by SCMPDS_5:15;
A21:  t.x > t.y implies Bt.x=t.y & Bt.y =t.x & Bt.a6=t.a6-1
      & Bt.a4=t.a4-1 by A6,A7,A8,Lm7;
A22:  t.x <= t.y implies Bt.x=t.x & Bt.y =t.y & Bt.a6=0
 by A6,A7,A8,Lm7;
A23:  y=intpos(m+(k+2)) by A8,A9,SCMP_GCD:1;
A24:  Bt.a4 >= 7+Bt.a6 by A6,A7,A8,Lm7;
      per cases;
      suppose
A25:    t.x > t.y;
        now
          let i be Nat;
          assume
          1<=i & i <= len f2;
          hence f2.i=IExec(WH,Q,t).intpos(m+i) by A11
            .=IExec(WH,Q,Initialize Bt).intpos(m+i) by A6,A7,A8,Lm14;
        end;
        then
A26:    f2 is_FinSequence_on IExec(WH,Q,Initialize Bt),m;
A27:    k+1 < k+2 by XREAL_1:6;
        consider h be FinSequence of INT such that
A28:    len h=len f1 and
A29:    for i be Nat st 1<=i & i <= len h holds h.i=Bt.
        intpos(m+ i) by Th1;
        k+1 > k by XREAL_1:29;
        then
A30:    len h > k by A13,A28,XXREAL_0:2;
A31:    now
          let i be Nat;
          assume that
A32:      i <> k+1 & i<>k+2 and
A33:      1 <= i and
A34:      i <= len f1;
A35:      m+i <> t.a4-1 & m+i <> t.a4 by A8,A9,A32;
          m+i >= m+1 by A33,XREAL_1:6;
          then
A36:      m+i >= 7 by A16,XXREAL_0:2;
          thus h.i=Bt.intpos(m+i) by A28,A29,A33,A34
            .=t.intpos(m+i) by A6,A7,A8,A36,A35,Lm7
            .=f1.i by A10,A33,A34;
        end;
        now
          let i,j be Nat;
          assume that
A37:      1 <= i and
A38:      i <= j and
A39:      j <= k;
A40:      j <= len f1 by A28,A30,A39,XXREAL_0:2;
          then
A41:      i <= len f1 by A38,XXREAL_0:2;
A42:      k < k+1 by XREAL_1:29;
          then
A43:      j < k+1 by A39,XXREAL_0:2;
          k+1 < k+1+1 by XREAL_1:29;
          then
A44:      k < k+1+1 by A42,XXREAL_0:2;
          j >= 1 by A37,A38,XXREAL_0:2;
          then
A45:      h.j=f1.j by A31,A39,A42,A44,A40;
          j < k+2 by A39,A44,XXREAL_0:2;
          then h.i=f1.i by A31,A37,A38,A43,A41;
          hence h.i <= h.j by A14,A37,A38,A43,A45,FINSEQ_6:def 9;
        end;
        then
A46:    h is_non_decreasing_on 1,k by FINSEQ_6:def 9;
A47:    len f1 >= k+1+1 by A13,INT_1:7;
A48:    1 <= k+1 by NAT_1:11;
        then
A49:    1 <= k+2 by A27,XXREAL_0:2;
        then
A50:    h.(k+2)=t.x by A23,A21,A25,A28,A29,A47;
        then
A51:    h.(k+2)=f1.(k+1) by A10,A13,A17,A48;
A52:    Bt.a4-Bt.a6-1=m by A9,A21,A25;
A53:    h.(k+1)=t.y by A13,A17,A21,A25,A28,A29,NAT_1:11;
        then h.(k+1)=f1.(k+2) by A10,A23,A49,A47;
        then
A54:    f1,h are_fiberwise_equipotent by A13,A28,A31,A48,A49,A47,A51,Th3;
A55:    h is_FinSequence_on Initialize Bt,m
         proof let i be Nat;
          assume 1 <= i & i <= len h;
           then h.i=Bt.intpos(m+i) by A29;
          hence thesis by SCMPDS_5:15;
         end;
        h,f2 are_fiberwise_equipotent
         by A4,A8,A12,A15,A24,A21,A25,A28,A52,A26,A30,A46,A55,A18,A19,A20;
        hence f1,f2 are_fiberwise_equipotent by A54,CLASSES1:76;
A56:    f2 is_non_decreasing_on 1, k+1
 by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A18,A19,A20,A26,A30,A46;
        now
          let i,j be Nat;
          assume that
A57:      1 <= i and
A58:      i <= j and
A59:      j <= (k+1)+1;
          per cases by A59,NAT_1:8;
          suppose
            j <= k+1;
            hence f2.i <= f2.j by A56,A57,A58,FINSEQ_6:def 9;
          end;
          suppose
A60:        j = k+1+1;
            hereby
              per cases;
              suppose
                i=j;
                hence f2.i <= f2.j;
              end;
              suppose
                i<>j;
                then i < j by A58,XXREAL_0:1;
                then i <= k+1 by A60,NAT_1:13;
                then consider mm be Nat such that
A61:            1 <= mm and
A62:            mm <= k+1 and
A63:            f2.i=h.mm by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A26,A30,A46
,A57,A18,A19,A20;
A64:            f2.j=h.(k+2) by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A26,A30
,A46,A27,A47,A60,A18,A19,A20;
                hereby
                  per cases;
                  suppose
                    mm=k+1;
                    hence
                    f2.i <= f2.j by A13,A17,A21,A22,A28,A29,A50,A61,A63,A64;
                  end;
                  suppose
A65:                mm<>k+1;
                    mm < k+2 by A27,A62,XXREAL_0:2;
                    then mm < len h by A28,A47,XXREAL_0:2;
                    then
A66:                h.mm=f1.mm by A28,A31,A27,A61,A62,A65;
                    f2.j=f1.(k+1) by A10,A13,A17,A48,A50,A64;
                    hence f2.i <= f2.j by A14,A61,A62,A63,A66,FINSEQ_6:def 9;
                  end;
                end;
              end;
            end;
          end;
        end;
        hence f2 is_non_decreasing_on 1,(k+1)+1 by FINSEQ_6:def 9;
        hereby
          let i be Nat;
          assume that
A67:      i>(k+1)+1 and
A68:      i <= len f1;
A69:      k+1 < k+1+1 by XREAL_1:29;
          then
A70:      i > k+1 by A67,XXREAL_0:2;
          1 <= k+1 by NAT_1:11;
          then
A71:      1 <= i by A70,XXREAL_0:2;
          thus f2.i=h.i by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A26,A30,A46
,A68,A70,A18,A19,A20
            .=f1.i by A31,A67,A68,A69,A71;
        end;
        hereby
          let i be Nat;
          assume that
A72:      1 <= i and
A73:      i <= (k+1)+1;
          per cases;
          suppose
A74:        i=k+1+1;
             reconsider j=k+1 as Nat;
            take j;
            thus 1 <= j by NAT_1:11;
            thus j <= (k+1)+1 by NAT_1:11;
            thus f2.i=f1.j by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A26,A30,A46
,A27,A47,A51,A74,A18,A19,A20;
          end;
          suppose
            i<>k+1+1;
            then i < k+1+1 by A73,XXREAL_0:1;
            then i <= k+1 by NAT_1:13;
            then consider mm be Nat such that
A75:        1 <= mm and
A76:        mm <= k+1 and
A77:        f2.i=h.mm by A4,A8,A12,A15,A24,A21,A25,A28,A52,A55,A26,A30,A46,A72
,A18,A19,A20;
            hereby
A78:          k+2=(k+1)+1;
              per cases;
              suppose
A79:            mm=k+1;
                 reconsider j=k+2 as Nat;
                take j;
                thus 1 <= j by A78,NAT_1:11;
                thus j <= k+1+1;
                thus f2.i=f1.j by A10,A23,A49,A47,A53,A77,A79;
              end;
              suppose
A80:            mm<>k+1;
                 reconsider mm as Nat;
                take mm;
                thus 1 <= mm by A75;
                thus mm <= k+1+1 by A27,A76,XXREAL_0:2;
                mm < k+2 by A27,A76,XXREAL_0:2;
                then mm < len f1 by A47,XXREAL_0:2;
                hence f2.i=f1.mm by A31,A27,A75,A76,A77,A80;
              end;
            end;
          end;
        end;
      end;
      suppose
A81:    t.x <= t.y;
A82:    now
          let i be Nat;
          assume that
A83:      i>=1 and
A84:      i <= len f1;
A85:      f1.i=t.intpos(m+i) by A10,A83,A84;
      Bt.DataLoc(Bt.a,6) =0 by A15,A22,A81,SCMP_GCD:1;
          then
A86:      (Initialize Bt).DataLoc(Bt.a,6) =0 by SCMPDS_5:15;
          m+i >= m+1 by A83,XREAL_1:6;
          then
A87:      m+i >= 7 by A16,XXREAL_0:2;
A88: (Initialize Bt).intpos(m+i) = Bt.intpos(m+i) by SCMPDS_5:15;
A89: (Initialize Bt).DataLoc((Initialize Bt).GBP,6) <= 0 by A86,SCMPDS_5:15;
          per cases;
          suppose
A90:        m+i=t.a4-1;
            hence f1.i=IExec(WH,Q,Initialize Bt).x
             by A8,A9,A17,A22,A81,A85,A88,A89,SCMPDS_8:23
              .=IExec(WH,Q,Initialize t).x by A6,A7,A8,Lm14,A5
              .=f2.i by A8,A9,A11,A12,A13,A17,A83,A90,A5;
          end;
          suppose
A91:        m+i=t.a4;
            hence f1.i=IExec(WH,Q,Initialize Bt).y
             by A8,A9,A23,A22,A81,A85,A88,A89,SCMPDS_8:23
              .=IExec(WH,Q,Initialize t).y by A6,A7,A8,Lm14,A5
              .=f2.i by A8,A9,A11,A12,A23,A83,A84,A91,A5;
          end;
          suppose
            m+i<>t.a4-1 & m+i<>t.a4;
            hence f1.i=Bt.intpos (m+i)
             by A6,A7,A8,A87,A85,Lm7
              .=IExec(WH,Q,Initialize Bt).intpos (m+i) by A88,A89,SCMPDS_8:23
              .=IExec(WH,Q,Initialize t).intpos (m+i) by A6,A7,A8,Lm14,A5
              .=f2.i by A11,A12,A83,A84,A5;
          end;
        end;
        then
A92:    f1=f2 by A12,FINSEQ_1:14;
        thus f1,f2 are_fiberwise_equipotent by A12,A82,FINSEQ_1:14;
        now
          let i, j be Nat;
          assume that
A93:      1 <= i and
A94:      i <= j and
A95:      j <= (k+1)+1;
          per cases by A95,NAT_1:8;
          suppose
            j <= k+1;
            hence f1.i <= f1.j by A14,A93,A94,FINSEQ_6:def 9;
          end;
          suppose
A96:        j = k+1+1;
            hereby
              per cases;
              suppose
                i=j;
                hence f1.i <= f1.j;
              end;
              suppose
                i<>j;
                then i < j by A94,XXREAL_0:1;
                then i <= k+1 by A96,NAT_1:13;
                then
A97:            f1.i <= f1.(k+1) by A14,A93,FINSEQ_6:def 9;
                1<=k+1 by NAT_1:11;
                then
A98:            f1.(k+1)=t.x by A10,A13,A17;
                1<=(k+1)+1 & j<=len f1 by A13,A96,INT_1:7,NAT_1:11;
                then f1.j=t.y by A10,A23,A96;
                hence f1.i <= f1.j by A81,A97,A98,XXREAL_0:2;
              end;
            end;
          end;
        end;
        hence f2 is_non_decreasing_on 1,(k+1)+1 by A92,FINSEQ_6:def 9;
        thus for i be Nat st i>(k+1)+1 & i <= len f1 holds f1.i=f2.
        i by A12,A82,FINSEQ_1:14;
        thus for i be Nat st 1 <= i & i <= (k+1)+1
          ex j be Nat st 1 <= j & j <= (k+1)+1 & f2.i=f1.j by A92;
      end;
    end;
  end;
A99: P[0 qua Nat]
  proof
    let t be 0-started State of SCMPDS, Q;
    let f1,f2 be FinSequence of INT;
A100: Initialize t = t by MEMSTR_0:44;
    assume that
    t.a4 >= 7+t.a6 and
A101: t.a=0 & 0=t.a6 and
    m=t.a4-t.a6-1 and
A102: f1 is_FinSequence_on t,m and
A103: f2 is_FinSequence_on IExec(WH,Q,t),m and
A104: len f1=len f2 and
    len f1 > 0 and
    f1 is_non_decreasing_on 1,0;
A105: t.DataLoc(t.a,6) =0 by A101,SCMP_GCD:1;
A106: now
      let i be Nat;
      assume
A107: 1 <= i & i <= len f1;
      thus f1.i=t.intpos(m+i) by A102,A107
        .=IExec(WH,Q,Initialize t).intpos(m+i) by A105,A100,SCMPDS_8:23
        .=f2.i by A103,A104,A107,A100;
    end;
    hence f1,f2 are_fiberwise_equipotent by A104,FINSEQ_1:14;
    thus f2 is_non_decreasing_on 1,0+1 by FINSEQ_6:165;
    thus for i be Nat st i>0+1 & i <= len f1 holds f1.i=f2.i by A106;
    f1=f2 by A104,A106,FINSEQ_1:14;
    hence thesis;
  end;
A108: for k be Nat holds P[k] from NAT_1:sch 2(A99,A3);
  assume
  len f= len g & len f > n & f is_non_decreasing_on 1,n;
  hence thesis by A1,A2,A108;
end;
