hcju/stacksqa huggingface dataset:
The question is local on $Y$ hence we may assume $Y$ affine. Let $K$ be an algebraic closure of the residue field $\kappa(y)$. Our assumption is that $(X_y)_K$ has $\geq d$ connected components. Then for a suitable quasi-compact open $X' \subset X$ the scheme $(X'_y)_K$ has $\geq d$ connected components; details omitted. After replacing $X$ by $X'$ we may assume $X$ is quasi-compact. Then $f$ is quasi-finite. Let $x_1, \ldots, x_n$ be the points of $X$ lying over $y$. Apply Lemma \ref{lemma-etale-splits-off-quasi-finite-part-technical-variant} to get an \'etale neighbourhood $(U, u) \to (Y, y)$ and a decomposition $$ U \times_Y X = W \amalg \ \coprod\nolimits_{i = 1, \ldots, n} \ \coprod\nolimits_{j = 1, \ldots, m_i} V_{i, j} $$ as in locus citatus. Observe that $n_{X/Y}(y) = \sum_i m_i$ in this situation; some details omitted. Since $f$ is universally open, we see that $V_{i, j} \to U$ is open for all $i, j$. Hence after shrinking $U$ we may assume $V_{i, j} \to U$ is surjective for all $i, j$. This proves that $n_{U \times_Y X/U} \geq \sum_i m_i = n_{X/Y}(y) \geq d$. Since the construction of $n_{X/Y}$ is compatible with base change the proof is complete.
The openness of $Y_d$ is immediate from Lemma \ref{lemma-count-geometric-fibres-universally-open}. To prove finiteness over $Y_d$ we redo the argument of the proof of that lemma. Namely, let $y \in Y_d$. Then there are at most $d$ points of $X$ lying over $y$. Say $x_1, \ldots, x_n$ are the points of $X$ lying over $y$. Apply Lemma \ref{lemma-etale-splits-off-quasi-finite-part-technical-variant} to get an \'etale neighbourhood $(U, u) \to (Y, y)$ and a decomposition $$ U \times_Y X = W \amalg \ \coprod\nolimits_{i = 1, \ldots, n} \ \coprod\nolimits_{j = 1, \ldots, m_i} V_{i, j} $$ as in locus citatus. Observe that $d = n_{X/Y}(y) = \sum_i m_i$ in this situation; some details omitted. Since $f$ is universally open, we see that $V_{i, j} \to U$ is open for all $i, j$. Hence after shrinking $U$ we may assume $V_{i, j} \to U$ is surjective for all $i, j$ and we may assume $U$ maps into $W$. This proves that $n_{U \times_Y X/U} \geq \sum_i m_i = d$. Since the construction of $n_{X/Y}$ is compatible with base change we know that $n_{U \times_Y X/U} = d$. This means that $W$ has to be empty and we conclude that $U \times_Y X \to U$ is finite. By Descent, Lemma \ref{descent-lemma-descending-property-finite} this implies that $X \to Y$ is finite over the image of the open morphism $U \to Y$. In other words, we see that $f$ is finite over an open neighbourhood of $y$ as desired.
This follows immediately from the second description of $\int_\pi w$ given above. To prove it from the definition, you use that if $E/F$ is a finite extension of fields and $F'/F$ is another field extension, then writing $(E \otimes_F F')_{red} = \prod E'_i$ as a product of fields finite over $F'$, we have $$ [E : F]_s = \sum [E'_i : F']_s $$ To prove this equality pick an algebraically closed field extension $\Omega/F'$ and observe that \begin{align*} [E : F]_s & = |\Mor_F(E, \Omega)| \\ & = |\Mor_{F'}(E \otimes_F F', \Omega)| \\ & = |\Mor_{F'}((E \otimes_F F')_{red}, \Omega)| \\ & = \sum |\Mor_{F'}(E'_i, \Omega)| \\ & = \sum [E'_i : F']_s \end{align*} where we have used Fields, Lemma \ref{fields-lemma-separable-degree}.
Consider a diagram $$ \xymatrix{ X' \ar[d]_{f'} & U' \ar[l]^{h'} \ar[d]^{\pi'} \\ Y' & V' \ar[l]_{g'} } $$ as in Definition \ref{definition-weighting} for the morphism $f'$. For any $v' \in V'$ we have to show that $\int_{\pi'} (w' \circ h')$ is constant in an open neighbourhood of $v'$. By Lemma \ref{lemma-weighting-check-after-etale-base-change} (and the fact that \'etale morphisms are open) we may replace $V'$ by any \'etale neighbourhood of $v'$. After replacing $V'$ by an \'etale neighbourhood of $v'$ we may assume that $U' = U'_1 \amalg \ldots \amalg U'_n$ where each $U'_i$ has a unique point $u'_i$ lying over $v'$ such that $\kappa(u'_i)/\kappa(v')$ is purely inseparable, see Lemma \ref{lemma-etale-splits-off-quasi-finite-part-technical-variant}. Clearly, it suffices to prove that $\int_{U'_i \to V'} w'|_{U'_i}$ is constant in a neighbourhood of $v'$. This reduces us to the case discussed in the next paragraph. \medskip\noindent We have $v' \in V'$ and there is a unique point $u'$ of $U'$ lying over $v'$ with $\kappa(u')/\kappa(v')$ purely inseparable. Denote $x \in X$ and $y \in Y$ the image of $u'$ and $v'$. We can find an \'etale neighbourhood $(V, v) \to (Y, y)$ and an open $U \subset X_V$ such that $\pi : U \to V$ is finite and such that there is a unique point $u \in U$ lying over $v$ which maps to $x \in X$ via the projection $h : U \to X$ such that moreover $\kappa(u)/\kappa(v)$ is purely inseparable. This is possible by the lemma used above. Consider the morphism $$ U'' = U \times_X U' \longrightarrow V \times_Y V' = V'' $$ Since $u$ and $u'$ both map to $x \in X$ there is a point $u'' \in U''$ mapping to $(u, u')$. Denote $v'' \in V''$ the image of $u''$. After replacing $V', v'$ by $V'', v''$  we may assume that the composition $V' \to Y' \to Y$ factors through a map of \'etale neighbourhoods $(V', v') \to (V, v)$ such that the induced morphism $X'_{V'} = X_{V'} \to X_V$ sends $u'$ to $u$. Inside the base change $X'_{V'} = X_{V'}$ we have two open subschemes, namely $U'$ and the inverse image $U_{V'}$ of $U \subset X_V$. By construction both contain a unique point lying over $v'$, namely $u'$ for both of them. Thus after shrinking $V'$ we may assume these open subsets are the same; namely, $U' \setminus (U' \cap U_{V'})$ and $U_{V'} \setminus (U' \cap U_{V'})$ have a closed image in $V'$ and these images do not contain $v'$. Thus $U' = U_{V'}$ and we find a cartesian diagram as in Lemma \ref{lemma-weighting-check-after-etale-base-change}. Since $\int_\pi (w \circ h)$ is locally constant by assumption we conclude.
Since the property is preserved by base change, see Lemma \ref{lemma-weighting-base-change}, it suffices to prove that $f$ is open. Since we may also replace $X$ by any open of $X$, it suffices to prove that $f(X)$ is open. Let $y \in f(X)$. Choose $x \in X$ with $f(x) = y$. It suffices to prove that $f(X)$ contains an open neighbourhood of $y$ and it suffices to do so after replacing $Y$ by an \'etale neighbourhood of $y$. By \'etale localization of quasi-finite morphisms, see Section \ref{section-etale-localization}, we may assume there is an open neighbourhood $U \subset X$ of $x$ such that $\pi = f|_U : U \to Y$ is finite. Then $\int_\pi w|_U$ is locally constant and has positive value at $y$. Hence $\pi(U)$ contains an open neighbourhood of $y$ and the proof is complete.
Consider a diagram as in Definition \ref{definition-weighting}. Let $u \in U$ with images $x, y, v$ in $X, Y, V$. Then we claim that $$ \text{length}_{\mathcal{O}_{X, x}} (\mathcal{O}_{X, x}/\mathfrak m_y \mathcal{O}_{X, x}) = \text{length}_{\mathcal{O}_{U, u}} (\mathcal{O}_{U, u}/\mathfrak m_v \mathcal{O}_{U, u}) $$ and $$ [\kappa(x) : \kappa(y)]_i = [\kappa(u) : \kappa(v)]_i $$ The first equality follows as $\mathcal{O}_{X, x} \to \mathcal{O}_{U, u}$ is a flat local homomorphism such that $\mathfrak m_y \mathcal{O}_{U, u} = \mathfrak m_v \mathcal{O}_{U, u}$ and $\mathfrak m_x \mathcal{O}_{U, u} = \mathfrak m_u$ (because $\mathcal{O}_{Y, y} \to \mathcal{O}_{V, v}$ and $\mathcal{O}_{X, x} \to \mathcal{O}_{U, u}$ are unramified) and hence the equality by Algebra, Lemma \ref{algebra-lemma-pullback-module}. The second equality follows because $\kappa(v)/\kappa(y)$ is a finite separable extension and $\kappa(u)$ is a factor of $\kappa(x) \otimes_{\kappa(y)} \kappa(v)$ and hence the inseparable degree is unchanged. Having said this, we see that formation of the function in the lemma commutes with \'etale base change. This reduces the problem to the discussion of the next paragraph. \medskip\noindent Assume that $f$ is a finite, flat morphism of finite presentation. We have to show that $\int_f w$ is locally constant on $Y$. In fact, $f$ is finite locally free (Morphisms, Lemma \ref{morphisms-lemma-finite-flat}) and we will show that $\int_f w$ is equal to the degree of $f$ (which is a locally constant function on $Y$). Namely, for $y \in Y$ we see that \begin{align*} (\textstyle{\int}_f w)(y) & = \sum\nolimits_{f(x) = y} \text{length}_{\mathcal{O}_{X, x}} (\mathcal{O}_{X, x}/\mathfrak m_y \mathcal{O}_{X, x}) [\kappa(x) : \kappa(y)]_i [\kappa(x) : \kappa(y)]_s \\ & = \sum\nolimits_{f(x) = y} \text{length}_{\mathcal{O}_{X, x}} (\mathcal{O}_{X, x}/\mathfrak m_y \mathcal{O}_{X, x}) [\kappa(x) : \kappa(y)] \\ & = \text{length}_{\mathcal{O}_{Y, y}}((f_*\mathcal{O}_X)_y/ \mathfrak m_y (f_*\mathcal{O}_X)_y) \end{align*} Last equality by Algebra, Lemma \ref{algebra-lemma-pushdown-module}. The final number is the rank of $f_*\mathcal{O}_X$ at $y$ as desired.
It follows from Algebra, Lemmas \ref{algebra-lemma-quasi-finite-strict-henselization} and \ref{algebra-lemma-characterize-henselian} that $\mathcal{O}_{Y, y}^{sh} \to \mathcal{O}_{X, x}^{sh}$ is finite. Since $Y$ is unibranch there is a unique minimal prime $\mathfrak p$ in $\mathcal{O}_{Y, y}^{sh}$. Write $$ (\kappa(\mathfrak p) \otimes_{\mathcal{O}_{Y, y}^{sh}} \mathcal{O}_{X, x}^{sh})_{red} = \prod K_i $$ as a finite product of fields. We set $w(x) = \sum [K_i : \kappa(\mathfrak p)]_s$. \medskip\noindent Since this definition is clearly insensitive to \'etale localization, in order to show that $w$ is a weighting we reduce to showing that if $f$ is a finite morphism, then $\int_f w$ is locally constant. Observe that the value of $\int_f w$ in a generic point $\eta$ of $Y$ is just the number of points of the geometric fibre $X_{\overline{\eta}}$ of $X \to Y$ over $\eta$. Moreover, since $Y$ is unibranch a point $y$ of $Y$ is the specialization of a unique generic point $\eta$. Hence it suffices to show that $(\int_f w)(y)$ is equal to the number of points of $X_{\overline{\eta}}$. After passing to an affine neighbourhood of $y$ we may assume $X \to Y$ is given by a finite ring map $A \to B$. Suppose $\mathcal{O}_{Y, y}^{sh}$ is constructed using a map $\kappa(y) \to k$ into an algebraically closed field $k$. Then $$ \mathcal{O}_{Y, y}^{sh} \otimes_A B = \prod\nolimits_{f(x) = y} \prod\nolimits_{\varphi \in \Mor_{\kappa(y)}(\kappa(x), k)} \mathcal{O}_{X, x}^{sh} $$ by the references on strict henselization given above. Observe that the minimal prime $\mathfrak p$ of $\mathcal{O}_{Y, y}^{sh}$ maps to the prime of $A$ corresponding to $\eta$. Hence we see that the desired equality holds because the number of points of a geometric fibre is unchanged by a field extension.
The question is Zariski local on $X$ and $Y$, hence we may assume $X$ and $Y$ are affine. (Observe that the restriction of a weighting to an open is a weighting of the restriction of $f$ to that open.) By Lemma \ref{lemma-weighting-base-change} after base change we still have a weighthing. If we can find a surjective morphism $Y' \to Y$ of finite presentation such that the level sets of $w$ pull back to locally constructible subsets of $X' = Y' \times_Y X$, then we conclude by Morphisms, Theorem \ref{morphisms-theorem-chevalley}. We may choose an immersion $X \to T$ where $T \to Y$ is finite, see Lemma \ref{lemma-quasi-finite-separated-pass-through-finite}. By Morphisms, Lemma \ref{morphisms-lemma-massage-finite} after replacing $Y$ by $Y'$ surjective finite locally free over $Y$, replacing $X$ by $Y' \times_Y X$ and $T$ by a scheme finite locally free over $Y'$ containing $Y' \times_Y T$ as a closed subscheme, we may assume $T$ is finite locally free over $Y$, contains closed subschemes $T_i$ mapping isomorphically to $Y$ such that $T = \bigcup_{i = 1, \ldots, n} T_i$ (set theoretically). Observe that for $I \subset \{1, \ldots, n\}$ the intersection $\bigcap_{i \in I} T_i$ is a constructible closed subset of $T$ (and hence maps to a constructible closed subset of $Y$). \medskip\noindent For a disjoint union decomposition $\{1, \ldots, n\} = I_1 \amalg \ldots \amalg I_r$ with nonempty parts consider the subset $Y_{I_1, \ldots, I_r} \subset Y$ consisting of points $y \in Y$ such that $T_y = \{x_1, \ldots, x_r\}$ consists of exactly $r$ points with $x_j \in T_i \Leftrightarrow i \in I_j$. This is a constructible partition of $Y$, hence we may assume that $Y = Y_{I_1, \ldots, I_r}$ for some disjoint union decomposition $\{1, \ldots, n\} = I_1 \amalg \ldots \amalg I_r$. (You can base change by an affine scheme $Y'$ of finite presentation over $Y$ such that the image of $Y' \to Y$ is exactly $Y_{I_1, \ldots, I_r}$, see Algebra, Lemma \ref{algebra-lemma-constructible-is-image}.) Thus $T = T(1) \amalg \ldots \amalg T(r)$ with $T(j) = \bigcap_{i \in I_j} T_i$ is a decomposition of $T$ into disjoint closed (and hence open) subsets. Intersecting with the locally closed subscheme $X$ we obtain an analogous decomposition $X = X(1) \amalg \ldots \amalg X(r)$ into open and closed parts. The morphism $X(j) \to Y$ an immersion. Since $w$ is a weigthing, it follows that $w|_{X(j)}$ is locally constant\footnote{In fact, if $f : X \to Y$ is an immersion and $w$ is a weighting of $f$, then $f$ restricts to an open map on the locus where $w$ is nonzero.} and we conclude.
By Lemma \ref{lemma-weighting-check-after-etale-base-change} formation of the function $\int_f w$ commutes with arbitrary base change and by Lemma \ref{lemma-weighting-base-change} after base change we still have a weighthing. This means that if we can find $Y' \to Y$ surjective and of finite presentation, then it suffices to prove the result after base change to $Y'$, see Morphisms, Theorem \ref{morphisms-theorem-chevalley}. \medskip\noindent The question is local on $Y$ hence we may assume $Y$ is affine. Then $X$ is quasi-compact and quasi-separated (as $f$ is of finite presentation). Suppose that $X = U \cup V$ are quasi-compact open. Then we have $$ \textstyle{\int}_f w = \textstyle{\int}_{f|_U} w|_U + \textstyle{\int}_{f|_V} w|_V - \textstyle{\int}_{f|_{U \cap V}} w|_{U \cap V} $$ Thus if we know the result for $w|_U$, $w|_V$, $w|_{U \cap V}$ then we know the result for $w$. By the induction principle (Cohomology of Schemes, Lemma \ref{coherent-lemma-induction-principle}) it suffices to prove the lemma when $X$ is affine. \medskip\noindent Assume $X$ and $Y$ are affine. We may choose an open immersion $X \to T$ where $T \to Y$ is finite, see Lemma \ref{lemma-quasi-finite-separated-pass-through-finite}. Because we may still base change with a suitable $Y' \to Y$ we can use Morphisms, Lemma \ref{morphisms-lemma-massage-finite} to reduce to the case where all residue field extensions induced by the morphism $T \to Y$ (and a foriori induced by $X \to Y$) are trivial. In this situation $\int_f w$ is just taking the sums of the values of $w$ in fibres. The level sets of $w$ are locally constructible in $X$ (Lemma \ref{lemma-jumps-w}). The function $w$ only takes a finite number of values by Properties, Lemma \ref{properties-lemma-stratification-locally-finite-constructible}. Hence we conclude by Morphisms, Theorem \ref{morphisms-theorem-chevalley} and some elementary arguments on sums of integers.
Let $x \in X$ with image $y \in Y$. Choose an \'etale neighbourhood $(V, v) \to (Y, y)$ and an open $U \subset X_V$ such that $\pi : U \to V$ is finite and there is a unique point $u \in U$ mapping to $v$ with $\kappa(u)/\kappa(v)$ purely inseparable. See Lemma \ref{lemma-etale-makes-quasi-finite-finite-multiple-points-var}. Then $(\int_\pi w|_U)(v) = w(u)$. It follows from Definition \ref{definition-weighting} that after replacing $V$ by a neighbourhood of $v$ we we have $w|_U(u') \leq w|_U(u) = w(x)$ for all $u' \in U$. Namely, $w|_U(u')$ occurs as a summand in the expression for $(\int_\pi w|_U)(\pi(u'))$. This proves the lemma because the \'etale morphism $U \to X$ is open.
Let $y \in Y$. Let $x_1, \ldots, x_r \in X$ be the points lying over $y$. Apply Lemma \ref{lemma-etale-splits-off-quasi-finite-part-technical-variant} to get an \'etale neighbourhood $(U, u) \to (Y, y)$ and a decomposition $$ U \times_Y X = W \amalg \ \coprod\nolimits_{i = 1, \ldots, n} \ \coprod\nolimits_{j = 1, \ldots, m_i} V_{i, j} $$ as in locus citatus. Observe that $(\int_f w)(y) = \sum w(v_{i, j})$ where $w(v_{i, j}) = w(x_i)$. Since $\int_{V_{i, j} \to U} w|_{V_{i, j}}$ is locally constant by definition, we may after shrinking $U$ assume these functions are constant with value $w(v_{i, j})$. We conclude that $$ \textstyle{\int}_{U \times_Y X \to U} w|_{U \times_Y X} = \textstyle{\int}_{W \to U} w|_W + \sum \textstyle{\int}_{V_{i, j} \to U} w|_{V_{i, j}} = \textstyle{\int}_{W \to U} w|_W + (\int_f w)(y) $$ This is $\geq (\int_f w)(y)$ and we conclude because $U \to Y$ is open and formation of the integral commutes with base change (Lemma \ref{lemma-weighting-check-after-etale-base-change}).
It follows from Lemma \ref{lemma-jumps-w} and Properties, Lemma \ref{properties-lemma-stratification-locally-finite-constructible} that $w$ only takes a finite number of values on $X$. It follows from Morphisms, Lemma \ref{morphisms-lemma-locally-quasi-finite-qc-source-universally-bounded} that $X \to Y$ has bounded geometric fibres. This shows that $\int_f w$ is bounded.
Observe that $Y_d$ is open by Lemma \ref{lemma-semicontinuous-int-w}. Let $y \in Y_d$. Say $x_1, \ldots, x_n$ are the points of $X$ lying over $y$. Apply Lemma \ref{lemma-etale-splits-off-quasi-finite-part-technical-variant} to get an \'etale neighbourhood $(U, u) \to (Y, y)$ and a decomposition $$ U \times_Y X = W \amalg \ \coprod\nolimits_{i = 1, \ldots, n} \ \coprod\nolimits_{j = 1, \ldots, m_i} V_{i, j} $$ as in locus citatus. Observe that $d = \sum w(v_{i, j})$ where $w(v_{i, j}) = w(x_i)$. Since $\int_{V_{i, j} \to U} w|_{V_{i, j}}$ is locally constant by definition, we may after shrinking $U$ assume these functions are constant with value $w(v_{i, j})$. We conclude that $$ \textstyle{\int}_{U \times_Y X \to U} w|_{U \times_Y X} = \textstyle{\int}_{W \to U} w|_W + \sum \textstyle{\int}_{V_{i, j} \to U} w|_{V_{i, j}} = \textstyle{\int}_{W \to U} w|_W + (\int_f w)(y) $$ This is $\geq (\int_f w)(y) = d$ and we conclude that $W$ must be the emptyset. Thus $U \times_Y X \to U$ is finite. By Descent, Lemma \ref{descent-lemma-descending-property-finite} this implies that $X \to Y$ is finite over the image of the open morphism $U \to Y$. In other words, we see that $f$ is finite over an open neighbourhood of $y$ as desired.
Choose $b_1, \ldots, b_n \in B$ generating $B$ as an $A$-module. For each $i$ choose a monic $P_i \in A[x]$ such that $P_i(b_i) = 0$ in $B$, see Algebra, Lemma \ref{algebra-lemma-finite-is-integral}. Thus $B$ is a quotient of the finite free $A$-algebra $B' = A[x_1, \ldots, x_n]/(P_1(x_1), \ldots, P_n(x_n))$. Let $J \subset B'$ be the kernel of the surjection $B' \to B$. Then $J =(f_1, \ldots, f_m)$ is finitely generated as $B$ is a finitely generated $A$-algebra, see Algebra, Lemma \ref{algebra-lemma-compose-finite-type}. Choose an $A$-basis $b'_1, \ldots, b'_N$ of $B'$. Consider the algebra $$ A_{univ} = A[z_1, \ldots, z_N, y_1, \ldots, y_m]/I $$ where $I$ is the ideal generated by the coefficients in $A[z_1, \ldots, z_n, y_1, \ldots, y_m]$ of the basis elements $b'_1, \ldots, b'_N$ of the expresssion $$ (\sum z_j b'_j)^2 - \sum z_j b'_j + \sum y_k f_k $$ in $B'[z_1, \ldots, z_N, y_1, \ldots, y_m]$. By construction the element $\sum z_j b'_j$ maps to an idempotent $e_{univ}$ in the algebra $B \otimes_A A_{univ}$. Moreover, if $e \in B \otimes_A A'$ is an idempotent, then we can lift $e$ to an element of the form $\sum b'_j \otimes a'_j$ in $B' \otimes_A A'$ and we can find $a''_k \in A'$ such that $$ (\sum b'_j \otimes a'_j)^2 - \sum b'_j \otimes a'_j + \sum f_k \otimes a''_k $$ is zero in $B' \otimes_A A'$. Hence we get an $A$-algebra map $A_{univ} \to A$ sending $z_j$ to $a'_j$ and $y_k$ to $a''_k$ mapping $e_{univ}$ to $e$. This finishes the proof.
Recall that a finite type morphism is quasi-finite if and only if it has relative dimension $0$, see Morphisms, Lemma \ref{morphisms-lemma-locally-quasi-finite-rel-dimension-0}. By Lemma \ref{lemma-Noetherian-approximation-dimension-d} applied with $d = 0$ we reduce to the case where $X$ and $Y$ are Noetherian. We may choose an open immersion $X \to X'$ such that $X' \to Y$ is finite, see Algebra, Lemma \ref{algebra-lemma-quasi-finite-open-integral-closure}. Note that if we have $Y' \to Y$ and $U'$ as in (2), then $$ U' \to Y' \times_Y X \to Y' \times_Y X' $$ is open immersion between schemes finite over $Y'$ and hence is closed as well. We conclude that $U'$ corresponds to an idempotent in $$ \Gamma(Y', \mathcal{O}_{Y'}) \otimes_{\Gamma(Y, \mathcal{O}_Y)} \Gamma(X', \mathcal{O}_{X'}) $$ whose corresponding open and closed subset is contained in the open $Y' \times_Y X$. Let $Y'_{univ} \to Y$ and idempotent $$ e'_{univ} \in \Gamma(Y_{univ}, \mathcal{O}_{Y_{univ}}) \otimes_{\Gamma(Y, \mathcal{O}_Y)} \Gamma(X', \mathcal{O}_{X'}) $$ be the pair constructed in Lemma \ref{lemma-open-and-closed-in-finite} for the ring map $\Gamma(Y, \mathcal{O}_Y) \to \Gamma(X', \mathcal{O}_{X'})$ (here we use that $Y$ is Noetherian to see that $X'$ is of finite presentation over $Y$). Let $U'_{univ} \subset Y'_{univ} \times_Y X'$ be the corresponding open and closed subscheme. Then we see that $$ U'_{univ} \setminus Y'_{univ} \times_Y X $$ is a closed subset of $U'_{univ}$ and hence has closed image $T \subset Y'_{univ}$. If we set $Y_{univ} = Y'_{univ} \setminus T$ and $U_{univ}$ the restriction of $U'_{univ}$ to $Y_{univ} \times_Y X$, then we see that the lemma is true.
By Lemma \ref{lemma-jumps-w} the level sets of $w$ are constructible subsets $E_k$ of $X$. This implies the function $w$ only takes a finite number of values by Properties, Lemma \ref{properties-lemma-stratification-locally-finite-constructible}. Thus there exists an $i$ such that $E_k$ descends to a construcible subset $E_{i, k}$ in $X_i$ for all $k$; moreover, we may assume $X_i = \coprod E_{i, k}$. This follows as the topological space of $X$ is the limit in the category of topological spaces of the spectral spaces $X_i$ along a directed system with spectral transition maps. See Limits, Section \ref{limits-section-descent} and Topology, Section \ref{topology-section-limits-spectral}. We define $w_i : X_i \to \mathbf{Z}$ such that its level sets are the constructible sets $E_{i, k}$. \medskip\noindent Choose $Y_{i, univ} \to Y_i$ and $U_{i, univ} \subset Y_{i, univ} \times_{Y_i} X_i$ as in Lemma \ref{lemma-open-and-closed-in-quasi-finite}. By the universal property of the construction, in order to show that $w_i$ is a weighting, it would suffice to show that $$ \tau_i = \textstyle{\int}_{U_{i, univ} \to Y_{i, univ}} w_i|_{U_{i, univ}} $$ is locally constant on $Y_{i, univ}$. By Lemma \ref{lemma-jumps-int-w} this function has constructible level sets but it may not (yet) be locally constant. Set $Y_{univ} = Y_{i, univ} \times_{Y_i} Y$ and let $U_{univ} \subset Y_{univ} \times_Y X$ be the inverse image of $U_{i, univ}$. Then, since the pullback of $w$ to $Y_{univ} \times_Y X$ is a weighting for $Y_{univ} \times_Y X \to Y_{univ}$ (Lemma \ref{lemma-weighting-base-change}) we do have that $$ \tau = \textstyle{\int}_{U_{univ} \to Y_{univ}} w_i|_{U_{univ}} $$ is locally constant on $Y_{univ}$. Thus the level sets of $\tau$ are open and closed. Finally, we have $Y_{univ} = \lim_{i' \geq i} Y_{i', univ}$ and the level sets of $\tau$ are the inverse limits of the level sets of $\tau_{i'}$ (similarly defined). Hence the references above imply that for sufficiently large $i'$ the level sets of $\tau_{i'}$ are open as well. For such an index $i'$ we conclude that $w_{i'}$ is a weighting of $f_{i'}$ as desired.