This question was previously posted [here](https://math.stackexchange.com/questions/4185940/is-the-p-adic-density-of-the-image-of-a-polynomial-always-rational) on MSE.


Let $P(x)$ be a polynomial with integer coefficients, and let $p$ be a prime number. For $n\in\mathbb N$, let $I\_n$ be the number of integers $i\in\{1,\dotsc,p^n\}$ such that there is an integer $x$ for which $P(x)\equiv i\bmod p^n$. Now define
$$\delta:=\lim\_{n\rightarrow\infty}\frac{I\_n}{p^n}.$$
Remark that this limit exists since $\frac{I\_n}{p^n}\geq \frac{I\_{n+1}}{p^{n+1}}$ for all $n$. One could say that $\delta$ is ‘the $p$-adic density of the image of $P$’.


Now I have the following question: is $\delta$ a rational number for all polynomials $P$ and primes $p$?


This question is connected to another question [Cardinality of the image of a polynomial modulo $p^n$](https://mathoverflow.net/questions/295365/cardinality-of-the-image-of-a-polynomial-modulo-pn) on MathOverflow, which asks for general information on the behavior of $I\_n$ as $n\rightarrow\infty$.



Is the p-adic density of the image of a polynomial always rational?
Using the strategies suggested by @Merosity on MSE and @Gro-Tsen and @RP\_ on MO, I have found a proof that the density is indeed always rational.


Let $P$ be a polynomial with integer coefficients, and let $p$ be a prime number. If $P$ is a constant polynomial, then we obtain $\delta=0$ which is rational. So assume that $P$ is nonconstant. We shall prove that $\delta$ is rational by means of a chain of lemmas. Each lemma only uses the previous lemma.


**Lemma**


Let $g:\mathbb Z\_p\rightarrow\mathbb Z\_p$ be a power series
$g(x)=\sum\_{i=0}^{\infty}g\_ix^i$ with $g\_i\in\mathbb Z\_p$ for all $i$ and
$g\_i\rightarrow0$ as $i\rightarrow\infty$. Suppose that $g'(0)=1$. Then the
restriction of $g$ to $p\mathbb Z\_p$ has image $g(0)+p\mathbb Z\_p$.


**Proof**


The proof is analoguous to that of Hensel's lemma.$\tag\*{$\blacksquare$}$


Now let $v\in\mathbb Z\_p$ for which $P'(v)=0$, and let
$n\_v\geq2$ be the largest integer such that $(x-v)^{n\_v}$
divides $P(x)-P(v)$. Let $Q\_v(x)\in\mathbb Z\_p[x]$ be the polynomial such that $P(x)=P(v)+(x-v)^{n\_v}Q\_v(x-v)$. Now $Q\_v(0)\neq0$.


**Lemma**
For all $v\in\mathbb Z\_p$ such that $P'(v)=0$, there is an integer $N\_v\in\mathbb N$ such that $$P(v+p^{N\_v}\mathbb Z\_p)=P(v)+p^{n\_vN\_v}Q\_v(0)f\_v(\mathbb Z\_p),$$ where $f\_v:\mathbb Z\_p\rightarrow\mathbb Z\_p$ is defined by $f\_v(z):=z^{n\_v}$.


**Proof**
Define the function $R:\mathbb Z\_p\rightarrow\mathbb Z\_p$ by $$R(x)=\sum\_{i=0}^{\infty}r\_ix^i:=\sum\_{i=0}^{\infty}p^{2i}n\_v^{i}\binom{\frac{1}{n\_v}}{i}x^i.$$ For all $i$, we have $v\_p(r\_i)=v\_p(p^{2i}n\_v^{i}\binom{\frac{1}{n\_v}}{i})\geq v\_p(p^{2i})-v\_p(i!)>i$, so all $r\_i$ are $p$-adic numbers and $\lim\_{i\rightarrow\infty}r\_i=0$. Therefore, $R(x)$ is well-defined.\
It follows from the definition of $R$ that $R(x)^{n\_v}=1+p^2n\_vx$ for all $x\in\mathbb Z\_p$. Now define the function $K:\mathbb Z\_p\rightarrow \mathbb Z\_p$ by $$K(x):=R\left(\frac{Q\_v(p^2n\_vQ\_v(0)x)-Q\_v(0)}{p^2n\_vQ\_v(0)}\right).$$ Then $K(x)=\sum\_{i=0}^{\infty}k\_ix^i$ for coefficients $k\_i\in\mathbb Z\_p$ with $\lim\_{i\rightarrow\infty}k\_i=0$.
It follows for all $x\in\mathbb Z\_p$ that $$Q\_v(0)K(x)^{n\_v}=Q\_v(0)\left(1+p^2n\_v\frac{Q\_v(p^2n\_vQ\_v(0)x)-Q\_v(0)}{p^2n\_vQ\_v(0)}\right)=Q\_v(p^2n\_vQ\_v(0)x).$$
Therefore, we see that \begin{align\*}P(v+p^2n\_vQ\_v(0)x)&=P(v)+(p^2n\_vQ\_v(0)x)^{n\_v}Q\_v(p^2n\_vQ\_v(0)x)\\
 &=P(v)+(p^2n\_vQ\_v(0)x)^{n\_v}Q\_v(0)K(x)^{n\_v}\\
 &=P(v)+Q\_v(0)(p^2n\_vQ\_v(0)xK(x))^{n\_v}\end{align\*}
for all $x\in\mathbb Z\_p$. Since $\frac{d(xK(x))}{dx}\big|\_{x=0}=K(0)=R(0)=r\_0=1$, we can use the previous lemma to see that the image of $xK(x)$ restricted to $p\mathbb Z\_p$ is $p\mathbb Z\_p$. Therefore, the image of $P$ restricted to $v+p^3n\_vQ\_v(0)\mathbb Z\_p$ is $P(v)+Q\_v(0)(p^3n\_vQ\_v(0))^{n\_v}f\_v(\mathbb Z\_p)$. So the lemma holds for $N\_v:=v\_p(p^3n\_vQ\_v(0))$.
$\tag\*{$\blacksquare$}$


**Lemma** For all $v\in\mathbb Z\_p$ such that $P'(v)=0$, there is a finite set $S\_v\subset\mathbb Z$ such that $$P(v+p^{N\_v}\mathbb Z\_p)=P(v)+p^{n\_vN\_v}Q\_v(0)\left(\{0\}\cup\left(\bigcup\_{s\in S\_v}\bigcup\_{i=0}^{\infty}p^{in\_v}(s+p^{2v\_p(n\_v)+1}\mathbb Z\_p)\right)\right).$$


**Proof**
Define $S\_v:=\{a^{n\_v}\mid 0<a<p^{v\_p(n\_v)+1},p\nmid a\}$. Then it follows from arguments similar to the proof of Hensel's lemma that for all $i\geq0$, the image of $f\_v$ restricted to $p^i\mathbb Z\_p\backslash p^{i+1}\mathbb Z\_p$ is equal to $p^{in\_v}\bigcup\_{s\in S\_v}(s+p^{2v\_p(n\_v)+1}\mathbb Z\_p)$. Taking the union over all $i$, we see that the image of $f\_v$ equals $\{0\}\cup\left(\bigcup\_{s\in S\_v}\bigcup\_{i=0}^{\infty}p^{in\_v}(s+p^{2v\_p(n\_v)+1}\mathbb Z\_p)\right)$. Therefore, this lemma follows from the previous lemma.
$\tag\*{$\blacksquare$}$


**Lemma**
For all $\sigma\in P(\mathbb Z\_p)$, there is an integer $M\_{\sigma}\geq0$ such that $$P(\mathbb Z\_p)\cap(\sigma+p^{M\_{\sigma}}\mathbb Z\_p)$$ has rational $p$-adic density.


**Proof**
First, suppose that there is an $x\in\mathbb Z\_p$ such that $P(x)=\sigma$ and $P'(x)\neq0$. Then it follows from arguments similar to Hensel's lemma that $P(\mathbb Z\_p)$ contains a neighbourhood of $\sigma$. This immediately proves the lemma.\
Now suppose that for all $x\in\mathbb Z\_p$ such that $P(x)=\sigma$, we have $P'(x)=0$. Let $V\_{\sigma}:=P^{-1}(\sigma)$, then $V\_{\sigma}$ is a finite set since $P$ is nonconstant. Since $P$ is continuous, we can choose $M\_{\sigma}\in\mathbb Z\_{\geq0}$ such that $P^{-1}(\sigma+p^{M\_{\sigma}}\mathbb Z\_p)$ is contained in $\bigcup\_{v\in V\_{\sigma}}(v+p^{N\_v}\mathbb Z\_p)$. Now it follows that $$P(\mathbb Z\_p)\cap(\sigma+p^{M\_{\sigma}}\mathbb Z\_p)=\bigcup\_{v\in V\_{\sigma}}P(v+p^{N\_v}\mathbb Z\_p)\cap(\sigma+p^{M\_{\sigma}}\mathbb Z\_p).$$
Using the previous lemma, we see that this set equals
$$\bigcup\_{v\in V\_{\sigma}}\left(\sigma+p^{n\_vN\_v}Q\_v(0)\left(\{0\}\cup\left(\bigcup\_{s\in S\_v}\bigcup\_{i=0}^{\infty}p^{in\_v}(s+p^{2v\_p(n\_v)+1}\mathbb Z\_p)\right)\right)\right)\cap(\sigma+p^{M\_{\sigma}}\mathbb Z\_p).$$
Let $n:=\mathrm{lcm}\_{v\in V\_{\sigma}}(n\_v)$. Then there exists an integer $C>0$ and a finite collection of numbers $a\_l\in \mathbb Z\_p\backslash p^{C}\mathbb Z\_p$, $1\leq l\leq L$, such that our set can be written as
$$P(\mathbb Z\_p)\cap (\sigma+p^{M\_{\sigma}}\mathbb Z\_p)=
\{\sigma\}\cup\bigcup\_{l=1}^{L}\left(\sigma+\bigcup\_{i=0}^{\infty}p^{in}(a\_l+p^{C}\mathbb Z\_p)\right).$$
The $p$-adic density of this set is $$\lvert\{a\_l\bmod p^{C}\mid 1\leq l\leq L\}\rvert\cdot \frac{p^n}{p^n-1}\cdot p^{-C}$$ which is a rational number.
$\tag\*{$\blacksquare$}$


**Theorem**
The $p$-adic density of $P(\mathbb Z\_p)$ is rational.


**Proof**
When we define $B\_{\sigma}:=\sigma+p^{M\_{\sigma}}\mathbb Z\_p$ for all $\sigma\in P(\mathbb Z\_p)$, then $\{B\_{\sigma}\mid \sigma\in P(\mathbb Z\_p)\}$ is an open cover of $P(\mathbb Z\_p)$. Since $\mathbb Z\_p$ is a compact set and $P$ is continuous, the image $P(\mathbb Z\_p)$ is also a compact set. Therefore, the open cover has a finite subcover $\{B\_{\sigma\_1},\dots,B\_{\sigma\_q}\}$ which is minimal. The sets in this subcover must be pairwise disjoint, so it follows that $P(\mathbb Z\_p)$ is the disjoint union of the sets $B\_{\sigma\_i}\cap P(\mathbb Z\_p)$ for $1\leq i\leq q$. Therefore, the $p$-adic density of $P(\mathbb Z\_p)$ is the sum of the densities of these sets. By the last lemma, all those densities are rational. Therefore their sum is also rational.$\tag\*{$\blacksquare$}$


