hcju/stacksqa huggingface dataset:
Write $S = R[x_1, \ldots, x_n]/(f_1, \ldots, f_m)$. We may factor $R \to S$ as $R \to R[x_1] \to R[x_1, x_2] \to \ldots \to R[x_1, \ldots, x_{n-1}] \to S$. Hence we may assume that $S = R[x]/(f_1, \ldots, f_m)$. In this case we factor the map as $R \to R[x] \to S$, and by Lemma \ref{lemma-closed-fp} we reduce to the case $S = R[x]$. By Lemma \ref{lemma-qc-open} suffices to show that if $T = (\bigcup_{i = 1\ldots n} D(f_i)) \cap V(g_1, \ldots, g_m)$ for $f_i , g_j \in R[x]$ then the image in $\Spec(R)$ is constructible. Since finite unions of constructible sets are constructible, it suffices to deal with the case $n = 1$, i.e., when $T = D(f) \cap V(g_1, \ldots, g_m)$. \medskip\noindent Note that if $c \in R$, then we have $$ \Spec(R) = V(c) \amalg D(c) = \Spec(R/(c)) \amalg \Spec(R_c), $$ and correspondingly $\Spec(R[x]) = V(c) \amalg D(c) = \Spec(R/(c)[x]) \amalg \Spec(R_c[x])$. The intersection of $T = D(f) \cap V(g_1, \ldots, g_m)$ with each part still has the same shape, with $f$, $g_i$ replaced by their images in $R/(c)[x]$, respectively $R_c[x]$. Note that the image of $T$ in $\Spec(R)$ is the union of the image of $T \cap V(c)$ and $T \cap D(c)$. Using Lemmas \ref{lemma-open-fp} and \ref{lemma-closed-fp} it suffices to prove the images of both parts are constructible in $\Spec(R/(c))$, respectively $\Spec(R_c)$. \medskip\noindent Let us assume we have $T = D(f) \cap V(g_1, \ldots, g_m)$ as above, with $\deg(g_1) \leq \deg(g_2) \leq \ldots \leq \deg(g_m)$. We are going to use induction on $m$, and on the degrees of the $g_i$. Let $d = \deg(g_1)$, i.e., $g_1 = c x^{d_1} + l.o.t$ with $c \in R$ not zero. Cutting $R$ up into the pieces $R/(c)$ and $R_c$ we either lower the degree of $g_1$ (and this is covered by induction) or we reduce to the case where $c$ is invertible. If $c$ is invertible, and $m > 1$, then write $g_2 = c' x^{d_2} + l.o.t$. In this case consider $g_2' = g_2 - (c'/c) x^{d_2 - d_1} g_1$. Since the ideals $(g_1, g_2, \ldots, g_m)$ and $(g_1, g_2', g_3, \ldots, g_m)$ are equal we see that $T = D(f) \cap V(g_1, g_2', g_3\ldots, g_m)$. But here the degree of $g_2'$ is strictly less than the degree of $g_2$ and hence this case is covered by induction. \medskip\noindent The bases case for the induction above are the cases (a) $T = D(f) \cap V(g)$ where the leading coefficient of $g$ is invertible, and (b) $T = D(f)$. These two cases are dealt with in Lemmas \ref{lemma-affineline-special} and \ref{lemma-affineline-open}.
It is enough to prove part (\ref{item-finite-kappa}) of the theorem for the case of a polynomial algebra $k[x_1, \ldots, x_n]$, because any finitely generated $k$-algebra is a quotient of such a polynomial algebra. We prove this by induction on $n$. The case $n = 0$ is clear. Suppose that $\mathfrak m$ is a maximal ideal in $k[x_1, \ldots, x_n]$. Let $\mathfrak p \subset k[x_n]$ be the intersection of $\mathfrak m$ with $k[x_n]$. \medskip\noindent If $\mathfrak p \not = (0)$, then $\mathfrak p$ is maximal and generated by an irreducible monic polynomial $P$ (because of the Euclidean algorithm in $k[x_n]$). Then $k' = k[x_n]/\mathfrak p$ is a finite field extension of $k$ and contained in $\kappa(\mathfrak m)$. In this case we get a surjection $$ k'[x_1, \ldots, x_{n-1}] \to k'[x_1, \ldots, x_n] = k' \otimes_k k[x_1, \ldots, x_n] \longrightarrow \kappa(\mathfrak m) $$ and hence we see that $\kappa(\mathfrak m)$ is a finite extension  of $k'$ by induction hypothesis. Thus $\kappa(\mathfrak m)$ is finite over $k$ as well. \medskip\noindent If $\mathfrak p = (0)$ we consider the ring extension $k[x_n] \subset k[x_1, \ldots, x_n]/\mathfrak m$. This is a finitely generated ring extension, hence of finite presentation by Lemmas \ref{lemma-obvious-Noetherian} and \ref{lemma-Noetherian-finite-type-is-finite-presentation}. Thus the image of $\Spec(k[x_1, \ldots, x_n]/\mathfrak m)$ in $\Spec(k[x_n])$ is constructible by Theorem \ref{theorem-chevalley}. Since the image contains $(0)$ we conclude that it contains a standard open $D(f)$ for some $f\in k[x_n]$ nonzero. Since clearly $D(f)$ is infinite we get a contradiction with the assumption that $k[x_1, \ldots, x_n]/\mathfrak m$ is a field (and hence has a spectrum consisting of one point). \medskip\noindent To prove part (\ref{item-polynomial-ring-Jacobson}) let $I \subset R$ be a radical ideal, with $R$ of finite type over $k$. Let $f \in R$, $f \not \in I$. Pick a maximal ideal $\mathfrak m'$ in the nonzero ring $R_f/IR_f = (R/I)_f$. Let $\mathfrak m \subset R$ be the inverse image of $\mathfrak m'$ in $R$. We see that $I \subset \mathfrak m$ and $f \not \in \mathfrak m$. If we show that $\mathfrak m$ is a maximal ideal of $R$, then we are done. We clearly have $$ k \subset R/\mathfrak m \subset \kappa(\mathfrak m'). $$ By part (\ref{item-finite-kappa}) the field extension $k \subset \kappa(\mathfrak m')$ is finite. Hence $R/\mathfrak m$ is a field by Fields, Lemma \ref{fields-lemma-subalgebra-algebraic-extension-field}. Thus $\mathfrak m$ is maximal and the proof is complete.
If $I$ is finite then the result follows from the Hilbert Nullstellensatz, Theorem \ref{theorem-nullstellensatz}. In the rest of the proof we assume $I$ is infinite. It suffices to prove the result for $\mathfrak m \subset k[\{x_i\}_{i \in I}]$ maximal in the polynomial ring on variables $x_i$, since $S$ is a quotient of this. As $I$ is infinite the set of monomials $x_{i_1}^{e_1} \ldots x_{i_r}^{e_r}$, $i_1, \ldots, i_r \in I$ and $e_1, \ldots, e_r \geq 0$ has cardinality at most equal to the cardinality of $I$. Because the cardinality of $I \times \ldots \times I$ is the cardinality of $I$, and also the cardinality of $\bigcup_{n \geq 0} I^n$ has the same cardinality. (If $I$ is finite, then this is not true and in that case this proof only works if $k$ is uncountable.) \medskip\noindent To arrive at a contradiction pick $T \in \kappa(\mathfrak m)$ transcendental over $k$. Note that the $k$-linear map $T : \kappa(\mathfrak m) \to \kappa(\mathfrak m)$ given by multiplication by $T$ has the property that $P(T)$ is invertible for all monic polynomials $P(t) \in k[t]$. Also, $\kappa(\mathfrak m)$ has dimension at most the cardinality of $I$ over $k$ since it is a quotient of the vector space $k[\{x_i\}_{i \in I}]$ over $k$ (whose dimension is $\# I$ as we saw above). This is impossible by Lemma \ref{lemma-dimension}. \medskip\noindent To show that $S$ is Jacobson we argue as follows. If not then there exists a prime $\mathfrak q \subset S$ and an element $f \in S$, $f \not \in \mathfrak q$ such that $\mathfrak q$ is not maximal and $(S/\mathfrak q)_f$ is a field, see Lemma \ref{lemma-characterize-jacobson}. But note that $(S/\mathfrak q)_f$ is generated by at most $\# I + 1$ elements. Hence the field extension $k \subset (S/\mathfrak q)_f$ is algebraic (by the first part of the proof). This implies that $\kappa(\mathfrak q)$ is an algebraic extension of $k$ hence $\mathfrak q$ is maximal by Lemma \ref{lemma-finite-residue-extension-closed}. This contradiction finishes the proof.
A colimit of a directed system of flat modules is flat, as taking directed colimits is exact and commutes with tensor product. Hence if $M$ is the colimit of a directed system of free finite modules then $M$ is flat. \medskip\noindent For the converse, first recall that any module $M$ can be written as the colimit of a directed system of finitely presented modules, in the following way.  Choose a surjection $f: R^I \to M$ for some set $I$, and let $K$ be the kernel.  Let $E$ be the set of ordered pairs $(J, N)$ where $J$ is a finite subset of $I$ and $N$ is a finitely generated submodule of $R^J \cap K$. Then $E$ is made into a directed partially ordered set by defining $(J, N) \leq (J', N')$ if and only if $J \subset J'$ and $N \subset N'$.  Define $M_e = R^J/N$ for $e = (J, N)$, and define $f_{ee'}: M_e \to M_{e'}$ to be the natural map for $e \leq e'$.  Then $(M_e, f_{ee'})$ is a directed system and the natural maps $f_e: M_e \to M$ induce an isomorphism $\colim_{e \in E} M_e \xrightarrow{\cong} M$. \medskip\noindent Now suppose $M$ is flat.  Let $I = M \times \mathbf{Z}$, write $(x_i)$ for the canonical basis of $R^{I}$, and take in the above discussion $f: R^I \to M$ to be the map sending $x_i$ to the projection of $i$ onto $M$. To prove the theorem it suffices to show that the $e \in E$ such that $M_e$ is free form a cofinal subset of $E$.  So let $e = (J, N) \in E$ be arbitrary. By Lemma \ref{lemma-flat-factors-fp} there is a free finite module $F$ and maps $h: R^J/N \to F$ and $g: F \to M$ such that the natural map $f_e: R^J/N \to M$ factors as $R^J/N \xrightarrow{h} F \xrightarrow{g} M$.  We are going to realize $F$ as $M_{e'}$ for some $e' \geq e$. \medskip\noindent Let $\{ b_1, \ldots, b_n \}$ be a finite basis of $F$.  Choose $n$ distinct elements $i_1, \ldots, i_n \in I$ such that $i_{\ell} \notin J$ for all $\ell$, and such that the image of $x_{i_{\ell}}$ under $f: R^I \to M$ equals the image of $b_{\ell}$ under $g: F \to M$.  This is possible since every element of $M$ can be written as $f(x_i)$ for infinitely many distinct $i \in I$ (by our choice of $I$).  Now let $J' = J \cup \{i_1, \ldots , i_n \}$, and define $R^{J'} \to F$ by $x_i \mapsto h(x_i)$ for $i \in J$ and $x_{i_{\ell}} \mapsto b_{\ell}$ for $\ell = 1, \ldots, n$.  Let $N' = \Ker(R^{J'} \to F)$. Observe: \begin{enumerate} \item The square $$ \xymatrix{ R^{J'} \ar[r] \ar@{^{(}->}[d] & F \ar[d]^{g} \\ R^{I} \ar[r]_{f} & M } $$ is commutative, %$R^{J'} \to F$ factors $f: R^I \to M$, hence $N' \subset K = \Ker(f)$; \item $R^{J'} \to F$ is a surjection onto a free finite module, hence it splits and so $N'$ is finitely generated; \item $J \subset J'$ and $N \subset N'$. \end{enumerate} By (1) and (2) $e' = (J', N')$ is in $E$, by (3) $e' \geq e$, and by construction $M_{e'} = R^{J'}/N' \cong F$ is free.
First suppose $M$ is projective.  Then $M$ is a direct summand of a free module, so $M$ is flat and Mittag-Leffler since these properties pass to direct summands. By Kaplansky's theorem (Theorem \ref{theorem-projective-direct-sum}), $M$ satisfies (3). \medskip\noindent Conversely, suppose $M$ satisfies (1)-(3).  Since being flat and Mittag-Leffler passes to direct summands, $M$ is a direct sum of flat, Mittag-Leffler, countably generated $R$-modules. Lemma \ref{lemma-countgen-projective} implies $M$ is a direct sum of projective modules. Hence $M$ is projective.
We are going to construct a Kaplansky d\'evissage of $M$ to show that it is a direct sum of projective modules and hence projective.  By Theorem \ref{theorem-projective-direct-sum} we can write $M \otimes_R S = \bigoplus_{i \in I} Q_i$ as a direct sum of countably generated $S$-modules $Q_i$.  Choose a well-ordering on $M$.  By transfinite induction we are going to define an increasing family of submodules $M_{\alpha}$ of $M$, one for each ordinal $\alpha$, such that $M_{\alpha} \otimes_R S$ is a direct sum of some subset of the $Q_i$. \medskip\noindent For $\alpha = 0$ let $M_0 = 0$.  If $\alpha$ is a limit ordinal and $M_{\beta}$ has been defined for all $\beta < \alpha$, then define $M_{\beta} = \bigcup_{\beta < \alpha} M_{\beta}$.  Since each $M_{\beta} \otimes_R S$ for $\beta < \alpha$ is a direct sum of a subset of the $Q_i$, the same will be true of $M_{\alpha} \otimes_R S$.  If $\alpha + 1$ is a successor ordinal and $M_{\alpha}$ has been defined, then define $M_{\alpha + 1}$ as follows.  If $M_{\alpha} = M$, then let $M_{\alpha +1} = M$.  Otherwise choose the smallest $x \in M$ (with respect to the fixed well-ordering) such that $x \notin M_{\alpha}$. Since $S$ is flat over $R$, $(M/M_{\alpha}) \otimes_R S = M \otimes_R S/M_{\alpha} \otimes_R S$, so since $M_{\alpha} \otimes_R S$ is a direct sum of some $Q_i$, the same is true of $(M/M_{\alpha}) \otimes_R S$.   By Lemma \ref{lemma-adapted-submodule}, we can find a countably generated $R$-submodule $P$ of $M/M_{\alpha}$ containing the image of $x$ in $M/M_{\alpha}$ and such that $P \otimes_R S$ (which equals $\Im(P \otimes_R S \to M \otimes_R S)$ since $S$ is flat over $R$) is a direct sum of some $Q_i$. Since $M \otimes_R S = \bigoplus_{i \in I} Q_i$ is projective and projectivity passes to direct summands, $P \otimes_R S$ is also projective.  Thus by Lemma \ref{lemma-ffdescent-countable-projectivity}, $P$ is projective.  Finally we define $M_{\alpha + 1}$ to be the preimage of $P$ in $M$, so that $M_{\alpha + 1}/M_{\alpha} = P$ is countably generated and projective.  In particular $M_{\alpha}$ is a direct summand of $M_{\alpha + 1}$ since projectivity of $M_{\alpha + 1}/M_{\alpha}$ implies the sequence $0 \to M_{\alpha} \to M_{\alpha + 1} \to M_{\alpha + 1}/M_{\alpha} \to 0$ splits. \medskip\noindent Transfinite induction on $M$ (using the fact that we constructed $M_{\alpha + 1}$ to contain the smallest $x \in M$ not contained in $M_{\alpha}$) shows that each $x \in M$ is contained in some $M_{\alpha}$.  Thus, there is some large enough ordinal $S$ satisfying: for each $x \in M$ there is $\alpha \in S$ such that $x \in M_{\alpha}$.  This means $(M_{\alpha})_{\alpha \in S}$ satisfies property (1) of a Kaplansky d\'evissage of $M$.  The other properties are clear by construction.  We conclude $M = \bigoplus_{\alpha + 1 \in S} M_{\alpha + 1}/M_{\alpha}$. Since each $M_{\alpha + 1}/M_{\alpha}$ is projective by construction, $M$ is projective.
Let us prove a coefficient ring exists. First we prove this in case the characteristic of the residue field $\kappa$ is zero. Namely, in this case we will prove by induction on $n > 0$ that there exists a section $$ \varphi_n : \kappa \longrightarrow R/\mathfrak m^n $$ to the canonical map $R/\mathfrak m^n \to \kappa = R/\mathfrak m$. This is trivial for $n = 1$. If $n > 1$, let $\varphi_{n - 1}$ be given. The field extension $\mathbf{Q} \subset \kappa$ is formally smooth by Proposition \ref{proposition-characterize-separable-field-extensions}. Hence we can find the dotted arrow in the following diagram $$ \xymatrix{ R/\mathfrak m^{n - 1} & R/\mathfrak m^n \ar[l] \\ \kappa \ar[u]^{\varphi_{n - 1}} \ar@{..>}[ru] & \mathbf{Q} \ar[l] \ar[u] } $$ This proves the induction step. Putting these maps together $$ \lim_n\ \varphi_n : \kappa \longrightarrow R = \lim_n\ R/\mathfrak m^n $$ gives a map whose image is the desired coefficient ring. \medskip\noindent Next, we prove the existence of a coefficient ring in the case where the characteristic of the residue field $\kappa$ is $p > 0$. Namely, choose a Cohen ring $\Lambda$ with $\kappa = \Lambda/p\Lambda$, see Lemma \ref{lemma-cohen-rings-exist}. In this case we will prove by induction on $n > 0$ that there exists a map $$ \varphi_n : \Lambda/p^n\Lambda \longrightarrow R/\mathfrak m^n $$ whose composition with the reduction map $R/\mathfrak m^n \to \kappa$ produces the given isomorphism $\Lambda/p\Lambda = \kappa$. This is trivial for $n = 1$. If $n > 1$, let $\varphi_{n - 1}$ be given. The ring map $\mathbf{Z}/p^n\mathbf{Z} \to \Lambda/p^n\Lambda$ is formally smooth by Lemma \ref{lemma-cohen-ring-formally-smooth}. Hence we can find the dotted arrow in the following diagram $$ \xymatrix{ R/\mathfrak m^{n - 1} & R/\mathfrak m^n \ar[l] \\ \Lambda/p^n\Lambda \ar[u]^{\varphi_{n - 1}} \ar@{..>}[ru] & \mathbf{Z}/p^n\mathbf{Z} \ar[l] \ar[u] } $$ This proves the induction step. Putting these maps together $$ \lim_n\ \varphi_n : \Lambda = \lim_n\ \Lambda/p^n\Lambda \longrightarrow R = \lim_n\ R/\mathfrak m^n $$ gives a map whose image is the desired coefficient ring. \medskip\noindent The final statement of the theorem follows readily. Namely, if $y_1, \ldots, y_n$ are generators of the ideal $\mathfrak m$, then we can use the map $\Lambda \to R$ just constructed to get a map $$ \Lambda[[x_1, \ldots, x_n]] \longrightarrow R, \quad x_i \longmapsto y_i. $$ Since both sides are $(x_1, \ldots, x_n)$-adically complete this map is surjective by Lemma \ref{lemma-completion-generalities} as it is surjective modulo $(x_1, \ldots, x_n)$ by construction.
Proof of (1). If $x_1, \ldots, x_n$ are generators of $M_1$ and $y_1, \ldots, y_m \in M_2$ are elements whose images in $M_3$ are generators of $M_3$, then $x_1, \ldots, x_n, y_1, \ldots, y_m$ generate $M_2$. \medskip\noindent Part (3) is immediate from the definition. \medskip\noindent Proof of (5). Assume $M_3$ is finitely presented and $M_2$ finite. Choose a presentation $$ R^{\oplus m} \to R^{\oplus n} \to M_3 \to 0 $$ By Lemma \ref{lemma-lift-map} there exists a map $R^{\oplus n} \to M_2$ such that the solid diagram $$ \xymatrix{ & R^{\oplus m} \ar[r] \ar@{..>}[d] & R^{\oplus n} \ar[r] \ar[d] & M_3 \ar[r] \ar[d]^{\text{id}} & 0 \\ 0 \ar[r] & M_1 \ar[r] & M_2 \ar[r] & M_3 \ar[r] & 0 } $$ commutes. This produces the dotted arrow. By the snake lemma (Lemma \ref{lemma-snake}) we see that we get an isomorphism $$ \Coker(R^{\oplus m} \to M_1) \cong \Coker(R^{\oplus n} \to M_2) $$ In particular we conclude that $\Coker(R^{\oplus m} \to M_1)$ is a finite $R$-module. Since $\Im(R^{\oplus m} \to M_1)$ is finite by (3), we see that $M_1$ is finite by part (1). \medskip\noindent Proof of (4). Assume $M_2$ is finitely presented and $M_1$ is finite. Choose a presentation $R^{\oplus m} \to R^{\oplus n} \to M_2 \to 0$. Choose a surjection $R^{\oplus k} \to M_1$. By Lemma \ref{lemma-lift-map} there exists a factorization $R^{\oplus k} \to R^{\oplus n} \to M_2$ of the composition $R^{\oplus k} \to M_1 \to M_2$. Then $R^{\oplus k + m} \to R^{\oplus n} \to M_3 \to 0$ is a presentation. \medskip\noindent Proof of (2). Assume that $M_1$ and $M_3$ are finitely presented. The argument in the proof of part (1) produces a commutative diagram $$ \xymatrix{ 0 \ar[r] & R^{\oplus n} \ar[d] \ar[r] & R^{\oplus n + m} \ar[d] \ar[r] & R^{\oplus m} \ar[d] \ar[r] & 0 \\ 0 \ar[r] & M_1 \ar[r] & M_2 \ar[r] & M_3 \ar[r] & 0 } $$ with surjective vertical arrows. By the snake lemma we obtain a short exact sequence $$ 0 \to \Ker(R^{\oplus n} \to M_1) \to \Ker(R^{\oplus n + m} \to M_2) \to \Ker(R^{\oplus m} \to M_3) \to 0 $$ By part (5) we see that the outer two modules are finite. Hence the middle one is finite too. By (4) we see that $M_2$ is of finite presentation.
This is similar to the proof of part (4) of Lemma \ref{lemma-compose-finite-type}. We may assume $S = R[x_1, \ldots, x_n]/J$. Choose $y_1, \ldots, y_m \in M$ which generate $M$ as an $R$-module and choose relations $\sum a_{ij} y_j = 0$, $i = 1, \ldots, t$ which generate the kernel of $R^{\oplus m} \to M$. For any $i = 1, \ldots, n$ and $j = 1, \ldots, m$ write $$ x_i y_j = \sum a_{ijk} y_k $$ for some $a_{ijk} \in R$. Consider the $S$-module $N$ generated by $y_1, \ldots, y_m$ subject to the relations $\sum a_{ij} y_j = 0$, $i = 1, \ldots, t$ and $x_i y_j = \sum a_{ijk} y_k$, $i = 1, \ldots, n$ and $j = 1, \ldots, m$. Then $N$ has a presentation $$ S^{\oplus nm + t} \longrightarrow S^{\oplus m} \longrightarrow N \longrightarrow 0 $$ By construction there is a surjective map $\varphi : N \to M$. To finish the proof we show $\varphi$ is injective. Suppose $z = \sum b_j y_j \in N$ for some $b_j \in S$. We may think of $b_j$ as a polynomial in $x_1, \ldots, x_n$ with coefficients in $R$. By applying the relations of the form $x_i y_j = \sum a_{ijk} y_k$ we can inductively lower the degree of the polynomials. Hence we see that $z = \sum c_j y_j$ for some $c_j \in R$. Hence if $\varphi(z) = 0$ then the vector $(c_1, \ldots, c_m)$ is an $R$-linear combination of the vectors $(a_{i1}, \ldots, a_{im})$ and we conclude that $z = 0$ as desired.
One of the implications follows from Lemma \ref{lemma-finite-over-subring}. To see the other assume that $M$ is finite as an $S$-module. Pick $x_1, \ldots, x_n \in S$ which generate $S$ as an $R$-module. Pick $y_1, \ldots, y_m \in M$ which generate $M$ as an $S$-module. Then $x_i y_j$ generate $M$ as an $R$-module.
This lemma is a special case of Categories, Lemma \ref{categories-lemma-colimits-coproducts-coequalizers} but we will also prove it directly in this case. Namely, note that $\phi_i = \phi_j\circ \mu_{ij}$ in the above construction. To show the pair $(M, \phi_i)$ is the colimit we have to show it satisfies the universal property: for any other such pair $(Y, \psi_i)$ with $\psi_i : M_i \to Y$, $\psi_i = \psi_j\circ \mu_{ij}$, there is a unique $R$-module homomorphism $g : M \to Y$ such that the following diagram commutes: $$ \xymatrix{ M_i \ar[rr]^{\mu_{ij}} \ar[dr]^{\phi_i} \ar[ddr]_{\psi_i} & & M_j\ar[dl]_{\phi_j} \ar[ddl]^{\psi_j} \\ & M \ar[d]^{g}\\ & Y } $$ And this is clear because we can define $g$ by taking the map $\psi_i$ on the summand $M_i$ in the direct sum $\bigoplus M_i$.
Write $M = \colim M_i$ and $N = \colim N_i$ and $\phi = \colim \phi_i$ (as yet to be constructed). We will use the explicit description of $M$ and $N$ in Lemma \ref{lemma-colimit} without further mention. The condition of the lemma is equivalent to the condition that $$ \xymatrix{ \bigoplus_{i\in I} M_i \ar[r] \ar[d]_{\bigoplus\phi_i} & M \ar[d]^\phi \\ \bigoplus_{i\in I} N_i \ar[r] & N } $$ commutes. Hence it is clear that if $\phi$ exists, then it is unique. To see that $\phi$ exists, it suffices to show that the kernel of the upper horizontal arrow is mapped by $\bigoplus \phi_i$ to the kernel of the lower horizontal arrow. To see this, let $j \leq k$ and $x_j \in M_j$. Then $$ (\bigoplus \phi_i)(x_j - \mu_{jk}(x_j)) = \phi_j(x_j) - \phi_k(\mu_{jk}(x_j)) = \phi_j(x_j) - \nu_{jk}(\phi_j(x_j)) $$ which is in the kernel of the lower horizontal arrow as required.
It is clear that $ \xymatrix{ \colim_i L_i \ar[r]^\varphi & \colim_i M_i \ar[r]^\psi & \colim_i N_i } $ is a complex. For each $i \in I$, there is a canonical $R$-module morphism $H_i \to H$ (sending each $[m] \in H_i = \Ker(\psi_i) / \Im(\varphi_i)$ to the residue class in $H = \Ker(\psi) / \Im(\varphi)$ of the image of $m$ in $\colim_i M_i$). These give rise to a morphism $\colim_i H_i \to H$. It remains to show that this morphism is surjective and injective. \medskip\noindent We are going to repeatedly use the description of colimits over $I$ as in Lemma \ref{lemma-directed-colimit} without further mention. Let $h \in H$. Since $H = \Ker(\psi)/\Im(\varphi)$ we see that $h$ is the class mod $\Im(\varphi)$ of an element $[m]$ in $\Ker(\psi) \subset \colim_i M_i$. Choose an $i$ such that $[m]$ comes from an element $m \in M_i$. Choose a $j \geq i$ such that $\nu_{ij}(\psi_i(m)) = 0$ which is possible since $[m] \in \Ker(\psi)$. After replacing $i$ by $j$ and $m$ by $\mu_{ij}(m)$ we see that we may assume $m \in \Ker(\psi_i)$. This shows that the map $\colim_i H_i \to H$ is surjective. \medskip\noindent Suppose that $h_i \in H_i$ has image zero on $H$. Since $H_i = \Ker(\psi_i)/\Im(\varphi_i)$ we may represent $h_i$ by an element $m \in \Ker(\psi_i) \subset M_i$. The assumption on the vanishing of $h_i$ in $H$ means that the class of $m$ in $\colim_i M_i$ lies in the image of $\varphi$. Hence there exists a $j \geq i$ and an $l \in L_j$ such that $\varphi_j(l) = \mu_{ij}(m)$. Clearly this shows that the image of $h_i$ in $H_j$ is zero. This proves the injectivity of $\colim_i H_i \to H$.
By Categories, Lemma \ref{categories-lemma-split-into-directed} we may write $\mathcal{I} = \coprod_{j \in J} \mathcal{I}_j$ with each $\mathcal{I}_j$ a filtered category, and $J$ possibly empty. By Categories, Lemma \ref{categories-lemma-directed-category-system} taking colimits over the index categories $\mathcal{I}_j$ is the same as taking the colimit over some directed set. Hence Lemma \ref{lemma-directed-colimit-exact} applies to these colimits. This reduces the problem to showing that coproducts in the category of $R$-modules over the set $J$ are exact. In other words, exact sequences $L_j \to M_j \to N_j$ of $R$ modules we have to show that $$ \bigoplus\nolimits_{j \in J} L_j \longrightarrow \bigoplus\nolimits_{j \in J} M_j \longrightarrow \bigoplus\nolimits_{j \in J} N_j $$ is exact. This can be verified by hand, and holds even if $J$ is empty.