let n be Element of NAT ; :: thesis: for p being Prime st n <> 0 holds
ex f being FinSequence of NAT st
( len f = n & ( for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) ) & p |-count n = Sum f )

let p be Prime; :: thesis: ( n <> 0 implies ex f being FinSequence of NAT st
( len f = n & ( for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) ) & p |-count n = Sum f ) )

assume A1: n <> 0 ; :: thesis: ex f being FinSequence of NAT st
( len f = n & ( for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) ) & p |-count n = Sum f )

defpred S1[ Nat, set ] means ( ( $2 = 1 implies p |^ $1 divides n ) & ( p |^ $1 divides n implies $2 = 1 ) & ( $2 = 0 implies not p |^ $1 divides n ) & ( not p |^ $1 divides n implies $2 = 0 ) );
A3: for k being Nat st k in Seg n holds
ex x being set st S1[k,x]
proof
let k be Nat; :: thesis: ( k in Seg n implies ex x being set st S1[k,x] )
assume k in Seg n ; :: thesis: ex x being set st S1[k,x]
per cases ( p |^ k divides n or not p |^ k divides n ) ;
suppose A4: p |^ k divides n ; :: thesis: ex x being set st S1[k,x]
set x = 1;
take 1 ; :: thesis: S1[k,1]
thus S1[k,1] by A4; :: thesis: verum
end;
suppose A5: not p |^ k divides n ; :: thesis: ex x being set st S1[k,x]
set x = 0 ;
take 0 ; :: thesis: S1[k, 0 ]
thus S1[k, 0 ] by A5; :: thesis: verum
end;
end;
end;
consider f being FinSequence such that
A6: dom f = Seg n and
A7: for k being Nat st k in Seg n holds
S1[k,f . k] from FINSEQ_1:sch 1(A3);
now
let x be set ; :: thesis: ( x in rng f implies x in NAT )
assume x in rng f ; :: thesis: x in NAT
then consider k being set such that
A8: ( k in dom f & f . k = x ) by FUNCT_1:def 5;
reconsider k = k as Element of NAT by A8;
S1[k,f . k] by A6, A7, A8;
hence x in NAT by A8; :: thesis: verum
end;
then rng f c= NAT by TARSKI:def 3;
then reconsider f = f as FinSequence of NAT by FINSEQ_1:def 4;
take f ; :: thesis: ( len f = n & ( for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) ) & p |-count n = Sum f )

thus len f = n by A6, FINSEQ_1:def 3; :: thesis: ( ( for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) ) & p |-count n = Sum f )

thus for k being Element of NAT st k in dom f holds
( ( f . k = 1 implies p |^ k divides n ) & ( p |^ k divides n implies f . k = 1 ) & ( f . k = 0 implies not p |^ k divides n ) & ( not p |^ k divides n implies f . k = 0 ) ) by A6, A7; :: thesis: p |-count n = Sum f
set f1 = ((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 );
set n1 = p |-count n;
set n2 = n -' (p |-count n);
A9: now end;
A14: len (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) = (len ((p |-count n) |-> 1)) + (len ((n -' (p |-count n)) |-> 0 )) by FINSEQ_1:35
.= (p |-count n) + (len ((n -' (p |-count n)) |-> 0 )) by FINSEQ_1:def 18
.= (p |-count n) + (n -' (p |-count n)) by FINSEQ_1:def 18
.= (p |-count n) + (n - (p |-count n)) by A9, XREAL_1:235 ;
then A15: dom f = dom (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) by A6, FINSEQ_1:def 3;
A16: for x being set st x in dom f holds
f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x
proof
let x be set ; :: thesis: ( x in dom f implies f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x )
assume A17: x in dom f ; :: thesis: f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x
then A18: x in dom (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) by A6, A14, FINSEQ_1:def 3;
set ff1 = (p |-count n) |-> 1;
set ff2 = (n -' (p |-count n)) |-> 0 ;
reconsider x1 = x as Element of NAT by A17;
per cases ( x1 in dom ((p |-count n) |-> 1) or ex m being Nat st
( m in dom ((n -' (p |-count n)) |-> 0 ) & x1 = (len ((p |-count n) |-> 1)) + m ) )
by A18, FINSEQ_1:38;
suppose A19: x1 in dom ((p |-count n) |-> 1) ; :: thesis: f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x
end;
suppose ex m being Nat st
( m in dom ((n -' (p |-count n)) |-> 0 ) & x1 = (len ((p |-count n) |-> 1)) + m ) ; :: thesis: f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x
then consider m being Nat such that
A26: ( m in dom ((n -' (p |-count n)) |-> 0 ) & x = (len ((p |-count n) |-> 1)) + m ) ;
A27: m in Seg (n -' (p |-count n)) by A26, FUNCOP_1:19;
then ((n -' (p |-count n)) |-> 0 ) . m = 0 by FUNCOP_1:13;
then A28: (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x = 0 by A26, FINSEQ_1:def 7;
m >= 1 by A27, FINSEQ_1:3;
then m + (p |-count n) > 0 + (p |-count n) by XREAL_1:8;
then A29: x1 > p |-count n by A26, FINSEQ_1:def 18;
not p |^ x1 divides n hence f . x = (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) . x by A6, A7, A17, A28; :: thesis: verum
end;
end;
end;
set fa = (p |-count n) |-> 1;
set fb = (n -' (p |-count n)) |-> 0 ;
Sum (((p |-count n) |-> 1) ^ ((n -' (p |-count n)) |-> 0 )) = (Sum ((p |-count n) |-> 1)) + (Sum ((n -' (p |-count n)) |-> 0 )) by RVSUM_1:105
.= ((p |-count n) * 1) + (Sum ((n -' (p |-count n)) |-> 0 )) by RVSUM_1:110
.= (p |-count n) + ((n -' (p |-count n)) * 0 ) by RVSUM_1:110 ;
hence p |-count n = Sum f by A15, A16, FUNCT_1:9; :: thesis: verum