Suppose that I am given a subscheme $Y$ of $\mathbf{P}^n\_{\mathbf{Z}}$, flat over $\operatorname{Spec}\mathbf{Z}$ and with smooth generic fiber $Y\_{\mathbf{Q}}$, defined by the vanishing of some homogeneous polynomials
$$
F\_1, \ldots, F\_k \in \mathbf{Z}[X\_0,\ldots,X\_n].
$$
How does one determine the set $S$ consisting of primes $p$ such that the fiber $Y\_{\mathbf{F}\_p}$ is non-smooth? 


The way I'm going about the problem seems a bit crude to me, and has some problems. In particular, I can't prove that my algorithm solves the problem.


For simplicity suppose that $k=1$, and write $F=F\_1$. In a nutshell, I compute the derivatives $f\_i := \frac{\partial F}{\partial X\_i}$, and determine an integer $N$ such that $N$ is contained in the ideal $I = (F, f\_1, \ldots, f\_n) \subset \mathbf{Z}[X\_0,\ldots,X\_n]$ by repeatedly taking resultants of polynomials in $I$. Then at least for all $p$ not dividing $N$, the fiber $Y\_{\mathbf{F}\_p}$ is smooth, since for such $p$ the ideal $I\_p \subset \mathbf{F}\_p[X\_0,\ldots,X\_n]$ generated by the reduced polynomials $\widetilde{F}$, $\widetilde{f}\_1$,$\ldots$,$\widetilde{f}\_n$ contains $1$.


One problem is that it's quite expensive computationally. I'm using resultants to eliminate the variables $X\_i$ one by one, say in the order $i=0,1,\ldots,n$. Then every time I've eliminated one of the $X\_i$s, I get a lot of polynomials that don't contain $X\_0$ up to $X\_i$, and I take them *all* into the next elimination round. (You have to be careful when the resultant comes out $0$, and perhaps there are some other subtleties that I'm forgetting, but this is basically it.) 
Another problem with this is that the final outcome seems to depend on the order in which I take the $i$s. (This may have something to do with singularities being located at infinity with respect to one of the $X\_i$s [**edit:** on second thought, this doesn't make any sense; see comment by François], but I really can't see the geometry of what I'm doing clearly enough to be confident about this.) And I don't see why my method necessarily gives me the whole $S$ - instead of some upper bound on it - even when *all* orderings of the $X\_i$ are taken into account. 


My questions: 


1. Does my method give the whole set $S$?
2. If yes, why? If no, what method does work?
3. Regardless of the answers to 1. and 2., is there a faster or more natural way of finding the primes of bad reduction?



How do you compute the primes of bad reduction?
Assume for simplicity that $Y$ has pure relative dimension $d$. By considering the standard affine cover of $\mathbf{P}^n\_{\mathbf{Z}}$, one easily reduces to the case where $Y=V(F\_1,\ldots,F\_k)$ is a closed subscheme of $\mathbf{A}^n\_{\mathbf{Z}}$. Then the special fiber $Y\_p = V(F\_{1,p},\ldots,F\_{k,p}) \subset \mathbf{A}^n\_{\mathbf{F}\_p}$ is smooth if and only if for every $x \in Y\_p(\overline{\mathbf{F}}\_p)$, the Jacobian matrix $(\frac{\partial F\_{i,p}}{\partial X\_j}(x))$ has rank $n-d$. Note that $Y\_p$ is $d$-dimensional by the flatness assumption, so all geometric tangent spaces have dimension $\geq d$, which implies that the rank of the Jacobian matrix is everywhere $\leq n-d$. Thus $Y\_p$ is smooth if and only if the ideal generated by $F\_{1,p},\ldots,F\_{k,p}$ together with all $(n-d)$-minors of the Jacobian matrix is equal to $\mathbf{F}\_p[X\_1,\ldots,X\_n]$.


Now consider the ideal $I$ of $R=\mathbf{Z}[X\_1,\ldots,X\_n]$ generated by $F\_1,\ldots,F\_k$ together with all $(n-d)$-minors of the Jacobian matrix. Since the generic fiber of $Y$ is smooth, we have $I \cap \mathbf{Z}=N\mathbf{Z}$ for some integer $N \geq 1$, and the prime factors of $N$ are precisely the primes of bad reduction of $Y$.


Proof. If $p$ doesn't divide $N$ then $(I,p)$ contains $N$ and $p$, so $(I,p)=R$ and $Y\_p$ is smooth. If $p$ divides $N$, write $N=p^k M$ with $p$ not dividing $M$. If we had $(I,p)=R$, then we would also have $(I,p^k)=R$. Then $M \in (MI,p^k M)=(MI,N) \subset I$, a contradiction. Thus $Y\_p$ is not smooth.


You can compute the integer $N$ using Gröbner bases for polynomials over $\mathbf{Z}$, see e.g. <http://magma.maths.usyd.edu.au/magma/handbook/text/1112#12189> for the Magma implementation. I'm not expert in Gröbner bases, so I would appreciate if someone could confirm whether it is always possible to find $I \cap \mathbf{Z}$ when a set of generators of $I$ is given, and whether the Magma implementation works in all cases.


