Let $M$ be a finitely presented module over the ring $R$. Suppose that for all primes $P\subset R$ the $k(P)$ vector space $M\otimes _Rk(P)$ has a dimension $d(P)$ independent of $P$.
Can I conclude that $M$ is flat over $R$?
I am asking because I want to better understand the criterion for a family of projective schemes to be flat over some base in terms of invariance of their Hilbert polynomial.
I checked some examples.
For example let $M$ be the ideal of a point $P$ of an affine curve $C$.
Here $d(P)$ is the dimension of the Zariski tangent space of $C$at $P$ so that the proposed criterion for flatness holds.

2$\begingroup$ In general equidimensionality of the fibres is necessary, but not sufficient in order to guarantee flatness. However, it is also sufficient when $R$ is regular of dimension $1$, or when $R$ is regular of arbitrary dimension and $M$ is CohenMacaulay. See S. Kovacs' answer to the following MO question: mathoverflow.net/questions/75317/… $\endgroup$ – Francesco Polizzi Jan 14 '17 at 9:59

1$\begingroup$ Ah, sorry, I slightly misread the question. You are asking about flatness of a (finitely presented) module over the ring $R$, so in geometric terms you want to know about the flatness of a coherent sheaf over an affine scheme (and not about the flatness of a morphism of schemes). Then the correct answer is given by abx in his comment: in the case where the fibres are of constant dimension, flatness occurs whenever $R$ is without nilpotents. $\endgroup$ – Francesco Polizzi Jan 14 '17 at 10:22
Yes if $R$ is reduced (no nilpotent elements). This is (for instance) Lemma 1 p. 51 in Mumford's Abelian Varieties (2nd edition). No in general: just take $R=k[\varepsilon ]/(\varepsilon ^2)$, $M=k$.

$\begingroup$ Thanks a lot abx: perfect answer! Strangely I can accept your answer but not upvote you. Anyway, in my eyes your real reputation is huge since long ago! $\endgroup$ – gregorsamsa Jan 14 '17 at 10:34