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 Th15:
  for p st rng p c= {0,1} & p is not dominated_by_0 ex k st 2*k+1
  = min*{N : 2*Sum(p|N) > N} & 2*k+1 <= dom p & k = Sum (p|(2*k)) & p.(2*k) = 1
proof
  let p such that
A1: rng p c= {0,1} and
A2: p is not dominated_by_0;
  set M={N : 2*Sum(p|N) > N};
  M c= NAT
  proof
    let x be object;
    assume x in M;
    then ex N st x=N & 2*Sum(p|N) > N;
    hence thesis by ORDINAL1:def 12;
  end;
  then reconsider M as Subset of NAT;
  consider k be Nat such that
A3: k <= dom p and
A4: 2*Sum(p|k) > k by A1,A2;
  reconsider k as Nat;
  k in M by A4;
  then reconsider M as non empty Subset of NAT;
  min*M in M by NAT_1:def 1;
  then consider n be Nat such that
A5: min*M=n and
A6: 2*Sum(p|n) > n;
A7: Sum(p|0) = 0;
  Sum(p|n) > 0 by A6;
  then n>0 by A7;
  then reconsider n1=n-1 as Nat by NAT_1:20;
  reconsider S=Sum(p|n1) as Nat;
  take S;
  k in M by A4;
  then
A8: k >= n by A5,NAT_1:def 1;
  then
A9: dom p >= n by A3,XXREAL_0:2;
A10: 2*Sum(p|n1) = n1
  proof
A11: n1 < n1+1 by NAT_1:13;
    then Segm n1 c= Segm(n1+1) by NAT_1:39;
    then
A12: (p|n)|n1=p|n1 by RELAT_1:74;
    n = len p & p|dom p = p or n <len p by A9,XXREAL_0:1;
    then
A13: len(p|n) = n1+1 by AFINSQ_1:11;
    then n1 in Segm(len (p|n)) by A11,NAT_1:44;
    then
A14: (p|n).n1 in rng(p|n) by FUNCT_1:3;
    (p|n)=((p|n)|n1)^<%(p|n).n1%> by A13,AFINSQ_1:56;
    then Sum(p|n)=Sum(p|n1)+ Sum <%(p|n).n1%> by A12,AFINSQ_2:55;
    then
A15: 2*Sum(p|n1)+ 2* Sum <%(p|n).n1%> >= n+1 by A6,NAT_1:13;
    n1 < n1+1 by NAT_1:13;
    then not n1 in M by A5,NAT_1:def 1;
    then
A16: 2*Sum(p|n1) <= n1;
    (p|n).n1 in {0,1} by A1,A14;
    then
A17: (p|n).n1 =0 or (p|n).n1 = 1 by TARSKI:def 2;
    assume 2*Sum(p|n1) <> n1;
    then Sum <%(p|n).n1%> = (p|n).n1 & 2*Sum(p|n1)<n1 by A16,AFINSQ_2:53
,XXREAL_0:1;
    then 2*Sum(p|n1) + 2*Sum <%(p|n).n1%> < n1+2 by A17,XREAL_1:8;
    hence contradiction by A15;
  end;
  p.n1=1
  proof
    Segm n c= Segm len p by A9,NAT_1:39;
    then
A18: dom(p|n)=n1+1 by RELAT_1:62;
A19: Sum <%0%>=0 & (p|n)=((p|n)|n1)^<%(p|n).n1%> by A18,AFINSQ_1:56,AFINSQ_2:53
;
    assume
A20: p.n1<>1;
A21: n1 <n1+1 by NAT_1:13;
    then n1 < len p by A9,XXREAL_0:2;
    then
A22: n1 in dom p by AFINSQ_1:86;
    Segm n1 c= Segm n by A21,NAT_1:39;
    then
A23: (p|n)|n1=p|n1 by RELAT_1:74;
    n1 in Segm n by A21,NAT_1:44;
    then n1 in dom p/\n by A22,XBOOLE_0:def 4;
    then
A24: (p|n).n1=p.n1 by FUNCT_1:48;
A25: n1 <n1+1 by NAT_1:13;
    p.n1 in rng p by A22,FUNCT_1:3;
    then p.n1=0 by A1,A20,TARSKI:def 2;
    then Sum (p|n)=Sum (p|n1) +(0 qua Nat) by A19,A24,A23,AFINSQ_2:55;
    hence thesis by A6,A10,A25;
  end;
  hence thesis by A3,A5,A8,A10,XXREAL_0:2;
end;
