Math-PlanePath

 view release on metacpan or  search on metacpan

lib/Math/PlanePath/WythoffPreliminaryTriangle.pm  view on Meta::CPAN

=head1 SYNOPSIS

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

=head1 DESCRIPTION

X<Kimberling, Clark>This path is the Wythoff preliminary triangle by Clark
Kimberling,

=cut

# math-image  --path=WythoffPreliminaryTriangle --output=numbers --all --size=60x14

=pod

     13  | 105 118 131 144  60  65  70  75  80  85  90  95 100
     12  |  97 110  47  52  57  62  67  72  77  82  87  92    
     11  |  34  39  44  49  54  59  64  69  74  79  84        
     10  |  31  36  41  46  51  56  61  66  71  76            
      9  |  28  33  38  43  48  53  58  63  26                
      8  |  25  30  35  40  45  50  55  23                    
      7  |  22  27  32  37  42  18  20                        
      6  |  19  24  29  13  15  17                            
      5  |  16  21  10  12  14                                
      4  |   5   7   9  11                                    
      3  |   4   6   8                                        
      2  |   3   2                                            
      1  |   1                                                
    Y=0  |                                                    
         +-----------------------------------------------------
           X=0   1   2   3   4   5   6   7   8   9  10  11  12

A given N is at an X,Y position in the triangle according to where row
number N of the Wythoff array "precurses" back to.  Each Wythoff row is a
Fibonacci recurrence.  Starting from the pair of values in the first and
second columns of row N it can be run in reverse by

    F[i-1] = F[i+i] - F[i]

It can be shown that such a reverse always reaches a pair Y and X with
YE<gt>=1 and 0E<lt>=XE<lt>Y, hence making the triangular X,Y arrangement
above.

    N=7 WythoffArray row 7 is 17,28,45,73,...
    go backwards from 17,28 by subtraction
       11 = 28 - 17
        6 = 17 - 11
        5 = 11 - 6
        1 = 6 - 5
        4 = 5 - 1
    stop on reaching 4,1 which is Y=4,X=1 with Y>=1 and 0<=X<Y

Conversely a coordinate pair X,Y is reckoned as the start of a Fibonacci
style recurrence,

    F[i+i] = F[i] + F[i-1]   starting F[1]=Y, F[2]=X       

Iterating these values gives a row of the Wythoff array
(L<Math::PlanePath::WythoffArray>) after some initial iterations.  The N
value at X,Y is the row number of the Wythoff array which is reached.  Rows
are numbered starting from 1.  For example,

    Y=4,X=1 sequence:       4, 1, 5, 6, 11, 17, 28, 45, ...
    row 7 of WythoffArray:                  17, 28, 45, ...
    so N=7 at Y=4,X=1

=cut

# =head2 Phi Slope Blocks
# 
# The effect of each step backwards is to move to successive blocks of values
# with slope golden ratio phi=(sqrt(5)+1)/2.
# 
# Suppose no backwards steps were applied, so Y,X were the first two values of
# Wythoff row N.  In the example above that would be N=7 at Y=17,X=28.  The
# first two values of the Wythoff array are
# 
#     Y = W[0,r] = r-1 + floor(r*phi)       # r = row numbered from 1
#     X = W[1,r] = r-1 + 2*floor(r*phi)
# 
# So this would put N values on a line of slope Y/X = 1/phi = 0.618.  The
# portion of that line which falls within 0E<lt>=XE<lt>Y

=pod

=cut

# (r-1 + floor(r*phi)) / (r-1 + 2*floor(r*phi))
#   ~= (r-1+r*phi)/(r-1+2*r*phi)
#    = (r*(phi+1) - 1) / (r*(2phi+1) - 1)
#   -> r*(phi+1) / r*(2*phi+1)
#    = (phi+1) / (2*phi+1)
#    = 1/phi = 0.618

=pod

=head1 FUNCTIONS

See L<Math::PlanePath/FUNCTIONS> for the behaviour common to all path
classes.

=over 4

=item C<$path = Math::PlanePath::WythoffPreliminaryTriangle-E<gt>new ()>

Create and return a new path object.

=back

=head1 OEIS

Entries in Sloane's Online Encyclopedia of Integer Sequences related to
this path include

=over

L<http://oeis.org/A165360> (etc)

=back



( run in 0.737 second using v1.01-cache-2.11-cpan-71847e10f99 )