hcju/stacksqa huggingface dataset:
By Lemma \ref{lemma-local-cohomology-noetherian} we have $R\Gamma_{\mathfrak m} = R\Gamma_Z$. Thus $$ R\Gamma_Z(\omega_A^\bullet) = R\Gamma_{\mathfrak m}(\omega_A^\bullet) = \text{hocolim}\ R\Hom_A(A/\mathfrak m^n, \omega_A^\bullet) $$ by Lemma \ref{lemma-local-cohomology-ext}. Let $E'$ be an injective hull of the residue field. By Lemma \ref{lemma-dualizing-finite-length} we can find isomorphisms $$ R\Hom_A(A/\mathfrak m^n, \omega_A^\bullet) \cong \Hom_A(A/\mathfrak m^n, E')[0] $$ compatible with transition maps. Since $E' = \bigcup E'[\mathfrak m^n] = \colim \Hom_A(A/\mathfrak m^n, E')$ by Lemma \ref{lemma-union-artinian} we conclude that $E \cong E'$ and that all other cohomology groups of the complex $R\Gamma_Z(\omega_A^\bullet)$ are zero.
By Lemma \ref{lemma-dualizing} we see that $R\Hom_A(K, \omega_A^\bullet)$ is an object of $D_{\textit{Coh}}(A)$. It follows that the cohomology modules of the derived completion of $R\Hom_A(K, \omega_A^\bullet)$ are equal to the usual completions $\Ext^i_A(K, \omega_A^\bullet)^\wedge$ by More on Algebra, Lemma \ref{more-algebra-lemma-derived-completion-pseudo-coherent}. On the other hand, we have $R\Gamma_{\mathfrak m} = R\Gamma_Z$ for $Z = V(\mathfrak m)$ by Lemma \ref{lemma-local-cohomology-noetherian}. Moreover, the functor $\Hom_A(-, E)$ is exact hence factors through cohomology. Hence the lemma is consequence of Theorem \ref{theorem-local-duality}.
This follows immediately from Lemma \ref{lemma-sitting-in-degrees}. Here are two other ways to see that it is true. \medskip\noindent First alternative. By Nakayama's lemma we see that $\delta$ is the smallest integer such that $\Hom_A(H^{-\delta}(\omega_A^\bullet), \kappa) \not = 0$. In other words, it is the smallest integer such that $\Ext_A^{-\delta}(\omega_A^\bullet, \kappa)$ is nonzero. Using Lemma \ref{lemma-dualizing} and the fact that $\omega_A^\bullet$ is normalized this is equal to the smallest integer such that $\Ext_A^\delta(\kappa, A)$ is nonzero. This is equal to the depth of $A$ by Algebra, Lemma \ref{algebra-lemma-depth-ext}. \medskip\noindent Second alternative. By the local duality theorem (in the form of Lemma \ref{lemma-special-case-local-duality}) $\delta$ is the smallest integer such that $H^\delta_\mathfrak m(A)$ is nonzero. This is equal to the depth of $A$ by Lemma \ref{lemma-depth}.
If $\mathfrak p$ is a generic point of $\text{Supp}(M)$, then $\text{depth}(M_\mathfrak p) = \dim(M_\mathfrak p) = 0$ and hence $\mathfrak p \in U$. This proves denseness. If $\mathfrak p \in U$, then we see that $$ R\Hom_A(M, \omega_A^\bullet)_\mathfrak p = R\Hom_{A_\mathfrak p}(M_\mathfrak p, (\omega_A^\bullet)_\mathfrak p) $$ has a unique nonzero cohomology module, say in degree $i_0$, by Lemma \ref{lemma-local-CM}. Since $R\Hom_A(M, \omega_A^\bullet)$ has only a finite number of nonzero cohomology modules $H^i$ and since each of these is a finite $A$-module, we can find an $f \in A$, $f \not \in \mathfrak p$ such that $(H^i)_f = 0$ for $i \not = i_0$. Then $R\Hom_A(M, \omega_A^\bullet)_f$ has a unique nonzero cohomology module and reversing the arguments just given we find that $D(f) \subset U$.
Let $A$ be a regular ring of finite dimension $d$. Then $A$ has finite global dimension $d$, see Algebra, Lemma \ref{algebra-lemma-finite-gl-dim-finite-dim-regular}. Hence $\Ext^{d + 1}_A(M, A) = 0$ for all $A$-modules $M$, see Algebra, Lemma \ref{algebra-lemma-projective-dimension-ext}. Thus $A$ has finite injective dimension as an $A$-module by More on Algebra, Lemma \ref{more-algebra-lemma-injective-amplitude}. It follows that $A[0]$ is a dualizing complex, hence $A$ is Gorenstein by the remark following the definition.
For invertible objects of $D(A)$, see More on Algebra, Lemma \ref{more-algebra-lemma-invertible-derived} and the discussion in Section \ref{section-dualizing}. \medskip\noindent By Lemma \ref{lemma-dualizing-localize} for every $\mathfrak p$ the complex $(\omega_A^\bullet)_\mathfrak p$ is a dualizing complex over $A_\mathfrak p$. By definition and uniqueness of dualizing complexes (Lemma \ref{lemma-dualizing-unique}) we see that (1)(b) holds. \medskip\noindent To see (1)(c) assume that $A_\mathfrak p$ is Gorenstein. Let $n_x$ be the unique integer such that $H^{n_{x}}((\omega_A^\bullet)_\mathfrak p)$ is nonzero and isomorphic to $A_\mathfrak p$. Since $\omega_A^\bullet$ is in $D^b_{\textit{Coh}}(A)$ there are finitely many nonzero finite $A$-modules $H^i(\omega_A^\bullet)$. Thus there exists some $f \in A$, $f \not \in \mathfrak p$ such that only $H^{n_x}((\omega_A^\bullet)_f)$ is nonzero and generated by $1$ element over $A_f$. Since dualizing complexes are faithful (by definition) we conclude that $A_f \cong H^{n_x}((\omega_A^\bullet)_f)$. In this way we see that $A_\mathfrak q$ is Gorenstein for every $\mathfrak q \in D(f)$. This proves that the set in (1)(c) is open. \medskip\noindent Proof of (1)(a). The implication $\Leftarrow$ follows from (1)(b). The implication $\Rightarrow$ follows from the discussion in the previous paragraph, where we showed that if $A_\mathfrak p$ is Gorenstein, then for some $f \in A$, $f \not \in \mathfrak p$ the complex $(\omega_A^\bullet)_f$ has only one nonzero cohomology module which is invertible. \medskip\noindent If $A[0]$ is a dualizing complex then $A$ is Gorenstein by part (1). Conversely, we see that part (1) shows that $\omega_A^\bullet$ is locally isomorphic to a shift of $A$. Since being a dualizing complex is local (Lemma \ref{lemma-dualizing-glue}) the result is clear.
If $A$ is Gorenstein, then $B$ is Gorenstein by Lemma \ref{lemma-divide-by-nonzerodivisor}. Conversely, suppose that $B$ is Gorenstein. Then $\Ext^i_B(\kappa, B)$ is zero for $i \gg 0$ (Lemma \ref{lemma-gorenstein-ext}). Recall that $R\Hom(B, -) : D(A) \to D(B)$ is a right adjoint to restriction (Lemma \ref{lemma-right-adjoint}). Hence $$ R\Hom_A(\kappa, A) = R\Hom_B(\kappa, R\Hom(B, A)) = R\Hom_B(\kappa, B[1]) $$ The final equality by direct computation or by Lemma \ref{lemma-compute-for-effective-Cartier-algebraic}. Thus we see that $\Ext^i_A(\kappa, A)$ is zero for $i \gg 0$ and $A$ is Gorenstein (Lemma \ref{lemma-gorenstein-ext}).
By More on Algebra, Definition \ref{more-algebra-definition-local-complete-intersection} we can write $B = A[x_1, \ldots, x_n]/I$ where $I$ is a Koszul-regular ideal. Observe that a polynomial ring over a Gorenstein ring $A$ is Gorenstein: reduce to $A$ local and then use Lemmas \ref{lemma-dualizing-polynomial-ring} and \ref{lemma-gorenstein}. A Koszul-regular ideal is by definition locally generated by a Koszul-regular sequence, see More on Algebra, Section \ref{more-algebra-section-ideals}. Looking at local rings of $A[x_1, \ldots, x_n]$ we see it suffices to show: if $R$ is a Noetherian local Gorenstein ring and $f_1, \ldots, f_c \in \mathfrak m_R$ is a Koszul regular sequence, then $R/(f_1, \ldots, f_c)$ is Gorenstein. This follows from Lemma \ref{lemma-gorenstein-divide-by-nonzerodivisor} and the fact that a Koszul regular sequence in $R$ is just a regular sequence (More on Algebra, Lemma \ref{more-algebra-lemma-noetherian-finite-all-equivalent}).
Below we will use without further mention that a local Gorenstein ring has finite injective dimension as well as Lemma \ref{lemma-gorenstein-ext}. By More on Algebra, Lemma \ref{more-algebra-lemma-pseudo-coherence-and-base-change-ext} we have $$ \Ext^i_A(\kappa_A, A) \otimes_A B = \Ext^i_B(B/\mathfrak m_A B, B) $$ for all $i$. \medskip\noindent Assume (2). Using that $R\Hom(B/\mathfrak m_A B, -) : D(B) \to D(B/\mathfrak m_A B)$ is a right adjoint to restriction (Lemma \ref{lemma-right-adjoint}) we obtain $$ R\Hom_B(\kappa_B, B) = R\Hom_{B/\mathfrak m_A B}(\kappa_B, R\Hom(B/\mathfrak m_A B, B)) $$ The cohomology modules of $R\Hom(B/\mathfrak m_A B, B)$ are the modules $\Ext^i_B(B/\mathfrak m_A B, B) = \Ext^i_A(\kappa_A, A) \otimes_A B$. Since $A$ is Gorenstein, we conclude only a finite number of these are nonzero and each is isomorphic to a direct sum of copies of $B/\mathfrak m_A B$. Hence since $B/\mathfrak m_A B$ is Gorenstein we conclude that $R\Hom_B(B/\mathfrak m_B, B)$ has only a finite number of nonzero cohomology modules. Hence $B$ is Gorenstein. \medskip\noindent Assume (1). Since $B$ has finite injective dimension, $\Ext^i_B(B/\mathfrak m_A B, B)$ is $0$ for $i \gg 0$. Since $A \to B$ is faithfully flat we conclude that $\Ext^i_A(\kappa_A, A)$ is $0$ for $i \gg 0$. We conclude that $A$ is Gorenstein. This implies that $\Ext^i_A(\kappa_A, A)$ is nonzero for exactly one $i$, namely for $i = \dim(A)$, and $\Ext^{\dim(A)}_A(\kappa_A, A) \cong \kappa_A$ (see Lemmas \ref{lemma-normalized-finite}, \ref{lemma-apply-CM}, and \ref{lemma-gorenstein-CM}). Thus we see that $\Ext^i_B(B/\mathfrak m_A B, B)$ is zero except for one $i$, namely $i = \dim(A)$ and $\Ext^{\dim(A)}_B(B/\mathfrak m_A B, B) \cong B/\mathfrak m_A B$. Thus $B/\mathfrak m_A B$ is Gorenstein by Lemma \ref{lemma-normalized-finite}.
Since $A$ is Gorenstein $\omega_A^\bullet = A[d]$ is a normalized dualizing complex for $A$. Also $E$ is the only nonzero cohomology module of $R\Gamma_\mathfrak m(\omega_A^\bullet)$ sitting in degree $0$, see Lemma \ref{lemma-local-cohomology-of-dualizing}. By Lemma \ref{lemma-torsion-tensor-product} we have $$ E \otimes_A^\mathbf{L} \kappa = R\Gamma_\mathfrak m(\omega_A^\bullet) \otimes_A^\mathbf{L} \kappa = R\Gamma_\mathfrak m(\omega_A^\bullet \otimes_A^\mathbf{L} \kappa) = R\Gamma_\mathfrak m(\kappa[d]) = \kappa[d] $$ and the lemma follows.
It is clear that $\omega_A^\bullet \otimes_A B$ is in $D^b_{\textit{Coh}}(B)$. Let $\kappa_A$ and $\kappa_B$ be the residue fields of $A$ and $B$. By More on Algebra, Lemma \ref{more-algebra-lemma-base-change-RHom} we see that $$ R\Hom_B(\kappa_B, \omega_A^\bullet \otimes_A B) = R\Hom_A(\kappa_A, \omega_A^\bullet) \otimes_A B = \kappa_A[0] \otimes_A B = \kappa_B[0] $$ Thus $\omega_A^\bullet \otimes_A B$ has finite injective dimension by More on Algebra, Lemma \ref{more-algebra-lemma-finite-injective-dimension-Noetherian-local}. Finally, we can use the same arguments to see that $$ R\Hom_B(\omega_A^\bullet \otimes_A B, \omega_A^\bullet \otimes_A B) = R\Hom_A(\omega_A^\bullet, \omega_A^\bullet) \otimes_A B = A \otimes_A B = B $$ as desired.
It is clear that $\omega_A^\bullet \otimes_A B$ is in $D^b_{\textit{Coh}}(B)$. By More on Algebra, Lemma \ref{more-algebra-lemma-base-change-RHom} we see that $$ R\Hom_B(K \otimes_A B, \omega_A^\bullet \otimes_A B) = R\Hom_A(K, \omega_A^\bullet) \otimes_A B $$ for any $K \in D^b_{\textit{Coh}}(A)$. For any ideal $IB \subset J \subset B$ there is a unique ideal $I \subset J' \subset A$ such that $A/J' \otimes_A B = B/J$. Thus $\omega_A^\bullet \otimes_A B$ has finite injective dimension by More on Algebra, Lemma \ref{more-algebra-lemma-finite-injective-dimension-Noetherian-radical}. Finally, we also have $$ R\Hom_B(\omega_A^\bullet \otimes_A B, \omega_A^\bullet \otimes_A B) = R\Hom_A(\omega_A^\bullet, \omega_A^\bullet) \otimes_A B = A \otimes_A B = B $$ as desired.
Immediate from Lemmas \ref{lemma-flat-unramified} and \ref{lemma-flat-iso-mod-I}. See More on Algebra, Sections \ref{more-algebra-section-henselian-pairs}, \ref{more-algebra-section-permanence-completion}, and \ref{more-algebra-section-permanence-henselization} and Algebra, Sections \ref{algebra-section-completion} and \ref{algebra-section-completion-noetherian} for information on completions and henselizations.
Part (5) follows from Proposition \ref{proposition-dualizing-essentially-finite-type} and Lemma \ref{lemma-completion-henselization-dualizing}. By Lemma \ref{lemma-regular-gorenstein} a regular local ring has a dualizing complex. A complete Noetherian local ring is the quotient of a regular local ring by the Cohen structure theorem (Algebra, Theorem \ref{algebra-theorem-cohen-structure-theorem}). Let $A$ be a Dedekind domain. Then every ideal $I$ is a finite projective $A$-module (follows from Algebra, Lemma \ref{algebra-lemma-finite-projective} and the fact that the local rings of $A$ are discrete valuation ring and hence PIDs). Thus every $A$-module has finite injective dimension at most $1$ by More on Algebra, Lemma \ref{more-algebra-lemma-injective-amplitude}. It follows easily that $A[0]$ is a dualizing complex.
Since we already know the result holds for Cohen-Macaulay instead of Gorenstein, we may in each step assume the ring we have is Cohen-Macaulay. This is not particularly helpful for the proof, but psychologically may be useful. \medskip\noindent Part (A). Let $k \subset K$ be a finitely generated field extension. Let $R$ be a Gorenstein $k$-algebra. We can find a global complete intersection $A = k[x_1, \ldots, x_n]/(f_1, \ldots, f_c)$ over $k$ such that $K$ is isomorphic to the fraction field of $A$, see Algebra, Lemma \ref{algebra-lemma-colimit-syntomic}. Then $R \to R \otimes_k A$ is a relative global complete intersection. Hence $R \otimes_k A$ is Gorenstein by Lemma \ref{lemma-gorenstein-lci}. Thus $R \otimes_k K$ is too as a localization. \medskip\noindent Proof of (B). This is clear because a ring is Gorenstein if and only if all of its local rings are Gorenstein. \medskip\noindent Part (C). Let $A \to B \to C$ be flat maps of Noetherian rings. Assume the fibres of $A \to B$ are Gorenstein and $B \to C$ is regular. We have to show the fibres of $A \to C$ are Gorenstein. Clearly, we may assume $A = k$ is a field. Then we may assume that $B \to C$ is a regular local homomorphism of Noetherian local rings. Then $B$ is Gorenstein and $C/\mathfrak m_B C$ is regular, in particular Gorenstein (Lemma \ref{lemma-regular-gorenstein}). Then $C$ is Gorenstein by Lemma \ref{lemma-flat-under-gorenstein}. \medskip\noindent Part (D). This follows from Lemma \ref{lemma-flat-under-gorenstein}. Part (E) is immediate as the condition does not refer to the ground field.
Let $\mathfrak p$ be a prime of $A$. The formal fibre of $A$ at $\mathfrak p$ is isomorphic to the formal fibre of $A/\mathfrak p$ at $(0)$. The quotient $A/\mathfrak p$ has a dualizing complex (Lemma \ref{lemma-dualizing-quotient}). Thus it suffices to check the statement when $A$ is a local domain and $\mathfrak p = (0)$. Let $\omega_A^\bullet$ be a dualizing complex for $A$. Then $\omega_A^\bullet \otimes_A A^\wedge$ is a dualizing complex for the completion $A^\wedge$ (Lemma \ref{lemma-flat-unramified}). Then $\omega_A^\bullet \otimes_A K$ is a dualizing complex for the fraction field $K$ of $A$ (Lemma \ref{lemma-dualizing-localize}). Hence $\omega_A^\bullet \otimes_A K$ is isomorphic ot $K[n]$ for some $n \in \mathbf{Z}$. Similarly, we conclude a dualizing complex for the formal fibre $A^\wedge \otimes_A K$ is $$ \omega_A^\bullet \otimes_A A^\wedge \otimes_{A^\wedge} (A^\wedge \otimes_A K) = (\omega_A^\bullet \otimes_A K) \otimes_K (A^\wedge \otimes_A K) \cong (A^\wedge \otimes_A K)[n] $$ as desired.
Part (A). Let $k \subset K$ be a finitely generated field extension. Let $R$ be a $k$-algebra which is a local complete intersection. We can find a global complete intersection $A = k[x_1, \ldots, x_n]/(f_1, \ldots, f_c)$ over $k$ such that $K$ is isomorphic to the fraction field of $A$, see Algebra, Lemma \ref{algebra-lemma-colimit-syntomic}. Then $R \to R \otimes_k A$ is a relative global complete intersection. It follows that $R \otimes_k A$ is a local complete intersection by Divided Power Algebra, Lemma \ref{dpa-lemma-avramov}. \medskip\noindent Proof of (B). This is clear because a ring is a local complete intersection if and only if all of its local rings are complete intersections. \medskip\noindent Part (C). Let $A \to B \to C$ be flat maps of Noetherian rings. Assume the fibres of $A \to B$ are local complete intersections and $B \to C$ is regular. We have to show the fibres of $A \to C$ are local complete intersections. Clearly, we may assume $A = k$ is a field. Then we may assume that $B \to C$ is a regular local homomorphism of Noetherian local rings. Then $B$ is a complete intersection and $C/\mathfrak m_B C$ is regular, in particular a complete intersection (by definition). Then $C$ is a complete intersection by Divided Power Algebra, Lemma \ref{dpa-lemma-avramov}. \medskip\noindent Part (D). This follows by the same arguments as in (C) from the other implication in Divided Power Algebra, Lemma \ref{dpa-lemma-avramov}. Part (E) is immediate as the condition does not refer to the ground field.
Suppose that $\psi_1 : P_1 = R[x_1, \ldots, x_n] \to A$ and $\psi_2 : P_2 = R[y_1, \ldots, y_m] \to A$ are two surjections from polynomial rings onto $A$. Then we get a commutative diagram $$ \xymatrix{ R[x_1, \ldots, x_n, y_1, \ldots, y_m] \ar[d]^{x_i \mapsto g_i} \ar[rr]_-{y_j \mapsto f_j} & & R[x_1, \ldots, x_n] \ar[d] \\ R[y_1, \ldots, y_m] \ar[rr] & & A } $$ where $f_j$ and $g_i$ are chosen such that $\psi_1(f_j) = \psi_2(y_j)$ and $\psi_2(g_i) = \psi_1(x_i)$. By symmetry it suffices to prove the functors defined using $P \to A$ and $P[y_1, \ldots, y_m] \to A$ are isomorphic. By induction we may assume $m = 1$. This reduces us to the case discussed in the next paragraph. \medskip\noindent Here $\psi : P \to A$ is given and $\chi : P[y] \to A$ induces $\psi$ on $P$. Write $Q = P[y]$. Choose $g \in P$ with $\psi(g) = \chi(y)$. Denote $\pi : Q \to P$ the $P$-algebra map with $\pi(y) = g$. Then $\chi = \psi \circ \pi$ and hence $\chi^! = \psi^! \circ \pi^!$ as both are adjoint to the restriction functor $D(A) \to D(Q)$ by the material in Section \ref{section-trivial}. Thus $$ \chi^!\left(K \otimes_R^\mathbf{L} Q\right)[n + 1] = \psi^!\left(\pi^!\left(K \otimes_R^\mathbf{L} Q\right)[1]\right)[n] $$ Hence it suffices to show that $\pi^!(K \otimes_R^\mathbf{L} Q[1]) = K \otimes_R^\mathbf{L} P$ Thus it suffices to show that the functor $\pi^!(-) : D(Q) \to D(P)$ is isomorphic to $K \mapsto K \otimes_Q^\mathbf{L} P[-1]$. This follows from Lemma \ref{lemma-compute-for-effective-Cartier-algebraic}.
Choose a factorization $R \to P \to A$ as in the definition of $\varphi^!$. The functor $- \otimes_R^\mathbf{L} : D(R) \to D(P)$ preserves the subcategories $D^+, D^+_{\textit{Coh}}, D^-, D^-_{\textit{Coh}}, D^b_{\textit{Coh}}$. The functor $R\Hom(A, -) : D(P) \to D(A)$ preserves $D^+$ and $D^+_{\textit{Coh}}$ by Lemma \ref{lemma-exact-support-coherent}. If $R \to A$ is perfect, then $A$ is perfect as a $P$-module, see More on Algebra, Lemma \ref{more-algebra-lemma-perfect-ring-map}. Recall that the restriction of $R\Hom(A, K)$ to $D(P)$ is $R\Hom_P(A, K)$. By More on Algebra, Lemma \ref{more-algebra-lemma-dual-perfect-complex} we have $R\Hom_P(A, K) = E \otimes_P^\mathbf{L} K$ for some perfect $E \in D(P)$. Since we can represent $E$ by a finite complex of finite projective $P$-modules it is clear that $R\Hom_P(A, K)$ is in $D^-(P), D^-_{\textit{Coh}}(P), D^b_{\textit{Coh}}(P)$ as soon as $K$ is. Since the restriction functor $D(A) \to D(P)$ reflects these subcategories, the proof is complete.
Choose a factorization $R \to P \to A$ where $P$ is a polynomial ring over $R$. This gives a corresponding factorization $R' \to P' \to A'$ by base change. Since we have $(K \otimes_R^\mathbf{L} P) \otimes_P^\mathbf{L} P' = (K \otimes_R^\mathbf{L} R') \otimes_{R'}^\mathbf{L} P'$ by More on Algebra, Lemma \ref{more-algebra-lemma-double-base-change} it suffices to construct maps $$ R\Hom(A, K \otimes_R^\mathbf{L} P[n]) \otimes_A^\mathbf{L} A' \longrightarrow R\Hom(A', (K \otimes_R^\mathbf{L} P[n]) \otimes_P^\mathbf{L} P') $$ functorial in $K$. For this we use the map (\ref{equation-base-change}) constructed in Section \ref{section-base-change-trivial-duality} for $P, A, P', A'$. The map is an isomorphism for $K \in D^+(R)$ by Lemma \ref{lemma-flat-bc-surjection}.
We may choose a factorization $R \to P \to A$ where $P$ is a polynomial ring over $R$ such that $A$ is a perfect $P$-module, see More on Algebra, Lemma \ref{more-algebra-lemma-perfect-ring-map}. This gives a corresponding factorization $R' \to P' \to A'$ by base change. Since we have $(K \otimes_R^\mathbf{L} P) \otimes_P^\mathbf{L} P' = (K \otimes_R^\mathbf{L} R') \otimes_{R'}^\mathbf{L} P'$ by More on Algebra, Lemma \ref{more-algebra-lemma-double-base-change} it suffices to construct maps $$ R\Hom(A, K \otimes_R^\mathbf{L} P[n]) \otimes_A^\mathbf{L} A' \longrightarrow R\Hom(A', (K \otimes_R^\mathbf{L} P[n]) \otimes_P^\mathbf{L} P') $$ functorial in $K$. We have $$ A \otimes_P^\mathbf{L} P' = A \otimes_R^\mathbf{L} R' = A' $$ The first equality by More on Algebra, Lemma \ref{more-algebra-lemma-base-change-comparison} applied to $R, R', P, P'$. The second equality because $A$ and $R'$ are tor independent over $R$. Hence $A$ and $P'$ are tor independent over $P$ and we can use the map (\ref{equation-base-change}) constructed in Section \ref{section-base-change-trivial-duality} for $P, A, P', A'$ get the desired arrow. By Lemma \ref{lemma-bc-surjection} to finish the proof it suffices to prove that $A$ is a perfect $P$-module which we saw above.
Choose a polynomial ring $P = A[x_1, \ldots, x_n]$ over $A$ and a surjection $P \to B$. Choose elements $c_1, \ldots, c_m \in C$ generating $C$ over $B$. Set $Q = P[y_1, \ldots, y_m]$ and denote $Q' = Q \otimes_P B = B[y_1, \ldots, y_m]$. Let $\chi : Q' \to C$ be the surjection sending $y_j$ to $c_j$. Picture $$ \xymatrix{ & Q \ar[r]_{\psi'} & Q' \ar[r]_\chi & C \\ A \ar[r] & P \ar[r]^\psi \ar[u] & B \ar[u] } $$ By Lemma \ref{lemma-flat-bc-surjection} for $M \in D(P)$ we have an arrow $\psi^!(M) \otimes_B^\mathbf{L} Q' \to (\psi')^!(M \otimes_P^\mathbf{L} Q)$ which is an isomorphism whenever $M$ is bounded below. Also we have $\chi^! \circ (\psi')^! = (\chi \circ \psi')^!$ as both functors are adjoint to the restriction functor $D(C) \to D(Q)$ by Section \ref{section-trivial}. Then we see \begin{align*} b^!(a^!(K)) & = \chi^!(\psi^!(K \otimes_A^\mathbf{L} P)[n] \otimes_B^\mathbf{L} Q)[m] \\ & \to \chi^!((\psi')^!(K \otimes_A^\mathbf{L} P \otimes_P^\mathbf{L} Q))[n + m] \\ & = (\chi \circ \psi')^!(K\otimes_A^\mathbf{L} Q)[n + m] \\ & = (b \circ a)^!(K) \end{align*} where we have used in addition to the above More on Algebra, Lemma \ref{more-algebra-lemma-double-base-change}.
Suppose that $A$ is generated by $n > 1$ elements over $R$. Then can factor $R \to A$ as a composition of two finite ring maps where in both steps the number of generators is $< n$. Since we have Lemma \ref{lemma-composition-shriek-algebraic} and Lemma \ref{lemma-composition-right-adjoints} we conclude that it suffices to prove the lemma when $A$ is generated by one element over $R$. Since $A$ is finite over $R$, it follows that $A$ is a quotient of $B = R[x]/(f)$ where $f$ is a monic polynomial in $x$ (Algebra, Lemma \ref{algebra-lemma-finite-is-integral}). Again using the lemmas on composition and the fact that we have agreement for surjections by definition, we conclude that it suffices to prove the lemma for $R \to B = R[x]/(f)$. In this case, the functor $\varphi^!$ is isomorphic to $K \mapsto K \otimes_R^\mathbf{L} B$; you prove this by using Lemma \ref{lemma-compute-for-effective-Cartier-algebraic} for the map $R[x] \to B$ (note that the shift in the definition of $\varphi^!$ and in the lemma add up to zero). For the functor $R\Hom(B, -) : D(R) \to D(B)$ we can use Lemma \ref{lemma-RHom-is-tensor-special} to see that it suffices to show $\Hom_R(B, R) \cong B$ as $B$-modules. Suppose that $f$ has degree $d$. Then an $R$-basis for $B$ is given by $1, x, \ldots, x^{d - 1}$. Let $\delta_i : B \to R$, $i = 0, \ldots, d - 1$ be the $R$-linear map which picks off the coefficient of $x^i$ with respect to the given basis. Then $\delta_0, \ldots, \delta_{d - 1}$ is a basis for $\Hom_R(B, R)$. Finally, for $0 \leq i \leq d - 1$ a computation shows that $$ x^i \delta_{d - 1} = \delta_{d - 1 - i} + b_1 \delta_{d - i} + \ldots + b_i \delta_{d - 1} $$ for some $c_1, \ldots, c_d \in R$\footnote{If $f = x^d + a_1 x^{d - 1} + \ldots + a_d$, then $c_1 = -a_1$, $c_2 = a_1^2 - a_2$, $c_3 = -a_1^3 + 2a_1a_2 -a_3$, etc.}. Hence $\Hom_R(B, R)$ is a principal $B$-module with generator $\delta_{d - 1}$. By looking at ranks we conclude that it is a rank $1$ free $B$-module.