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


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


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

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

where each a[i] is chosen to make the term as big as possible without the total exceeding the target sqrt(S).

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


    1, 3, 5, 5, 16, etc
    starting i=1

For a perfect square, the expansion is a finite sequence of 1s summing to the root. This is unlikely to be interesting, but works as a $seq sequence.

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


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

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

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


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


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



Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 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 <>.