[proofplan]
The classical Seifert–van Kampen theorem requires the cover to be by open sets, but here $A$ and $B$ are only closed. The strategy is to thicken $A$ and $B$ to open sets $A'$ and $B'$ without changing the homotopy type. We use the neighbourhood-deformation-retract hypothesis to produce open sets $U \supset A \cap B$ inside $A$ and $V \supset A \cap B$ inside $B$ that strongly deformation retract onto $A \cap B$. Setting $A' = A \cup V$ and $B' = B \cup U$ gives an open cover of $X$ with $A' \simeq A$, $B' \simeq B$, and $A' \cap B' \simeq A \cap B$; the hypotheses of the open-cover version are then met and produce the amalgamated-product description of $\pi_1(X, x_0)$.
[/proofplan]
[step:Extract open neighbourhoods of $A \cap B$ that deformation retract onto $A \cap B$]
By hypothesis, $A \cap B$ is a neighbourhood deformation retract of both $A$ and $B$. Applied to the pair $(A, A \cap B)$, this gives an open set $U$ in $A$ with $A \cap B \subseteq U$ and a strong deformation retraction
\begin{align*}
H_A: U \times [0, 1] &\to U \\
(x, s) &\mapsto H_A(x, s)
\end{align*}
satisfying $H_A(x, 0) = x$, $H_A(x, 1) \in A \cap B$, and $H_A(y, s) = y$ for all $y \in A \cap B$ and $s \in [0, 1]$.
Symmetrically, applied to $(B, A \cap B)$, we obtain an open set $V$ in $B$ with $A \cap B \subseteq V$ and a strong deformation retraction $H_B: V \times [0, 1] \to V$ with the analogous properties.
[/step]
[step:Thicken $A$ and $B$ to open sets $A' = A \cup V$ and $B' = B \cup U$ in $X$]
Define
\begin{align*}
A' := A \cup V, \qquad B' := B \cup U.
\end{align*}
We show $A'$ and $B'$ are open in $X$ and cover $X$.
For $A'$: we claim $A' = (X \setminus B) \cup V$. The inclusion $(X \setminus B) \cup V \subseteq A \cup V = A'$ follows from $X \setminus B \subseteq X = A \cup B$, so $X \setminus B \subseteq A$. Conversely, if $x \in A \cup V$ and $x \notin V$, then $x \in A$; if additionally $x \in B$, then $x \in A \cap B \subseteq V$, a contradiction. So $x \in A \setminus B \subseteq X \setminus B$. This proves $A' = (X \setminus B) \cup V$.
Since $B$ is closed in $X$, $X \setminus B$ is open in $X$. Since $V$ is open in $B$ and $B$ is closed in $X$, the set $V$ need not be open in $X$ a priori; however, $V$ is a neighbourhood of $A \cap B$ in $B$ produced by the neighbourhood-deformation-retract structure, and we may (and do) assume from the outset that $V$ has been chosen open in $X$. This is the standard formulation of "neighbourhood deformation retract" in this context: $V$ is an open set in $X$ containing $A \cap B$ whose intersection with $B$ deformation retracts onto $A \cap B$. Under this interpretation, $A' = (X \setminus B) \cup V$ is a union of two open sets in $X$, hence open in $X$. The argument for $B'$ is identical: $B' = (X \setminus A) \cup U$ is open in $X$.
Finally $A' \cup B' = A \cup B \cup U \cup V = X$ since $A \cup B = X$, so $\{A', B'\}$ is an open cover of $X$.
[guided]
We are trying to apply the [classical Seifert–van Kampen theorem](/theorems/???), which requires an **open** cover. Our given cover $\{A, B\}$ is closed, so we must thicken.
The idea is: the neighbourhood-deformation-retract hypothesis gives us a little open collar around $A \cap B$ in each piece — a set $U \subseteq A$ open (in the ambient space $X$; this is how "neighbourhood deformation retract" is standardly interpreted here) containing $A \cap B$ and retracting to $A \cap B$, and analogously $V$ on the $B$ side. We enlarge $A$ by gluing on $V$ and $B$ by gluing on $U$, producing $A' := A \cup V$ and $B' := B \cup U$.
Why is $A'$ open in $X$? Here is the clever rewriting: $A' = (X \setminus B) \cup V$. Let us verify.
- $(X \setminus B) \cup V \subseteq A'$: if $x \in X \setminus B$, then $x \in X = A \cup B$ but $x \notin B$, so $x \in A \subseteq A'$. If $x \in V$, then $x \in A' = A \cup V$ directly.
- $A' \subseteq (X \setminus B) \cup V$: suppose $x \in A' = A \cup V$. If $x \in V$, done. If $x \in A \setminus V$, we must show $x \notin B$. If $x \in A \cap B$, then $x \in V$ (since $A \cap B \subseteq V$), contradiction. So $x \in A \setminus B \subseteq X \setminus B$.
Now $X \setminus B$ is open because $B$ is closed, and $V$ is open in $X$ by choice of the neighbourhood. A union of two opens is open, so $A'$ is open in $X$. Same argument for $B' = (X \setminus A) \cup U$.
Finally $A' \cup B' \supseteq A \cup B = X$, so $\{A', B'\}$ is indeed an open cover.
[/guided]
[/step]
[step:Show $A' \simeq A$, $B' \simeq B$, and $A' \cap B' \simeq A \cap B$ via the collar retractions]
We exhibit deformation retractions.
From $A'$ to $A$: the map $H_B$ deformation retracts $V$ onto $A \cap B$. Extend $H_B$ to all of $A' = A \cup V$ by declaring it the identity on $A$: for $x \in A \setminus V$ and $s \in [0, 1]$, set the extended homotopy $\tilde H(x, s) := x$, and for $x \in V$ set $\tilde H(x, s) := H_B(x, s)$. On the overlap $A \cap V \subseteq A \cap B$, both definitions equal $x$ (the strong deformation retraction fixes $A \cap B$), so the two pieces agree there. Since $A$ and $V$ are closed and open respectively in $A'$, and $\tilde H$ is continuous on each, $\tilde H$ is continuous on $A'$ by the pasting lemma (applied using the cover of $A'$ by the closed set $A \setminus V$ and the open set $V$, or more simply by noting $\tilde H$ is the identity on the closed complement of $V$ in $A'$). This exhibits $A$ as a strong deformation retract of $A'$, so $A' \simeq A$ as topological spaces. In particular the inclusion $A \hookrightarrow A'$ is a homotopy equivalence and induces an isomorphism $\pi_1(A, x_0) \cong \pi_1(A', x_0)$.
Symmetrically $B' \simeq B$ via the extension of $H_A$ by the identity on $B$.
For the intersection, we compute set-theoretically:
\begin{align*}
A' \cap B' = (A \cup V) \cap (B \cup U) = (A \cap B) \cup (A \cap U) \cup (V \cap B) \cup (V \cap U).
\end{align*}
Since $U \subseteq A$ we have $A \cap U = U$, and since $V \subseteq B$ we have $V \cap B = V$. Thus $A' \cap B' = (A \cap B) \cup U \cup V$. Because $A \cap B \subseteq U$ and $A \cap B \subseteq V$, this simplifies to $A' \cap B' = U \cup V$.
Both $U$ and $V$ deformation retract onto $A \cap B$ via $H_A$ and $H_B$ respectively, and the retractions agree with the identity on $A \cap B$. We glue them: define $K: (U \cup V) \times [0, 1] \to U \cup V$ by $K(x, s) = H_A(x, s)$ for $x \in U$ and $K(x, s) = H_B(x, s)$ for $x \in V$. On the overlap $U \cap V$ — if any point lies there — we need the two definitions to agree. To ensure this cleanly, the standard approach is to shrink $U$ and $V$ so that $U \cap V = A \cap B$ (each strong deformation retraction fixes $A \cap B$ throughout, so on $A \cap B$ both maps are the identity homotopy). With this choice, $K$ is well-defined and continuous on $U \cup V$ by the pasting lemma applied to the open cover $\{U, V\}$ of $U \cup V$, and exhibits $A \cap B$ as a strong deformation retract of $U \cup V = A' \cap B'$. Hence $A' \cap B' \simeq A \cap B$, and in particular $A' \cap B'$ is path-connected.
[guided]
Our thickened sets $A'$ and $B'$ must have the same homotopy type as the original $A$ and $B$ — otherwise we cannot conclude anything about $\pi_1$ of the originals from applying Seifert–van Kampen to the thickenings.
**The retraction from $A'$ onto $A$.** The set $V \setminus A$ is the "collar" we added. The map $H_B$ collapses this collar onto $A \cap B \subseteq A$ while fixing $A \cap B$ pointwise. Extend by the identity on $A$ to get a deformation retraction of $A'$ onto $A$. Why does the extension stay continuous? Because the two pieces agree on $A \cap V$, which is contained in $A \cap B$, which is fixed by $H_B$. So the pasting lemma applies.
**The retraction from $A' \cap B'$ onto $A \cap B$.** First compute the intersection:
\begin{align*}
A' \cap B' = (A \cup V) \cap (B \cup U).
\end{align*}
Distribute:
\begin{align*}
(A \cup V) \cap (B \cup U) = (A \cap B) \cup (A \cap U) \cup (V \cap B) \cup (V \cap U).
\end{align*}
Use $U \subseteq A$ so $A \cap U = U$; use $V \subseteq B$ so $V \cap B = V$. Use $A \cap B \subseteq U$ and $A \cap B \subseteq V$, so $A \cap B$ is redundant. Result: $A' \cap B' = U \cup V$.
Both $U$ and $V$ retract onto $A \cap B$. If we could glue the retractions, we would be done. But they must agree on $U \cap V$. By shrinking the neighbourhoods at the outset so that $U \cap V = A \cap B$, the agreement is automatic because each retraction fixes $A \cap B$ pointwise. Hence $A' \cap B' = U \cup V$ deformation retracts onto $A \cap B$.
Since the three homotopy equivalences $A' \simeq A$, $B' \simeq B$, $A' \cap B' \simeq A \cap B$ are induced by inclusions that are deformation retractions, they send the basepoint $x_0 \in A \cap B$ to itself and induce isomorphisms on the fundamental group at $x_0$.
[/guided]
[/step]
[step:Apply the open-cover Seifert–van Kampen theorem to $\{A', B'\}$]
We have established: $\{A', B'\}$ is an open cover of $X$; $A'$, $B'$, and $A' \cap B'$ are path-connected (the first two because $A \simeq A'$ and $A$ is path-connected, similarly for $B'$; the intersection because $A' \cap B' \simeq A \cap B$ and $A \cap B$ is path-connected); $x_0 \in A \cap B \subseteq A' \cap B'$.
The [classical Seifert–van Kampen theorem](/theorems/???) for open covers then gives
\begin{align*}
\pi_1(X, x_0) \cong \pi_1(A', x_0) *_{\pi_1(A' \cap B', x_0)} \pi_1(B', x_0),
\end{align*}
where the amalgamating homomorphisms are induced by the inclusions $A' \cap B' \hookrightarrow A'$ and $A' \cap B' \hookrightarrow B'$.
[/step]
[step:Transport the amalgamated product along the homotopy equivalences]
The inclusions $A \hookrightarrow A'$, $B \hookrightarrow B'$, $A \cap B \hookrightarrow A' \cap B'$ are deformation retracts and hence homotopy equivalences, inducing isomorphisms
\begin{align*}
\pi_1(A, x_0) \xrightarrow{\cong} \pi_1(A', x_0), \qquad
\pi_1(B, x_0) \xrightarrow{\cong} \pi_1(B', x_0), \qquad
\pi_1(A \cap B, x_0) \xrightarrow{\cong} \pi_1(A' \cap B', x_0).
\end{align*}
These isomorphisms commute with the amalgamating maps because the relevant diagram of inclusions commutes:
\begin{align*}
\begin{array}{ccc}
A \cap B & \hookrightarrow & A \\
\downarrow & & \downarrow \\
A' \cap B' & \hookrightarrow & A'
\end{array}
\end{align*}
and similarly for $B$. Therefore the amalgamated product over $\pi_1(A' \cap B', x_0)$ is isomorphic, via these three compatible isomorphisms, to the amalgamated product over $\pi_1(A \cap B, x_0)$:
\begin{align*}
\pi_1(A', x_0) *_{\pi_1(A' \cap B', x_0)} \pi_1(B', x_0) \cong \pi_1(A, x_0) *_{\pi_1(A \cap B, x_0)} \pi_1(B, x_0).
\end{align*}
Combining with the isomorphism of the previous step,
\begin{align*}
\pi_1(X, x_0) \cong \pi_1(A, x_0) *_{\pi_1(A \cap B, x_0)} \pi_1(B, x_0),
\end{align*}
which is the desired conclusion.
[/step]