Math::N...qrtEngel(3)
β¨ 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 ofsqrt($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::NumSeqMath::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
- fedora 43: perl-Math-NumSeq 75-11.fc43 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms