12. (18 points) The inverse function of $f(x)$ is $y=\frac{x}{1+x}$, $g_{n}(x)+\frac{1}{f_{n}(x)}=0$, let $f_{1}(x)=f(x)$, and for $n>1\left(n \in \mathbf{N}_{+}\right)$, $f_{n}(x)=f_{n-1}\left(f_{n-1}(x)\right)$. Find the analytical expression for $g_{n}(x)\left(n \in \mathbf{N}_{+}\right)$.
(3) $\left\{\begin{array}{l}5-d+\frac{3}{q}=4, \\ 5+d+3 q=16\end{array} \Rightarrow 3 q+\frac{3}{q}=10\right.$ $\Rightarrow q=3$ or $\frac{1}{3} \Rightarrow d_{1,2}=1+\frac{3}{q_{1,2}}$.
Clearly, the larger $d$ is 10.
(4) $\left\{\begin{array}{l}5-d+\frac{3}{q}=8 \\ 5+d+3 q=8\end{array} \Rightarrow q+\frac{1}{q}=2\right.$ $\Rightarrow q=1 \Rightarrow d=0$.
In summary, the maximum value of $d$ is $4+\frac{55+7 \sqrt{61}}{2}$.
Therefore, the largest $a_{3}$ is $9+\frac{55+7 \sqrt{61}}{2}$.
12. From $y=\frac{x}{1+x}$, it is easy to get $f(x)=\frac{x}{1-x}$.

Thus, $\frac{1}{f(x)}=\frac{1}{x}-1$.
From $g_{n}(x)+\frac{1}{f_{n}(x)}=0$, we have
$g_{n}(x)=-\frac{1}{f_{n}(x)}$.
Also, $\frac{1}{f_{1}(x)}=\frac{1}{f(x)}=\frac{1}{x}-1$, so
$\frac{1}{f_{2}(x)}=\frac{1}{f_{1}\left(f_{1}(x)\right)}=\frac{1}{f_{1}(x)}-1=\frac{1}{x}-2$,
$\frac{1}{f_{3}(x)}=\frac{1}{f_{2}\left(f_{2}(x)\right)}=\frac{1}{f_{2}(x)}-2=\frac{1}{x}-2^{2}$,
$\qquad$
By this, we conjecture $\frac{1}{f_{n}(x)}=\frac{1}{x}-2^{n-1}\left(n \in \mathbf{N}_{+}\right)$.
We will prove this by induction on $n \in \mathbf{N}_{+}$.
Assume that when $n=k$, $\frac{1}{f_{k}(x)}=\frac{1}{x}-2^{k-1}$ holds.
When $n=k+1$, we have
$\frac{1}{f_{k+1}(x)}=\frac{1}{f_{k}\left(f_{k}(x)\right)}=\frac{1}{f_{k}(x)}-2^{k-1}=\frac{1}{x}-2^{k}$.
Thus, the conjecture holds for $n=k+1$.
Therefore, for all $n \in \mathbf{N}_{+}$, we have
$g_{n}(x)=-\frac{1}{f_{n}(x)}=2^{n-1}-\frac{1}{x}$.