I am trying to understand a scribe note on choosing the right number of hash functions $k$ for a bloomfilter of size $n$ and $m$ elements. The following is stated:
Suppose we are given the ratio $\frac{m}{n}$ and want to optimize the number $k$. If $$g=\ln(f)=k\ln(1-e^{-kn/m})$$ and we let $p=e^{-kn/m}$. Then the derivative of $g$ is: $$\frac{dg}{dk}=\ln(1-p)+\frac{kn}{m}\cdot\frac{p}{1-p}$$ This confuses me because when I try to differentiate $g$ I get the following: $$\begin{equation} \frac{dg}{dk}=\ln(1-p)+\frac{1}{1-e^{-km/n}} \cdot \frac{e^{-km/n} \cdot m-kn}{m^2} \end{equation}$$
Link to equation (on page 2): http://people.math.gatech.edu/~randall/AlgsF09/bloomfilters.pdf
This is because you also have to differentiate $p$ as it depends on $k$. It goes like this: first note $$ \frac{d}{dk} p = \frac d{dk} e^{-kn/m} =-\frac{n}{m} e^{-kn/m} =-\frac{n}{m}p$$ Then applying product rule and chain rule, \begin{align} \frac{dg}{dk} = \frac{d}{dk}(k(\ln(1-p)) &=\ln(1-p) + k\frac{d}{dk}(\ln (1-p))\\ &=\ln(1-p) + k\frac{\frac{d}{dk}(1-p)}{1-p}\\ &=\ln(1-p) + k\frac{0-\frac{dp}{dk}}{1-p}\\ &=\ln(1-p) + k \frac{-\left(-\frac nmp\right)}{1-p}\\ &=\ln(1-p)+\frac{kn}m\cdot\frac{p}{1-p} \end{align}