
theorem Th48:
  for n being Element of NAT, p being Prime
  ex f being FinSequence of REAL st len f = 2*n &
  (for k being Element of NAT st k in dom f holds
  f.k = [\(2*n)/(p|^k)/] - 2*[\n/(p|^k)/]) & p |-count (2*n choose n) = Sum f
proof
  let n be Element of NAT;
  let p be Prime;
  set f0=n|->0;
  consider f1 being FinSequence of NAT such that
A1: len f1 = n and
A2: for k being Element of NAT st k in dom f1 holds f1.k=[\ n/(p|^k) /] and
A3: p |-count (n!) = Sum f1 by Th47;
  consider f2 being FinSequence of NAT such that
A4: len f2 = 2*n and
A5: for k being Element of NAT st k in dom f2 holds f2.k=[\ (2*n)/(p|^k) /] and
A6: p |-count ((2*n)!) = Sum f2 by Th47;
  reconsider f2 as FinSequence of REAL by FINSEQ_2:24,NUMBERS:19;
  set f = f2+((-(f1^f0))+(-(f1^f0)));
  take f;
A7: dom (f1^f0) = Seg (len f1 + len f0) by FINSEQ_1:def 7
    .= Seg (n+n) by A1,CARD_1:def 7
    .= Seg (2*n);
A8: dom ((-(f1^f0))+(-(f1^f0))) = dom (-(f1^f0)) /\ dom (-(f1^f0))
          by VALUED_1:def 1
    .= Seg (2*n) by A7,VALUED_1:8;
A9: dom f = dom f2 /\ dom ((-(f1^f0))+(-(f1^f0))) by VALUED_1:def 1
    .= Seg (2*n) /\ Seg (2*n) by A4,A8,FINSEQ_1:def 3;
  hence len f = 2*n by FINSEQ_1:def 3;
  thus for k being Element of NAT st k in dom f holds f.k=[\(2*n)/(p|^k)/]- 2*
  [\n/(p|^k)/]
  proof
    let k be Element of NAT;
    assume
A10: k in dom f;
    then
A11: k in dom f2 by A4,A9,FINSEQ_1:def 3;
A12: f.k = f2.k+((-(f1^f0))+(-(f1^f0))).k by A10,VALUED_1:def 1
      .=f2.k+((-(f1^f0)).k+(-(f1^f0)).k) by A8,A9,A10,VALUED_1:def 1
      .=f2.k+2*(-(f1^f0)).k
      .=f2.k+2*(-(f1^f0).k) by RVSUM_1:17
      .=f2.k-2*(f1^f0).k
      .=[\(2*n)/(p|^k)/]-2*(f1^f0).k by A5,A11;
    per cases by A7,A9,A10,FINSEQ_1:25;
    suppose
A13:  k in dom f1;
      then (f1^f0).k=f1.k by FINSEQ_1:def 7
        .=[\n/(p|^k)/] by A2,A13;
      hence thesis by A12;
    end;
    suppose
      ex e being Nat st e in dom f0 & k=len f1 + e;
      then consider e being Nat such that
A14:  e in dom f0 and
A15:  k=len f1 + e;
  dom f0 = Seg n by FUNCOP_1:13;
      then e >= 1 by A14,FINSEQ_1:1;
      then e + len f1 >= 1 + len f1 by XREAL_1:6;
      then
A16:  k > 1 + n or k = 1 + n by A1,A15,XXREAL_0:1;
A17:  (f1^f0).k = f0.e by A14,A15,FINSEQ_1:def 7
        .= 0;
      p>1 by INT_2:def 4;
      then p to_power k >= p to_power (1+n) by A16,POWER:39;
      then p|^k >= p to_power (1+n) by POWER:41;
      then
A18:  p|^k >= p|^(1+n) by POWER:41;
A19:  p>1 by INT_2:def 4;
      then p*p|^n>1*p|^n by XREAL_1:68;
      then p|^(1+n)>p|^n by NEWTON:6;
      then
