On polynomials over finite ring Let $R$ be a finite commutative ring with unity ; then does there exist a non-empty proper subset $A \subseteq R$ and $f(X) \in R[X]$ such that $f(r)=1 , \forall r \in A$ and $f(r)=0 , \forall r \notin A$ ?
 A: So effectively, you're asking this question:


*

*$\;$Given a finite ring $R$, is there always some polynomial $f \in R[x]$ such that $f(R)=\{0,1\}$?


For a counterexample, take $R = Z_6$, and suppose $f \in R[x]$ is such that $f(R)=\{0,1\}$.

Suppose $f(a) = 1$ and $f(b) = 0$.

Let $r \in R$.

If $r$ has the same parity as $a$, then $f(r)$ has the same parity as $f(a)$, hence $f(r)=1$.

Similarly, if $r$ has the same parity as $b$, then $f(r)$ has the same parity as $f(b)$, hence $f(r)=0$.

It follows that either 
$$f(0) = f(2) = f(4) = 1\;\;\text{and}\;\;f(1) = f(3) = f(5) = 0$$
$$\text{or}$$
$$f(0) = f(2) = f(4) = 0\;\;\text{and}\;\;f(1) = f(3) = f(5) = 1$$
But then we have a contradiction, since $f(0)$ must be congruent to $f(3),\;$mod $3$.  
A: Such an $f$ exists iff $R$ is local.
First, suppose $R$ is local.  Since $R$ is finite, its unique maximal ideal is the nilradical, so every element of $R$ is either nilpotent or a unit.  There is then some $n$ such that $r^n=0$ for every nilpotent $n$ and $r^n=1$ for every unit $r$.  You can then take $f(X)=X^n$.
Now suppose $R$ is not local.  Equivalently, this means either $R$ is the zero ring (in which case $R$ has no nonempty proper subsets) or $R$ is isomorphic to a direct product $S\times T$ of two nontrivial rings $S$ and $T$.  Then given any $f\in R[X]$, consider its images $f_S\in S[X]$ and $f_T\in T[X]$.  Note that the set of values which $f$ takes is the product of the set of values $f_S$ takes and the set of values $f_T$ takes.  So the set of values $f$ takes must be a "rectangle" in the product $S\times T$.  But since $S$ and $T$ both have more than one element, the set $\{0,1\}=\{(0,0),(1,1)\}\subset R$ is not a rectangle, so it cannot be the set of values taken by any polynomial.
