Let $p$ be a prime number and let $a_i$ be a sequence of natural numbers such that the series $\sum_{i=1}^\infty p^{a_i} x^i$ is rational. A warm-up question:

Question 1.Does it follow that the series $\sum_{i=1}^\infty a_i x^i$ is rational?

Let $p$ be a prime number and let $L$ be a regular language. Let $a\colon L\to \mathbb N$ be a function such that the series $$ \sum_{w\in L} p^{a(w)}x^{|w|} $$ is rational.

Queston 2.Does it follow that the series $\sum_{w\in L} a(w) x^{|w|}$ is rational?

# Motivation

Let $L$ be a regular language and let $T=T_w$, $w\in L$, be a family of finite dimensional matrices with integral coefficients. Consider the series $$ F(T,p)(x) := \sum_{w\in L} \dim_{\mathbb F_p}\ker_{\mathbb F_p} T_w \cdot x^{|w|}, $$ and the series $$ G(T,p)(x) := \sum_{w\in L} |\ker_{\mathbb F_p} T_w| \cdot x^{|w|}, $$ where $|\ker_{\mathbb F_p} T_w|$ is the number of elements in $\ker_{\mathbb F_p} T_w$. The relation between $G$ and $F$ is as in the questions above. In my specific situation the series $G$ is rational, roughly because the elements of $\ker_{\mathbb F_p} T_w$ also form a regular language. I would like to know that the series $F$ is rational because $F(T,p)(\frac{1}{2})$ is a so called $l^2$-Betti number over $\mathbb F_p$ and it would be very nice to know that these are rational in the case at hand.

# Remarks

In the key example I have (section 2-C is the relevant one) the series $$ F(T)(x) := \sum_{w\in L} \dim_{\mathbb C}\ker_{\mathbb C} T_w \cdot x^{|w|} $$ is transcendental, but all the series $F(T,p)$ are rational, because $a(w)$ are bounded, and in this case the answer to Question 2 is, as explained by Dylan below, positive. Reason for transcendality over complex numbers is that the family of vectors which make it transcendental have rapidly growing coefficients, and so no single prime number can detect this family. Questions above can be informally seen as asking whether "unboundedness of elements in the kernels" can also be a reason for the series not being rational.