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