Let $R$ be a Dedekind ring, let $S = \mathrm{Spec} R$, and let us suppose that $f: X \to S$ is a finite morphism. Note that $X$ is not required to be connected. Does there exist a "numerical criterion" that will produce a closed subscheme $S_0 \subset S$ such that $f$ is flat when restricted to $f^{-1}(S - S_0)$?
For example, let
Consider the following non-example: Let $F \in \mathbb{Z}[T]$ be a non-constant monic polynomialwith trivial content. Set , and set \[
X = \mathrm{Spec} \mathbb{Z}[T] / (F(T)), \qquad f: X \to \mathrm{Spec} \mathbb{Z}.
\]
Then
The structure morphism $f \ $ fails to be flat above any prime $p$ dividing the leading coefficient of $F$. This is what I mean by a numerical criterion for flatness: the (ideal generated by the) leading coefficient contains all of the information necessary to detect non-flatness. But I don't see how one might generalize it to a setting in which $X$ is defined by several equations in several variables. (In the application I have in mind, $ X$ is a finite group scheme cut out by a huge number of equations in three variables.)
Extending the previous example, suppose that $F \ $ is monic so that $X$ is and flatover $\mathrm{Spec} \mathbb{Z}$. . A prime $p$ occurs as a factor of the discriminant $\Delta(F)$ if and only if the fiber of $f$ over $p$ contains a non-smooth point. So the discriminant can be viewed as a numerical criterion for detecting (non-)smoothness. All of the data needed to determine smoothness is contained in the discriminant. Does there exist a similar one-step gadget for detecting (non-)flatness? (I say "one-step" to mean that the vanishing of infinitely many Tor groups is not an adequate solution. Is there a single Tor group that captures what I'm after?)

