Testing for primality in $\mathbb{Z}[\sqrt{-1}]$ in Mathematica is easy:
PrimeQ[n, GaussianIntegers -> True]
But how can I test for primality in, say, $\mathbb{Z}[\sqrt{-7}]$? I'm interested in a large number of quadratic rings, not just that one.
I'll try to be more specific in case it helps. Of course much of the work is exploratory but some things remain roughly constant. $n$, the number to be tested for primality, is roughly 10 digits long. $d$ is almost always from 13 to 50, and in any case not more than a thousand.
I tried to express the problem $$ p=(a+b\sqrt{-d})(c+e\sqrt{-d}) $$ as a Diophantine equation to use Mathematica's general solving tools, but they seem to not be up to the task. Using
f[d_, p_] := FindInstance[a c - b d e == p && a e + b c == 0 && a^2 + b^2 > 1, {a, b, c, e}, Integers]
I get
FindInstance::nsmet: The methods available to FindInstance are insufficient to find the requested instances or prove they do not exist
If I use
f[d_, p_] := Resolve[Exists[{a, b, c, e}, a c - b d e == p && a e + b c == 0 && a^2 + b^2 > 1], Integers]
the program runs forever (or at least more than half an hour; the analogous calculation on PARI/GP takes about 2 milliseconds). Finally
f[d_, p_] := FullSimplify[Reduce[{a c - b d e == p, a e + b c == 0, a^2 + b^2 > 1}, {a, b, c, e}, Integers]]
returns the result unsimplified.
Reduce[]to solve a Pell equation, for starters... – J. M.♦ Nov 1 '12 at 17:45Prime(because $2=a^2+5b^2$ has no solution) orNotPrime(because the ideal $(2)$ in the ring $\mathbb{Z}[\sqrt{-5}]$ is not prime). – David Speyer Feb 15 at 14:42