せっかく述語が分かれているから先に決めちゃうか
pn(P,N) :- nonvar(N), pn(P,0, N), !.
pn(P,N) :- pn(P,0, N).
pn(z,N, N).
pn(s(P1),N0, N) :- N1 is N0+1, pn(P1,N1, N).