Is this reasoning correct for average prime gap?

Since \begin{align} &\operatorname{li}(n)\sim\Pi (n)\equiv\sum _{k=1}^{\lfloor \log (n)\rfloor } \frac{\pi \left(n^{1/k}\right)}{k}\\ \end{align} then the average gap for \begin{align} &\Pi^{-1} (n)\sim\left(\frac{\partial \ \operatorname{li}(n)}{\partial n}\right)^{-1}=\log(n)\\ \end{align}

so, taking \begin{align} &\Pi (n)-\pi(n)=O\left(\frac{\sqrt{n}}{\log n}\right)\\ \end{align} (Ingham), we have \begin{align} &p_n-\Pi^{-1} (n)\sim\left(\frac{\partial }{\partial n}\frac{\sqrt{n}}{\log n}\right)^{-1}=\frac{2 \sqrt{n} \log^2 (n)}{\log (n)-2}\\ \end{align} which gives \begin{align} &g_n\sim\log n+O\left(\sqrt{\log n} \log \log n\right)\\ \end{align} where $g_n$ is the average prime gap, which agrees with Shanks' $\log p(g) \sim \sqrt{g}.$

I don't think the reasoning is correct. It's pretty clear that $$p_n-\Pi^{-1}(n)\sim\sqrt{\frac{n}{\log n}}\not\sim2\sqrt n\log n\sim\frac{2\sqrt n\log^2n}{\log n-2}$$ and I don't see any proof (or reason to expect proof) that the inverse of the partials gives the average gap size without further assumptions. In any case there's no justification for the last line giving $g_n$.
Instead, note that $(p_2-p_1)+(p_3-p_2)+\cdots+(p_{n+1}-p_n)$ telescopes to $p_{n+1}-p_1$ and so the average of the first $n$ gaps is $$\frac{p_{n+1}-p_1}{n}$$ which is $$\log n+\log\log n-1+\frac{\log\log n-2}{\log n}-\frac{(\log\log n)^2-6\log\log n+11}{2\log^2n}+O\left(\left(\frac{\log\log n}{\log n}\right)^3\right)$$ by a result of Cipolla (1902).
• Yes, I thought my $O$ term for $p_n-\Pi^{-1}(n)$ was a bit iffy & doubted the reasoning that led up to it - hence the question. re the last line, I took the $\frac{2 \sqrt{n} \log^2 (n)}{\log (n)-2}=O(\sqrt{n}/\log n)$ and replaced $n$ for $\log n$ - the average gap size for $\Pi^{-1}(n).$ By this rational, using your $p_n-\Pi^{-1}(n)\sim\sqrt{\frac{n}{\log n}},$ I get $g_n\sim\log n+\sqrt{\log n/ \log \log n},$ which certainly looks better numerically. Would you agree? – martin May 19 '15 at 9:36
• Of course the above argument rests on the gap for $\Pi^{-1}(n)\sim \log n,$ of which I am fairly sure, but of course I can't rely on the line of reasoning given in the OP for proof. – martin May 19 '15 at 9:45
• @martin: The average gap in $\Pi^{-1}(k)$ for $k=\{1,2,\ldots,n\}$ is $\log n+O(1)$. Average gaps are easy, but they don't really tell you anything about extremal gaps like Shanks' conjecture. (In any case advances in analytic number theory in the 80s and early 90s threw that conjecture in serious doubt.) – Charles May 19 '15 at 15:23