Flat module and torsion-free module All rings in this question are integral.
It is known that flat modules are torsion-free. Conversely, torsion-free modules over Prüfer domain (in particular, Dedekind domain) are flat, please see here. My questions are:


*

*Is there a general condition under which a torsion free module is flat?



*

*What is the simplest example of torsion-free non-flat module?

Edit: Since the example in Georges's answer is the coordinate ring of a singular curve, I want to ask the same questions for the coordinate ring $R$ of a smooth algebraic variety:


*

*Is there a general condition under which a torsion free module over $R$ is flat?

*What is the simplest example of torsion-free non-flat module over $R$?


 A: Here is an answer to the extra question regarding regular rings:
A finitely generated module is flat if and only if it is locally free, so for finitely generated modules your question translates to:

Q1 When is a torsion-free module/sheaf locally free?

and 

Q2 What is a simple example of a torsion-free (say coherent) sheaf on a smooth algebraic variety that is not locally free?

So, first of all, the locus where a torsion-free coherent sheaf on a smooth algebraic variety fails to be locally free is at least of codimension $2$, in particular we have the following partial answer to Q1:

A 1.1 Any torsion-free coherent sheaf on a smooth algebraic curve is locally free. 

This is not true in higher dimensions and you can find a counter example on any smooth algebraic variety of dimension at least $2$: 

A 2 Let $X$ be a smooth algebraic variety of dimension at least $2$ (e.g., $\mathbb A^2$) and let $\mathcal F=\mathfrak m_x\subset \mathcal O_X$ the (maximal) ideal of a closed point $x\in X$. Then $\mathcal F$ is not flat. (This should qualify as the simplest example possible with the requirement of $X$ being smooth given A1 above).

Proof of A 2 This ideal is isomorphic to $\mathcal O_X$ on the open set $X\setminus\{x\}$, but cannot be generated with less number of elements than the dimension of the local ring $\dim \mathcal O_{X,x}\geq 2$, so it cannot be locally free.
On a surface you have to do a little better to get local freeness:
The locus where a reflexive sheaf is not locally free is at least of codimension $3$, so 

A 1.2 Any reflexive sheaf on a smooth algebraic surface is locally free.

Being reflexive is equivalent to torsion-free and $S_2$. See more on $S_2$ in this answer.
A: If the question is only for commutative domains, then yes, torsion-free=flat iff it is Pruefer (see e.g. Fuchs/Salce, Thm. VI.9.10, actually due to Warfield), as was mentioned earlier. If not only domains are in question, then it can be said that Warfield showed that it is true whenever the ring's localizations at maximal ideals are valuation rings (let's call them Pruefer rings). I haven't checked if those are the only commutative rings for which this is true. If one leaves the realm of commutative rings, there is a much bigger class, so-called RD-rings, for which it is true. These are the rings for which Relative Divisibility is the same as purity (just as over the integers). An example is the first Weyl algebra over any field of char 0 (this is even a domain, though not commutative, so possibly not of interest to the poser of the question).
A: Dear liu,
1) If $A$ is a domain in which every finitely generated ideal is principal, then a module over $A$ is flat iff it is torsion free (Bourbaki, Comm.Alg.,I,§2, 4, Prop.3). Of course a PID has this property, but  the ring $\mathcal O(U)$ of holomorphic functions over  a connected open subset  $U\subset \mathbb C$ also has it, although it is not a PID.[Ah, I have just checked the definition of Prüfer and it seems that these rings are actually Prüfer, so you knew this. I'll leave this class of examples for the benefit of those who, like me, don't know the concept "Prüfer ring".]
2) A simple example of torsion free non flat module $E$ over a ring $A$ is $A=\mathbb C [t^2, t^3] \subset E=\mathbb C [t]$. This corresponds to the normalization of the cusp $S=Spec (\mathbb C[X,Y]/(Y^2-X^3))$ i.e. to the morphism $f: \mathbb A ^1 \to S \subset \mathbb A ^2$ given by $x=t^2, y=t^3$. Non-flatness is due to the fact that the fiber of $f$ at the origin is a double point on $\mathbb A ^1$ (supported at the origin) whereas the other fibers are simple points. This is a tiny particular case of the constancy of Hilbert polynomials in flat families. Of course there are direct proofs by pure algebra, but I hope you like geometry...
The end of Mumford's red book Here is a vast generalization of 2). Consider a locally noetherian integral scheme. If the scheme is not normal, its normalization is never flat over it.This is essentially proved in Matsumura's Commutative Ring Theory, Corollary to Theorem 23.9. (So if you are arithmetically inclined, $\mathbb Z[2i] \subset \mathbb Z[i]$  is a non flat algebra) . It is very easy to find a (slightly different) statement in the literature: the one and a half last lines of Mumford's Red Book !
Edit: I'm happy to report that I just located non-flatness of normalization in our friend Qing Liu's book Algebraic Geometry and Arithmetic Curves : 4.3.1. Example 3.5, page 136.
A: This is exactly the sort of basic question that I wish were asked more often.
The short answer is that a "typical" ideal in an integral domain $R$ is torsionfree but not flat.
First observe that if $R$ is a domain, then any ideal $I$ of $R$ is a submodule of the torsionfree $R$-module $R$ and is thus torsionfree.
Next, as Theo Buehler comments in Georges' answer, there is a precise criterion on $R$ for every torsionfree $R$-module to be flat: namely, that $R$ is a Prufer domain, i.e., every finitely generated ideal of $R$ is invertible.
For simplicity, let me restrict attention to Noetherian domains $R$..  (Later on I may come back and add more in the general case.)  Let $\mathfrak{p}$ be a prime ideal of height greater
than one.  (So such ideals exist iff $R$ itself has Krull dimension greater than one, e.g.
$k[x,y]$.)  As above, $\mathfrak{p}$ is a torsionfree $R$-module.  If $\mathfrak{p}$ were flat,
then since it is finitely generated it would be projective, or equivalently locally principal.  But localizing at $\mathfrak{p}$ and applying Krull's Principal Ideal Theorem we
get a contradiction.
Similarly, if $R$ is a one-dimensional Noetherian domain which is not a Dedekind domain, then it admits a non-invertible ideal, which is therefore a torsionfree nonflat module.  For instance if $R = \mathbb{Z}[\sqrt{-3}]$, then $\mathfrak{p} = \langle 1 + \sqrt{-3}, 1 - \sqrt{-3} \rangle$ is not locally principal.  See e.g. Section 3 of these notes for more details.
A: The stacks project gives an important class of (in general not Noetherian) rings over which every torsion-free module is flat: valuation rings. See Lemma 15.22.10. (Sorry, I don't know how to quote it by 'tags'.)
