[step:Construct the tree recursor and prove its uniqueness by tree induction]
Fix a type $D$, a function
\begin{align*}
d_0:A\to D,
\end{align*}
and a function
\begin{align*}
d_1:\mathsf{Tree}(A)\to\mathsf{Tree}(A)\to D\to D\to D.
\end{align*}
By the tree primitive recursion principle for the inductive type $\mathsf{Tree}(A)$, applied to the constant target type $D$, the leaf step $d_0$, and the node step $d_1$, there is a function
\begin{align*}
r:\mathsf{Tree}(A)\to D
\end{align*}
with beta computation rules, for every $a:A$,
\begin{align*}
r(\mathsf{leaf}(a))=d_0(a)
\end{align*}
and, for every $t_1,t_2:\mathsf{Tree}(A)$,
\begin{align*}
r(\mathsf{node}(t_1,t_2))=d_1(t_1,t_2,r(t_1),r(t_2)).
\end{align*}
Let
\begin{align*}
q:\mathsf{Tree}(A)\to D
\end{align*}
satisfy the same equations:
\begin{align*}
q(\mathsf{leaf}(a))=d_0(a)
\end{align*}
for every $a:A$, and
\begin{align*}
q(\mathsf{node}(t_1,t_2))=d_1(t_1,t_2,q(t_1),q(t_2))
\end{align*}
for every $t_1,t_2:\mathsf{Tree}(A)$.
Define
\begin{align*}
R:\mathsf{Tree}(A)\to\mathsf{Type}
\end{align*}
by
\begin{align*}
R(t)=\operatorname{Id}_D(q(t),r(t)).
\end{align*}
For a leaf $\mathsf{leaf}(a)$, the two leaf equations give
\begin{align*}
q(\mathsf{leaf}(a))=d_0(a)=r(\mathsf{leaf}(a)),
\end{align*}
so $R(\mathsf{leaf}(a))$ holds.
For a node, fix $t_1,t_2:\mathsf{Tree}(A)$ and induction hypotheses
\begin{align*}
p_1:\operatorname{Id}_D(q(t_1),r(t_1))
\end{align*}
and
\begin{align*}
p_2:\operatorname{Id}_D(q(t_2),r(t_2)).
\end{align*}
The recursion equations give
\begin{align*}
q(\mathsf{node}(t_1,t_2))=d_1(t_1,t_2,q(t_1),q(t_2))
\end{align*}
and
\begin{align*}
r(\mathsf{node}(t_1,t_2))=d_1(t_1,t_2,r(t_1),r(t_2)).
\end{align*}
First applying congruence in the third argument of $d_1(t_1,t_2,-,q(t_2))$ to $p_1$, and then congruence in the fourth argument of $d_1(t_1,t_2,r(t_1),-)$ to $p_2$, gives
\begin{align*}
d_1(t_1,t_2,q(t_1),q(t_2))=d_1(t_1,t_2,r(t_1),r(t_2)).
\end{align*}
By transitivity with the two node computation equations,
\begin{align*}
q(\mathsf{node}(t_1,t_2))=r(\mathsf{node}(t_1,t_2)).
\end{align*}
The tree induction principle applies because $R:\mathsf{Tree}(A)\to\mathsf{Type}$ is a dependent predicate, $R(\mathsf{leaf}(a))$ was constructed for every $a:A$, and the node construction sends hypotheses for $t_1$ and $t_2$ to a term of $R(\mathsf{node}(t_1,t_2))$. Therefore it gives
\begin{align*}
\prod_{t:\mathsf{Tree}(A)}\operatorname{Id}_D(q(t),r(t)).
\end{align*}
Thus $q(t)=r(t)$ for every $t:\mathsf{Tree}(A)$.
[/step]