(Feller Vol.1) the generating function for the probabilities that the event $S_n = r$ will occur exactly $k$ times (Feller Vol.1, P.283, Q.10) Find the generating function for the probabilities that the event $S_n = r$ will occur exactly $k$ times ($r > 0$ and $k >0$ fixed).
$(X_i)$ is a sequence of r.v. each of which assumes $1$ with probability $p$ and $-1$ with $q$. Let $S_n = X_1+X_2+ \cdots + X_n$. In order for this event to occur $k$ times, the path must first reach $r$ from the origin. Let this probability be $\phi^{(r)}_j$ (the probability that the first passage through $r$ at the $j$ th trial). Once it reaches $r$, we can think of $r$ as the origin. Then, the occurrence of this event $k$ times is equivalent to returning to the origin $k$ times. Let $f_{n-j}^{(k)}$ be the probability of the first $k$ returns to the origin at the $n-j$ trial. Let the event $S_n =r$ occurring $k$ times be $A_n$. Taken all together, we have that
$$P(A_n) = \sum_{j=0}^n\phi^{(r)}_j f^{(k)}_{n-j}.$$
Multiplying $s^n$ on both sides and summing over all non-negative integers,
$$\sum_{n=0}^{\infty} P(A_n) s^n = \sum_{n=0}^{\infty}\sum_{j=0}^n\phi^{(r)}_j f^{(k)}_{n-j}s^j s^{n-j} = \sum_{j=0}^\infty\phi^{(r)}_j s^j\sum_{n=j}^\infty f^{(k)}_{n-j}s^{n-j}.$$
Assuming that $F^{(k)}(s) =\sum_{n=1}^\infty f^{(k)}_{n}s^{n}$ and $\Phi^{(r)}(s) =\sum_{j=0}^\infty\phi^{(r)}_j s^j $. I found the generating function $F^{(k)}(s)\Phi^{(r)}(s)$. However, the answer is $|p-q|F^{(k)}(s)\Phi^{(r)}(s) $.
I was pondering where $|p-q|$ comes from. The textbook shows that the generating function $F(s)$ of $\{f_j\}$ (the probability of the first return to the origin at the $j$ th trial) is $1- \sqrt{1-4pqs^2}$. It follows that  $F(1)= 1- |p-q|$, which is basically $\sum_j f_j$. Then, $|p-q|$ is the probability that the first return to the origin never occurs. I guess that this has something to do with $|p-q|$ in the answer, but I can't figure it out. I would greatly appreciate if you give some help. Let me know if you need more context.

The event, the probability of which we are looking for, can be divided into 3 intervals:

*

*

*

*the first reaching the point $r$



*


*the last reaching the point $r$ at the $n$-th trial ($S_n = r$)



*


*not returning to the point $r$ during all the remaining trials.



These three intervals give three factors in the required generating function $\Phi^r(s)$, $F^k(s)$ and $|p-q|$ respectively.
