reserve x,y for object,
        D,D1,D2 for non empty set,
        i,j,k,m,n for Nat,
        f,g for FinSequence of D*,
        f1 for FinSequence of D1*,
        f2 for FinSequence of D2*;
reserve f for complex-valued Function,
        g,h for complex-valued FinSequence;

theorem Th38:
  for F be non empty FinSequence,
      G be finite Function st rng G c= rng F
  ex o be len F-element DoubleReorganization of dom G st
    for n holds
    (F.n = G.o_(n,1) &...& F.n = G.o_(n,len (o.n)) )
proof
  let F be non empty FinSequence,
      G be finite Function such that A1: rng G c= rng F;
  set D=dom G;
  set d = the one-to-one onto FinSequence of D;
  A2:rng d = D by FUNCT_2:def 3;
  then A3: card dom d = card D by CARD_1:70;
  A4:dom d = Seg len d by FINSEQ_1:def 3;
  A5:card D=len d & card G = card D by CARD_1:62,A3;
  defpred P[Nat] means
    $1 <= card G implies
      ex o be len F-element DoubleReorganization of d.:(Seg $1) st
      for k holds
          (F.k = G.(o_(k,1)) &...& F.k = G.(o_(k,len (o.k))));
  A6: P[0]
  proof
    assume 0 <= card G;
    take o= the len F-element DoubleReorganization of d.:(Seg 0);
    let i,j;
    thus thesis;
  end;
  A7:P[i] implies P[i+1]
  proof
    set i1=i+1,di1=d.i1;
    assume A8:P[i];
    assume A9: i1 <= card G;
    then consider o be len F-element DoubleReorganization of d.:(Seg i)
      such that
    A10: for j holds
      ( F.j = G.(o_(j,1)) &...& F.j = G.(o_(j,len (o.j)))) by NAT_1:13,A8;
    A11: len o =len F by CARD_1:def 7;
    then A12: dom o = dom F by FINSEQ_3:29;
    A13: Values o = d.:(Seg i) by Def7;
    A14: i1 in dom d by NAT_1:11,A5,A9,FINSEQ_3:25;
    then di1 in D by A2,FUNCT_1:def 3;
    then G.di1 in rng G by FUNCT_1:def 3;
    then consider x be object such that
    A15: x in dom F & F.x = G.di1 by A1,FUNCT_1:def 3;
    reconsider x as Nat by A15;
    set ox=o.x,I1=<*di1*>,oxI=ox^I1;
    A16: i < i1 by NAT_1:13;
    not di1 in rng ox
    proof
      assume d.i1 in rng ox;
      then consider y be object such that
      A17:y in dom ox & d.i1=ox.y by FUNCT_1:def 3;
      d.i1 in d.:(Seg i) by Th1,A15,A12,A13,A17;
      then consider z be object such that
      A18:z in dom d & z in Seg i & d.z = d.i1 by FUNCT_1:def 6;
      i1 in Seg i by A14,FUNCT_1:def 4,A18;
      hence thesis by FINSEQ_1:1,A16;
    end;
    then A19: oxI is one-to-one by GRAPHSP:1;
    A20: x in dom o by A15, A11,FINSEQ_3:29;
    ox in rng o by A15,A12,FUNCT_1:def 3;
    then A21: ox is FinSequence of d.:Seg i by FINSEQ_1:def 11;
    then A22: rng ox c= d.:Seg i by FINSEQ_1:def 4;
    A23:rng ox /\d.:Seg i = rng ox by A21,FINSEQ_1:def 4,XBOOLE_1:28;
    not i1 in Seg i by A16,FINSEQ_1:1;
    then {i1}  misses Seg i by ZFMISC_1:52,45;
    then A24:d.:{i1} /\d.:Seg i=d.:{} by FUNCT_1:62;
    then A25:d.:{i1} misses d.:Seg i;
    Im(d,i1)={di1} by A14,FUNCT_1:59;
    then A26:d.:{i1}={di1} by RELAT_1:def 16;
    A27: rng I1 = {di1} by FINSEQ_1:39;
    then rng oxI = rng ox \/ {di1} by FINSEQ_1:31;
    then A28: rng oxI /\(d.:Seg i) =rng ox \/ {}
      by A23,XBOOLE_1:23,A24,A26;
    A29: Seg i \/{i1} = Seg i1 by FINSEQ_1:9;
    then A30:d.:(Seg i) \/ d.:{i1} = d.:Seg i1 by RELAT_1:120;
    d.:Seg i c= d.:Seg i1 by XBOOLE_1:7,A29,RELAT_1:123;
    then A31: rng ox c= d.:Seg i1 by A22;
    set O= o +*(x,oxI);
    rng oxI \/ ((d.: Seg i) \rng ox) =
         rng ox \/ {di1} \/ ((d.: Seg i) \rng ox) by A27,FINSEQ_1:31
      .= rng ox \/ ({di1} \/  (d.:Seg i \rng ox)) by XBOOLE_1:4
      .= rng ox \/ (({di1} \/  d.:Seg i) \rng ox)
          by A22,A25,A26,XBOOLE_1:63,XBOOLE_1:87
      .= rng ox \/ ({di1} \/  d.:Seg i) by XBOOLE_1:39
      .=d.:Seg i1 by A26,A31,XBOOLE_1:12,A30;
      then reconsider O as len F-element DoubleReorganization of (d.:Seg i1)
        by A19,A20,Th37,A28;
      take O;
      let k;
      set Ok=O.k;
      A32: dom I1 = Seg 1 & Seg 1= {1} & I1.1 = di1 by FINSEQ_1:38,2;
      thus  F.k = G.(O_(k,1)) &...& F.k = G.(O_(k,len Ok))
      proof
        let j;
        assume A33:1 <= j & j <= len Ok;
        A34:F.k = G.(o_(k,1)) &...& F.k = G.(o_(k,len (o.k))) by A10;
        per cases;
        suppose A35: k<>x;
          then Ok=o.k by FUNCT_7:32;
          then F.k = G.(o_(k,j)) by A33,A34;
          hence thesis by A35,FUNCT_7:32;
        end;
        suppose A36:k=x;
          then A37: Ok = oxI by A15,A12,FUNCT_7:31;
          per cases;
          suppose A38: j in dom ox;
            then A39:oxI.j = ox.j & j <= len ox by FINSEQ_1:def 7,FINSEQ_3:25;
            o_(k,j) = oxI.j by A36,A38,FINSEQ_1:def 7
                   .= Ok.j by A36,A15,A12,FUNCT_7:31;
            hence thesis by A39,A36,A34,A33;
          end;
          suppose not j in dom ox;
            then consider n such that
            A40:n in dom I1 & j=len ox + n by A37,A33,FINSEQ_3:25,FINSEQ_1:25;
            n=1 by A32,A40,TARSKI:def 1;
            then F.k = G.(oxI.j) by A40,A32,FINSEQ_1:def 7,A15,A36
                     .= G.(Ok.j) by A36,A15,A12,FUNCT_7:31;
            hence thesis;
          end;
        end;
      end;
    end;
    A41:d.:Seg card D = D by A2,RELAT_1:113,A5,A4;
    P[i] from NAT_1:sch 2(A6,A7);
    then ex o be len F-element DoubleReorganization of dom G
      st
    for k holds
          (F.k = G.(o_(k,1)) &...& F.k = G.(o_(k,len (o.k)))) by A41,A5;
    hence thesis;
end;
