The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::PlanePath::WythoffArray -- table of Fibonacci recurrences

SYNOPSIS

 use Math::PlanePath::WythoffArray;
 my $path = Math::PlanePath::WythoffArray->new;
 my ($x, $y) = $path->n_to_xy (123);

DESCRIPTION

This path is the Wythoff array of Fibonacci recurrences, or Zeckendorf Fibonacci base trailing zeros.

     15  |  40   65  105  170  275  445  720 1165 1885 3050 4935
     14  |  38   62  100  162  262  424  686 1110 1796 2906 4702
     13  |  35   57   92  149  241  390  631 1021 1652 2673 4325
     12  |  33   54   87  141  228  369  597  966 1563 2529 4092
     11  |  30   49   79  128  207  335  542  877 1419 2296 3715
     10  |  27   44   71  115  186  301  487  788 1275 2063 3338
      9  |  25   41   66  107  173  280  453  733 1186 1919 3105
      8  |  22   36   58   94  152  246  398  644 1042 1686 2728
      7  |  19   31   50   81  131  212  343  555  898 1453 2351
      6  |  17   28   45   73  118  191  309  500  809 1309 2118
      5  |  14   23   37   60   97  157  254  411  665 1076 1741
      4  |  12   20   32   52   84  136  220  356  576  932 1508
      3  |   9   15   24   39   63  102  165  267  432  699 1131
      2  |   6   10   16   26   42   68  110  178  288  466  754
      1  |   4    7   11   18   29   47   76  123  199  322  521
    Y=0  |   1    2    3    5    8   13   21   34   55   89  144
         +-------------------------------------------------------
           X=0    1    2    3    4    5    6    7    8    9   10

N=1,2,3,5,8,etc on the X axis is the Fibonacci numbers. N=4,7,11,18,etc in the row Y=1 above it is the Lucas numbers.

All rows have the Fibonacci style recurrence F(X+1) = F(X)+F(X-1). For example at X=4,Y=2 the N=42 is 16+26, the sum of the two values to its left.

N=1,4,6,9,12,etc on the Y axis is the "spectrum" of the golden ratio, meaning its rounded down integer multiples. For example at Y=5 N=5+floor((5+1)*phi)=14.

    phi = (sqrt(5)+1)/2
    spectrum(k) = floor(phi*k)
    N on Y axis = Y + spectrum(Y+1)

The recurrence in each row starts as if there were two values Y and spectrum(Y+1) to the left of the axis, adding together to be Y+spectrum(Y+1) on the axis, then Y+2*spectrum(Y+1) in the X=1 column, etc.

If there's a common factor in the initial values in a row then that factor remains in all subsequent sums. For example the Y=2 row starts with two even numbers, and so the whole row is even.

Every N from 1 upwards occurs precisely once in the table. The recurrence means that in each row N grows as roughly a power phi^X, the same as the Fibonacci numbers, so they become large quite quickly.

Zeckendorf Base

The N values are arranged according to trailing zero bits when N is represented in the Zeckendorf base. This base makes N a sum of Fibonacci numbers, choosing at each stage the largest possible Fibonacci. For example

    Fibonacci F[0]=1, F[1]=2, F[2]=3, F[3]=5, etc

    45 = 34 + 8 + 3
       = F[7] + F[4] + F[2]
       = 10010100        1-bits at 7,4,2

The array in Zeckendorf base bits is

      8  |  101010  1010100  10101000 101010000 1010100000
      7  |  101001  1010010  10100100 101001000 1010010000
      6  |  100101  1001010  10010100 100101000 1001010000
      5  |  100001  1000010  10000100 100001000 1000010000
      4  |   10101   101010   1010100  10101000  101010000
      3  |   10001   100010   1000100  10001000  100010000
      2  |    1001    10010    100100   1001000   10010000
      1  |     101     1010     10100    101000    1010000
    Y=0  |       1       10       100      1000      10000
         +--------------------------------------------------
               X=0        1         2         3          4

The X coordinate is the number of trailing zeros, which is the lowest Fibonacci used in the sum.

The Y coordinate is formed by stripping any trailing zero bits, then the lowest 1, and then one more 0 above that. For example,

    N = 45 = Zeck 10010100
                      ^^^^ strip low zeros, low 1, and 0 above
    Y = Zeck(1001) = F[3]+F[0] = 5+1 = 6

The Zeckendorf form never has consecutive "11" bits, because after subtracting an F[k] the remainder is smaller than the next lower F[k-1]. Numbers with no concecutive "11" are also called the fibbinary numbers (see Math::NumSeq::Fibbinary).

Stripping low zeros is similar to what the PowerArray does with low zero digits in an ordinary base such as binary. Doing it in the Zeckendorf base is like taking out powers of the golden ratio phi=1.618.

FUNCTIONS

See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path classes.

$path = Math::PlanePath::WythoffArray->new ()

Create and return a new path object.

($x,$y) = $path->n_to_xy ($n)

Return the X,Y coordinates of point number $n on the path. Points begin at 1 and if $n < 0 then the return is an empty list.

$n = $path->xy_to_n ($x,$y)

Return the N point number at coordinates $x,$y. If $x<0 or $y<0 then there's no N and the return is undef.

N values grow rapidly with $x. Pass in a bignum type such as Math::BigInt for full precision.

($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)

The returned range is exact, meaning $n_lo and $n_hi are the smallest and biggest in the rectangle.

FORMULAS

Rectangle to N Range

Within each row increasing X is increasing N, and in each column increasing Y is increasing N. So for a rectangle the lower left corner is the minimum N and the upper right is the maximum N.

    |               N max
    |     ----------+
    |    |  ^       |
    |    |  |       |
    |    |   ---->  |
    |    +----------
    |   N min
    +-------------------

OEIS

The Wythoff array is in Sloane's Online Encyclopedia of Integer Sequences in various forms,

    http://oeis.org/A035614   (etc)

    A035614     X coordinate
    A035612     X+1 coordinate, columns numbered starting X=1
    A139764     N dropped down to X axis N value,
                  being the lowest Fibonacci in Zeckendorf form

    A019586     Y coordinate, the Wythoff row containing N
    A003603     Y+1 coordinate, fractalized Fibonacci numbers

    A000045     N on X axis, Fibonacci numbers skipping initial 0,1
    A000204     N on Y=1 row, Lucas numbers skipping initial 1,3

    A003622     N on Y axis, odd Zeckendorfs
    A001950     N+1 of those N on Y axis, anti-spectrum of phi
    A022342     N not on Y axis, even Zeckendorfs
    A000201     N+1 of those N not on Y axis, spectrum of phi
    A003849     1,0 if N on Y axis or not, being the Fibonacci word

    A035336     N in column X=1
    A020941     N on X=Y diagonal

    A083412     permutation N by Diagonals from Y axis downwards
    A035513     permutation N by Diagonals from X axis upwards
    A064274       inverse permutation

SEE ALSO

Math::PlanePath, Math::PlanePath::PowerArray, Math::PlanePath::FibonacciWordFractal

Math::NumSeq::Fibbinary, Math::NumSeq::Fibonacci, Math::NumSeq::LucasNumbers, Math::Fibonacci, Math::Fibonacci::Phi

HOME PAGE

http://user42.tuxfamily.org/math-planepath/index.html

LICENSE

Copyright 2012 Kevin Ryde

This file is part of Math-PlanePath.

Math-PlanePath 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-PlanePath 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-PlanePath. If not, see <http://www.gnu.org/licenses/>.