Kevin Ryde > Math-NumSeq-67 > Math::NumSeq::SqrtEngel

Math-NumSeq-67.tar.gz

Dependencies

Annotate this POD

Website

# CPAN RT

 Open 1
View/Report Bugs
Module Version: 67

# 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. 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```

is

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

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

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

# FUNCTIONS

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)`.

# BUGS

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

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