Math::NumSeq::SqrtContinuedPeriod -- period of the continued fraction for sqrt(i)
use Math::NumSeq::SqrtContinuedPeriod; my $seq = Math::NumSeq::SqrtContinuedPeriod->new; my ($i, $value) = $seq->next;
This the period of the repeating part of the continued fraction expansion of sqrt(i).
0, 1, 2, 0, 1, 2, 4, 2, etc
For example sqrt(12) is 3 then terms 2,6 repeating, which is period 2.
1 sqrt(12) = 3 + ----------- 2 + 1 ----------- 6 + 1 ---------- 2 + 1 --------- 6 + ... 2,6 repeating
All square root continued fractions like this comprise an integer part followed by repeating terms of some length. Perfect squares are an integer part only, nothing further, and the period for them is taken to be 0.
The continued fraction calculation has denominator value at each stage of the form
den =(P+sqrt(S)) / Q with 0 <= P <= root 0 < Q <= 2*root+1 where root=floor(sqrt(S))
The limited range of P,Q means a finite set of combinations at most root*(2*root+1), which is roughly 2*S. In practice it's much less.
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::SqrtContinuedPeriod->new (sqrt => $s)
Create and return a new sequence object giving the Continued expansion terms of
$value = $seq->ith ($i)
Return the period of sqrt($i).
Copyright 2011, 2012, 2013 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.