reserve k,i for Nat;
reserve D for non empty set;

theorem Th2:
  for q being FinSequence of D, n being Nat st NAT c= D & n>len q
  ex p being XFinSequence of D st len p=n & p is_an_xrep_of q
  proof
  let q be FinSequence of D, n be Nat;
  assume that
A1: NAT c= D and
A2: n>len q;
  reconsider n as Element of NAT by ORDINAL1:def 12;
  consider d2 being set such that
A3: d2 in D and
A4: d2=len q by A1;
  reconsider d=d2 as Element of D by A3;
  deffunc F(object)= IFEQ($1,0,d,IFLGT($1,len q,q.$1,q.$1,d));
  ex p being XFinSequence st len p = n & for k be Nat st k
  in n holds p.k=F(k) from AFINSQ_1:sch 2;
  then consider p being XFinSequence such that
A5: len p = n and
A6: for k be Nat st k in n holds p.k=F(k);
  rng p c= D
  proof
    let y be object;
    assume y in rng p;
    then consider x being object such that
A7: x in dom p and
A8: y=p.x by FUNCT_1:def 3;
    reconsider nx=x as Ordinal by A7;
    reconsider kx=nx as Element of NAT by A7;
A9: p.kx=F(kx) by A5,A6,A7;
    now
      per cases;
      case
        x=0;
        then F(x)=d by FUNCOP_1:def 8;
        hence p.x in D by A9;
      end;
      case
A10:    x<>0;
        then
A11:    F(x)=IFLGT(x,len q,q.x,q.x,d) by FUNCOP_1:def 8;
        now
          per cases;
          case
A12:        x in Segm len q;
            then
A13:        kx<len q by NAT_1:44;
            0+1<=kx by A10,NAT_1:13;
            then kx in Seg len q by A13,FINSEQ_1:1;
            then x in dom q by FINSEQ_1:def 3; then
A14:        q.x in rng q by FUNCT_1:def 3;
A15:        rng q c= D by FINSEQ_1:def 4;
            F(x)=q.x by A11,A12,Def2;
            hence p.x in D by A9,A14,A15;
          end;
          case
A16:        x=len q;
            0+1<=kx by A10,NAT_1:13;
            then kx in Seg len q by A16,FINSEQ_1:1;
            then x in dom q by FINSEQ_1:def 3;
            then
A17:        q.x in rng q by FUNCT_1:def 3;
A18:        rng q c= D by FINSEQ_1:def 4;
            F(x)=q.x by A11,A16,Def2;
            hence p.x in D by A9,A17,A18;
          end;
          case
            not (x in len q or x=len q);
            then F(x)=d by A11,Def2;
            hence p.x in D by A9;
          end;
        end;
        hence p.x in D;
      end;
    end;
    hence thesis by A8;
  end;
  then reconsider p as XFinSequence of D by RELAT_1:def 19;
  reconsider p2=Replace(p,0,d) as XFinSequence of D;
A19: for i st 1<=i & i<=len q holds p2.i=q.i
  proof
    let i;
    assume that
A20: 1<=i and
A21: i<=len q;
    i<len q or i=len q by A21,XXREAL_0:1;
    then
A22: i in Segm len q or i=len q by NAT_1:44;
    i<n by A2,A21,XXREAL_0:2;
    then
A23: i in Segm n by NAT_1:44;
    i in NAT by ORDINAL1:def 12;
    hence p2.i=p.i by A20,AFINSQ_1:44
      .=F(i) by A6,A23
      .=IFLGT(i,len q,q.i,q.i,d) by A20,FUNCOP_1:def 8
      .=q.i by A22,Def2;
  end;
A24: len p2=len p by AFINSQ_1:44;
  p2.0 =len q by A2,A4,A5,AFINSQ_1:44;
  then p2 is_an_xrep_of q by A1,A2,A5,A24,A19;
  hence thesis by A5,A24;
end;
