reserve x, x1, x2, y, X, D for set,
  i, j, k, l, m, n, N for Nat,
  p, q for XFinSequence of NAT,
  q9 for XFinSequence,
  pd, qd for XFinSequence of D;
reserve pN, qN for Element of NAT^omega;

theorem Th37:
  for n,m st 2*m <= n ex CardF be XFinSequence of NAT st card {pN:
pN in Domin_0(n,m) & {N:2*Sum(pN|N)=N & N > 0}<>{}} = Sum CardF & dom CardF = m
& for j st j < m holds CardF.j = card Domin_0(2*j,j) * card Domin_0(n-'2*(j+1),
  m -'(j+1))
proof
  let n,m such that
A1: 2*m <=n;
  set Z=Domin_0(n,m);
  defpred P[set,set] means for j st j=$1 holds $2={pN : pN in Domin_0(n,m) & 2
  * (j + 1) = min*{N: 2*Sum(pN|N) = N&N>0}};
  set W={pN: pN in Domin_0(n,m) & {N: 2*Sum(pN|N)=N & N>0}<>{}};
A2: for k st k in Segm m ex x be Element of bool Z st P[k,x]
  proof
    let k such that
    k in Segm m;
    set NN={pN : pN in Domin_0(n,m) & 2*(k+1) = min*{N: 2*Sum(pN|N)=N & N>0}};
    NN c= Z
    proof
      let x be object;
      assume x in NN;
      then ex pN st x=pN & pN in Z & 2*(k+1) = min*{N: 2*Sum(pN|N)=N&N>0};
      hence thesis;
    end;
    then reconsider NN as Element of bool Z;
    take NN;
    thus thesis;
  end;
  consider C be XFinSequence of bool Z such that
A3: dom C= Segm m & for k st k in Segm m holds P[k,C.k]
from STIRL2_1:sch 5(A2);
A4: W c= union rng C
  proof
    let x be object;
    assume x in W;
    then consider pN such that
A5: x=pN & pN in Domin_0(n,m) & {N: 2*Sum(pN|N)=N & N>0}<>{};
    set I={N: 2*Sum(pN|N)=N & N>0};
    I c= NAT
    proof
      let y be object;
      assume y in I;
      then ex i be Nat st i=y & 2*Sum(pN|i)=i & i>0;
      hence thesis by ORDINAL1:def 12;
    end;
    then reconsider I as non empty Subset of NAT by A5;
    min*I in I by NAT_1:def 1;
    then consider M be Nat such that
A6: min*I=M and
A7: 2*Sum (pN|M)=M and
A8: M>0;
    Sum (pN|M)>0 by A7,A8;
    then reconsider Sum1=Sum (pN|M)-1 as Nat by NAT_1:20;
    consider q such that
A9: pN=(pN|M)^q by Th1;
    Sum pN =Sum (pN|M)+Sum q by A9,AFINSQ_2:55;
    then m =Sum (pN|M)+Sum q by A5,Th20;
    then
A10: m >= Sum (pN|M) by NAT_1:11;
    Sum1+1 >Sum1 by NAT_1:13;
    then m > Sum1 by A10,XXREAL_0:2;
    then
A11: Sum1 in Segm m by NAT_1:44;
    then
    C.Sum1={qN:qN in Domin_0(n,m) & 2*(Sum1+1) = min*{N:2*Sum(qN|N)=N&N>0
    }} by A3;
    then
A12: pN in C.Sum1 by A5,A6,A7;
    C.Sum1 in rng C by A3,A11,FUNCT_1:3;
    hence thesis by A5,A12,TARSKI:def 4;
  end;
A13: for i,j st i in dom C & j in dom C & i<>j holds C.i misses C.j
  proof
    let i,j such that
A14: i in dom C and
A15: j in dom C and
A16: i<>j;
    assume C.i meets C.j;
    then C.i/\C.j<>{};
    then consider x being object such that
A17: x in C.i/\C.j by XBOOLE_0:def 1;
A18: x in C.j by A17,XBOOLE_0:def 4;
    C.j={qN : qN in Domin_0(n,m) & 2 *(j+1) = min*{N: 2*Sum(qN|N) = N & N
    >0 }} by A3,A15;
    then
A19: ex qN st x=qN & qN in Domin_0(n,m) & 2*(j+1)=min*{N:2*Sum(qN|N)=N&N>0
    } by A18;
A20: x in C.i by A17,XBOOLE_0:def 4;
    C.i={pN : pN in Domin_0(n,m) & 2 *(i+1) = min*{N: 2*Sum(pN|N) = N & N
    >0 }} by A3,A14;
    then
    ex pN st x=pN & pN in Domin_0(n,m) & 2 *(i+1) = min*{N: 2 *Sum(pN|N) =
    N & N>0} by A20;
    hence thesis by A16,A19;
  end;
A21: for k st k in dom C holds C.k is finite
  proof
    let k;
    assume k in dom C;
    then
A22: C.k in rng C by FUNCT_1:3;
    thus thesis by A22;
  end;
  consider CardC be XFinSequence of NAT such that
A23: dom CardC = dom C and
A24: for i st i in dom CardC holds CardC.i=card (C.i) and
A25: card union rng C = Sum(CardC) by A21,A13,STIRL2_1:66;
  take CardC;
  union rng C c= W
  proof
    let x be object;
    assume x in union rng C;
    then consider y such that
A26: x in y and
A27: y in rng C by TARSKI:def 4;
    consider j be object such that
A28: j in dom C and
A29: C.j=y by A27,FUNCT_1:def 3;
    reconsider j as Nat by A28;
    y={pN : pN in Domin_0(n,m) & 2 *(j+1)=min*{N:2*Sum(pN|N)=N&N>0}} by A3,A28
,A29;
    then consider pN such that
A30: x=pN & pN in Domin_0(n,m) & 2 *(j+1)=min*{N:2*Sum(pN|N)=N&N>0} by A26;
    2*(j+1)<>0;
    then {N : 2 * Sum(pN | N)=N & N>0} <>{} by A30,NAT_1:def 1;
    hence thesis by A30;
  end;
  hence card W = Sum CardC & dom CardC = m by A3,A23,A25,A4,XBOOLE_0:def 10;
  let j such that
A31: j < m;
A32: m >=j+1 by A31,NAT_1:13;
  then
A33: m-'(j+1)=m-(j+1) by XREAL_1:233;
  set P={pN : pN in Domin_0(n,m) & 2 *(j+1)=min*{N:2*Sum(pN|N)=N&N>0}};
  j < len C by A3,A31;
  then
A34: j in dom C by A3,NAT_1:44;
  then
A35: C.j=P by A3;
  2*(j+1)<= 2*m by A32,XREAL_1:64;
  then
A36: n-'2*(j+1)=n-2*(j+1) by A1,XREAL_1:233,XXREAL_0:2;
  CardC.j =card (C.j) by A23,A24,A34;
  hence thesis by A36,A33,A35,Th36;
end;
