Given rational numbers $a\_1,\ldots, a\_k$ and $u\_0, \ldots, u\_k$, let $(u\_n)\_{n \geq k}$ be the linear recurrence defined by
$$u\_n := a\_1 u\_{n-1} + \cdots + a\_k u\_{n-k}, \text{ for } n \geq k .$$
Obviously, $u\_n \in \mathbb{Q}$ for any $n \geq 0$.


My question is: *Is there an effective way to decide if it is true that $u\_n \in \mathbb{Z}$ for all sufficiently large $n$ ?*



Are the terms of a linear recurrence integral?
The problem is effectively decidable. To test whether $u\_n$ is eventually integral, first use the recurrence relation for $u\_n$ to construct relatively prime polynomials $A,B\in \mathbb{Z}[x]$ such that the rational function $A/B$ has power series expansion $\sum\_nu\_nx^n$. (Here *relatively prime* will always mean no common factor in the ring $\mathbb{Z}[x]$ besides $\pm1$.) Then the following Lemma provides an effective test on $A$ and $B$ that determines whether or not $u\_n$ is eventually integral.


*Lemma*. Suppose that $A,B\in \mathbb{Z}[x]$ are relatively prime, and that $A/B$ has power series expansion $\sum\_{n\ge0}u\_nx^n$. Let $B=cC$, where $c$ is the gcd of the coefficients of $B$. Then the sequence $u\_n$ is eventually integral if and only if


1. $B(0)=\pm c$.
2. $A$ is an element of the ideal of $\mathbb{Z}[x]$ generated by $c$ and $C$.


*Proof of the Lemma*. The *if* direction: we assume that Conditions 1 and 2 hold, and prove that the sequence $u\_k$ is eventually integral.


By Condition 2, 
$$A=cD+CE,$$
for some choice of $D,E\in \mathbb{Z}[x].$
Dividing by $B$, and using $B=cC$, 
$$\tag{\*}\dfrac{A}{B}=\dfrac{D}{C}+\dfrac{E}{c}.$$
But Condition 1 implies that $C$ has the form $\pm(1-xC\_1)$, for some $C\_1\in \mathbb{Z}[x]$. Therefore $D/C$ has the form
$$\pm D(1+(xC\_1)+(xC\_1)^2+\ldots).$$
It follows that the power series for $D/C$ has all integral coefficients. Since $E/c$ is a polynomial with rational coefficients, it follows from ($\*$) that the power series $\sum u\_kx^k$ for $A/B$ eventually has integral coefficients.


The *only if* direction: We assume that the sequence $u\_k$ is eventually integral, and verify Conditions 1 and 2.


*Remark*. At this point it will be convenient to extend the usual notion of the *content* of a polynomial to power series $f=\sum\_nu\_nx^n$ with eventually integral coefficients. Define
$$\gamma(f)=\prod\_{p \text{ prime}}p^{\min\_n(v\_p(u\_n))},$$
where $v\_p(u\_n)$ is the exponent to which $p$ appears in the rational number $u\_n$. 
If $P\in \mathbb{Z}[x]$ then the product $Pf$ again has eventually integral coefficients, and it holds that $\gamma(Pf)=\gamma(P)\gamma(f)$. The proof is similar to the case of two polynomials. 


*Proof of Condition 1*. Since $A$ and $B$ are relatively prime, there are polynomials $U,V\in \mathbb{Z}[x]$ and an integer $m\ne0$ such that $AU+BV=m$. Let $f=\sum\_nu\_nx^n$ be the power series expansion of $A/B$. By factoring out $B$, write the equation $AU+BV=m$ in the form
$$\tag{\*\*}B(fU+V)=m.$$
Since $c=\gamma(B)$, the multiplicativity of the content function $\gamma$ implies that
$$c\gamma(fU+V)=m.$$
But ($\*\*$) implies that $B(0)t=m$, where $t$ is the constant term of $fU+V$. Therefore $B(0)t=c\gamma(fU+V)$, or equivalently
$$ \dfrac{B(0)}{c}\cdot \dfrac{t}{\gamma(fU+V)}=1.$$
Since the two factors are both integers, it follows that $B(0)=\pm c$. This proves Condition 1.


*Proof of Condition 2*. As before, let $f$ denote the power series for $A/B$. We note that the power series $cf$ has all integer coefficients. Indeed, taking the content of both sides of the equation $A=Bf$, we have $$\gamma(A)=c\gamma(f)=\gamma(cf).$$ The equation implies that $cf$ has integer content. Therefore all coefficients of $cf$ are integers.


It follows that $f$ has the form
$D/c+g$, for some $D\in \mathbb{Z}[x]$ and some power series $g$ with integer coefficients. Multiplying the equation $A/B=D/c+g$ by $B$ and using the definition $B=cC$, we conclude that
$$A=CD+c\cdot(Cg).$$ But $Cg$ is visibly a polynomial, being a difference of two polynomials. Therefore $A$ is an element of the ideal of $\mathbb{Z}[x]$ generated by $c$ and $C$. This completes the proof of the Lemma.


*Notes*.


1. For the connection between generating functions of recurrence sequences and rational functions, see Chapter 4 of Richard Stanley's book *Enumerative Combinatorics*, v1.
2. Concerning Condition 2 of the Lemma, an algorithm for ideal membership in the ring $\mathbb{Z}[x]$ is given in Chapter 10 of *Ideals Varieties and Algorithms* by Cox, Little and OShea. But anyway in this case we need only determine whether $C$ divides $A$ in the ring $\mathbb{Z}/c\mathbb{Z}[x]$.
3. The proof of Condition 1 in the *only if* part of the Lemma is substantially the same as in the solution to Exercise 2a in Chapter 4 of Stanley's book.
4. Condition 1 in the Lemma by itself is equivalent to the requirement that the $u\_n$ have bounded denominators, that is, that there is a nonzero integer $M$ such that for all $n$, $Mu\_n\in\mathbb{Z}$.


