Math::N...edPeriod(3)

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

✨ 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 of sqrt($s). so fresh, so clean πŸŽ€
  • $value = $seq->ith ($i) β€” returns the period of sqrt($i). literally the main character of this whole module πŸ‘‘

🌈 SEE ALSO 🌈

  • Math::NumSeq
  • Math::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