TITLE: Does there exist a polynomial indicator function over $\mathbb{Z}_p[x_1,\dots,x_{p^3}]$ of degree at most $O(p^2)$?
QUESTION [5 upvotes]: The Problem
Let $p$ be a prime. Does there exist a $p^3$-variable polynomial $P$ over $\mathbb{Z}_p[x_1,\dots,x_{p^3}]$ such that

$P(\boldsymbol{0}) \equiv 0 \ (p)$
$P(\boldsymbol{x}) \equiv 1 \ (p)$ for any $\boldsymbol{x} \ne \boldsymbol{0}$.
$\deg{P} \in O{(p^2)}$ (its degree is at most some $2$-degree polynomial in $p$)

Meaning that $P$ is equivalent to the indicator function (or $1-$ the indicator function) over $\mathbb{Z}_p[x_1,\dots,x_{p^3}]$, and has degree of at most $O(p^2)$.
Fermat's Little Theorem
Due to Fermat's little theorem, for any prime $p$:
$$a^{p-1} \equiv \begin{cases}1 \quad \text{ if } a \not\equiv 0 \\ 0 \quad \text{ if } a\equiv 0\end{cases} \quad (p)$$
Trial and error
I have tried the following potential candidates, but they all fail in at least one of these aspects:
Trial 1:
$$P(\boldsymbol{x}) \stackrel{?}{=} \left(\sum_{i=1}^{p^3} x_i^{p-1}\right)^{p-1}$$

$P(\boldsymbol{0}) \equiv 0 \ (p) \quad \checkmark$
But if $\boldsymbol{x} = (\underbrace{1,\dots,1}_p,\underbrace{0,\dots,0}_{p^3-p})$, then

$$P(\boldsymbol{x}) = \left(\sum_{i=1}^{p} 1 + \sum_{i=p+1}^{p^3} 0 \right)^{p-1} = p^{p-1} \equiv 0^{p-1} \equiv 0 \quad (p)$$
So in this case, condition 2 fails to hold.
Trial 2:
$$P(\boldsymbol{x}) \stackrel{?}{=} 1-\prod_{i=1}^{p^3} (1-x_i)^{p-1}$$

Clearly holds in this case. $\quad \checkmark$

Also holds, $P(\boldsymbol{x}) = 1$ exactly if none of the $x_i$'s are $0$, a.k.a., if $\boldsymbol{x} \ne \boldsymbol{0}$. $\quad \checkmark$

However Condition 3 fails here. The polynomial's degree is $p^3(p-1) = O(p^4)$.


Trial 3:
$$P(\boldsymbol{x}) \stackrel{?}{=} \left(\sum_{\begin{matrix}I \subseteq \{1,\dots,p^3\} \\ |I| = kp \\ k \in \{1,\dots,p^2\}\end{matrix}} \left( \sum_{i\in I} x_i^{p-1}  \right)^{p-1}\right)^{p-1} + \left(\sum_{i=1}^{p^3} x_i^{p-1}\right)^{p-1}$$

$P(\boldsymbol{0}) \equiv 0 \ (p) \quad \checkmark$
$P(\boldsymbol{x}) \equiv 1  \ (p)$  also holds here. The right term is the exact same as the entire polynomial in Trial 1; and the left term equals $1$ for exactly the $\boldsymbol{x}^{p-1}$'s where number of $1$'s it contains is divisible by $p$. $\quad \checkmark$
However $\deg{P} = (p-1)^3 \in O(p^3)$. (But, we're getting closer. The last example was $O(p^4)$.)

Note:
$$P(\boldsymbol{x}) \stackrel{?}{=} 1-I(\boldsymbol{x} = 0)$$
where $I$ is the real indicator function.
However, $P$ needs to be a polynomial, so I can't just use the "regular" indicator function.
Context
I am trying to prove a theorem using the Chevalley-Warning theorem, which requires certain conditions for the degrees polynomials. The main issue is actually to construct such a polynomial, and once that's done, the theorem would basically "prove itself". However, it is possible, that such a polynomial doesn't exist.

REPLY [5 votes]: Since you bring up Chevalley-Warning how about the following counting argument. Here $V$ stands for the vector space $\Bbb{Z}_p^n$. In your case $n=p^3$ but the argument can be made more generally.
Observation. Consider the monomial $f(x_1,\ldots,x_n)=\prod_{i=1}^nx_i^{a_i}$ where $0\le a_i<p$ for $i$. Unless $a_i=p-1$ for all $i$, we have
$$\sum_{\mathbf{x}\in V}f(\mathbf{x})=0\in\Bbb{Z}_p.$$
Proof. Assume that for some index $i_0$ we have $m:=a_{i_0}<p-1$. If $m=0$ then the sum $\sum_{x\in\Bbb{Z}_p}x^m=p\cdot 1=0$. Otherwise there exists an element $a\in \Bbb{Z}_p\setminus\{0\}$ such that $a^m\neq1$ (the polynomial $x^m-1$ can have at most $m$ zeros in the field $\Bbb{Z}_p$). But $x$ ranges over the field $\Bbb{Z}_p$ as $ax$ does, so the monomial sum
$$
S=\sum_{x\in\Bbb{Z}_p}x^m=\sum_{x\in\Bbb{Z}_p}(ax)^m=a^mS
$$
implying that $S=0$. The claim follows from this because
$$
\sum_{\mathbf{x}\in V}f(\mathbf{x})=\prod_{i=1}^n\left(\sum_{x\in\Bbb{Z}_p}x^{a_i}\right)
$$
and if any $a_i<p-1$ then the corresponding factor vanishes and hence the entire sum.
The impossibility of your task follows from this. We can reduce the degree of any polynomial in $\Bbb{Z}_p[x_1,\ldots,x_n]$ by replacing any instance of $x_i^p$ with $x_i$ with the consequence that all the terms of your polynomial $P$ satisfy the constraints in the observation. A corollary of the observation is that the sum of the values of the polynomial $P$ over $V$ is zero unless the term $(x_1\cdots x_n)^{p-1}$ appears. For your indicator function the sum of its values is $-1\in\Bbb{Z}_p$. Hence it must have degree at least $n(p-1)=p^3(p-1)$.

When written as a polynomial, the characteristic function of a subset $S\subset V$ (after substituting $x_i^p$ and highe with lower degree equivalents) contains the term $(x_1\cdots x_n)^{p-1}$ unless the number of elements of $S$ is a multiple of $p$. In other words, the degree of the polynomial is then equal to $n(p-1)$.


The OP's attempt, trial #3, fails to work as hoped. If all the entries of the vector $\mathbf{x}$ are non-zero, then each sum
$$\sum_{i\in I}x_i^{p-1}=\sum_{i\in I, x_i\neq0}1=|I|\cdot1,$$
where $p\mid |I|$, automatically vanishes, as does the entire sum. Trial #2 is the only one that works, and it has degree $n(p-1)=p^3(p-1)$ as described by the observation and its corollary.