+
+\item Let
+$$
+ \set S = h(\pcn)
+ \cup
+ \bigcup_{\p \in \allpatches}
+ \bigcup_{H \in h(\pn) \lor H \in h(\py)}
+ \{ \baseof{E} \; | \; E \in \pendsof{H}{\pcy} \}
+$$
+
+and $W = w(h(\pcn))$
+
+\item While $\exists_{S \in \set S} S \ge W$,
+update $W \assign S$ and $\set S \assign \set S \, \backslash \{ S \}$
+
+(This will often remove $W$ from $\set S$. Afterwards, $\set S$
+is a collection of heads to be merged into $W$.)
+
+\item Choose an order of $\set S$, $S_i$ for $i=1 \ldots n$.
+
+\item For each $S_i$ in turn, choose a corresponding $M_i$
+such that $$
+ M_i \le S_i \land \left[
+ M_i \le W \lor \bigexists_{S_i, j<i} M_i \le s_i
+ \right]
+$$
+
+\item Set $\Gamma = \depsreqof{W}$.
+
+If there are multiple candidates we prefer $M_i \in \pcn$
+if available.
+
+\item For each $i \ldots 1..n$, update our putative direct
+dependencies:
+$$
+\Gamma \assign \text{\bf set-merge}\left(\Gamma,
+ \left[ \begin{cases}
+ M_i \in \pcn : & \depsreqof{M_i} \\
+ M_i \not\in \pcn : & \{ \}
+ \end{cases} \right],
+ \depsreqof{S_i}
+ \right)
+$$
+
+\item Finalise our putative direct dependencies
+$
+\Gamma \assign g(\pc, \Gamma)
+$
+
+\item For each direct dependency $\pd \in \Gamma$,
+
+\begin{enumerate}
+\item Add an edge $\pc \hasdirdep \pd$ to the digraph (adding nodes
+as necessary).
+If this results in a cycle, abort entirely (as the function $g$ is
+inappropriate; a different $g$ could work.)