TITLE: Average digit sum in different bases
QUESTION [12 upvotes]: Given two natural numbers $n\geq 1$ and $b\geq 2$, denote by $S_b(n)$ the sum of the digit of $n$ in its representation in base $b$. Clearly $S_b(n)$ varies from 1 (when $n$ is a power of $b$) to $(b-1)\lfloor\ln{n}/\ln{b}\rfloor$  (when $n=b^k-1$ for some integer $k$). However, for a fixed $n$, the value of $S_b(n)$ for a generic base $b$ should be of order $(b-1)/2\cdot\ln{n}/\ln{b}$. 
This lead to consider the average of $S_b(n)$ for $b\leq n$
$$S(n):=\sum_{b\leq n}S_b(n)$$
or (maybe better) the wieghted average
$$S_w(n):=\sum_{b\leq n}\frac{S_b(n)}{b}$$
There exists some asymptotics or non trivial bounds for $S(n)$ and $S_w(n)$?

REPLY [10 votes]: The observation by Greg Martin is indeed correct. I have worked with these expressions in my bachelor thesis, which can be accessed for free here: Digit Sums. Proposition 2.10, page 12 states that $$\sum_{2\leq b\leq n}S_b(n)\sim (1-\frac{\pi^2}{12})n^2$$
as $n \to \infty$.
Relationship between the two sums
We have
$$\sum_{2\leq b\leq n}\frac{S_b(n)}{b}=\frac{1}{n}\sum_{2\leq b\leq n}S_b(n)+\int_{1}^{n}\frac{\sum \limits_{2 \leq b \leq x}S_b(n)}{x^2}dx$$
Proof:
Set $n_0$ equal to a fixed positive integer, and consider the sum $\sum \limits_{2\leq b\leq n}\frac{S_b(n_0)}{b}$. If we let $(a_k)_{k=1,2,\ldots}$ be the sequence defined by $a_1=0$ and $a_t=S_t(n_0)$ for $t\geq 2$, and $\phi:t\mapsto\frac{1}{t}$. Then the sum becomes $\sum \limits_{k=1}^{n}a_k\phi(k)$, which by Abel's summation formula equals
$$\phi(n)\sum_{k=1}^na_k -\int_{1}^{n}\phi'(x)\sum_{k\leq x}a_k \;\;dx$$
or equivalently
$$\frac{1}{n}\sum_{2\leq b\leq n}S_b(n_0)+\int_{1}^{n}\frac{\sum \limits_{2 \leq b \leq x}S_b(n_0)}{x^2}dx$$
Setting $n_0$ equal to $n$ completes the proof.
Asymptotic formula for the second sum
Proposition 4.4, page 27 states that $$\int_{1}^{n}\frac{\sum \limits_{p \leq n}S_p(n)}{x^2}dx \sim (\frac{\pi^2}{12}-\gamma)\frac{n}{\log(n)},$$ as $n \to \infty$, where $\gamma$ is the Euler- Mascheroni constant. Here, the summation is taken over the primes $p$. If you modify the deduction of this formula, you could conclude that
$$\int_{1}^{n}\frac{\sum \limits_{2 \leq b \leq x}S_b(n)}{x^2}dx \sim (\frac{\pi^2}{12}-\gamma)n$$
Using the relationship we obtained for the two summands, along with these two asymptotic formulae, we get:
\begin{align}
\sum_{2\leq b\leq n}\frac{S_b(n)}{b}\;=&\;\frac{1}{n}\sum_{2\leq b\leq n}S_b(n)+\int_{1}^{n}\frac{\sum \limits_{2 \leq b \leq x}S_b(n)}{x^2}dx 
\\ \sim \; &(1-\frac{\pi^2}{12})n+(\frac{\pi^2}{12}-\gamma)n \\[2mm]
\sim \; &(1-\gamma)n & \\[2mm]
=&\; n \cdot 0.42278433\ldots
\end{align}
Which perfectly matches the the numerical heuristics as pointed out by Greg Martin.
What if we sum over only primes p?
Proposition 2.12(p.14), Propostion 4.4(p.27) and the forumlae on page 25 show that
\begin{align}\sum_{p \leq n}S_p(n)\; =\; &(1-\frac{\pi^2}{12})\frac{n^2}{\log(n)}+C\frac{n^2}{\log^2(n)}+o(\frac{n^2}{\log^2(n)}) \\
\sum_{p\leq n}\frac{S_p(n)}{p}\sim& \;(1-\gamma)\frac{n}{\log(n)},
\end{align}
where $C=0.119\ldots$