The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::NumSeq::SqrtEngel -- Engel expansion of a square root

SYNOPSIS

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

DESCRIPTION

This is terms in the Engel expansion of a square root. It approaches the root by a series

              1         1              1
   sqrt(s) = ---- + --------- + -------------- + ...
             a[1]   a[1]*a[2]   a[1]*a[2]*a[3]

The sequence values are each successive a[i]. For example sqrt(2)

              1     1      1        1          1
   sqrt(2) = --- + --- + ----- + ------- + ---------- + ...
              1    1*3   1*3*5   1*3*5*5   1*3*5*5*16

is

    1, 3, 5, 5, 16, etc

Each new 1/prod term is the biggest which keeps the total below sqrt(s), which means each a[i] is the smallest possible.

For a perfect square the expansion is a trivial 1s sequence adding up to the root. This is unlikely to be interesting but it works.

    1/1+1/1+...+1/1 = sqrt(perfect square)

FUNCTIONS

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

$seq = Math::NumSeq::SqrtEngel->new (sqrt => $s)

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

BUGS

The current code requires Math::BigInt sqrt(), which may mean BigInt 1.60 or higher (which comes with Perl 5.8.0).

SEE ALSO

Math::NumSeq, Math::NumSeq::SqrtDigits

HOME PAGE

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

LICENSE

Copyright 2011, 2012 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/>.