hcju/stacksqa huggingface dataset:
Using Lemma \ref{lemma-relative-dualizing-complex-algebra} and the algebraic version of this lemma (Dualizing Complexes, Lemma \ref{dualizing-lemma-relative-dualizing-composition}) we see that $E$ is affine locally the first component of a relative dualizing complex. In particular we see that $E$ is $S$-perfect since this may be checked affine locally, see Derived Categories of Schemes, Lemma \ref{perfect-lemma-affine-locally-rel-perfect}. \medskip\noindent Let us first prove the existence of $\zeta$ in case the morphisms $X \to S$ and $Y \to X$ are separated so that $\Delta_{X/S}$, $\Delta_{Y/X}$, and $\Delta_{Y/S}$ are closed immersions. Consider the following diagram $$ \xymatrix{ & & Y \ar@{=}[r] & Y \ar[d]^f \\ Y \ar[r]_{\Delta_{Y/X}} & Y \times_X Y \ar[d]_m \ar[r]_\delta \ar[ru]_q & Y \times_S Y \ar[d]^{f \times f} \ar[ru]_p & X\\ & X \ar[r]^{\Delta_{X/S}} & X \times_S X \ar[ru]_r } $$ where $p$, $q$, $r$ are the first projections. By Lemma \ref{lemma-sheaf-with-exact-support-internal-home} we have $$ R\SheafHom_{\mathcal{O}_{Y \times_S Y}}( \Delta_{Y/S, *}\mathcal{O}_Y, Lp^*E) = R\delta_*\left(R\SheafHom_{\mathcal{O}_{Y \times_X Y}}( \Delta_{Y/X, *}\mathcal{O}_Y, R\SheafHom(\mathcal{O}_{Y \times_X Y}, Lp^*E))\right) $$ By Lemma \ref{lemma-sheaf-with-exact-support-tensor} we have $$ R\SheafHom(\mathcal{O}_{Y \times_X Y}, Lp^*E) = R\SheafHom(\mathcal{O}_{Y \times_X Y}, L(f \times f)^*Lr^*K) \otimes_{\mathcal{O}_{Y \times_S Y}}^\mathbf{L} Lq^*M $$ By Lemma \ref{lemma-flat-bc-sheaf-with-exact-support} we have $$ R\SheafHom(\mathcal{O}_{Y \times_X Y}, L(f \times f)^*Lr^*K) = Lm^*R\SheafHom(\mathcal{O}_X, Lr^*K) $$ The last expression is isomorphic (via $\xi$) to $Lm^*\mathcal{O}_X = \mathcal{O}_{Y \times_X Y}$. Hence the expression preceding is isomorphic to $Lq^*M$. Hence $$ R\SheafHom_{\mathcal{O}_{Y \times_S Y}}( \Delta_{Y/S, *}\mathcal{O}_Y, Lp^*E) = R\delta_*\left(R\SheafHom_{\mathcal{O}_{Y \times_X Y}}( \Delta_{Y/X, *}\mathcal{O}_Y, Lq^*M)\right) $$ The material inside the parentheses is isomorphic to $\Delta_{Y/X, *}*\mathcal{O}_X$ via $\eta$. This finishes the proof in the separated case. \medskip\noindent In the general case we choose an open $W \subset X \times_S X$ such that $\Delta_{X/S}$ factors through a closed immersion $\Delta : X \to W$ and we choose an open $V \subset Y \times_X Y$ such that $\Delta_{Y/X}$ factors through a closed immersion $\Delta' : Y \to V$. Finally, choose an open $W' \subset Y \times_S Y$ whose intersection with $Y \times_X Y$ gives $V$ and which maps into $W$. Then we consider the diagram $$ \xymatrix{ & & Y \ar@{=}[r] & Y \ar[d]^f \\ Y \ar[r]_{\Delta'} & V \ar[d]_m \ar[r]_\delta \ar[ru]_q & W' \ar[d]^{f \times f} \ar[ru]_p & X\\ & X \ar[r]^\Delta & W \ar[ru]_r } $$ and we use exactly the same argument as before.
The assumption implies that $X$ is compactifyable over $Y$ hence $f^!$ is defined, see Section \ref{section-upper-shriek}. Let $j : W \to P$ be an open subscheme such that $X \to P$ factors through a closed immersion $i : X \to W$. Moreover, we have $f^! = i^! \circ j^! \circ g^!$ where $g : P \to Y$ is the given morphism. We have $g^!\mathcal{O}_Y = \wedge^d\Omega_{P/Y}[d]$ by Lemma \ref{lemma-smooth-proper} where $d$ is the locally constant function giving the relative dimension of $P$ over $Y$. We have $j^! = j^*$. We have $i^!\mathcal{O}_W = \wedge^c\mathcal{N}[-c]$ where $c$ is the codimension of $X$ in $W$ (a locally constant function on $X$) and where $\mathcal{N}$ is the normal sheaf of the Koszul-regular immersion $i$, see Lemma \ref{lemma-regular-immersion}. Combining the above we find $$ f^!\mathcal{O}_Y = \left(\wedge^c\mathcal{N} \otimes_{\mathcal{O}_X} \wedge^d\Omega_{P/Y}|_X\right)[d - c] $$ where we have also used Lemma \ref{lemma-perfect-comparison-shriek}. Thus $r = d|_X - c$ as locally constant functions on $X$. The conormal sheaf of $X \to P$ is the module $\mathcal{I}/\mathcal{I}^2$ where $\mathcal{I} \subset \mathcal{O}_W$ is the ideal sheaf of $i$, see Morphisms, Section \ref{morphisms-section-conormal-sheaf}. Consider the canonical exact sequence $$ \mathcal{I}/\mathcal{I}^2 \to \Omega_{P/Y}|_X \to \Omega_{X/Y} \to 0 $$ of Morphisms, Lemma \ref{morphisms-lemma-differentials-relative-immersion}. We obtain our map by an application of Lemma \ref{lemma-determinant}. \medskip\noindent If $f$ is smooth at $x$, then the map is an isomorphism by an application of Lemma \ref{lemma-determinant} and the fact that $\Omega_{X/Y}$ is locally free at $x$ of rank $r$. Conversely, assume that our map is an isomorphism on stalks at $x$. Then the lemma shows that $\Omega_{X/Y}$ is free of rank $r$ after replacing $X$ by an open neighbourhood of $x$. On the other hand, we may also assume that $X = \Spec(A)$ and $Y = \Spec(R)$ where $A = R[x_1, \ldots, x_n]/(f_1, \ldots, f_m)$ and where $f_1, \ldots, f_m$ is a Koszul regular sequence (this follows from the definition of local complete intersection morphisms). Clearly this implies $r = n - m$. We conclude that the rank of the matrix of partials $\partial f_j/\partial x_i$ in the residue field at $x$ is $m$. Thus after reordering the variables we may assume the determinant of $(\partial f_j/\partial x_i)_{1 \leq i, j \leq m}$ is invertible in an open neighbourhood of $x$. It follows that $R \to A$ is smooth at this point, see for example Algebra, Example \ref{algebra-example-make-standard-smooth}.
Let $U \subset X$ be the open subscheme over which $f$ is a local complete intersection morphism. Since $f$ has relative dimension $r$ at all generic points by assumption (4) we see that the locally constant function of Lemma \ref{lemma-fundamental-class-lci} is constant with value $r$ and we obtain a map $$ \wedge^r\Omega_{X/Y}|_U = \wedge^r \Omega_{U/Y} \longrightarrow \omega_{U/Y} = \omega_{X/Y}|_U $$ which is an isomorphism in the smooth points of $f$ (this locus is contained in $U$ because a smooth morphism is a local complete intersection morphism). By Lemma \ref{lemma-shriek-over-CM} and the assumption that $Y$ is Cohen-Macaulay the module $\omega_{X/Y}$ is $(S_2)$. Since $U$ contains all the points of codimension $1$ by condition (3) and using Divisors, Lemma \ref{divisors-lemma-depth-2-hartog} we see that $j_*\omega_{U/Y} = \omega_{X/Y}$. Hence the map over $U$ extends to $X$ and the proof is complete.
Part (1) is an immediate consequence of Lemma \ref{lemma-lift-map} and the fact that morphisms between pro-systems are the same as morphisms between the functors they corepresent, see Categories, Remark \ref{categories-remark-pro-category-copresheaves}. \medskip\noindent Let $K$ be as in (2). We can choose $K' \in D^b_{\textit{Coh}}(\mathcal{O}_X)$ whose restriction to $U$ is isomorphic to $K$, see Derived Categories of Schemes, Lemma \ref{perfect-lemma-lift-coherent}. By Derived Categories of Schemes, Proposition \ref{perfect-proposition-DCoh} we can represent $K'$ by a bounded complex $\mathcal{F}^\bullet$ of coherent $\mathcal{O}_X$-modules. Choose a quasi-coherent sheaf of ideals $\mathcal{I} \subset \mathcal{O}_X$ whose vanishing locus is $X \setminus U$ (for example choose $\mathcal{I}$ to correspond to the reduced induced subscheme structure on $X \setminus U$). Then we can set $K_n$ equal to the object represented by the complex $\mathcal{I}^n\mathcal{F}^\bullet$ as in the introduction to this section. \medskip\noindent Part (3) is immediate from parts (1) and (2).
Let $(K_n)$ be as in Lemma \ref{lemma-extension-by-zero} part (2). Choose an object $L'$ of $D^b_{\textit{Coh}}(\mathcal{O}_X)$ whose restriction to $U$ is $L$ (we can do this as the lemma shows). By Lemma \ref{lemma-lift-map} we can find an $n$ and a morphism $K_n \to L'$ on $X$ whose restriction to $U$ is the given arrow $K \to L$. We conclude there is a morphism $K' \to L'$ of $D^b_{\textit{Coh}}(\mathcal{O}_X)$ whose restriction to $U$ is the given arrow $K \to L$. \medskip\noindent By Derived Categories of Schemes, Proposition \ref{perfect-proposition-DCoh} we can find a morphism $\alpha^\bullet : \mathcal{F}^\bullet \to \mathcal{G}^\bullet$ of bounded complexes of coherent $\mathcal{O}_X$-modules representing $K' \to L'$. Choose a quasi-coherent sheaf of ideals $\mathcal{I} \subset \mathcal{O}_X$ whose vanishing locus is $X \setminus U$. Then we let $K_n = \mathcal{I}^n\mathcal{F}^\bullet$ and $L_n = \mathcal{I}^n\mathcal{G}^\bullet$. Observe that $\alpha^\bullet$ induces a morphism of complexes $\alpha_n^\bullet : \mathcal{I}^n\mathcal{F}^\bullet \to \mathcal{I}^n\mathcal{G}^\bullet$. From the construction of cones in Derived Categories, Section \ref{derived-section-cones} it is clear that $$ C(\alpha_n)^\bullet = \mathcal{I}^nC(\alpha^\bullet) $$ and hence we can set $M_n = C(\alpha_n)^\bullet$. Namely, we have a compatible system of distinguished triangles (see discussion in Derived Categories, Section \ref{derived-section-canonical-delta-functor}) $$ K_n \to L_n \to M_n \to K_n[1] $$ whose restriction to $U$ is isomorphic to the distinguished  triangle we started out with by axiom TR3 and Derived Categories, Lemma \ref{derived-lemma-third-isomorphism-triangle}.
Observe that the systems $(K_n|_U)$ and $(M_n|_U)$ are essentially constant as they are pro-isomorphic to constant systems. Denote $K$ and $M$ their values. By Derived Categories, Lemma \ref{derived-lemma-essentially-constant-2-out-of-3} we see that the inverse system $L_n|_U$ is essentially constant as well. Denote $L$ its value. Let $N \in D^b_{\textit{Coh}}(\mathcal{O}_X)$. Consider the commutative diagram $$ \xymatrix{ \ldots \ar[r] & \colim \Hom_X(M_n, N) \ar[r] \ar[d] & \colim \Hom_X(L_n, N) \ar[r] \ar[d] & \colim \Hom_X(K_n, N) \ar[r] \ar[d] & \ldots \\ \ldots \ar[r] & \Hom_U(M, N|_U) \ar[r] & \Hom_U(L, N|_U) \ar[r] & \Hom_U(K, N|_U) \ar[r] & \ldots } $$ By Lemma \ref{lemma-lift-map} and the fact that isomorphic ind-systems have the same colimit, we see that the vertical arrows two to the right and two to the left of the middle one are isomorphisms. By the 5-lemma we conclude that the middle vertical arrow is an isomorphism. Now, if $(L'_n)$ is a Deligne system whose restriction to $U$ has constant value $L$ (which exists by Lemma \ref{lemma-extension-by-zero}), then we have $\colim \Hom_X(L'_n, N) = \Hom_U(L, N|_U)$ as well. Hence the pro-systems $(L_n)$ and $(L'_n)$ are pro-isomorphic by Categories, Remark \ref{categories-remark-pro-category-copresheaves}.
If $X$ is affine, translated into algebra this is More on Algebra, Lemma \ref{more-algebra-lemma-consequence-Artin-Rees-bis}. In the general case, argue exactly as in the proof of that lemma replacing the reference to Artin-Rees in algebra with a reference to Cohomology of Schemes, Lemma \ref{coherent-lemma-Artin-Rees}. Details omitted.
Assume (1). To prove (2) holds we may assume $(K_n)$ is a Deligne system. By definition we may choose a bounded complex $\mathcal{F}^\bullet$ of coherent $\mathcal{O}_X$-modules and a quasi-coherent sheaf of ideals cutting out $X \setminus U$ such that $K_n$ is represented by $\mathcal{I}^n\mathcal{F}^\bullet$. Thus the result follows from Lemma \ref{lemma-consequence-Artin-Rees-bis}. \medskip\noindent Assume (2). We will prove that $(K_n)$ is as in (1) by induction on $b - a$. If $a = b$ then (1) holds essentially by assumption. If $a < b$ then we consider the compatible system of distinguished triangles $$ \tau_{\leq a}K_n \to K_n \to \tau_{\geq a + 1}K_n \to (\tau_{\leq a}K_n)[1] $$ See Derived Categories, Remark \ref{derived-remark-truncation-distinguished-triangle}. By induction on $b - a$ we know that $\tau_{\leq a}K_n$ and $\tau_{\geq a + 1}K_n$ are pro-isomorphic to Deligne systems. We conclude by Lemma \ref{lemma-deligne-system-2-out-of-3}.
By induction on $r$. If $r = 1$ then the result is clear. Assume $r > 1$. Set $V = W_1 \cup \ldots \cup W_{r - 1}$. By induction we see that $(K_n|_V)$ is a Deligne system. This reduces us to the discussion in the next paragraph. \medskip\noindent Assume $X = V \cup W$ is an open covering and $(K_n|_W)$ and $(K_n|_V)$ are pro-isomorphic to Deligne systems. We have to show that $(K_n)$ is pro-isomorphic to a Deligne system. Observe that $(K_n|_{V \cap W})$ is pro-isomorphic to a Deligne system (it follows immediately from the construction of Deligne systems that restrictions to opens preserves them). In particular the pro-systems $(K_n|_{U \cap V})$, $(K_n|_{U \cap W})$, and $(K_n|_{U \cap V \cap W})$ are essentially constant. It follows from the distinguished triangles in Cohomology, Lemma \ref{cohomology-lemma-exact-sequence-j-star} and Derived Categories, Lemma \ref{derived-lemma-essentially-constant-2-out-of-3} that $(K_n|_U)$ is essentially constant. Denote $K \in D^b_{\textit{Coh}}(\mathcal{O}_U)$ the value of this system. Let $L$ be an object of $D^b_{\textit{Coh}}(\mathcal{O}_X)$. Consider the diagram $$ \xymatrix{ \colim \Ext^{-1}(K_n|_V, L|_V) \oplus \colim \Ext^{-1}(K_n|_W, L|_W) \ar[r] \ar[d] & \Ext^{-1}(K|_{U \cap V}, L|_{U \cap V}) \oplus \Ext^{-1}(K|_{U \cap W}, L|_{U \cap W}) \ar[d] \\ \colim \Ext^{-1}(K_n|_{V \cap W}, L|_{V \cap W}) \ar[r] \ar[d] & \Ext^{-1}(K|_{U \cap V \cap W}, L|_{U \cap V \cap W}) \ar[d] \\ \colim \Hom(K_n, L) \ar[d] \ar[r] & \Hom(K|_U, L|_U) \ar[d] \\ \colim \Hom(K_n|_V, L|_V) \oplus \colim \Hom(K_n|_W, L|_W) \ar[r] \ar[d] & \Hom(K|_{U \cap V}, L|_{U \cap V}) \oplus \Hom(K|_{U \cap W}, L|_{U \cap W}) \ar[d] \\ \colim \Hom(K_n|_{V \cap W}, L|_{V \cap W}) \ar[r] & \Hom(K|_{U \cap V \cap W}, L|_{U \cap V \cap W}) } $$ The vertical sequences are exact by Cohomology, Lemma \ref{cohomology-lemma-mayer-vietoris-hom} and the fact that filtered colimits are exact. All horizontal arrows except for the middle one are isomorphisms by Lemma \ref{lemma-lift-map} and the fact that pro-isomorphic systems have the same colimits. Hence the middle one is an isomorphism too by the 5-lemma. It follows that $(K_n)$ is pro-isomorphic to a Deligne system for $K$. Namey, if $(K'_n)$ is a Deligne system whose restriction to $U$ has constant value $K$ (which exists by Lemma \ref{lemma-extension-by-zero}), then we have $\colim \Hom_X(K'_n, L) = \Hom_U(K, L|_U)$ as well. Hence the pro-systems $(K_n)$ and $(K'_n)$ are pro-isomorphic by Categories, Remark \ref{categories-remark-pro-category-copresheaves}.
[First proof] Let $K$ be an object of $D^b_{\textit{Coh}}(\mathcal{O}_U)$. Let $(K_n)$ be a Deligne system for $U \to X$ whose restriction to $U$ is constant with value $K$. Of course this means that $(K_n)$ represents $Rj_!K$ in $\text{Pro-}D^b_{\textit{Coh}}(\mathcal{O}_X)$. Observe that both $Rj'_!Rg_*K$ and $Rf_*Rj_!K$ restrict to the constant pro-object with value $Rg_*K$ on $V$. This is immediate for the first one and for the second one it follows from the fact that $(Rf_*K_n)|_V = Rg_*(K_n|_U) = Rg_*K$. By the uniqueness of Deligne systems in Lemma \ref{lemma-extension-by-zero} it suffices to show that $(Rf_*K_n)$ is pro-isomorphic to a Deligne system. The lemma referenced will also show that the isomorphism we obtain is functorial. \medskip\noindent Proof that $(Rf_*K_n)$ is pro-isomorphic to a Deligne system. First, we observe that the question is independent of the choice of the Deligne system $(K_n)$ corresponding to $K$ (by the aforementioned uniqueness). By Lemmas \ref{lemma-extension-by-zero-triangle} and \ref{lemma-deligne-system-2-out-of-3} if we have a distinguished triangle $$ K \to L \to M \to K[1] $$ in $D^b_{\textit{Coh}}(\mathcal{O}_U)$ and the result holds for $K$ and $M$, then the result holds for $L$. Using the distinguished triangles of canonical truncations (Derived Categories, Remark \ref{derived-remark-truncation-distinguished-triangle}) we reduce to the problem studied in the next paragraph. \medskip\noindent Let $\mathcal{F}$ be a coherent $\mathcal{O}_X$-module. Let $\mathcal{J} \subset \mathcal{O}_Y$ be a quasi-coherent sheaf of ideals cutting out $Y \setminus V$. Denote $\mathcal{J}^n\mathcal{F}$ the image of $f^*\mathcal{J}^n \otimes \mathcal{F} \to \mathcal{F}$. We have to show that $(Rf_*(\mathcal{J}^n\mathcal{F}))$ is a Deligne system. By Lemma \ref{lemma-characterize-extension-by-zero} the question is local on $Y$. Thus we may assume $Y = \Spec(A)$ is affine and $\mathcal{J}$ corresponds to an ideal $I \subset A$. By Lemma \ref{lemma-characterize-extension-by-zero-algebra} it suffices to show that the inverse system of cohomology modules $(H^p(X, I^n\mathcal{F}))$ is pro-isomorphic to the inverse system $(I^n M)$ for some finite $A$-module $M$. This is shown in Cohomology of Schemes, Lemma \ref{coherent-lemma-cohomology-powers-ideal-application}.
The fact that $X'$ is a compactification of $U$ over $X$ means precisely that $f : X' \to X$ is proper, that $j'$ is an open immersion, and $j = f \circ j'$. See More on Flatness, Section \ref{flat-section-compactify}. If $j'(U) = f^{-1}(j(U))$, then the lemma follows immediately from Lemma \ref{lemma-well-defined-pre}. If $j'(U) \not = f^{-1}(j(U))$, then denote $X'' \subset X'$ the scheme theoretic closure of $j' : U \to X'$ and denote $j'' : U \to X''$ the corresponding open immersion. Picture $$ \xymatrix{ & & X'' \ar[d]^{f'} \\ & & X' \ar[d]^f \\ U \ar[rr]^j \ar[rru]^{j'} \ar[rruu]^{j''} & & X } $$ By More on Flatness, Lemma \ref{flat-lemma-compactifications-cofiltered} part (c) and the discussion above we have isomorphisms $Rf'_* \circ Rj''_! = Rj'_!$ and $R(f \circ f')_* \circ Rj''_! = Rj_!$. Since $R(f \circ f')_* = Rf_* \circ Rf'_*$ we conclude.
Consider the category of compactifications of $X$ over $Y$, which is cofiltered according to More on Flatness, Theorem \ref{flat-theorem-nagata} and Lemmas \ref{flat-lemma-compactifications-cofiltered} and \ref{flat-lemma-compactifyable}. To every choice of a compactification $$ j : X \to \overline{X},\quad \overline{f} : \overline{X} \to Y $$ the construction above associates the functor $R\overline{f}_* \circ Rj_!$. Suppose given a morphism $g : \overline{X}_1 \to \overline{X}_2$ between compactifications $j_i : X \to \overline{X}_i$ over $Y$. Then we get an isomorphism $$ R\overline{f}_{2, *} \circ Rj_{2, !} = R\overline{f}_{2, *} \circ Rg_* \circ j_{1, !} = R\overline{f}_{1, *} \circ Rj_{1, !} $$ using Lemma \ref{lemma-well-defined} in the first equality. In this way we see our functor is independent of the choice of compactification up to isomorphism.
Choose a compactification $j : X \to \overline{X}$ over $Y$ and denote $\overline{f} : \overline{X} \to Y$ the structure morphism. Choose an inverse system of distinguished triangles $$ \overline{K}_n \to \overline{L}_n \to \overline{M}_n \to \overline{K}_n[1] $$ in $D^b_{\textit{Coh}}(\mathcal{O}_{\overline{X}})$ as in Lemma \ref{lemma-extension-by-zero-triangle} corresponding to the open immersion $j$ and the given distinguished triangle. Take $K_n = R\overline{f}_*\overline{K}_n$ and similarly for $L_n$ and $M_n$. This works by the very definition of $Rf_!$.
By the discussion in Categories, Remark \ref{categories-remark-pro-category-copresheaves} it suffices to show that we obtain the same answer if we compute $\Hom$ into $L$ in $D^b_{\textit{Coh}}(\mathcal{O}_Z)$. To do this we compute, using the notation in Remark \ref{remark-composition-lower-shriek}, as follows \begin{align*} \Hom_Z(Rg_!Rf_!K, L) & = \colim_n \Hom_Z(Rg_!M_n, L) \\ & = \colim_n \Hom_Y(M_n, g^!L) \\ & = \Hom_Y(Rf_!K, g^!L) \\ & = \Hom_X(K, f^!g^!L) \\ & = \Hom_X(K, (g \circ f)^!L) \\ & = \Hom_Z(R(g \circ f)_!K, L) \end{align*} The first equality is the definition of $Rg_!Rf_!K$. The second equality is Proposition \ref{proposition-duality-compactly-supported} for $g$. The third equality is the fact that $Rf_!K$ is given by $(M_n)$. The fourth equality is Proposition \ref{proposition-duality-compactly-supported} for $f$. The fifth equality is Lemma \ref{lemma-upper-shriek-composition}. The sixth is  Proposition \ref{proposition-duality-compactly-supported} for $g \circ f$.
Choose a compactification $j : U \to X$ over $k$. Let $\mathcal{I} \subset \mathcal{O}_X$ be a quasi-coherent ideal sheaf with $V(\mathcal{I}) = X \setminus U$. By Derived Categories of Schemes, Proposition \ref{perfect-proposition-DCoh} we may choose $M \in D^b_{\textit{Coh}}(\mathcal{O}_X)$ with $K = M|_U$. We have $$ H^i(U, K) = \Ext^i_U(\mathcal{O}_U, M|_U) = \colim \Ext^i_X(\mathcal{I}^n, M) = \colim H^i(X, R\SheafHom_{\mathcal{O}_X}(\mathcal{I}^n, M)) $$ by Lemma \ref{lemma-lift-map}. Since $\mathcal{I}^n$ is a coherent $\mathcal{O}_X$-module, we have $\mathcal{I}^n$ in $D^-_{\textit{Coh}}(\mathcal{O}_X)$, hence $R\SheafHom_{\mathcal{O}_X}(\mathcal{I}^n, M)$ is in $D^+_{\textit{Coh}}(\mathcal{O}_X)$ by Derived Categories of Schemes, Lemma \ref{perfect-lemma-coherent-internal-hom}. \medskip\noindent Let $\omega_{X/k}^\bullet = q^!\mathcal{O}_{\Spec(k)}$ where $q : X \to \Spec(k)$ is the structure morphism, see Section \ref{section-duality-proper-over-field}. We find that \begin{align*} \Hom_k( & H^i(X, R\SheafHom_{\mathcal{O}_X}(\mathcal{I}^n, M)), k) \\ & = \Ext^{-i}_X(R\SheafHom_{\mathcal{O}_X}(\mathcal{I}^n, M), \omega_{X/k}^\bullet) \\ & = H^{-i}(X, R\SheafHom_{\mathcal{O}_X}(R\SheafHom_{\mathcal{O}_X}( \mathcal{I}^n, M), \omega_{X/k}^\bullet)) \end{align*} by Lemma \ref{lemma-duality-proper-over-field}. By Lemma \ref{lemma-internal-hom-evaluate-isom} part (1) the canonical map $$ R\SheafHom_{\mathcal{O}_X}(M, \omega_{X/k}^\bullet) \otimes_{\mathcal{O}_X}^\mathbf{L} \mathcal{I}^n \longrightarrow R\SheafHom_{\mathcal{O}_X}(R\SheafHom_{\mathcal{O}_X}( \mathcal{I}^n, M), \omega_{X/k}^\bullet) $$ is an isomorphism. Observe that $\omega^\bullet_{U/k} = \omega^\bullet_{X/k}|_U$ because $p^!$ is constructed as $q^!$ composed with restriction to $U$. Hence $R\SheafHom_{\mathcal{O}_X}(M, \omega_{X/k}^\bullet)$ is an object of $D^b_{\textit{Coh}}(\mathcal{O}_X)$ which restricts to $R\SheafHom_{\mathcal{O}_U}(K, \omega_{U/k}^\bullet)$ on $U$. Hence by Lemma \ref{lemma-tensoring-Deligne-system} we conclude that $$ \lim H^{-i}(X, R\SheafHom_{\mathcal{O}_X}(M, \omega_{X/k}^\bullet) \otimes_{\mathcal{O}_X}^\mathbf{L} \mathcal{I}^n) $$ is an avatar for the right hand side of the equality of the lemma. Combining all the isomorphisms obtained in this manner we get the isomorphism of the lemma.
We strongly urge the reader to skip this proof. Choose $X$ and $M$ as in the proof of Lemma \ref{lemma-duality-compact-support}. We are going to drop the subscript $\mathcal{O}_X$ from $R\SheafHom$ and $\otimes^\mathbf{L}$. We write $$ H^i(U, K) = \colim H^i(X, R\SheafHom(\mathcal{I}^n, M)) $$ and $$ H^i(U', K|_{U'}) = \colim H^i(X, R\SheafHom((\mathcal{I}')^n, M)) $$ as in the proof of Lemma \ref{lemma-duality-compact-support} where we choose $\mathcal{I}' \subset \mathcal{I}$ as in the discussion in Remark \ref{remark-covariance-open-j-lower-shriek} so that the map $H^i(U, K) \to H^i(U', K|_{U'})$ is induced by the maps $(\mathcal{I}')^n \to \mathcal{I}^n$. We similarly write $$ H^i_c(U, R\SheafHom(K, \omega_{U/k}^\bullet)) = \lim H^i(X,  R\SheafHom(M, \omega_{X/k}^\bullet) \otimes^\mathbf{L} \mathcal{I}^n) $$ and $$ H^i_c(U', R\SheafHom(K|_{U'}, \omega_{U'/k}^\bullet)) = \lim H^i(X,  R\SheafHom(M, \omega_{X/k}^\bullet) \otimes^\mathbf{L} (\mathcal{I}')^n) $$ so that the arrow $H^i_c(U', R\SheafHom(K|_{U'}, \omega_{U'/k}^\bullet)) \to H^i_c(U, R\SheafHom(K, \omega_{U/k}^\bullet))$ is similarly deduced from the maps $(\mathcal{I}')^n \to \mathcal{I}^n$. The diagrams $$ \xymatrix{ R\SheafHom(M, \omega_{X/k}^\bullet) \otimes^\mathbf{L} \mathcal{I}^n \ar[rr] & & R\SheafHom(R\SheafHom(\mathcal{I}^n, M), \omega_{X/k}^\bullet) \\ R\SheafHom(M, \omega_{X/k}^\bullet) \otimes^\mathbf{L} (\mathcal{I}')^n \ar[rr] \ar[u] & & R\SheafHom(R\SheafHom((\mathcal{I}')^n, M), \omega_{X/k}^\bullet) \ar[u] } $$ commute because the construction of the horizontal arrows in Cohomology, Lemma \ref{cohomology-lemma-internal-hom-evaluate} is functorial in all three entries. Hence we finally come down to the assertion that the diagrams $$ \xymatrix{ \Hom_k(H^i(X, R\SheafHom(\mathcal{I}^n, M)), k) \ar[r] & H^{-i}(X, R\SheafHom(R\SheafHom( \mathcal{I}^n, M), \omega_{X/k}^\bullet)) \\ \Hom_k(H^i(X, R\SheafHom((\mathcal{I}')^n, M)), k) \ar[r] \ar[u] & H^{-i}(X, R\SheafHom(R\SheafHom( (\mathcal{I}')^n, M), \omega_{X/k}^\bullet)) \ar[u] } $$ commute. This is true because the duality isomorphism $$ \Hom_k(H^i(X, L), k) = \Ext^{-i}_X(L, \omega_{X/k}^\bullet) = H^{-i}(X, R\SheafHom(L, \omega_{X/k}^\bullet)) $$ is functorial for $L$ in $D_\QCoh(\mathcal{O}_X)$.