Kevin Ryde > Math-NumSeq-63 > Math::NumSeq::SqrtContinued

Math-NumSeq-63.tar.gz

Dependencies

Annotate this POD

Website

# CPAN RT

 Open 0
View/Report Bugs
Module Version: 63   Source   Latest Release: Math-NumSeq-69

# NAME

Math::NumSeq::SqrtContinued -- continued fraction expansion of a square root

# SYNOPSIS

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

# DESCRIPTION

This is terms in the continued fraction expansion of a square root. It approaches the root by

```                      1
sqrt(S) = a[0] + -----------
a[1] +   1
-----------
a[2] +   1
----------
a[3] + ...```

The first term a[0] is the integer part of the root, leaving a remainder 0 < r < 1 which is expressed as r=1/R with R > 1

```                     1
sqrt(S) = a[0] + ---
R```

Then a[1] is the integer part of that R, and so on recursively.

Values a[1] onwards are always a fixed-period repeating sequence. For example sqrt(14) is a[0]=3 and then 1,2,1,6 repeating. For some roots a single value repeats. For example sqrt(2) is a[0]=1 then 2 repeating. See SqrtContinuedPeriod for just the length of the period.

# FUNCTIONS

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

`\$seq = Math::NumSeq::SqrtContinued->new (sqrt => \$s)`

Create and return a new sequence object giving the Continued expansion terms of `sqrt(\$s)`.

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

Return the i'th term in the continued fraction, starting from i=0 for the integer part of the sqrt.

`\$i = \$seq->i_start ()`

Return 0, the first term in the sequence being i=0.

http://user42.tuxfamily.org/math-numseq/index.html