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
  ex f be increasing natural-valued FinSequence st
   n = (2|^f).1 + (2|^f,2) +...
proof
  set D=digits(n,2);
  consider d be XFinSequence of NAT such that
  A1: (dom d = dom D & for i being Nat st i in dom d holds d.i = (D.i)*(2|^i))
     & value(D,2) = Sum d by NUMERAL1:def 1;
  defpred P[Nat] means $1 <= len d implies
  ex f be increasing natural-valued FinSequence st
     (len f=0 or f.len f < $1) & Sum (2|^f) = Sum (d| $1);
  A2:P[0 qua Nat]
    proof
      assume 0<=len d;
      reconsider f=<*>NAT as increasing natural-valued FinSequence;
      take f;
      Sum (2|^f)=0 by RVSUM_1:72;
      hence thesis;
    end;
  A3:P[i] implies P[i+1]
    proof
      assume A4:P[i];
      set i1=i+1;
      assume A5:i1 <= len d;
      then consider f be increasing natural-valued FinSequence such that
      A6:(len f = 0 or f.len f < i) & Sum (2|^f) = Sum (d|i)
        by NAT_1:13,A4;
      A7: i in dom d by A5,NAT_1:13,AFINSQ_1:86;
      then A8:Sum (d|i1) = Sum (d|i) + d.i & d.i = (D.i)*(2|^i)
        by A1,AFINSQ_2:65;
      A9:D.i = 0 or D.i =1
      proof
        per cases;
        suppose n=0;
          then A10:D=<%0%> by NUMERAL1:def 2;
          then dom D=1 & 1 =Segm 1 by AFINSQ_1:def 4,ORDINAL1:def 17;
          then i < 1 by A5,NAT_1:13,A1;
          then i = 0 by NAT_1:25;
          hence thesis by A10;
        end;
        suppose n<>0;
          then 0<= D.i & D.i < 2 by A7,A1,NUMERAL1:def 2;
          hence thesis by NAT_1:23;
        end;
      end;
      per cases by A9;
      suppose A11:D.i=0;
        take f;
        thus thesis by A11,A8,A6,NAT_1:13;
      end;
      suppose A12:D.i =1;
        set fi = f^<*i*>;
        A13: len fi = len f +1 by FINSEQ_2:16;
        for e1,e2 be ExtReal st e1 in dom fi & e2 in dom fi & e1 < e2 holds
          fi.e1 < fi.e2
        proof
          let e1,e2 be ExtReal such that
          A14: e1 in dom fi & e2 in dom fi & e1 < e2;
          A15:1<= e1 & 1 <= e2 & e1 <= len f+1 & e2 <= len f+1
            by A14,A13,FINSEQ_3:25;
          per cases;
          suppose e1 <= len f & e2 <= len f;
            then e1 in dom f & e2 in dom f by A15,A14,FINSEQ_3:25;
            then f.e1 < f.e2 & f.e1 = fi.e1 & f.e2 = fi.e2
              by A14,VALUED_0:def 13,FINSEQ_1:def 7;
            hence thesis;
          end;
          suppose A16:e1 <= len f & e2 > len f;
            then e2 >= len f+1 by A14,NAT_1:13;
            then e2 = len f+1 by A15,XXREAL_0:1;
            then A17:fi.e2 = i by FINSEQ_1:42;
            A18:e1=len f or e1 < len f by A16,XXREAL_0:1;
            len f >= 1 by A16,A15,XXREAL_0:2;
            then A19:f.len f < i & len f in dom f & e1 in dom f
              by A14,A15,A16,A6,FINSEQ_3:25;
            then f.e1 <= f.len f by A18,VALUED_0:def 13;
            then f.e1 < i by A16,A14,FINSEQ_3:25,XXREAL_0:2, A6;
            hence thesis by A19,FINSEQ_1:def 7,A17;
          end;
          suppose e1 > len f & e2 <= len f;
            hence thesis by A14,XXREAL_0:2;
          end;
          suppose e1 > len f & e2 > len f;
            then e1 >= len f+1 & e2 >= len f+1 by A14,NAT_1:13;
            hence thesis by A15,A14,XXREAL_0:1;
          end;
        end;
        then reconsider fi as increasing natural-valued FinSequence
          by VALUED_0:def 13;
        take fi;
        fi.len fi = i & i < i1 by A13,NAT_1:13,FINSEQ_1:42;
        hence len fi=0 or fi.len fi < i+1;
        dom f = Seg len f by FINSEQ_1:def 3;
        then fi|len f = f by FINSEQ_1:21;
        then Sum (2|^fi) = Sum (2|^f) + (2|^fi.(len f+1)) by FINSEQ_2:16,Lm5;
        hence thesis by FINSEQ_1:42,A12,A8,A6;
      end;
  end;
  P[i] from NAT_1:sch 2(A2,A3);
  then consider f be increasing natural-valued FinSequence such that
  len f=0 or f.len f < len d and
  A20:Sum (2|^f) = Sum (d| len d);
  A21:Sum (2|^f) = (2|^f).1 + (2|^f,2)+... by Th22;
  Sum d = n by A1,NUMERAL1:5;
  hence thesis by A20,A21;
end;
