Math::N...bonacci(3)

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

πŸ’– Math::N...bonacci(3) β€” the spiro-Fibonacci situation πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation manual, and it's about Math::NumSeq::SpiroFibonacci. yes the title is literally abbreviated like that, it's giving mysterious. anyway. sit down, grab a snack πŸ“, we're doing number spirals.


✨ NAME ✨

Math::NumSeq::SpiroFibonacci β€” recurrence around a square spiral πŸŒ€


✨ SYNOPSIS ✨

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

no cap, that's the whole vibe right there. three lines and you're in. πŸ’…


✨ DESCRIPTION ✨

So these are the spiro-Fibonacci numbers by Neil Fernandez. Not me making that up, that's genuinely who it is, periodt.

The sequence is a recurrence:

SF[0] = 0
SF[1] = 1
SF[i] = SF[i-1] + SF[i-k]

and here's the tea: that offset k is the closest point on the preceding loop of a square spiral. (not to be dramatic but that's the entire personality of this function.)

The initial values are:

0, 1, 1, ..., 1, 2, 3, 4, ... 61, 69, 78, 88, 98, 108, ...
starting i=0

so it starts all cute and boring with a bunch of 1s and then highkey escalates. look at it go. 🌈

On the square spiral this is:

 98-88-78-69-61-54-48
  |                 |
108 10--9--8--7--6 42
  |  |           |  |
    11  1--1--1  5 36
     |  |     |  |  |
    12  1  0--1  4 31
     |  |        |  |
    13  1--1--2--3 27
     |              |
    14-15-16-18-21-24

Value 36 on the right is 31+5, being the immediately preceding 31 and the value on the next inward loop closest to that new 36 position. see? it's not random, it's ✨intentional✨.

At the corners the same inner value gets used three times, so for example 42=36+6, then 48=42+6 and 54=48+6, all using the corner "6". one number, three jobs, main character energy fr fr πŸ‘‘.

And for the innermost loop SF[2] through SF[7], the "0" at the origin is the inner value, hence the run of seven 1s at the start. that's why it looks like that. mystery solved πŸ•΅οΈ

πŸ¦‹ Absolute Differences πŸ¦‹

Optional recurrence_type => 'absdiff' changes the recurrence formula to an absolute difference:

SF[i] = abs (SF[i-1] - SF[i-k])

With the default initial values SF[0]=0 and SF[1]=1 this behaves as an XOR, always giving 0 or 1. yes, always. zero or one. that's it. that's the whole menu.

0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, ...

The result plotted around the square spiral is similar to some of the cellular automaton patterns which work on xor feedback. and honestly? it ate.

*** *    *  **       *     **  **      * * * *  * * **
* *  *****   *        *** * * * * *      ******** *****
 **   * * ****         * ********      *       **    *
  *    **  * *          **      *      **      * *   *
***     *   **           *     **      * *     ****  *
 * ******    *            *** * *      ****    *   * *
  ** * * *****             * ***       *   *   **  ***
*** **  ** * *              **o**      **  **  * * *
* *  *   *  **               * * *     * * * * ******
 **   ****   *              *  * **    *********     *
** **** * ****              ***    *   *        *    *
* ** * **  * *              * *******  **       **   *
 ** **  *   **              ** * * * * * *      * *  *
** ** ***    *              *  **  * ******     **** *
 *  *  * *****              *** ***        *    *   **

like??? the symmetry??? i'm obsessed 😭

🌸 Initial Values 🌸

Optional initial_0 and initial_1 can give different initial i=0 and i=1 values. For example initial_0=>1, initial_1=>0 gives:

1, 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 7, 8, 9, 11, 14, 17, 20, ...

flip the first two and the whole sequence changes its whole vibe. iconic behaviour, no notes. πŸ’œ


✨ FUNCTIONS ✨

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes. (go read that one too, it's the shared lore 🫢)

  • $seq = Math::NumSeq::SpiroFibonacci->new () β€” Create and return a new sequence object. fresh out the box, brand new, ready to spiral.
  • ($i, $value) = $seq->next() β€” Return the next index and value in the sequence.
⚠️ okay important one: when $value exceeds the range of a Perl unsigned integer the return is promoted to a Math::BigInt to keep full precision. so it will NOT silently lose your digits, it upgrades itself. we love a glow-up ✨

✨ SEE ALSO ✨

  • Math::NumSeq
  • Math::NumSeq::Fibonacci
  • Math::PlanePath::SquareSpiral

the friend group πŸ«‚


✨ HOME PAGE ✨

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


✨ LICENSE ✨

Copyright 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/>.

bestie that's the standard "no promises, it's free, be normal about it" legal speak. read it, it's real. πŸ’€

and that's the whole page!! πŸŽ€ this was Math::N...bonacci(3) from perl v5.42.0, dated 2025-07-25 β€” yes the manual page name really is abbreviated like that and yes it's still sending me. go forth and spiral, you've got this πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from