
theorem Th9:
  for n be Element of NAT holds len Decomp(n,2) = n+1
proof
  let n be Element of NAT;
  deffunc F(Nat) = <*$1,n-'$1*>;
  consider q be FinSequence such that
A1: len q = n and
A2: for k be Nat st k in dom q holds q.k = F(k) from FINSEQ_1:sch 2;
A3: dom q = Seg n by A1,FINSEQ_1:def 3;
  set q1 = q^<*<*0,n*>*>;
A4: dom q = Seg n by A1,FINSEQ_1:def 3;
A5: len q1 = n+1 by A1,FINSEQ_2:16;
  then
A6: dom q1 = Seg (n+1) by FINSEQ_1:def 3;
  now
    let x1,x2 be object;
    assume that
A7: x1 in dom q1 and
A8: x2 in dom q1 and
A9: q1.x1 = q1.x2;
    reconsider k1=x1, k2=x2 as Element of NAT by A7,A8;
    x2 in Seg n \/ {n+1} by A6,A8,FINSEQ_1:9;
    then
A10: x2 in Seg n or x2 in {n+1} by XBOOLE_0:def 3;
    x1 in Seg n \/ {n+1} by A6,A7,FINSEQ_1:9;
    then
A11: x1 in Seg n or x1 in {n+1} by XBOOLE_0:def 3;
    now
      per cases by A11,A10,TARSKI:def 1;
      suppose
A12:    x1 in Seg n & x2 in Seg n;
        then
A13:    q1.k1 = q.k1 & q1.k2 = q.k2 by A3,FINSEQ_1:def 7;
        q.k1 = <*k1,n-'k1*> & q.k2 = <*k2,n-'k2*> by A2,A4,A12;
        hence x1 = x2 by A9,A13,FINSEQ_1:77;
      end;
      suppose
A14:    x1 in Seg n & x2 = n+1;
        then
A15:    q1.k2 = <*0,n*> by A1,FINSEQ_1:42;
        q1.k1 = q.k1 by A3,A14,FINSEQ_1:def 7
          .= <*k1,n-'k1*> by A2,A4,A14;
        then k1 = 0 by A9,A15,FINSEQ_1:77;
        hence x1 = x2 by A14,FINSEQ_1:1;
      end;
      suppose
A16:    x1 = n+1 & x2 in Seg n;
        then
A17:    q1.k1 = <*0,n*> by A1,FINSEQ_1:42;
        q1.k2 = q.k2 by A3,A16,FINSEQ_1:def 7
          .= <*k2,n-'k2*> by A2,A4,A16;
        then k2 = 0 by A9,A17,FINSEQ_1:77;
        hence x1 = x2 by A16,FINSEQ_1:1;
      end;
      suppose
        x1 = n+1 & x2 = n+1;
        hence x1 = x2;
      end;
    end;
    hence x1 = x2;
  end;
  then q1 is one-to-one by FUNCT_1:def 4;
  then
A18: card(rng q1) = n+1 by A5,FINSEQ_4:62;
A19: rng q c= rng q1 by FINSEQ_1:29;
A20: rng q1 = {<*i,n-'i*> where i is Element of NAT : i <= n}
  proof
    thus rng q1 c= {<*i,n-'i*> where i is Element of NAT : i <= n}
    proof
      let x be object;
      assume x in rng q1;
      then consider j be Nat such that
A21:  j in dom q1 and
A22:  q1.j = x by FINSEQ_2:10;
      reconsider j as Element of NAT by ORDINAL1:def 12;
      j in Seg n \/ {n+1} by A6,A21,FINSEQ_1:9;
      then
A23:  j in Seg n or j in {n+1} by XBOOLE_0:def 3;
      now
        per cases by A23,TARSKI:def 1;
        suppose
A24:      j in Seg n;
          then
A25:      q1.j = q.j by A3,FINSEQ_1:def 7;
          q.j = <*j,n-'j*> & j <= n by A2,A4,A24,FINSEQ_1:1;
          hence thesis by A22,A25;
        end;
        suppose
          j = n+1;
          then q1.j = <*0,n*> by A1,FINSEQ_1:42
            .= <*0,n-'0*> by NAT_D:40;
          hence thesis by A22;
        end;
      end;
      hence thesis;
    end;
    let x be object;
    assume x in {<*i,n-'i*> where i is Element of NAT : i <= n};
    then consider i be Element of NAT such that
A26: x = <*i,n-'i*> and
A27: i <= n;
A28: i = 0 or i >= 0 qua Nat+1 by NAT_1:13;
    now
      per cases by A27,A28,FINSEQ_1:1;
      suppose
A29:    i = 0;
A30:    n+1 in dom q1 by A6,FINSEQ_1:4;
        q1.(n+1) = <*0,n*> by A1,FINSEQ_1:42
          .= x by A26,A29,NAT_D:40;
        hence thesis by A30,FUNCT_1:def 3;
      end;
      suppose
A31:    i in Seg n;
        then q.i = x by A2,A4,A26;
        then x in rng q by A3,A31,FUNCT_1:def 3;
        hence thesis by A19;
      end;
    end;
    hence thesis;
  end;
  consider A be finite Subset of 2-tuples_on NAT such that
A32: Decomp(n,2) = SgmX (TuplesOrder 2,A) and
A33: for p be Element of 2-tuples_on NAT holds p in A iff Sum p = n by Def4;
A34: A = {<*i,n-'i*> where i is Element of NAT : i <= n}
  proof
    thus A c= {<*i,n-'i*> where i is Element of NAT : i <= n}
    proof
      let x be object;
      assume
A35:  x in A;
      then reconsider p=x as Element of 2-tuples_on NAT;
      consider d1,d2 be Element of NAT such that
A36:  p = <*d1,d2*> by FINSEQ_2:100;
A37:  d1+d2 = Sum p by A36,RVSUM_1:77
        .= n by A33,A35;
      then n-d1 >= 0;
      then
A38:  d2 = n-'d1 by A37,XREAL_0:def 2;
      d1 <= n by A37,NAT_1:11;
      hence thesis by A36,A38;
    end;
    let x be object;
    assume x in { <*i,n-'i*> where i is Element of NAT : i <= n };
    then consider i be Element of NAT such that
A39: x = <*i,n-'i*> and
A40: i <= n;
A41: n-i >= 0 by A40,XREAL_1:48;
    Sum <*i,n-'i*> = i+(n-'i) by RVSUM_1:77
      .= i+(n-i) by A41,XREAL_0:def 2
      .= n;
    hence thesis by A33,A39;
  end;
  field TuplesOrder 2 = 2-tuples_on NAT by ORDERS_1:15;
  then TuplesOrder 2 linearly_orders 2-tuples_on NAT by ORDERS_1:37;
  hence thesis by A32,A34,A20,A18,ORDERS_1:38,PRE_POLY:11;
end;
