reserve i,j,k,n,m for Nat,
        b,b1,b2 for bag of n;

theorem
  for X being non empty set,
      A being finite Subset of X,
      R being Order of X st R linearly_orders A
  for i,k st 1 <= i <= k <= card A holds
    SgmX(R, rng (SgmX(R,A)|k))/.i = SgmX(R,A)/.i
proof
  let X be non empty set,
      A be finite Subset of X,
      R be Order of X;
  assume
A1:R linearly_orders A;
  set Sp = SgmX(R,A);
A2: card A = len Sp by A1,PRE_POLY:11;
A3: rng Sp =A by A1,PRE_POLY:def 2;
  defpred P[Nat] means
  for i st 1 <= i <= $1 <= card A holds
  SgmX(R, rng (Sp|$1))/.i = Sp/.i;
A4:  P[0];
A5:  for k st P[k] holds P[k+1]
  proof
    let k be Nat;set k1=k+1;
    assume
A6: P[k];
    let i be Nat such that
A7: 1<= i <= k1 <= card A;
A8: Sp is one-to-one by A1,PRE_POLY:10;
    set Spk1=Sp|k1;
A9: k < card A by A7,NAT_1:13;then
A10: len Spk1= k1 & len (Sp|k)= k by A7,A2,FINSEQ_1:59;
A11: k < len Sp by A7,A2,NAT_1:13;
A12: Spk1 = (Sp|k) ^ <*Sp.k1*> by A7,A2,NAT_1:13,FINSEQ_5:83;
A13: R linearly_orders rng (Sp|k1) by A3,RELAT_1:70,A1,ORDERS_1:38;
A14: 1<= k1 by NAT_1:11;
A15: k1 in dom Sp by NAT_1:11,A7,A2,FINSEQ_3:25; then
A16: Sp.k1 in rng Sp by FUNCT_1:def 3;
A17: Sp.k1 = Sp/.k1 by A15,PARTFUN1:def 6;
A18: k1 in Seg k1 by A14;
A19: Sp/.k1 in rng Spk1 by A15,A18,PARTFUN2:18;
A20: for y be Element of X st y in rng (Sp|k1) holds [y,Sp/.k1] in R
    proof
      let y be Element of X such that
A21:    y in rng Spk1;
      consider w be object such that
A22:    w in dom Spk1 & Spk1.w = y by A21,FUNCT_1:def 3;
      reconsider w as Nat by A22;
A23:  1<= w <= k1 by A22,A10,FINSEQ_3:25;
      then
A24:    Spk1.w = Sp.w by FINSEQ_3:112;
      w <= len Sp by A7,A2,A23,XXREAL_0:2;
      then
A25:    w in dom Sp by A23,FINSEQ_3:25;
      then
A26:    Sp/.w = Sp.w by PARTFUN1:def 6;
      per cases by A23,XXREAL_0:1;
      suppose
A27:      w=k1;
        R is_reflexive_in A by A1,ORDERS_1:def 9;
        hence [y,Sp/.k1] in R by A27,A17,A24,A22,A3,A16;
      end;
      suppose w <k1;
        hence [y,Sp/.k1] in R by A22,A24,A26,A25,A15,A1,PRE_POLY:def 2;
      end;
    end;
A28:len SgmX(R, rng (Sp|k1)) = card rng (Sp|k1) by A13,PRE_POLY:11
      .= k1 by A10,A8,FINSEQ_4:62;
A29:not Sp/.k1 in rng (Sp|k)
    proof
      assume Sp/.k1 in rng (Sp|k);
      then consider w be object such that
A30:    w in dom (Sp|k) & (Sp|k).w = Sp/.k1 by FUNCT_1:def 3;
      reconsider w as Nat by A30;
A31:  1<= w <= k by A30,A10,FINSEQ_3:25;
      w <= len Sp by A9,A2,A31,XXREAL_0:2;
      then
A32:  w in dom Sp by A31,FINSEQ_3:25;
      Sp.w = Sp.k1 by A30,A31,FINSEQ_3:112,A17;
      then w=k1 by A8,A15,A32,FUNCT_1:def 4;
      hence thesis by A31,NAT_1:13;
    end;
    rng Spk1 = rng (Sp|k) \/ rng <*Sp.k1*> by A12,FINSEQ_1:31
       .= rng (Sp|k) \/ {Sp.k1} by FINSEQ_1:38;
    then
A33:  rng (Sp|k1) = {Sp/.k1} \/ rng (Sp|k) by A15,PARTFUN1:def 6;
A34:  k1 in dom SgmX(R, rng (Sp|k1)) by A14,A28,FINSEQ_3:25;
    SgmX(R, rng (Sp|k1))/.k1 = Sp/.k1 by A28,A20,A19,A13,PRE_POLY:21;
    then
A35:for i being Element of NAT st 1 <= i & i <= k1-1
      holds SgmX(R,rng (Sp|k))/.i = SgmX(R,rng (Sp|k1))/.i
      by A13,A29,A33,A34,PRE_POLY:78;
A36: i in NAT by ORDINAL1:def 12;
    per cases by A7,XXREAL_0:1;
    suppose i <k1;
      then
A37: i <=k by NAT_1:13;
      hence SgmX(R,rng (Sp|k1))/.i = SgmX(R,rng (Sp|k))/.i by A36,A7,A35
      .= Sp/.i by A11,A6,A37,A7,A2;
    end;
    suppose i=k1;
      hence thesis by A20,A28,A19,A13,PRE_POLY:21;
    end;
  end;
  for k holds P[k] from NAT_1:sch 2(A4,A5);
  hence thesis;
end;
