
theorem Th47:
  for n being Element of NAT, p being Prime
  ex f being FinSequence of NAT st len f = n &
  (for k being Element of NAT st k in dom f holds f.k = [\ n/ (p|^k) /]) &
  p |-count (n!) = Sum f
proof
  defpred P[Nat] means for p being Prime ex f being FinSequence of
NAT st len f = $1 & (for k being Element of NAT st k in dom f holds f.k=[\ $1/(
  p|^k) /]) & p |-count ($1!) = Sum f;
  let n be Element of NAT;
  let p be Prime;
A1: for n being Nat st P[n] holds P[n+1]
  proof
    let n be Nat;
    assume
A2: P[n];
    for p being Prime ex f being FinSequence of NAT st len f = n+1 & (for
k being Element of NAT st k in dom f holds f.k=[\ (n+1)/(p|^k) /]) & p |-count
    ((n+1)!) = Sum f
    proof
      let p be Prime;
      consider fn being FinSequence of NAT such that
A3:   len fn = n and
A4:   for k being Element of NAT st k in dom fn holds fn.k=[\ n/(p|^k) /] and
A5:   p |-count (n!) = Sum fn by A2;
      reconsider fnn=fn as FinSequence of REAL by FINSEQ_2:24,NUMBERS:19;
      set fn0=fnn ^ <* In(0,REAL) *>;
      consider fn1 being FinSequence of NAT such that
A6:   len fn1 = n + 1 and
A7:   for k being Element of NAT st k in dom fn1 holds (fn1.k=1 iff p
      |^k divides (n+1)) & (fn1.k=0 iff not p|^k divides (n+1)) and
A8:   p |-count (n+1) = Sum fn1 by Th46;
A9:   Seg(n+1) = dom fn1 by A6,FINSEQ_1:def 3;
      set f = (fn ^ <* 0 *>)+fn1;
      for y being object st y in rng f holds y in NAT
               by ORDINAL1:def 12;
      then rng f c= NAT;
      then reconsider f as FinSequence of NAT by FINSEQ_1:def 4;
      take f;
      reconsider fn0 as FinSequence of REAL;
      reconsider fn1 as FinSequence of REAL by FINSEQ_2:24,NUMBERS:19;
A10:  dom f = dom fn0 /\ dom fn1 by VALUED_1:def 1;
A11:  len fn0 = len fn + len <* 0 *> by FINSEQ_1:22
        .= n + 1 by A3,FINSEQ_1:39;
      then Seg(n+1) = dom fn0 by FINSEQ_1:def 3;
      hence len f = n+1 by A10,A9,FINSEQ_1:def 3;
      thus for k being Element of NAT st k in dom f holds f.k=[\ (n+1)/(p|^k)
      /]
      proof
        let k be Element of NAT;
A12:    (p|^k)/(p|^k)=1 by XCMPLX_1:60;
        assume
A13:    k in dom f;
        then
A14:    f.k = fn0.k + fn1.k by VALUED_1:def 1;
A15:    k in dom fn0 by A10,A13,XBOOLE_0:def 4;
A16:    fn0.k=[\ n/(p|^k) /]
        proof
          per cases by A15,FINSEQ_1:25;
          suppose
A17:        k in dom fn;
            then fn.k=[\ n/(p|^k) /] by A4;
            hence thesis by A17,FINSEQ_1:def 7;
          end;
          suppose
            ex n1 being Nat st n1 in dom <* 0 *> & k=len fn + n1;
            then consider n1 being Nat such that
A18:        n1 in dom <* 0 *> and
A19:        k=len fn + n1;
            n1 in Seg 1 by A18,FINSEQ_1:38;
            then
A20:        n1=1 by FINSEQ_1:2,TARSKI:def 1;
            p>1 by INT_2:def 4;
            then
A21:        p*p|^n>1*p|^n & p|^n>n by Th3,XREAL_1:68;
            p|^(n+1)=p|^n*p by NEWTON:6;
            then p|^k>n by A3,A19,A20,A21,XXREAL_0:2;
            then n/(p|^k)<1 by XREAL_1:189;
            then
A22:        n/(p|^k)-1<1-1 by XREAL_1:9;
            fn0.(n+1)=<* 0 *>.1 by A3,A18,A20,FINSEQ_1:def 7;
            then fn0.k=0 by A3,A19,A20;
            hence thesis by A22,INT_1:def 6;
          end;
        end;
A23:    k in dom fn1 by A10,A13,XBOOLE_0:def 4;
        per cases;
        suppose
A24:      p|^k divides (n+1);
          then consider r being Nat such that
A25:      n+1=(p|^k)*r by NAT_D:def 3;
A26:      (n+1)/(p|^k) = r/((p|^k)/(p|^k)) by A25,XCMPLX_1:77
            .= r/(1/1) by XCMPLX_1:60
            .= r;
          ((p|^k)/(p|^k))+((-1)/(p|^k))-1<0 by A12;
          then
