I'm looking for a math function that taking an integer returns the sum of it's digits. I tried with this method:
-I've got a digit sequence $d_{k+1},d_{k},...,d_{1}$ with $d_{k+1}\ne 0$ and $d_i \in \{0,1,2 \dots , 9\}$ for all $1 \le i \le k+1$; this represents the number $A$ in base $10$, so: $$A = \sum_{i = 1}^{k+1} d_i 10^{i-1}$$
-Now I know that each digit is generated by: $$d_i = \sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\frac{A\,\, \pmod{10^i}-A\,\, \pmod{10^{i-1}} }{10^{i-1}}$$
-I expand the sum and I obtain: $$\frac{A\, \pmod{10}-A\,\, \pmod1}{1}+\frac{A\, \pmod{10^2}-A\,\, \pmod{10}}{10}+\cdots +\frac{A\, \pmod{ 10^i}-A\pmod{10^{i-1}}}{10^{i-1}}$$
-I have to simplify the denominator so: $$\frac{1\cdot (A\, \pmod{10}-A\,\, \pmod1)}{1}+\frac{10\cdot (\lfloor\frac{A}{10}\rfloor\, \pmod{10}-\lfloor\frac{A}{10}\rfloor\,\, \pmod 1)}{10}+\cdots +\frac{10^{i-1}\cdot (\lfloor{\frac{A}{10^{i-1}}}\rfloor\, \pmod{10}-\lfloor\frac{A}{10^{i-1}}\rfloor\,\, \pmod 1)}{10^{i-1}}$$
-I split the term: $$A\, \, \pmod{10}+\lfloor\frac{A}{10}\rfloor\, \, \pmod{10}+\cdots+\lfloor\frac{A}{10^{i-1}}\rfloor\, \, \pmod{10}-(A\, \, \pmod1+\lfloor\frac{A}{10}\rfloor\, \, \pmod1+\cdots +\lfloor\frac{A}{10^{i-1}}\rfloor\, \, \pmod1)$$
-Now I would have picked up $\pmod{10}$ and $\pmod1$: $$\left (\sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\lfloor\frac{A}{10^{i-1}}\rfloor\right)\, \, \pmod{10}-\left (\sum_{i=1}^{\left \lfloor \log_{10}(A)+1 \right \rfloor}\lfloor\frac{A}{10^{i-1}}\rfloor\right)\, \, \pmod1$$; but I can't. Any ideas to move forward?
Thanks
I worked on similar idea in my question many years ago. I asked to find any digit in a given number. There is an answer for my question to find any digit of a number via Fourier series expansion. Please check @Zander 's answer how to find the function. We can use it to find the sum of digit's numbers eaisly as shown below.
Let's define $d_n(A)$ is digit number of A, Where A is a real number. For example:
$d_3(2345.67)=2$
$d_0(2345.67)=5$
$d_{-1}(2345.67)=6$
We can write easily $d_n(A) = d_0(10^{-n}A)$ and $$A = \sum_{k=-\infty}^\infty 10^k d_k(A)$$ $$A = \sum_{k=-\infty}^\infty 10^k d_0(10^{-k}A)$$
If you notice the formulas above , it is enough to find out only $d_0(A)$.
If we find $d_0(A)$ ,any digit can be found by using it. $$ d_0(A) =\frac{9}{2} -\frac{10}{\pi}\sum_{k=1}^\infty b_k \sin\left(\frac{k\pi A}{5}\right) $$ where $$ b_k = \begin{cases}0 & \mathrm{if}~10\mid k\\ 1/k & \mathrm{otherwise}\end{cases} $$
Thus we can write the sum of integer number's digits :$T$
If A is a positive integer , you can write $T$ as $$ T=\sum_{k=0}^\infty d_0(10^{-k}A)$$