A20:  p|^k>p|^n by A18,XXREAL_0:2;
      per cases;
      suppose
        n=0;
        hence thesis by A12,A17;
      end;
      suppose
A21:    n<>0;
        (p|^n)/(p|^n)>n/(p|^n) by A19,Th3,XREAL_1:74;
        then
A22:    1>n/(p|^n) by XCMPLX_1:60;
        n/(p|^n)>n/(p|^k) by A20,A21,XREAL_1:76;
        then 1>n/(p|^k) by A22,XXREAL_0:2;
        then 1-1>n/(p|^k)-1 by XREAL_1:9;
        hence thesis by A12,A17,INT_1:def 6;
      end;
    end;
  end;
  p |-count (2*n choose n) = Sum f
  proof
    per cases;
    suppose
A23:  n=0; then
A24:    2*n choose n = 1 by NEWTON:19;
      p>1 by INT_2:def 4;
      then
A25:  p |-count (2*n choose n) = 0 by A24,NAT_3:21;
      len f = 0 by A9,A23,FINSEQ_1:def 3;
      hence thesis by A25,PROB_3:62;
    end;
    suppose
A26:  n<>0;
A27:  2*n-n=n;
A28:  n+n>n+0 by A26,XREAL_1:6;
      then (2*n choose n)*((n!)*(n!)) = ((2*n)!)/((n!)*(n!))*((n!)*(n!)) by A27
,NEWTON:def 3
        .= (2*n)! by XCMPLX_1:87;
      then
A29:  ((n!) * (n!)) divides ((2*n)!) by NAT_D:def 3;
      2*n choose n = ((2*n)!)/((n!)*(n!)) by A28,A27,NEWTON:def 3;
      then
A30:  2*n choose n = ((n!) * (n!)) * (((2*n)!) div ((n!) * (n!))) /((n!)*
      (n!)) by A29,NAT_D:3
        .= ((2*n)!) div ((n!) * (n!)) by XCMPLX_1:89;
A31:  -(f1^f0) is Element of len(-(f1^f0))-tuples_on REAL by FINSEQ_2:92;
A32:  p |-count (((2*n)!) div ((n!)*(n!))) = p |-count ((2*n)!) -' p
      |-count ((n!)*(n!)) by A29,NAT_3:31
        .= p |-count ((2*n)!) - p |-count ((n!)*(n!)) by A29,NAT_3:30
,XREAL_1:233;
A33:  ((-(f1^f0))+(-(f1^f0))) is Element of len((-(f1^f0))+(-(f1^f0)))
      -tuples_on REAL by FINSEQ_2:92;
      len((-(f1^f0))+(-(f1^f0)))=len f2 & f2 is Element of len(f2)
      -tuples_on REAL by A4,A8,FINSEQ_1:def 3,FINSEQ_2:92;
      then Sum f = Sum f2 + Sum((-(f1^f0))+(-(f1^f0))) by A33,RVSUM_1:89
        .= Sum f2 + (Sum(-(f1^f0)) + Sum(-(f1^f0))) by A31,RVSUM_1:89
        .= Sum f2 + (- Sum(f1^f0) + Sum(-(f1^f0))) by RVSUM_1:88
        .= Sum f2 + (- Sum(f1^f0) + (- Sum(f1^f0))) by RVSUM_1:88
        .= Sum f2 - 2*Sum(f1^f0)
        .= Sum f2 - 2*(Sum(f1) + Sum(f0)) by RVSUM_1:75
        .= Sum f2 - 2*(Sum f1 + n*0) by RVSUM_1:80
        .= p |-count ((2*n)!) -(p |-count (n!) + p |-count (n!)) by A3,A6
        .= p |-count (((2*n)!) div ((n!)*(n!))) by A32,NAT_3:28;
      hence thesis by A30;
    end;
  end;
  hence thesis;
end;
