Dirichlet's Unit Theorem tells us all units in the integer ring of a real quadratic field, say $\mathbb{Z}[\sqrt{d}]$, are powers of a single "fundamental unit". Meaning there exists $\alpha=a+b\sqrt{d}$ such that $N(\alpha)=a^2-db^2=\pm1$ and that for any other unit $\beta$ there exists an integer $k$ such that $\beta=\alpha^k$.
What I'm wondering is whether there's a formula for $a$ and $b$ in terms of $d$. For $d=2$ for example, we have $a=b=1$ and $\alpha=1+\sqrt{2}$.
I understand also that $a^2-db^2=\pm1$ is essentially a solution to Pell's equation. One can find a table of solutions for $d=1,...,128$ on Wikipedia $-$ but no formula. That same wikipedia article also points out that the smallest solutions for some particular $d$ can be very large relative to $d$. For example, with $d=313$, the smallest solution is $$a, b = 32188120829134849, 1819380158564160.$$ That's not encouraging for the existence of a formula.
This came up because in a theorem on $\mathbb{Z}[\sqrt{2}]$ I'm hoping to generalize to $\mathbb{Z}[\sqrt{d}]$ in general. The most encouraging route for proving the generalization makes heavy use of the value of $b$.
What branch of math should one even walk down in hopes of spotting an answer?
Not formula but algorithm of course exist. In pari/gp command
bnfinit('X^2-d).fureturn fundamental unit.gp-code:
output: