Math::N...edPeriod(3)
β¨ NAME β¨
okay bestie, so Math::NumSeq::SqrtContinuedPeriod is the whole vibe here β it gives you the period of the continued fraction for sqrt(i). yes, that's the actual name, it's giving "my parents named me after a math paper" π
πΈ SYNOPSIS πΈ
use Math::NumSeq::SqrtContinuedPeriod;
my $seq = Math::NumSeq::SqrtContinuedPeriod->new;
my ($i, $value) = $seq->next;
that's it, that's the whole entry point, no cap π«Ά
π¦ DESCRIPTION π¦
so this module hands you the period of the repeating part of the continued fraction expansion of sqrt(i). like, the little loop that keeps going forever and ever.
the sequence starts out like:
0, 1, 2, 0, 1, 2, 4, 2, etc
let's do a real example because numbers are so much cuter when they mean something. take sqrt(12) β it's 3 and then the terms 2,6 just keep repeating, which means the period is 2.
1
sqrt(12) = 3 + -----------
2 + 1
-----------
6 + 1
----------
2 + 1
---------
6 + ... 2,6 repeating
every square root continued fraction looks like this btw: an integer part, then repeating terms of some length. the whole structure is so iconic honestly.
perfect squares though? they're built different π β they're just an integer part with nothing further, and the period for them is taken to be 0.
the continued fraction calculation has a denominator value at each stage shaped like:
den =(P+sqrt(S)) / Q
with
0 <= P <= root
0 < Q <= 2*root+1
where root=floor(sqrt(S))
and because P and Q are limited to that range, you only ever get a finite set of combinations β at most root*(2*root+1), which is roughly 2*S. in practice though it's way less than that. the math really said "I'll be efficient about it" β¨
π FUNCTIONS π
peep "FUNCTIONS" in Math::NumSeq for the behaviour that's common to all sequence classes, bestie β this module doesn't reinvent the wheel.
$seq = Math::NumSeq::SqrtContinuedPeriod->new (sqrt => $s)β makes a new sequence object that gives you the continued expansion terms ofsqrt($s). so fresh, so clean π$value = $seq->ith ($i)β returns the period ofsqrt($i). literally the main character of this whole module π
π SEE ALSO π
Math::NumSeqMath::NumSeq::SqrtContinued
go read those next, they're the friends in this little friend group π
π HOME PAGE π
<http://user42.tuxfamily.org/math-numseq/index.html>
π 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/>.
fr fr, that's the legal stuff, don't skip it, it's important π
and that's a wrap bestie π«Ά this lil page is perl v5.42.0, dated 2025-07-25, and it's the Math::N...edPeriod(3) manual β you ate that, periodt π
β¨
π¦ 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