Question: If $n>2$ let $p_n$ be the $n-$th prime number. I write $\xi_{n}$ for the simple periodic continued fraction: $$ \xi_n:=[2;4,6,8,\ldots,p_{n}-3,\overline{p_n-1}]. $$ How can I find the numbers $P,D$ and $Q$ such that $\xi_{n}$ can be rewritten as $$ \frac{P+\sqrt{D}}{Q} $$ ?
Per Wikipedia $\xi_n$ is a quadratic irrational number and so is an algebraic number of degrees 2. In particular $\xi_n$ is the root of the real quadratic equation $ \alpha_{0}x^2+\alpha_{1}x+\alpha_{2} $ from which it follows that $\xi_n$ can be rewritten as $ \frac{P+\sqrt{D}}{Q}. $ Below are some examples:
- If $n$ is equal to 2 then $p_2=3$ and so $\xi_2:=[2;\overline{2}];$ which can be rewritten as $1+\sqrt{2}.$
- If $n$ is equal to 3 then $p_3=5$ and so $\xi_3:=[2;\overline{4}];$ which can be rewritten as $\sqrt{5}.$
- If $n$ is equal to 4 then $p_4=7$ and so $\xi_4:=[2;4,\overline{6}];$ which can be rewritten as $\frac{17+\sqrt{10}}{9}.$
- If $n$ is equal to 5 then $p_5=11$ and so $\xi_5:=[2;4,6,8,\overline{10}];$ which can be rewritten as ?
- If $n$ is equal to 6 then $p_6=13$ and so $\xi_6:=[2;4,6,8,10,\overline{12}];$ which can be rewritten as ?
- If $n$ is equal to 7 then $p_7=17$ and so $\xi_7:=[2;4,6,8,10,12,14,\overline{16}];$ which can be rewritten as ?
One trick I was shown is to substitute $$ x=\cfrac{1}{(p_{n}-1)+\cfrac{1}{(p_{n}-1)+\cfrac{1}{(p_{n}-1)+...}}}=[\overline{p_{n}-1}]; $$ so that $$ \frac{1}{x}=p_{n}-1+x $$ I could then multpily the LHS and RHS by $x$ to get the quadratic equation $$ x^2+xp_{n}-x-1=0 $$ Another substitution yields: $$ \xi_{n}=2+\cfrac{1}{4+\cfrac{1}{6+\cfrac{1}{\ddots\frac{1}{p_{n}-3+x}}}} $$ This approach seemed reasonable when $n$ was small say less than 4. But it proved difficult as $n$ became larger.
First of all, your usage of primes is a bit of a red herring; since your continued fraction $\xi_n$ only uses $p_n$ but not any previous primes, you might as well look at $\zeta_n=[2;4,6,8,\ldots,\overline{2n}]$; your $\xi_n$ is then just $\xi_n=\zeta_{(p_n-1)/2}$.
Next, as you've already noted and as Will Jagy notes in his answer, the purely periodic CF at the bottom of your fraction is easy to evaluate: if $x=[\overline{2n}]$ then $x=2n+1/x$, so $x^2=2nx+1$ and $x^2-2nx-1=0$, and the quadratic equation quickly gives $x=n+\sqrt{n^2+1}$.
The last piece of the puzzle is the representation of the Moebius transformations that Will Jagy mentions. First, let's consider the affine space $\mathbb{A}$ over $\mathbb{R}$ where elements are equivalence classes of vectors $\left[\begin{smallmatrix}s\\t\end{smallmatrix}\right]$ (with $s$ and $t$ not both zero) and two vectors $\left[\begin{smallmatrix}s\\t\end{smallmatrix}\right]$ and $\left[\begin{smallmatrix}u\\v\end{smallmatrix}\right]$ are equivalent if $sv=tu$ (or, equivalently, there's some $\lambda$ with $s=\lambda u$ and $t=\lambda v$). This space looks a lot like $\mathbb{R}$: every element except for those of the form $\left[\begin{smallmatrix}c\\0\end{smallmatrix}\right]$ is equivalent to a unique element of the form $\left[\begin{smallmatrix}\alpha\\1\end{smallmatrix}\right]$ (where $\alpha=s/t$), and we can define arithmetic operations on equivalence classes of elements in ways that are compatible with this. (I'm being a bit sloppy here, but details shouldn't be too hard to find if you're interested.)
Now, we can define an action of 2x2 matrices on the affine space in the most natural way possible, matrix multiplication: if $M=\left(\begin{smallmatrix}a&b\\c&d\end{smallmatrix}\right)$ is a nonsingular 2x2 matrix and $\sigma=\left[\begin{smallmatrix}s\\t\end{smallmatrix}\right]$, then $\tau=M\sigma=\left[\begin{smallmatrix}as+bt\\cs+dt\end{smallmatrix}\right]$ is also a member of the affine space. (Convince yourself that if $\sigma\equiv\zeta$ in the affine space then $M\sigma\equiv M\zeta$, so this is really an operation on the equivalence classes.) Because this is just a matrix multiplication, it has all the correct behaviors with respect to associativity etc.; $M(N\sigma)=(MN)\sigma$, so it forms a proper group action. This is (essentially) the projective linear group or Moebius group over the (affine) real line. (Note that really the elements of the group are equivalence classes of matrices, since if $M=\alpha N$ for some $\alpha\in\mathbb{R}$ then $M\sigma=N\sigma$ for all $\sigma\in\mathbb{A}$; I'm glossing over this a bit here.)
What does this have to do with continued fractions? Well, if $x$ is some real number, then $[a;x]$ is $a+1/x = (xa+1)/x$, and this can be represented as the matrix $M_a=\left(\begin{smallmatrix}a&1\\1&0\end{smallmatrix}\right)$ acting on the element $\xi=\left[\begin{smallmatrix}x\\1\end{smallmatrix}\right]$ of $\mathbb{A}$. Extending this out, the continued fraction $[a_0;a_1,a_2,\ldots,a_n,x]$ can be represented as $M_{a_0}M_{a_1}\ldots M_{a_n}\left[\begin{smallmatrix}x\\1\end{smallmatrix}\right]$. This should give you a recurrence formula that you can use to determine the coefficients of your quadratic number; whether you can get anything 'cleaner' than that recurrence relation, though, seems dubious.