![]() | 1 | initial version |
Via the reference within this page: http://www.numbertheory.org/php/surd.html
I found a more elegant algorithm than the one sketched above:
Algorithm for finding the period of a quadratic irrational
Input: (a,b,c)∈Z×N×Z and b not a perfect square. This triple represents a+√bc.
If c does not divide b−a2 then multiply everything by |c||c| , and get new triple that we call (a′,b′,c′)
Set P0=a′ , Q0=c′, d=c′.
For k≥0 set
(a) αk=Pk+√dQk
(b) ak=⌊αk⌋
(c) Pk+1=akQk−Pk
(d) Qk+1=d−P2k+1Qk
Then α0=a+√bc=[a0,a1,a2,...]
Let k<l be the first pair of integers which satisfy that (Pk,Qk)=(Pl,Ql) then the period of α0 is (ak,…,al−1) .
Hopefully this will help implementing it...