hcju/stacksqa huggingface dataset:
By replacing $R$ with $R/(I_1 \cap I_2)$ and $M$ by $M/(I_1 \cap I_2)M$ we may assume that $I_1 \cap I_2 = 0$. Let $J \subset R$ be an ideal. To prove that $M$ is flat over $R$ we have to show that $J \otimes_R M \to M$ is injective, see Algebra, Lemma \ref{algebra-lemma-flat}. By flatness of $M/I_1M$ over $R/I_1$ the map $$ J/(J \cap I_1) \otimes_R M = (J + I_1)/I_1 \otimes_{R/I_1} M/I_1M \longrightarrow M/I_1M $$ is injective. As $0 \to (J \cap I_1) \to J \to J/(J \cap I_1) \to 0$ is exact we obtain a diagram $$ \xymatrix{ (J \cap I_1) \otimes_R M \ar[r] \ar[d] & J \otimes_R M \ar[r] \ar[d] & J/(J \cap I_1) \otimes_R M \ar[r] \ar[d] & 0 \\ M \ar@{=}[r] & M \ar[r] & M/I_1M } $$ hence it suffices to show that $(J \cap I_1) \otimes_R M \to M$ is injective. Since $I_1 \cap I_2 = 0$ the ideal $J \cap I_1$ maps isomorphically to an ideal $J' \subset R/I_2$ and we see that $(J \cap I_1) \otimes_R M = J' \otimes_{R/I_2} M/I_2M$. By flatness of $M/I_2M$ over $R/I_2$ the map $J' \otimes_{R/I_2} M/I_2M \to M/I_2M$ is injective, which clearly implies that $(J \cap I_1) \otimes_R M \to M$ is injective.
Note that $I$ exists by Lemma \ref{lemma-flattening-artinian}. The implication $\Rightarrow$ follows from Algebra, Lemma \ref{algebra-lemma-flat-base-change}. Let $\varphi : R \to R'$ be such that $M \otimes_R R'$ is flat over $R'$. Let $J = \Ker(\varphi)$. By Algebra, Lemma \ref{algebra-lemma-descent-flatness-injective-map-artinian-rings} and as $R' \otimes_R M = R' \otimes_{R/J} M/JM$ is flat over $R'$ we conclude that $M/JM$ is flat over $R/J$. Hence $I \subset J$ as desired.
Assume (\ref{equation-flat-at-primes-over}) holds for $(R \to S, I \subset R, M)$. Let $I'(S \otimes_R R') \subset \mathfrak q'$ be a prime of $S \otimes_R R'$. Let $\mathfrak q \subset S$ be the corresponding prime of $S$. Then $IS \subset \mathfrak q$. Note that $(M \otimes_R R')_{\mathfrak q'}$ is a localization of the base change $M_{\mathfrak q} \otimes_R R'$. Hence $(M \otimes_R R')_{\mathfrak q'}$ is flat over $R'$ as a localization of a flat module, see Algebra, Lemmas \ref{algebra-lemma-flat-base-change} and \ref{algebra-lemma-flat-localization}.
Assume (\ref{equation-flat-at-primes-over}) holds for $(R' \to S \otimes_R R', IR', M \otimes_R R')$. Pick a prime $IS \subset \mathfrak q \subset S$. Let $I \subset \mathfrak p \subset R$ be the corresponding prime of $R$. By assumption there exists a prime $\mathfrak p' \in V(I')$ of $R'$ lying over $\mathfrak p$ and $R_{\mathfrak p} \to R'_{\mathfrak p'}$ is flat. Choose a prime $\overline{\mathfrak q}' \subset \kappa(\mathfrak q) \otimes_{\kappa(\mathfrak p)} \kappa(\mathfrak p')$ which corresponds to a prime $\mathfrak q' \subset S \otimes_R R'$ which lies over $\mathfrak q$ and over $\mathfrak p'$. Note that $(S \otimes_R R')_{\mathfrak q'}$ is a localization of $S_{\mathfrak q} \otimes_{R_{\mathfrak p}} R'_{\mathfrak p'}$. By assumption the module $(M \otimes_R R')_{\mathfrak q'}$ is flat over $R'_{\mathfrak p'}$. Hence Algebra, Lemma \ref{algebra-lemma-base-change-flat-up-down} implies that $M_{\mathfrak q}$ is flat over $R_{\mathfrak p}$ which is what we wanted to prove.
We are going to write $S_\lambda = S \otimes_R R_\lambda$, $S' = S \otimes_R R'$, $M_\lambda = M \otimes_R R_\lambda$, and $M' = M \otimes_R R'$. The base change $S'$ is of finite presentation over $R'$ and $M'$ is of finite presentation over $S'$ and similarly for the versions with subscript $\lambda$, see Algebra, Lemma \ref{algebra-lemma-base-change-finiteness}. By Algebra, Theorem \ref{algebra-theorem-openness-flatness} the set $$ U' = \{\mathfrak q' \in \Spec(S') \mid M'_{\mathfrak q'}\text{ is flat over }R'\} $$ is open in $\Spec(S')$. Note that $V(I'S')$ is a quasi-compact space which is contained in $U'$ by assumption. Hence there exist finitely many $g'_j \in S'$, $j = 1, \ldots, m$ such that $D(g'_j) \subset U'$ and such that $V(I'S') \subset \bigcup D(g'_j)$. Note that in particular $(M')_{g'_j}$ is a flat module over $R'$. \medskip\noindent We are going to pick increasingly large elements $\lambda \in \Lambda$. First we pick it large enough so that we can find $g_{j, \lambda} \in S_{\lambda}$ mapping to $g'_j$. The inclusion $V(I'S') \subset \bigcup D(g'_j)$ means that $I'S' + (g'_1, \ldots, g'_m) = S'$ which can be expressed as $1 = \sum z_sh_s + \sum f_jg'_j$ for some $z_s \in I'$, $h_s, f_j \in S'$. After increasing $\lambda$ we may assume such an equation holds in $S_\lambda$. Hence we may assume that $V(I_\lambda S_\lambda) \subset \bigcup D(g_{j, \lambda})$. By Algebra, Lemma \ref{algebra-lemma-flat-finite-presentation-limit-flat} we see that for some sufficiently large $\lambda$ the modules $(M_\lambda)_{g_{j, \lambda}}$ are flat over $R_\lambda$. In particular the module $M_\lambda$ is flat over $R_\lambda$ at all the primes lying over the ideal $I_\lambda$.
Assume (\ref{equation-flat-at-primes}) holds for $(R', I')$. Let $I''S'' + JS'' \subset \mathfrak q''$ be a prime of $S''$. Let $\mathfrak q' \subset S'$ be the corresponding prime of $S'$. Then both $I'S' \subset \mathfrak q'$ and $JS' \subset \mathfrak q'$ because the corresponding conditions hold for $\mathfrak q''$. Note that $(M'')_{\mathfrak q''}$ is a localization of the base change $M'_{\mathfrak q'} \otimes_R R''$. Hence $(M'')_{\mathfrak q''}$ is flat over $R''$ as a localization of a flat module, see Algebra, Lemmas \ref{algebra-lemma-flat-base-change} and \ref{algebra-lemma-flat-localization}.
Assume (\ref{equation-flat-at-primes}) holds for $(R'', I'')$. Pick a prime $I'S' + JS' \subset \mathfrak q' \subset S'$. Let $I' \subset \mathfrak p' \subset R'$ be the corresponding prime of $R'$. By assumption there exists a prime $\mathfrak p'' \in V(I'')$ of $R''$ lying over $\mathfrak p'$ and $R'_{\mathfrak p'} \to R''_{\mathfrak p''}$ is flat. Choose a prime $\overline{\mathfrak q}'' \subset \kappa(\mathfrak q') \otimes_{\kappa(\mathfrak p')} \kappa(\mathfrak p'')$. This corresponds to a prime $\mathfrak q'' \subset S'' = S' \otimes_{R'} R''$ which lies over $\mathfrak q'$ and over $\mathfrak p''$. In particular we see that $I''S'' \subset \mathfrak q''$ and that $JS'' \subset \mathfrak q''$. Note that $(S' \otimes_{R'} R'')_{\mathfrak q''}$ is a localization of $S'_{\mathfrak q'} \otimes_{R'_{\mathfrak p'}} R''_{\mathfrak p''}$. By assumption the module $(M' \otimes_{R'} R'')_{\mathfrak q''}$ is flat over $R''_{\mathfrak p''}$. Hence Algebra, Lemma \ref{algebra-lemma-base-change-flat-up-down} implies that $M'_{\mathfrak q'}$ is flat over $R'_{\mathfrak p'}$ which is what we wanted to prove.
We first prove the lemma in case $R \to S$ is of finite presentation and then we explain what needs to be changed in the general case. We are going to write $S_\lambda = S \otimes_R R_\lambda$, $S' = S \otimes_R R'$, $M_\lambda = M \otimes_R R_\lambda$, and $M' = M \otimes_R R'$. The base change $S'$ is of finite presentation over $R'$ and $M'$ is of finite presentation over $S'$ and similarly for the versions with subscript $\lambda$, see Algebra, Lemma \ref{algebra-lemma-base-change-finiteness}. By Algebra, Theorem \ref{algebra-theorem-openness-flatness} the set $$ U' = \{\mathfrak q' \in \Spec(S') \mid M'_{\mathfrak q'}\text{ is flat over }R'\} $$ is open in $\Spec(S')$. Note that $V(I'S' + JS')$ is a quasi-compact space which is contained in $U'$ by assumption. Hence there exist finitely many $g'_j \in S'$, $j = 1, \ldots, m$ such that $D(g'_j) \subset U'$ and such that $V(I'S' + JS') \subset \bigcup D(g'_j)$. Note that in particular $(M')_{g'_j}$ is a flat module over $R'$. \medskip\noindent We are going to pick increasingly large elements $\lambda \in \Lambda$. First we pick it large enough so that we can find $g_{j, \lambda} \in S_{\lambda}$ mapping to $g'_j$. The inclusion $V(I'S' + JS') \subset \bigcup D(g'_j)$ means that $I'S' + JS' + (g'_1, \ldots, g'_m) = S'$ which can be expressed as $$ 1 = \sum y_tk_t + \sum z_sh_s + \sum f_jg'_j $$ for some $z_s \in I'$, $y_t \in J$, $k_t, h_s, f_j \in S'$. After increasing $\lambda$ we may assume such an equation holds in $S_\lambda$. Hence we may assume that $V(I_\lambda S_\lambda + J S_\lambda) \subset \bigcup D(g_{j, \lambda})$. By Algebra, Lemma \ref{algebra-lemma-flat-finite-presentation-limit-flat} we see that for some sufficiently large $\lambda$ the modules $(M_\lambda)_{g_{j, \lambda}}$ are flat over $R_\lambda$. In particular the module $M_\lambda$ is flat over $R_\lambda$ at all the primes corresponding to points of $V(I_\lambda S_\lambda + J S_\lambda)$. \medskip\noindent In the case that $S$ is essentially of finite presentation, we can write $S = \Sigma^{-1}C$ where $R \to C$ is of finite presentation and $\Sigma \subset C$ is a multiplicative subset. We can also write $M = \Sigma^{-1}N$ for some finitely presented $C$-module $N$, see Algebra, Lemma \ref{algebra-lemma-construct-fp-module}. At this point we introduce $C_\lambda$, $C'$, $N_\lambda$, $N'$. Then in the discussion above we obtain an open $U' \subset \Spec(C')$ over which $N'$ is flat over $R'$. The assumption that (\ref{equation-flat-at-primes}) is true means that $V(I'S' + JS')$ maps into $U'$, because for a prime $\mathfrak q' \subset S'$, corresponding to a prime $\mathfrak r' \subset C'$ we have $M'_{\mathfrak q'} = N'_{\mathfrak r'}$. Thus we can find $g'_j \in C'$ such that $\bigcup D(g'_j)$ contains the image of $V(I'S' + JS')$. The rest of the proof is exactly the same as before.
Let $J \subset R$ be an ideal. Apply Algebra, Lemma \ref{algebra-lemma-flat-module-powers} to the module $M/JM$ over the ring $R/J$. Then we see that $(M/JM)_{\mathfrak q}$ is flat over $R/J$ for all primes $\mathfrak q$ of $S/JS$ if and only if $M/(J + \mathfrak m^n)M$ is flat over $R/(J + \mathfrak m^n)$ for all $n \geq 1$. We will use this remark below. \medskip\noindent For every $n \geq 1$ the local ring $R/\mathfrak m^n$ is Artinian. Hence, by Lemma \ref{lemma-flattening-artinian} there exists a smallest ideal $I_n \supset \mathfrak m^n$ such that $M/I_nM$ is flat over $R/I_n$. It is clear that $I_{n + 1} + \mathfrak m^n$ is contains $I_n$ and applying Lemma \ref{lemma-intersection-flat} we see that $I_n = I_{n + 1} + \mathfrak m^n$. Since $R = \lim_n\ R/\mathfrak m^n$ we see that $I = \lim_n\ I_n/\mathfrak m^n$ is an ideal in $R$ such that $I_n = I + \mathfrak m^n$ for all $n \geq 1$. By the initial remarks of the proof we see that $I$ verifies (1) and (2). Some details omitted.
The implication (2) $\Rightarrow$ (1) follows from Lemma \ref{lemma-base-change-flat-at-primes-over}. Let $\varphi : R \to R'$ be as in the lemma satisfying (1). We have to show that $\varphi(I) = 0$. This is equivalent to the condition that $\varphi(I)R' = 0$. By Artin-Rees in the Noetherian local ring $R'$ (see Algebra, Lemma \ref{algebra-lemma-intersect-powers-ideal-module-zero}) this is equivalent to the condition that $\varphi(I)R' + (\mathfrak m')^n = (\mathfrak m')^n$ for all $n > 0$. Hence this is equivalent to the condition that the composition $\varphi_n : R \to R' \to R'/(\mathfrak m')^n$ annihilates $I$ for each $n$. Now assumption (1) for $\varphi$ implies assumption (1) for $\varphi_n$ by Lemma \ref{lemma-base-change-flat-at-primes-over}. This reduces us to the case where $R'$ is Artinian local. \medskip\noindent Assume $R'$ Artinian. Let $J = \Ker(\varphi)$. We have to show that $I \subset J$. By the construction of $I$ in Lemma \ref{lemma-flattening-complete-local-noetherian} it suffices to show that $(M/JM)_{\mathfrak q}$ is flat over $R/J$ for every prime $\mathfrak q$ of $S/JS$ lying over $\mathfrak m$. As $R'$ is Artinian, condition (1) signifies that $M \otimes_R R'$ is flat over $R'$. As $R'$ is Artinian and $R/J \to R'$ is a local injective ring map, it follows that $R/J$ is Artinian too. Hence the flatness of $M \otimes_R R' = M/JM \otimes_{R/J} R'$ over $R'$ implies that $M/JM$ is flat over $R/J$ by Algebra, Lemma \ref{algebra-lemma-descent-flatness-injective-map-artinian-rings}. This concludes the proof.
The implication (2) $\Rightarrow$ (1) follows from Lemma \ref{lemma-base-change-flat-at-primes-over}. Let $\varphi : R \to R'$ be as in the lemma satisfying (1). As $R$ is Noetherian we see that $R \to S$ is of finite presentation and $M$ is an $S$-module of finite presentation. Write $R' = \colim_\lambda R_\lambda$ as a directed colimit of local $R$-subalgebras $R_\lambda \subset R'$, with maximal ideals $\mathfrak m_\lambda = R_\lambda \cap \mathfrak m'$ such that each $R_\lambda$ is essentially of finite type over $R$. By Lemma \ref{lemma-limit-preserving-flat-at-primes-over} we see that condition (\ref{equation-flat-at-primes-over}) holds for $(R_\lambda \to S \otimes_R R_\lambda, \mathfrak m_\lambda, M \otimes_R R_\lambda)$ for some $\lambda$. Hence Lemma \ref{lemma-flattening-complete-local-noetherian-property-by-finite-type} applies to the ring map $R \to R_\lambda$ and we see that $I$ maps to zero in $R_\lambda$, a fortiori it maps to zero in $R'$.
Write $P(T) = T^d + a_1T^{d - 1} + \ldots + a_0$. Set $R' = R[x]/(x^d + a_1x^{d - 1} + \ldots + a_0)$. Set $\alpha$ equal to the congruence class of $x$. Then it is clear that $P(\alpha) = 0$. Thus we win by Lemma \ref{lemma-have-one-root}.
Let $x_1, \ldots, x_n \in S$ be generators of $S$ over $R$. For each $i$ we can choose a monic polynomial $P_i(T) \in R[T]$ such that $P(x_i) = 0$ in $S$, see Algebra, Lemma \ref{algebra-lemma-finite-is-integral}. Say $\deg(P_i) = d_i$. By Lemma \ref{lemma-adjoin-one-root} (applied $\sum d_i$ times) there exists a finite free ring extension $R \subset R'$ such that each $P_i$ splits completely: $$ P_i(T) = \prod\nolimits_{j = 1, \ldots, d_i} (T - \alpha_{ij}) $$ for certain $\alpha_{ik} \in R'$. Let $R'[T_1, \ldots, T_n] \to S \otimes_R R'$ be the $R'$-algebra map which maps $T_i$ to $x_i \otimes 1$. As this maps $P_i(T_i)$ to zero, this induces the desired surjection.
Let $M$ be an $R$-module such that $M \otimes_R S$ is flat over $S$. By Algebra, Lemma \ref{algebra-lemma-flatness-descends} in order to prove that $M$ is flat we may replace $R$ by any faithfully flat ring extension. By Lemma \ref{lemma-finite-split} we can find a finite locally free ring extension $R \subset R'$ such that $S' = S \otimes_R R' = R'[T_1, \ldots, T_n]/J$ for some ideal $J \subset R'[T_1, \ldots, T_n]$ which contains the  elements of the form $P_i(T_i)$ with $P_i(T) = \prod_{j = 1, \ldots, d_i} (T - \alpha_{ij})$ for some $\alpha_{ij} \in R'$. Note that $R'$ is Noetherian and that $R' \subset S'$ is a finite extension of rings. Hence we may replace $R$ by $R'$ and assume that $S$ has a presentation as in Lemma \ref{lemma-split-image}. Note that $\Spec(S) \to \Spec(R)$ is surjective, see Algebra, Lemma \ref{algebra-lemma-integral-overring-surjective}. Thus, using Lemma \ref{lemma-split-image} we conclude that $I = \bigcap J_{\underline{k}}$ is an ideal such that $V(I) = \Spec(R)$. This means that $I \subset \sqrt{(0)}$, and since $R$ is Noetherian that $I$ is nilpotent. The maps $\Phi_{\underline{k}}$ induce commutative diagrams $$ \xymatrix{ S \ar[rr] & & R/J_{\underline{k}} \\ & R \ar[lu] \ar[ru] } $$ from which we conclude that $M/J_{\underline{k}}M$ is flat over $R/J_{\underline{k}}$. By Lemma \ref{lemma-intersection-flat} we see that $M/IM$ is flat over $R/I$. Finally, applying Algebra, Lemma \ref{algebra-lemma-lift-flatness} we conclude that $M$ is flat over $R$.
Choose a presentation $$ R[x_1, \ldots, x_n]^{\oplus t} \to R[x_1, \ldots, x_n]^{\oplus r} \to M \to 0. $$ Let's say that the first map is given by the $r \times t$-matrix $T = (f_{ij})$ with $f_{ij} \in R[x_1, \ldots, x_n]$. Write $f_{ij} = \sum f_{ij, I} x^I$ with $f_{ij, I} \in R$ (multi-index notation). Consider diagrams $$ \xymatrix{ R \ar[r] & S \\ R_\lambda \ar[u] \ar[r] & S_\lambda \ar[u] } $$ where $R_\lambda$ is a finitely generated $\mathbf{Z}$-subalgebra of $R$ containing all $f_{ij, I}$ and $S_\lambda$ is a finite $R_\lambda$-subalgebra of $S$. Let $M_\lambda$ be the finite $R_\lambda[x_1, \ldots, x_n]$-module defined by a presentation as above, using the same matrix $T$ but now viewed as a matrix over $R_\lambda[x_1, \ldots, x_n]$. Note that $S$ is the directed colimit of the $S_\lambda$ (details omitted). By Algebra, Lemma \ref{algebra-lemma-flat-finite-presentation-limit-flat} we see that for some $\lambda$ the module $M_\lambda \otimes_{R_\lambda} S_\lambda$ is flat over $S_\lambda$. By Lemma \ref{lemma-descent-flatness-injective-finite-Noetherian-rings} we conclude that $M_\lambda$ is flat over $R_\lambda$. Since $M = M_\lambda \otimes_{R_\lambda} R$ we win by Algebra, Lemma \ref{algebra-lemma-flat-base-change}.
We have seen the equivalence of (1) and (2) in Lemma \ref{lemma-finite-torsion-free-submodule-free}. We have seen the equivalence of (4) and (5) in Algebra, Lemma \ref{algebra-lemma-criterion-no-embedded-primes}. The equivalence between (3) and (5) is immediate from the definition. A localization of a torsion free module is torsion free (Lemma \ref{lemma-localize-torsion}), hence it is clear that a $M$ has no associated primes different from $(0)$. Thus (1) implies (5). Conversely, assume (5). If $M$ has torsion, then there exists an embedding $R/I \subset M$ for some nonzero ideal $I$ of $R$. Hence $M$ has an associated prime different from $(0)$ (see Algebra, Lemmas \ref{algebra-lemma-ass} and \ref{algebra-lemma-ass-zero}). This is an embedded associated prime which contradicts the assumption.
The implication ``flat $\Rightarrow$ torsion free'' is Lemma \ref{lemma-flat-torsion-free}. For the converse, assume $M$ is torsion free. By the equational criterion of flatness (see Algebra, Lemma \ref{algebra-lemma-flat-eq}) we have to show that every relation in $M$ is trivial. To do this assume that $\sum_{i = 1, \ldots, n} a_i x_i = 0$ with $x_i \in M$ and $a_i \in A$. After renumbering we may assume that $v(a_1) \leq v(a_i)$ for all $i$. Hence we can write $a_i = a'_i a_1$ for some $a'_i \in A$. Note that $a'_1 = 1$. As $M$ is torsion free we see that $x_1 = - \sum_{i \geq 2} a'_i x_i$. Thus, if we choose $y_i = x_i$, $i = 2, \ldots, n$ then $$ x_1 = \sum\nolimits_{j \geq 2} -a'_j y_j, \quad x_i = y_i, (i \geq 2)\quad 0 = a_1 \cdot (-a'_j) + a_j \cdot 1 (j \geq 2) $$ shows that the relation was trivial (to be explicit the elements $a_{ij}$ are defined by setting $a_{11} = 0$, $a_{1j} = -a'_j$ for $j > 1$, and $a_{ij} = \delta_{ij}$ for $i, j \geq 2$).
Proof of (1). Since a PID is a Dedekind domain (Algebra, Lemma \ref{algebra-lemma-PID-dedekind}), it suffices to prove this for Dedekind domains. By Lemma \ref{lemma-check-torsion} and Algebra, Lemma \ref{algebra-lemma-flat-localization} it suffices to check the statement over $A_\mathfrak m$ for $\mathfrak m \subset A$ maximal. Since $A_\mathfrak m$ is a discrete valuation ring (Algebra, Lemma \ref{algebra-lemma-characterize-Dedekind}) we win by Lemma \ref{lemma-valuation-ring-torsion-free-flat}. \medskip\noindent Proof of (2). Follows from Algebra, Lemma \ref{algebra-lemma-finite-projective} and (1). \medskip\noindent Proof of (3). Let $A$ be a PID and let $M$ be a finite torsion free module. By Lemma \ref{lemma-finite-torsion-free-submodule-free} we see that $M \subset A^{\oplus n}$ for some $n$. We argue that $M$ is free by induction on $n$. The case $n = 1$ expresses exactly the fact that $A$ is a PID. If $n > 1$ let $M' \subset R^{\oplus n - 1}$ be the image of the projection onto the last $n - 1$ summands of $R^{\oplus n}$. Then we obtain a short exact sequence $0 \to I \to M \to M' \to 0$ where $I$ is the intersection of $M$ with the first summand $R$ of $R^{\oplus n}$. By induction we see that $M$ is an extension of finite free $R$-modules, whence finite free.
Let $M_{tors} \subset M$ be the torsion submodule. Then we have $\Hom_R(M, R) = \Hom_R(M/M_{tors}, R)$ (holds over any domain). Hence we may assume that $M$ is torsion free. Then $M$ is free by Lemma \ref{lemma-dedekind-torsion-free-flat} and the lemma is clear.
The localization of $j : M \to \Hom_R(\Hom_R(M, R), R)$ at a prime $\mathfrak p$ is the corresponding map for the module $M_\mathfrak p$ over the Noetherian local domain $R_\mathfrak p$. See Algebra, Lemma \ref{algebra-lemma-hom-from-finitely-presented}. Thus the lemma holds by Algebra, Lemma \ref{algebra-lemma-characterize-zero-local}.
We will use without further mention that $\Hom_R(N, N')$ is a finite $R$-module for any finite $R$-modules $N$ and $N'$, see Algebra, Lemma \ref{algebra-lemma-ext-noetherian}. We take duals to get a sequence $$ \Hom_R(M, R) \leftarrow \Hom_R(M', R) \leftarrow \Hom_R(M'', R) $$ Dualizing again we obtain a commutative diagram $$ \xymatrix{ \Hom_R(\Hom_R(M, R), R) \ar[r]_j & \Hom_R(\Hom_R(M', R), R) \ar[r] & \Hom_R(\Hom_R(M'', R), R) \\ M \ar[u] \ar[r] & M' \ar[u] \ar[r] & M'' \ar[u] } $$ We do not know the top row is exact. But, by assumption the middle vertical arrow is an isomorphism and the right vertical arrow is injective (Lemma \ref{lemma-reflexive-torsion-free}). We claim $j$ is injective. Assuming the claim a diagram chase shows that the left vertical arrow is an isomorphism, i.e., $M$ is reflexive. \medskip\noindent Proof of the claim. Consider the exact sequence $\Hom_R(M',R)\to \Hom_R(M,R)\to Q \to 0$ defining $Q$. One applies Algebra, Lemma \ref{algebra-lemma-hom-from-finitely-presented} to obtain $$ \Hom_K(M'\otimes_R K,K) \to \Hom_K(M\otimes_R K,K) \to Q\otimes_R K\to 0 $$ But $M \otimes_R K \to M' \otimes_R K$ is an injective map of vector spaces, hence split injective, so $Q \otimes_R K = 0$, that is, $Q$ is torsion. Then one gets the exact sequence  $$ 0 \to \Hom_R(Q,R) \to \Hom_R(\Hom_R(M,R),R) \to \Hom_R(\Hom_R(M',R),R) $$ and $\Hom_R(Q,R)=0$ because $Q$ is torsion.
Observe that a finite free module is reflexive. By Lemma \ref{lemma-sequence-reflexive} we see that (2) implies (1). Assume $M$ is reflexive. Choose a presentation $R^{\oplus m} \to R^{\oplus n} \to \Hom_R(M, R) \to 0$. Dualizing we get an exact sequence $$ 0 \to \Hom_R(\Hom_R(M, R), R) \to R^{\oplus n} \to N \to 0 $$ with $N = \Im(R^{\oplus n} \to R^{\oplus m})$ a torsion free module. As $M = \Hom_R(\Hom_R(M, R), R)$ we get an exact sequence as in (2).
Choose a short exact sequence $0 \to M \to F \to N \to 0$ with $F$ finite free and $N$ torsion free, see Lemma \ref{lemma-characterize-reflexive}. Since $R \to R'$ is flat we obtain a short exact sequence $0 \to M \otimes_R R' \to F \otimes_R R' \to N \otimes_R R' \to 0$ with $F \otimes_R R'$ finite free and $N \otimes_R R'$ torsion free (Lemma \ref{lemma-flat-pullback-torsion}). Thus $M \otimes_R R'$ is reflexive by Lemma \ref{lemma-characterize-reflexive}.
Choose a presentation $R^{\oplus m} \to R^{\oplus n} \to M \to 0$. Then we obtain $$ 0 \to \Hom_R(M, N) \to N^{\oplus n} \to N' \to 0 $$ with $N' = \Im(N^{\oplus n} \to N^{\oplus m})$ torsion free. We conclude by Lemma \ref{lemma-sequence-reflexive}.
Choose a presentation $R^{\oplus m} \to R^{\oplus n} \to M \to 0$. Dualizing we get an exact sequence $$ 0 \to \Hom_R(M, N) \to N^{\oplus n} \to N' \to 0 $$ with $N' = \Im(N^{\oplus n} \to N^{\oplus m})$. A submodule of a module with depth $\geq 1$ has depth $\geq 1$; this follows immediately from the definition. Thus part (1) is clear. For (2) note that here the assumption and the previous remark implies $N'$ has depth $\geq 1$. The module $N^{\oplus n}$ has depth $\geq 2$. From Algebra, Lemma \ref{algebra-lemma-depth-in-ses} we conclude $\Hom_R(M, N)$ has depth $\geq 2$.
Since localizing at primes commutes with taking $\Hom_R$ for finite $R$-modules (Algebra, Lemma \ref{algebra-lemma-ext-noetherian}) parts (1) and (2) follow immediately from Lemma \ref{lemma-hom-into-depth}. Part (3) follows from (2) and Lemma \ref{lemma-hom-into-torsion-free}.
Let $\mathfrak p$ be an associated prime of $\Ker(\varphi)$. Then there exists an element $x \in M_\mathfrak p$ which is in the kernel of $M_\mathfrak p \to N_\mathfrak p$ and is annihilated by $\mathfrak pR_\mathfrak p$ (Algebra, Lemma \ref{algebra-lemma-associated-primes-localize}). This is impossible in both cases. Hence $\text{Ass}(\Ker(\varphi)) = \emptyset$ and we conclude $\Ker(\varphi) = 0$ by Algebra, Lemma \ref{algebra-lemma-ass-zero}.