# Polynomial detecting congruence conditions

It is well-known that a prime number $p$ is $\equiv 1 \pmod 4$ iff $p=x^2+y^2$ for some integers $x,y$ (except for $p=2$). My question is: is there an irreducible homogeneous polynomial $f \in \Bbb Z[x_1, ..., x_n]$ of total degree $>1$, such that $p \equiv 3 \pmod 4$ iff $p \in \mathrm{Im}(f)$ (up to finitely many exceptions) ? I saw this question, but this is also the condition $p \mid f(y)$ for some $y \in \Bbb Z^n$ (and not $p=f(y)$ as I want).

More generally, given $M \geq 1$ and $S \subset \Bbb Z/M\Bbb Z$, when is there $n \geq 1$ and an irreducible homogeneous polynomial $f \in \Bbb Z[x_1, ..., x_n]$ of total degree $>1$, such that a prime $p$ is in the image of $f$ iff $[p]_M \in S$, up to finitely many exceptions?

• @JyrkiLahtonen : if $p = 3 \pmod 4$, then $w := p-2 = 1 \pmod 4$, but $w$ might not be prime, so we can't deduce that $w=x^2+y^2$ for some $x,y$ (it depends on the various $\ell$-adic valuations of $w$…) – Alphonse Jun 7 '18 at 9:24
• Anyway, I think that in the case of binary quadratic forms this question is well understood. Many cite Cox's book. IIRC the forms sharing the same discriminant cover primes in different residue classes modulo the discriminant, but they do not cover all the coprime residue classes. As you observec, the discriminant $\Delta=4$ is a case in point. Algebraic number theory (and class field theory) give answers as to which residue classes are covered. If Will Jagy (or somebody else in the know) shows up... – Jyrki Lahtonen Jun 8 '18 at 9:28
• With higher degree forms - it's complicated. Non-abelian class field theory won't spew out residue classes (but I don't know the details). From cyclotomic extensions we may get something more, but a prime is presented by the norm polynomial iff it splits completely, when it will also split in the quadratic intermediate field... Sorry, entering a territory where I may unwittingly give misinformation :-( – Jyrki Lahtonen Jun 8 '18 at 9:35
• @Mastrem, yes, that is indeed correct, so now the OP has changed the question to add a requirement on the degree. I'll offer the polynomial $(4x_1 + 3)(x^2_2 + x^2_3 + x^2_4 + x^2_5)$ so the OP can change the question again. – Infinity Jun 8 '18 at 19:23
• Oh, and $4(x^2_1 + x^2_2 + x^2_3 + x^2_4) + 3$. – Infinity Jun 9 '18 at 0:34