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;

theorem Th17:
  for p st p is dominated_by_0 & {N: 2*Sum(p|N) = N & N > 0} = {}
  & len p > 0 ex q st p = <%0%>^q & q is dominated_by_0
proof
  let p such that
A1: p is dominated_by_0 and
A2: {N: 2*Sum(p|N)=N & N>0}={} & len p > 0;
  set M={N: 2*Sum(p|N)=N & N>0};
  consider q such that
A3: p=p|1^q by Th1;
  take q;
A4: rng p c= {0,1} by A1;
  rng q c= rng p by A3,AFINSQ_1:25;
  then
A5: rng q c= {0,1} by A4;
  len p >= 1 by A2,NAT_1:14;
  then Segm 1 c= Segm len p by NAT_1:39;
  then
A6: dom (p|1)=1 by RELAT_1:62;
A7: p|1=<%(p|1).0%> by A6,AFINSQ_1:34;
  0 in Segm 1 by NAT_1:44;
  then
A8: (p|1).0=p.0 by A6,FUNCT_1:47;
  hence p=<%0%>^q by A1,A3,A7,Th3;
  assume q is not dominated_by_0;
  then consider i such that
  i <= dom q and
A9: 2*Sum(q|i) > i by A5;
reconsider i as Nat;
  p|(1+i)=(p|1)^(q|i) by A3,A6,AFINSQ_1:59;
  then
A10: Sum (p|(1+i))=Sum <%p.0%>+Sum (q|i) by A7,A8,AFINSQ_2:55;
A11: 2*Sum(q|i) >= i+1 by A9,NAT_1:13;
  Sum <%p.0%>=p.0 by AFINSQ_2:53;
  then
A12: Sum (p|(1+i))=(0 qua Nat)+Sum (q|i) by A1,A10,Th3;
  then 1+i >=2*Sum (q|i) by A1,Th2;
  then 1+i =2*Sum (q|i) by A11,XXREAL_0:1;
  then 1+i in M by A12;
  hence thesis by A2;
end;
