Math::N...qrtEngel(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

✨ Math::NumSeq::SqrtEngel πŸ’–

okay so bestie, welcome to Math::NumSeq::SqrtEngel β€” she's part of the User Contributed Perl Documentation family, and she does exactly one thing but she does it gorgeously: she hands you the Engel expansion of a square root. no cap. πŸŽ€


🌸 SYNOPSIS 🌸

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

like, three lines and you're already getting terms. iconic behavior honestly. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So. These are the terms in the Engel expansion of a square root, and the way it works is that the expansion sneaks up on the root with a series like this:

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

and every single a[i] is picked to make that term as big as possible without the running total ever tipping over the target sqrt(S). it's giving "greedy but make it math". 🧚

The sequence values are each successive a[i]. so for sqrt(2) you get:

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

which is literally just

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

and yes, starting i=1 β€” she's a one-indexed queen, no zero-index nonsense here. πŸ‘‘

Now, if you feed her a perfect square, the expansion is a finite sequence of 1s that sums right up to the root. ngl that's unlikely to be interesting to you, but it totally works as a $seq sequence, so there's that. πŸ’€

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

✨ FUNCTIONS ✨

Peep "FUNCTIONS" in Math::NumSeq for all the behaviour that's common to every sequence class out there. 🫢

  • $seq = Math::NumSeq::SqrtEngel->new (sqrt => $integer) β€” makes you a brand new sequence object and hands it back, dishing out the Engel expansion terms of sqrt($integer). that's the whole gig. slay. 🌈

πŸ’€ BUGS πŸ’€

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

so like. heads up. she has a dependency and she's not shy about it. πŸ™ˆ


πŸ”₯ SEE ALSO πŸ”₯

  • Math::NumSeq
  • Math::NumSeq::SqrtDigits

go read those too, they're the friend group. πŸ’œ


πŸ‘‘ HOME PAGE πŸ‘‘

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

that's the link, bestie, copy it, paste it, live your truth. ⭐


πŸŽ€ LICENSE πŸŽ€

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 <http://www.gnu.org/licenses/>.


and that's the whole page, babes 🫢 this one shipped in perl v5.42.0 on 2025-07-25, and it's still living in the Math::N...qrtEngel(3) corner of your friendly neighbourhood man pages. mwah. πŸ’–βœ¨

πŸ“¦ where this page comes from