[guided]Generalization is the one genuinely new case compared with the propositional Deduction Theorem. The trick is to split on whether $p$ was used as a hypothesis in the sub-proof of $r$.
**Setup.** $q_i = (\forall x)\,r$ was obtained by applying Gen to $q_j = r$, where the Gen side condition requires that $x$ is not free in any hypothesis used to derive $r$ from $S \cup \{p\}$. Let $H \subseteq S \cup \{p\}$ be the hypotheses actually used. By induction, $S \vdash p \Rightarrow r$.
**Why split on whether $p \in H$?** Because the Gen side condition gives different information in the two cases:
- If $p \notin H$, then $r$ was derivable from $S$ alone — the premise $p$ was superfluous in that sub-proof — and we can reproduce the Gen step entirely within $S$.
- If $p \in H$, then the Gen side condition constrains $p$: specifically, $x$ is not free in $p$. This is precisely the hypothesis of Axiom 7, which lets us commute $\forall x$ across $\Rightarrow$.
**Sub-case 1: $p \notin H$.** Since $H \subseteq S$, the sub-proof deriving $r$ from $S \cup \{p\}$ is in fact a proof of $r$ from $S$. Gen applies there too (the side condition on $x$ is unchanged), giving $S \vdash (\forall x)\,r$. Then Axiom 1 ($((\forall x)\,r) \Rightarrow (p \Rightarrow (\forall x)\,r)$) plus Modus Ponens gives $S \vdash p \Rightarrow (\forall x)\,r$.
**Sub-case 2: $p \in H$.** The Gen side condition tells us $x$ is not free in $p$. By induction $S \vdash p \Rightarrow r$. Apply Gen to this new derivation:
\begin{align*}
S \vdash (\forall x)(p \Rightarrow r).
\end{align*}
Does Gen apply? We must check the side condition: $x$ is not free in any hypothesis from $S$ used to derive $p \Rightarrow r$. By the way the inductive construction was built, these are (a subset of) the hypotheses from $S$ used in deriving $r$ in the original proof — i.e.\ members of $H \cap S$ — and the original Gen side condition guarantees $x$ is not free in any of them. So Gen is legitimate.
Now apply Axiom 7:
\begin{align*}
(\forall x)(p \Rightarrow r) \Rightarrow (p \Rightarrow (\forall x)\,r),
\end{align*}
valid because $x$ is not free in $p$. Modus Ponens delivers $S \vdash p \Rightarrow (\forall x)\,r$.
**Why the case split is unavoidable.** If we naively tried to apply Axiom 7 without first checking that $x$ is not free in $p$, we would fail: the axiom's side condition is precisely this freshness condition. Sub-case 1 is the case where Axiom 7 is unavailable (we don't know $x$ isn't free in $p$), but fortunately $p$ wasn't used anyway, so we can sidestep it entirely. Sub-case 2 is the case where Axiom 7 is available, and we use it.
**Where does Soundness relate?** The premise that the Gen condition controls which variables can be quantified away is what makes the Deduction Theorem true — without it, the forward direction would fail. For example, $\{p(x)\} \vdash (\forall x)\,p(x)$ by Gen if we incorrectly allowed Gen over a free variable of a hypothesis, but $\vdash p(x) \Rightarrow (\forall x)\,p(x)$ is not valid. The Gen side condition blocks this spurious derivation, and the analysis above is precisely what respects that block.[/guided]