reserve a,b,d,n,k,i,j,x,s for Nat;

theorem Th28:
  for p be Prime, k be Nat holds
     (p |-count Product primesFinS k = 1 iff primeindex p < k) &
     (p |-count Product primesFinS k = 0 iff primeindex p >= k)
proof
  defpred P[Nat] means
  for p be Prime holds
     (p |-count Product primesFinS $1 = 1 iff primeindex p < $1) &
     (p |-count Product primesFinS $1 = 0 iff primeindex p >= $1);
A1: P[0]
  proof
    let p be Prime;
A2: Product primesFinS 0 = 1 by RVSUM_1:94;
    p > 1 by INT_2:def 4;
    then p |-count Product primesFinS 0 = 0 by A2,NAT_3:21;
    hence thesis;
  end;
A3: P[n] implies P[n+1]
  proof
    assume
A4:   P[n];
    set n1=n+1;
    let p be Prime;
A5:   Product primesFinS n1 = Product (primesFinS n) * (primenumber n)
      by Th25;
A6:   p |-count Product primesFinS n1 =
     (p |-count Product primesFinS n) + (p|-count (primenumber n))
      by A5,NAT_3:28;
A7:   n in NAT by ORDINAL1:def 12;
A8:   p > 1 by INT_2:def 4;
    thus p |-count Product primesFinS n1 = 1 iff primeindex p < n1
    proof
      thus p |-count Product primesFinS n1 = 1 implies primeindex p < n1
      proof
        assume p |-count Product primesFinS n1 = 1;
        then
A9:       (p |-count Product primesFinS n)+(p|-count (primenumber n))=1
          by A6;
        per cases;
        suppose p = primenumber n;
          then primeindex p = n by A7,NUMBER10:def 4;
          hence thesis by NAT_1:13;
        end;
        suppose p<>primenumber n;
          then (p|-count (primenumber n))=0 by A8,NAT_3:24;
          then p |-count Product primesFinS n = 1 by A9;
          then primeindex p < n by A4;
          hence thesis by NAT_1:13;
        end;
      end;
      assume primeindex p < n1;
      then primeindex p <= n by NAT_1:13;
      then per cases by XXREAL_0:1;
      suppose
A10:      primeindex p = n;
        then primenumber n = p by NUMBER10:def 4;
        then
A11:      (p|-count (primenumber n))=1 by A8,NAT_3:22;
        p |-count Product primesFinS n = 0 by A10,A4;
        hence thesis by A6,A11;
      end;
      suppose
A12:      primeindex p < n;
        then p < primenumber n by NUMBER13:12;
        then
A13:      p|-count (primenumber n) = 0 by A8,NAT_3:24;
        p |-count Product primesFinS n = 1 by A12,A4;
        hence thesis by A6,A13;
      end;
    end;
    thus p |-count Product primesFinS n1 = 0 implies primeindex p >= n1
    proof
      assume p |-count Product primesFinS n1 = 0;
      then (p |-count Product primesFinS n) + (p|-count (primenumber n))=0
        by A6;
      then p |-count Product primesFinS n = 0 & p|-count (primenumber n) = 0;
      then primeindex p >= n & primenumber n <> p by A4,A8,NAT_3:22;
      then primeindex p >= n & primeindex p <> n by NUMBER10:def 4;
      then primeindex p > n by XXREAL_0:1;
      hence thesis by NAT_1:13;
    end;
    assume
A14:  primeindex p >= n1;
    then primeindex p >= n by NAT_1:13;
    then
A15:  p |-count Product primesFinS n = 0 by A4;
A16:  p >= primenumber n1 by A14,NUMBER13:12;
    n < n1 by NAT_1:13;
    then
    primenumber n1 > primenumber n by MOEBIUS2:21;
    then p > primenumber n by A16,XXREAL_0:2;
    then (p|-count (primenumber n))=0 by A8,NAT_3:24;
    then p |-count Product primesFinS n1 = 0 by A6,A15;
    hence thesis;
  end;
  P[n] from NAT_1:sch 2(A1,A3);
  hence thesis;
end;
