and 1 contributors

# NAME

Math::NumSeq::SqrtContinuedPeriod -- period of the continued fraction for sqrt(i)

# SYNOPSIS

`````` use Math::NumSeq::SqrtContinuedPeriod;
my \$seq = Math::NumSeq::SqrtContinuedPeriod->new;
my (\$i, \$value) = \$seq->next;``````

# DESCRIPTION

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.

# FUNCTIONS

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 `sqrt(\$s)`.

`\$value = \$seq->ith (\$i)`

Return the period of sqrt(\$i).