hcju/stacksqa huggingface dataset:
Part (1) follows immediately from Lemma \ref{lemma-key} and the definitions. If $A$ is reduced, then there exists an injection $A \to A' = \prod_{\mathfrak p \subset A\text{ minimal}} A_\mathfrak p$ of $A$ into an absolutely flat ring (Algebra, Lemma \ref{algebra-lemma-reduced-ring-sub-product-fields} and Lemma \ref{lemma-product-fields-absolutely-flat}). If $A \to B$ is flat, then the induced map $B \to B' = B \otimes_A A'$ is injective too. By Lemma \ref{lemma-base-change-weakly-etale} the ring map $A' \to B'$ is weakly \'etale. By part (1) we see that $B'$ is absolutely flat. By Lemma \ref{lemma-absolutely-flat} the ring $B'$ is reduced. Hence $B$ is reduced.
Part (1) follows from the factorization $$ C \otimes_A C \longrightarrow C \otimes_B C \longrightarrow C $$ of the multiplication map, the fact that $$ C \otimes_B C = (C \otimes_A C) \otimes_{B \otimes_A B} B, $$ the fact that a base change of a flat map is flat, and the fact that the composition of flat ring maps is flat. See Algebra, Lemmas \ref{algebra-lemma-flat-base-change} and \ref{algebra-lemma-composition-flat}. Part (2) follows from (1) and the fact (just used) that the composition of flat ring maps is flat.
Assume $B \to C$ is faithfully flat and $C \otimes_A C \to C$ is flat. Consider the commutative diagram $$ \xymatrix{ C \otimes_A C \ar[r] & C \\ B \otimes_A B \ar[r] \ar[u] & B \ar[u] } $$ The vertical arrows are flat, the top horizontal arrow is flat. Hence $C$ is flat as a $B \otimes_A B$-module. The map $B \to C$ is faithfully flat and $C = B \otimes_B C$. Hence $B$ is flat as a $B \otimes_A B$-module by Algebra, Lemma \ref{algebra-lemma-flatness-descends-more-general}. This proves (1). Part (2) follows from (1) and the fact that $A \to B$ is flat if $A \to C$ is flat and $B \to C$ is faithfully flat (Algebra, Lemma \ref{algebra-lemma-flatness-descends-more-general}).
Write $B \to C$ as the composition $B \to B \otimes_A C \to C$. The first map is flat as the base change of the flat ring map $A \to C$. The second is the base change of the flat ring map $B \otimes_A B \to B$ by the ring map $B \otimes_A B \to B \otimes_A C$, hence flat. Thus $B \to C$ is flat. The ring map $C \otimes_A C \to C \otimes_B C$ is surjective, hence an epimorphism. Thus Lemma \ref{lemma-key} implies, that since $C$ is flat over $C \otimes_A C$ it follows that $C$ is flat over $C \otimes_B C$.
Let $I \subset B \otimes_A B$ be the kernel of the flat surjective map $B \otimes_A B \to B$. Then $I$ is a pure ideal (Algebra, Definition \ref{algebra-definition-pure-ideal}), so $I^2 = I$ (Algebra, Lemma \ref{algebra-lemma-pure}). Since $\Omega_{B/A} = I/I^2$ (Algebra, Lemma \ref{algebra-lemma-differentials-diagonal}) we obtain the vanishing. This means $B$ is formally unramified over $A$ by Algebra, Lemma \ref{algebra-lemma-characterize-formally-unramified}.
An \'etale ring map is flat and the map $B \otimes_A B \to B$ is also \'etale as a map between \'etale $A$-algebras (Algebra, Lemma \ref{algebra-lemma-map-between-etale}). This proves (2). \medskip\noindent Let $B_i$ be a directed system of weakly \'etale $A$-algebras. Then $B = \colim B_i$ is flat over $A$ by Algebra, Lemma \ref{algebra-lemma-colimit-flat}. Note that the transition maps $B_i \to B_{i'}$ are flat by Lemma \ref{lemma-weakly-etale-permanence}. Hence $B$ is flat over $B_i$ for each $i$, and we see that $B$ is flat over $B_i \otimes_A B_i$ by Algebra, Lemma \ref{algebra-lemma-composition-flat}. Thus $B$ is flat over $B \otimes_A B = \colim B_i \otimes_A B_i$ by Algebra, Lemma \ref{algebra-lemma-colimit-rings-flat}. \medskip\noindent Part (1) can be proved directly, but also follows by combining (2) and (3).
By Lemma \ref{lemma-go-down} we see that any subfield $K \subset L' \subset L$ the map $L' \otimes_K L' \to L'$ is flat. Thus we may assume $L$ is a finitely generated field extension of $K$. In this case the fact that $L/K$ is formally unramified (Lemma \ref{lemma-formally-unramified}) implies that $L/K$ is finite separable, see Algebra, Lemma \ref{algebra-lemma-characterize-separable-algebraic-field-extensions}.
Parts (1) and (2) are equivalent because every $K$-algebra is flat over $K$. Part (3) implies (1) and (2) by Lemma \ref{lemma-when-weakly-etale} \medskip\noindent Assume (1) and (2) hold. We will prove (3) and the finite statement of the lemma. A field is absolutely flat ring, hence $B$ is a absolutely flat ring by Lemma \ref{lemma-absolutely-flat-over-absolutely-flat}. Hence $B$ is reduced and every local ring is a field, see Lemma \ref{lemma-absolutely-flat}. \medskip\noindent Let $\mathfrak q \subset B$ be a prime. The ring map $B \to B_\mathfrak q$ is weakly \'etale, hence $B_\mathfrak q$ is weakly \'etale over $K$ (Lemma \ref{lemma-composition-weakly-etale}). Thus $B_\mathfrak q$ is a separable algebraic extension of $K$ by Lemma \ref{lemma-absolutely-flat-fields}. \medskip\noindent Let $K \subset A \subset B$ be a finitely generated $K$-sub algebra. We will show that $A$ is \'etale over $K$ which will finish the proof of the lemma. Then every minimal prime $\mathfrak p \subset A$ is the image of a prime $\mathfrak q$ of $B$, see Algebra, Lemma \ref{algebra-lemma-injective-minimal-primes-in-image}. Thus $\kappa(\mathfrak p)$ as a subfield of $B_\mathfrak q = \kappa(\mathfrak q)$ is separable algebraic over $K$. Hence every generic point of $\Spec(A)$ is closed (Algebra, Lemma \ref{algebra-lemma-finite-residue-extension-closed}). Thus $\dim(A) = 0$. Then $A$ is the product of its local rings, e.g., by Algebra, Proposition \ref{algebra-proposition-dimension-zero-ring}. Moreover, since $A$ is reduced, all local rings are equal to their residue fields wich are finite separable over $K$. This means that $A$ is \'etale over $K$ by Algebra, Lemma \ref{algebra-lemma-etale-over-field} and finishes the proof.
Let $\mathfrak p$ be a prime of $A$. Then $\kappa(\mathfrak p) \to B \otimes_A \kappa(\mathfrak p)$ is weakly \'etale by Lemma \ref{lemma-base-change-weakly-etale}. Hence $B \otimes_A \kappa(\mathfrak p)$ is a filtered colimit of \'etale $\kappa(\mathfrak p)$-algebras by Lemma \ref{lemma-absolutely-flat-over-field}. Hence for $\mathfrak q \subset B$ lying over $\mathfrak p$ the extension $\kappa(\mathfrak p) \subset \kappa(\mathfrak q)$ is a filtered colimit of finite separable extensions by Algebra, Lemma \ref{algebra-lemma-etale-over-field}.
If $A$ has weak dimension $\leq 1$, then the resolution $0 \to I \to A \to A/I \to 0$ shows that every ideal $I$ is flat by Lemma \ref{lemma-last-one-flat}. Hence (1) $\Rightarrow$ (2). \medskip\noindent Assume (4). Let $M$ be an $A$-module. Choose a surjection $F \to M$ where $F$ is a free $A$-module. Then $\Ker(F \to M)$ is flat by assumption, and we see that $M$ has tor dimension $\leq 1$ by Lemma \ref{lemma-tor-dimension}. Hence (4) $\Rightarrow$ (1). \medskip\noindent Every ideal is the union of the finitely generated ideals contained in it. Hence (3) implies (2) by Algebra, Lemma \ref{algebra-lemma-colimit-flat}. Thus (3) $\Leftrightarrow$ (2). \medskip\noindent Assume (2). Suppose that $N \subset M$ with $M$ a flat $A$-module. We will prove that $N$ is flat. We can write $M = \colim M_i$ with each $M_i$ finite free, see Algebra, Theorem \ref{algebra-theorem-lazard}. Setting $N_i \subset M_i$ the inverse image of $N$ we see that $N = \colim N_i$. By Algebra, Lemma \ref{algebra-lemma-colimit-flat}. it suffices to prove $N_i$ is flat and we reduce to the case $M = R^{\oplus n}$. In this case the module $N$ has a finite filtration by the submodules $R^{\oplus j} \cap N$ whose subquotients are ideals. By (2) these ideals are flat and hence $N$ is flat by Algebra, Lemma \ref{algebra-lemma-flat-ses}. Thus (2) $\Rightarrow$ (4). \medskip\noindent Assume $A$ satisfies (1) and let $\mathfrak p \subset A$ be a prime ideal. By Lemmas \ref{lemma-when-weakly-etale} and \ref{lemma-weak-dimension-goes-up} we see that $A_\mathfrak p$ satisfies (1). We will show $A$ is a valuation ring if $A$ is a local ring satisfying (3). Let $f \in \mathfrak m$ be a nonzero element. Then $(f)$ is a flat nonzero module generated by one element. Hence it is a free $A$-module by Algebra, Lemma \ref{algebra-lemma-finite-flat-local}. It follows that $f$ is a nonzerodivisor and $A$ is a domain. If $I \subset A$ is a finitely generated ideal, then we similarly see that $I$ is a finite free $A$-module, hence (by considering the rank) free of rank $1$ and $I$ is a principal ideal. Thus $A$ is a valuation ring by Algebra, Lemma \ref{algebra-lemma-characterize-valuation-ring}. Thus (1) $\Rightarrow$ (5). \medskip\noindent Assume (5). Let $I \subset A$ be a finitely generated ideal. Then $I_\mathfrak p \subset A_\mathfrak p$ is a finitely generated ideal in a valuation ring, hence principal (Algebra, Lemma \ref{algebra-lemma-characterize-valuation-ring}), hence flat. Thus $I$ is flat by Algebra, Lemma \ref{algebra-lemma-flat-localization}. Thus (5) $\Rightarrow$ (3). This finishes the proof of the lemma.
Let $I \subset A$ be a finitely generated ideal. By Lemma \ref{lemma-weak-dimension-at-most-1} it suffices to show that $I$ is a flat $A$-module. Let $I_j \subset A_j$ be the image of $I$. Observe that $I_j = I \otimes_A A_j$, hence $I \to \prod I_j$ is surjective by Algebra, Proposition \ref{algebra-proposition-fg-tensor}. Thus $I = \prod I_j$. Since $A_j$ is a valuation ring, the ideal $I_j$ is generated by a single element (Algebra, Lemma \ref{algebra-lemma-characterize-valuation-ring}). Say $I_j = (f_j)$. Then $I$ is generated by the element $f = (f_j)$. Let $e \in A$ be the idempotent which has a $0$ or $1$ in $A_j$ depending on whether $f_j$ is $0$ or not. Then $f = g e$ for some nonzerodivisor $g \in A$: take $g = (g_j)$ with $g_j = 1$ if $f_j = 0$ and $g_j = f_j$ else. Thus $I \cong (e)$ as a module. We conclude $I$ is flat as $(e)$ is a direct summand of $A$. The final statement is true because $K = S^{-1}A$ where $S = \prod (A_j \setminus \{0\})$.
For every $x \in K$, $x \not \in A$ pick $V_x \subset K$ as in Algebra, Lemma \ref{algebra-lemma-find-valuation-rings}. Set $V = \prod_{x \in K \setminus A} V_x$ and $L = \prod_{x \in K \setminus A} K$. The ring $V$ has weak dimension at most $1$ by Lemma \ref{lemma-product-weak-dimension-at-most-1} which also shows that $V \to L$ is a localization. A localization is flat and an epimorphism, see Algebra, Lemmas \ref{algebra-lemma-flat-localization} and \ref{algebra-lemma-epimorphism-local}.
Let $x \in B$ be integral over $A$. Let $A' = A[x] \subset B$. Then $A'$ is a finite ring extension of $A$ by Algebra, Lemma \ref{algebra-lemma-characterize-finite-in-terms-of-integral}. To show $A = A'$ it suffices to show $A \to A'$ is an epimorphism by Algebra, Lemma \ref{algebra-lemma-finite-epimorphism-surjective}. Note that $A'$ is flat over $A$ by assumption on $A$ and the fact that $B$ is flat over $A$ (Lemma \ref{lemma-weak-dimension-at-most-1}). Hence the composition $$ A' \otimes_A A' \to B \otimes_A A' \to B \otimes_A B \to B $$ is injective, i.e., $A' \otimes_A A' \cong A'$ and the lemma is proved.
Choose a diagram as in Lemma \ref{lemma-product-found-valuation-rings}. As $A \to B$ is flat, the base change gives a cartesian diagram $$ \xymatrix{ B \ar[d] \ar[r] & B \otimes_A K \ar[d] \\ B \otimes_A V \ar[r] & B \otimes_A L } $$ of rings. Note that $V \to B \otimes_A V$ is weakly \'etale (Lemma \ref{lemma-base-change-weakly-etale}), hence $B \otimes_A V$ has weak dimension at most $1$ by Lemma \ref{lemma-weak-dimension-goes-up}. Note that $B \otimes_A V \to B \otimes_A L$ is a flat, injective, epimorphism of rings as a flat base change of such (Algebra, Lemmas \ref{algebra-lemma-flat-base-change} and \ref{algebra-lemma-base-change-epimorphism}). By Lemma \ref{lemma-weak-dimension-at-most-1-integrally-closed} we see that $B \otimes_A V$ is integrally closed in $B \otimes_A L$. It follows from the cartesian property of the diagram that $B$ is integrally closed in $B \otimes_A K$.
Write $B$ as a filtered colimit $B = \colim B_i$ of finite $A$-sub algebras. If we prove the results for each $B_i$, then the result follows for $B$. See Algebra, Lemma \ref{algebra-lemma-colimit-henselian}. If $A \to B$ is finite, then $B$ is a product of local henselian rings by Algebra, Lemma \ref{algebra-lemma-finite-over-henselian}. Since $B$ is a domain we see that $B$ is a local ring. The maximal ideal of $B$ lies over the maximal ideal of $A$ by going up for $A \to B$ (Algebra, Lemma \ref{algebra-lemma-integral-going-up}). If $A$ is strictly henselian, then the field extension $\kappa(\mathfrak m_A) \subset \kappa(\mathfrak m_B)$ being algebraic, has to be purely inseparable. Of course, then $\kappa(\mathfrak m_B)$ is separably algebraically closed and $B$ is strictly henselian.
Any maximal ideal of $D$ lies over the maximal ideal of $B$ by going up for the integral ring map $B \to D$ (Algebra, Lemma \ref{algebra-lemma-integral-going-up}). Now $D/\mathfrak m_B D = \kappa(\mathfrak m_B) \otimes_A C = \kappa(\mathfrak m_B) \otimes_{\kappa(\mathfrak m_A)} C/\mathfrak m_A C$. The spectrum of $C/\mathfrak m_A C$ consists of a single point, namely $\mathfrak m_C$. Thus the spectrum of $D/\mathfrak m_B D$ is the same as the spectrum of $\kappa(\mathfrak m_B) \otimes_{\kappa(\mathfrak m_A)} \kappa(\mathfrak m_C)$ which is a single point by our assumption that either $\kappa(\mathfrak m_A) \subset \kappa(\mathfrak m_C)$ or $\kappa(\mathfrak m_A) \subset \kappa(\mathfrak m_B)$ is purely inseparable. This proves that $D$ is local and that the ring maps $B \to D$ and $C \to D$ are local.
Part (1) follows from Lemma \ref{lemma-absolutely-flat-over-absolutely-flat} but of course it follows from part (3) as well. Part (3) follows from Lemma \ref{lemma-absolutely-flat-over-field} and the fact that \'etale $K$-algebras are finite products of finite separable extensions of $K$, see Algebra, Lemma \ref{algebra-lemma-etale-over-field}. Part (3) implies (2). Part (4) follows from (3) as a product of fields is a field if and only if it has no nontrivial idempotents. \medskip\noindent If $S \subset B$ is a subalgebra, then it is the filtered colimit of its finitely generated subalgebras which are all \'etale over $K$ by the above and hence $S$ is weakly \'etale over $K$ by Lemma \ref{lemma-absolutely-flat-over-field}. If $B \to Q$ is a quotient algebra, then $Q$ is the filtered colimit of $K$-algebra quotients of finite products $\prod_{i \in I} L_i$ of finite separable extensions $L_i/K$. Such a quotient is of the form $\prod_{i \in J} L_i$ for some subset $J \subset I$ and hence the result holds for quotients by the same reasoning. \medskip\noindent The statement on tensor products follows in a similar manner or by combining Lemmas \ref{lemma-base-change-weakly-etale} and \ref{lemma-composition-weakly-etale}.
Let $B_1, B_2 \subset A$ be weakly \'etale $K$-subalgebras. Then $B_1 \otimes_K B_2$ is weakly \'etale over $K$ and so is the image of $B_1 \otimes_K B_2 \to A$ (Lemma \ref{lemma-class-weakly-etale-over-field}). Thus the collection $\mathcal{B}$ of weakly \'etale $K$-subalgebras $B \subset A$ is directed and the colimit $B_{max} = \colim_{B \in \mathcal{B}} B$ is a weakly \'etale $K$-algebra by Lemma \ref{lemma-when-weakly-etale}. Hence the image of $B_{max} \to A$ is weakly \'etale over $K$ (previous lemma cited). It follows that this image is in $\mathcal{B}$ and hence $\mathcal{B}$ has a maximal element (and the image is the same as $B_{max}$).
Proof of (1). This is true because the image of $B_{max}(A') \to A$ is weakly \'etale over $K$ by Lemma \ref{lemma-class-weakly-etale-over-field}. \medskip\noindent Proof of (2). By (1) we have $B_{max}(A') \subset B_{max}(A)$. Conversely, $B_{max}(A) \cap A'$ is a weakly \'etale $K$-algebra by Lemma \ref{lemma-class-weakly-etale-over-field} and hence contained in $B_{max}(A')$. \medskip\noindent Proof of (3). By (1) there is a map $\colim B_{max}(A_i) \to A$ which is injective because the system is filtered and $B_{max}(A_i) \subset A_i$. The colimit $\colim B_{max}(A_i)$ is weakly \'etale over $K$ by Lemma \ref{lemma-when-weakly-etale}. Hence we get an injective map $\colim B_{max}(A_i) \to B_{max}(A)$. Suppose that $a \in B_{max}(A)$. Then $a$ generates a finitely presented $K$-subalgebra $B \subset B_{max}(A)$. By Algebra, Lemma \ref{algebra-lemma-characterize-finite-presentation} there is an $i$ and a $K$-algebra map $f : B \to A_i$ lifting the given map $B \to A$. Since $B$ is weakly \'etale by Lemma \ref{lemma-class-weakly-etale-over-field}, we see that $f(B) \subset B_{max}(A_i)$ and we conclude that $a$ is in the image of $\colim B_{max}(A_i) \to B_{max}(A)$. \medskip\noindent Proof of (4). Write $B_{max}(A_{red}) = \colim B_i$ as a filtered colimit of \'etale $K$-algebras (Lemma \ref{lemma-absolutely-flat-over-field}). By Algebra, Lemma \ref{algebra-lemma-smooth-strong-lift} for each $i$ there is a $K$-algebra map $f_i : B_i \to A$ lifting the given map $B_i \to A_{red}$. It follows that the canonical map $B_{max}(A_{red}) \to B_{max}(A)$ is surjective. The kernel consists of nilpotent elements and hence is zero as $B_{max}(A_{red})$ is reduced (Lemma \ref{lemma-class-weakly-etale-over-field}). \medskip\noindent Proof of (5). Omitted. \medskip\noindent Proof of (6). Follows from Lemma \ref{lemma-class-weakly-etale-over-field} part (4).
First note that a minimal prime $\mathfrak r$ of $C$ maps to a minimal prime $\mathfrak p$ in $A$ and to a minimal prime $\mathfrak q$ of $B$ because the ring maps $A \to C$ and $B \to C$ are flat (by going down for flat ring map Algebra, Lemma \ref{algebra-lemma-flat-going-down}). Hence it suffices to show that the strict henselization of $(A/\mathfrak p \otimes_k B/\mathfrak q)_{ \mathfrak m_A \otimes_k B + A \otimes_k \mathfrak m_B}$ has a unique minimal prime ideal. By Algebra, Lemma \ref{algebra-lemma-quotient-strict-henselization} the rings $A/\mathfrak p$, $B/\mathfrak q$ are strictly henselian. Hence we may assume that $A$ and $B$ are strictly henselian local domains and our goal is to show that $C$ has a unique minimal prime. By Lemma \ref{lemma-geometrically-unibranch} the integral closure $A'$ of $A$ in its fraction field is a normal local domain with residue field $k$. Similarly for the integral closure $B'$ of $B$ into its fraction field. By Algebra, Lemma \ref{algebra-lemma-geometrically-normal-tensor-normal} we see that $A' \otimes_k B'$ is a normal ring. Hence its localization $$ R = (A' \otimes_k B')_{ \mathfrak m_{A'} \otimes_k B' + A' \otimes_k \mathfrak m_{B'}} $$ is a normal local domain. Note that $A \otimes_k B \to A' \otimes_k B'$ is integral (hence gong up holds -- Algebra, Lemma \ref{algebra-lemma-integral-going-up}) and that $\mathfrak m_{A'} \otimes_k B' + A' \otimes_k \mathfrak m_{B'}$ is the unique maximal ideal of $A' \otimes_k B'$ lying over $\mathfrak m_A \otimes_k B + A \otimes_k \mathfrak m_B$. Hence we see that $$ R = (A' \otimes_k B')_{ \mathfrak m_A \otimes_k B + A \otimes_k \mathfrak m_B} $$ by Algebra, Lemma \ref{algebra-lemma-unique-prime-over-localize-below}. It follows that $$ (A \otimes_k B)_{ \mathfrak m_A \otimes_k B + A \otimes_k \mathfrak m_B} \longrightarrow R $$ is integral. We conclude that $R$ is the integral closure of $(A \otimes_k B)_{ \mathfrak m_A \otimes_k B + A \otimes_k \mathfrak m_B}$ in its fraction field, and by Lemma \ref{lemma-geometrically-unibranch} once again we conclude that $C$ has a unique prime ideal.
By Lemma \ref{lemma-henselization-noetherian} the map $A^h \to A^\wedge$ is flat and injective. Combining going down (Algebra, Lemma \ref{algebra-lemma-flat-going-down}) and Algebra, Lemma \ref{algebra-lemma-injective-minimal-primes-in-image} we see that part (1) holds. Part (2) follows from this, Definition \ref{definition-number-of-branches}, and the fact that $A^\wedge$ is henselian (Algebra, Lemma \ref{algebra-lemma-complete-henselian}). By Lemma \ref{lemma-henselization-noetherian} we have $(A^\wedge)^{sh} = A^{sh} \otimes_{A^h} A^\wedge$. Thus we can repeat the arguments above using the flat injective map $A^{sh} \to (A^\wedge)^{sh}$ to prove (3).
Follows from Lemma \ref{lemma-nr-branches-completion} and the fact that there are only a finite number of branches for both $A$ and $A^\wedge$ by Algebra, Lemma \ref{algebra-lemma-Noetherian-irreducible-components} and the fact that $A^h$ and $A^\wedge$ are Noetherian (Lemma \ref{lemma-henselization-noetherian}).
Choose generators $f_1, \ldots, f_r$ of $I$. Write $$ C_{f_i} = (A_{f_i})_{e_i} $$ for some idempotent $e_i \in A_{f_i}$. Write $e_i = a_i/f_i^n$ for some $a_i \in A$ and $n \geq 0$; we may use the same $n$ for all $i = 1, \ldots, r$. After replacing $a_i$ by $f_i^ma_i$ and $n$ by $n + m$ for a suitable $m \gg 0$, we may assume $a_i^2 = f_i^n a_i$ for all $i$. Since $e_i$ maps to $1$ in $C_{f_if_j} = (A_{f_if_j})_{e_j} = A_{f_if_ja_j}$ we see that $$ (f_if_ja_j)^N(f_j^n a_i  - f_i^na_j) = 0 $$ for some $N$ (we can pick the same $N$ for all pairs $i, j$). Using $a_j^2 = f_j^na_j$ this gives $$ f_i^{N + n} f_j^{N + nN} a_j = f_i^N f_j^{N + n} a_ia_j^N $$ After increasing $n$ to $n + N + nN$ and replacing $a_i$ by $f_i^{N + nN}a_i$ we see that $f_i^n a_j$ is in the ideal of $a_i$ for all pairs $i, j$. Let $C' = A/(a_1, \ldots, a_r)$. Then $$ C'_{f_i} = A_{f_i}/(a_i) = A_{f_i}/(e_i) $$ because $a_j$ is in the ideal generated by $a_i$ after inverting $f_i$. Since for an idempotent $e$ of a ring $B$ we have $B = B_e \times B/(e)$ we see that the conclusion of the lemma holds for $f$ equal to one of $f_1, \ldots, f_r$. Using glueing of functions, in the form of Algebra, Lemma \ref{algebra-lemma-cover}, we conclude that the result holds for all $f \in I$. Namely, for $f \in I$ the elements $f_1, \ldots, f_r$ generate the unit ideal in $A_f$ so $A_f \to (C \times C')_f$ is an isomorphism if and only if this is the case after localizing at $f_1, \ldots, f_r$.
Let $f \in I$. Since $B^\wedge$ is Noetherian (Algebra, Lemma \ref{algebra-lemma-completion-Noetherian-Noetherian}), we see that $J$ is a finitely generated ideal. Hence we conclude from Algebra, Lemma \ref{algebra-lemma-ideal-is-squared-union-connected} that $$ C_f = ((B^\wedge)_f)_e $$ for some idempotent $e \in (B^\wedge)_f$. By Lemma \ref{lemma-glueing-sum-components-open} we can find a surjection $B^\wedge \to C'$ such that $B^\wedge \to C \times C'$ becomes an isomorphism after inverting any $f \in I$. Observe that $C \times C'$ is a finite $B^\wedge$-algebra. \medskip\noindent Choose generators $f_1, \ldots, f_r \in I$. Denote $\alpha_i : (C \times C')_{f_i} \to B_{f_i} \otimes_B B^\wedge$ the inverse of the isomorphism of $(B^\wedge)_{f_i}$-algebras we obtained above. Denote $\alpha_{ij} : (B_{f_i})_{f_j} \to (B_{f_j})_{f_i}$ the obvious $B$-algebra isomorphism. Consider the object $$ (C \times C', B_{f_i}, \alpha_i, \alpha_{ij}) $$ of the category $\text{Glue}(B \to B^\wedge, f_1, \ldots, f_r)$ introduced in Remark \ref{remark-glueing-data}. We omit the verification of conditions (1)(a) and (1)(b). Since $B \to B^\wedge$ is a flat map (Algebra, Lemma \ref{algebra-lemma-completion-flat}) inducing an isomorphism $B/IB \to B^\wedge/IB^\wedge$ we may apply Proposition \ref{proposition-equivalence} and Remark \ref{remark-formal-glueing-algebras}. We conclude that $C \times C'$ is isomorphic to $D \otimes_B B^\wedge$ for some finite $B$-algebra $D$. Then $D/ID \cong C/IC \times C'/IC'$. Let $\overline{e} \in D/ID$ be the idempotent corresponding to the factor $C/IC$. By Lemma \ref{lemma-lift-idempotent-upstairs} there exists an \'etale ring map $B \to B'$ which induces an isomorphism $B/IB \to B'/IB'$ such that $D' = D \otimes_B B'$ contains an idempotent $e$ lifting $\overline{e}$. Since $C \times C'$ is $I$-adically complete the pair $(C \times C', IC \times IC')$ is henselian (Lemma \ref{lemma-complete-henselian}). Thus we can factor the map $B \to C \times C'$ through $B'$. Doing so we may replace $B$ by $B'$ and $D$ by $D'$. Then we find that $D = D_e \times D_{1 - e} = D/(1 - e) \times D/(e)$ is a product of finite type $A$-algebras and the completion of the first part is $C$ and the completion of the second part is $C'$.