A27:      (p|^k+(-1))/(p|^k)-1<0 by XCMPLX_1:62;
          [\ n/(p|^k) /] + 1 = [\ n/(p|^k) +1 /] by INT_1:28
            .=[\ n/(p|^k) + (p|^k)/(p|^k) /] by XCMPLX_1:60
            .=[\ (n+p|^k)/(p|^k) /] by XCMPLX_1:62
            .=[\ ((n+1)+(p|^k -1))/(p|^k) /]
            .=[\ (n+1)/(p|^k) + (p|^k-1)/(p|^k) /] by XCMPLX_1:62
            .=(n+1)/(p|^k) + [\ (p|^k-1)/(p|^k) /] by A26,INT_1:28
            .=(n+1)/(p|^k) + 0 by A27,INT_1:def 6
            .=[\ (n+1)/(p|^k) /] by A26;
          hence thesis by A7,A14,A23,A16,A24;
        end;
        suppose
A28:      not p|^k divides (n+1);
          set m=(n+1) mod (p|^k);
          set d=(n+1) div (p|^k);
A29:      n+1 = (p|^k) * d + m by NAT_D:2;
          then not m=0 by A28,NAT_D:def 3;
          then m+1>0+1 by XREAL_1:6;
          then m>=1 by NAT_1:13;
          then
A30:      m-1>=1-1 by XREAL_1:9;
          m<p|^k & 0+p|^k<1+p|^k by NAT_D:1,XREAL_1:6;
          then m<p|^k+1 by XXREAL_0:2;
          then m-1<p|^k+1-1 by XREAL_1:9;
          then (m-1)/(p|^k)<(p|^k)/(p|^k) by XREAL_1:74;
          then
A31:      (m-1)/(p|^k)-1<1-1 by A12,XREAL_1:9;
          m/(p|^k)<(p|^k)/(p|^k) by NAT_D:1,XREAL_1:74;
          then
A32:      m/(p|^k)-1<1-1 by A12,XREAL_1:9;
A33:      fn1.k=0 by A7,A23,A28;
          n = (p|^k) * d + (m-1) by A29;
          then [\ n/(p|^k) /] = [\ ((p|^k) * d)/(p|^k) + (m-1)/(p|^k) /] by
XCMPLX_1:62
            .= [\ d*((p|^k)/(p|^k)) + (m-1)/(p|^k) /] by XCMPLX_1:74
            .= [\ d*1 + (m-1)/(p|^k) /] by XCMPLX_1:60
            .= d + [\ (m-1)/(p|^k) /] by INT_1:28
            .= d + 0 by A30,A31,INT_1:def 6
            .= d + [\ m/(p|^k) /] by A32,INT_1:def 6
            .= [\ d*1 + m/(p|^k) /] by INT_1:28
            .= [\ d*((p|^k)/(p|^k)) + m/(p|^k) /] by XCMPLX_1:60
            .= [\ ((p|^k) * d)/(p|^k) + m/(p|^k) /] by XCMPLX_1:74
            .= [\ ((p|^k) * d + m)/(p|^k) /] by XCMPLX_1:62
            .= [\ (n+1)/(p|^k) /] by NAT_D:2;
          hence thesis by A14,A16,A33;
        end;
      end;
      reconsider fn1 as Element of (n+1)-tuples_on REAL by A6,FINSEQ_2:92;
      reconsider fn0 as Element of (n+1)-tuples_on REAL by A11,FINSEQ_2:92;
A34:  p |-count (n!) + p |-count (n+1) = p |-count (n!*(n+1)) by NAT_3:28
        .= p |-count ((n+1)!) by NEWTON:15;
      Sum f = Sum fn0 + Sum fn1 by RVSUM_1:89
        .= Sum fn + 0 + p |-count (n+1) by A8,RVSUM_1:74
        .= p |-count (n!) + p |-count (n+1) by A5;
      hence thesis by A34;
    end;
    hence thesis;
  end;
A35: P[0]
  proof
    set f = <*>NAT;
    let p be Prime;
    take f;
    thus len f = 0;
    thus for k being Element of NAT st k in dom f holds f.k=[\ 0/(p|^k) /];
    p<>1 by INT_2:def 4;
    hence thesis by NAT_3:21,NEWTON:12,RVSUM_1:72;
  end;
  for n being Nat holds P[n] from NAT_1:sch 2(A35,A1);
  then consider f being FinSequence of NAT such that
A36: ( len f = n & for k being Element of NAT st k in dom f holds f.k=[\
  n/(p|^k) /] )& p |-count (n!) = Sum f;
  take f;
  thus thesis by A36;
end;
