Homologue of integer valued polynomials over unique factorization domains I am seeking for a non trivial homologue of an integer valued polynomial over a unique factorization domain, other than $\mathbb Z$.
More precisely, I ask for a unique factorization domain $R\not= \mathbb Z$, with quotient field $K$, and a polynomial $P$ belonging to $K[X] - R[X]$ such that $P(R)\subseteq R$. If possible, examples in both null and positive characteristics will be welcome.
Note: Here is what I've obtained. Assume that $p$ is a prime, and let $R$ be the localization of $\mathbb Z$ at $p$. The "modulo p" homomorphism $\mathbb Z \to \mathbb Z/p$ extends canonically $R\to \mathbb Z/p$. Let $P = {1\over p}(X^p - X)$. Since $m^p - m = 0 \mod p$ for every $m\in R$, $P(m) \in R$ for every $m\in R$.
Still, I'm not very satisfied with this example because it is too close to the case $R = \mathbb Z$.
 A: One example are the Gaussian integers $R=\mathbb{Z}[i]$ with $P(x)=\frac{1+i}{2}(x^2+x) \in \mathbb{Q(i)}[x]$. Clearly $P(x)\not\in \mathbb{Z}[i][x]$, and for $z=a+bi \in \mathbb{Z}[i]$ you can verify that
$$P(z)=(T(a)-T(b))(1+i)-ab(1-i)+bi \in \mathbb{Z}[i]$$
where $T(k)=k(k+1)/2\in \mathbb{Z}$, hence $P(R)\subseteq R$.
A: Converting my comment into an answer, as requested. I'm assuming you are familiar wih the theory of finitely generated abelian groups.
I. First set of examples.
Lemma. Let $R$ be an integral domain which is finitely generated as an additive abelian group. Then for all $a\in R, a\neq 0$, the quotient ring $R/(a)$ is finite.
Proof. $R$ is in fact a free abelian group: it is finitely generated and has no $\mathbb{Z}$-torsion since $R$ is an integral domain. If $(e_1,\ldots,e_n)$ is a $\mathbb{Z}$-basis of $R$, $(ae_1,\ldots,ae_n)$ is a $\mathbb{Z}$-basis of $aR$ (again because $R$ is an integral somain). Hence, $R/aR$ is the quotient of two free abelian groups of same rank, hence is finite.
Examples. Take a PID $R$ which is finitely generated as an abelian group. Take $\pi$ be a prime element. Then $\pi R$ is maximal, since $R$ is a PID. Hence $R/\pi R$ is a field, which is finite by the previous lemma.
If $q$ is the number of elements of $R/\pi R$, set $P=\dfrac{1}{\pi}(X^q-X)$. Then $P(R)\subset R$.
Concrete examples of such $R$: any ring of integers of a number field which is a PID, such as $\mathbb{Z}[i],\mathbb{Z}[j],\mathbb{Z}[i\sqrt{2}],\mathbb{Z}[\sqrt{2}],\mathbb{Z}[\dfrac{-1+i\sqrt{19}}{2}],\mathbb{Z}[\zeta_p], p<23,\mathbb{Z}[\sqrt[3]{2}]$...
II. Second set of examples. Take $R=\mathbb{F}_q[T]$, take $\pi\in R$ an irreducible polynomial of degree $d$. Then $R/(\pi)$ is a finite field with $q^d$ elements. Set $P=\dfrac{1}{\pi}(X^{q^d}-X)$.
