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

NAME

Math::PlanePath::CoprimeColumns -- coprime x,y by columns

SYNOPSIS

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

DESCRIPTION

This path visits points X,Y which are coprime, meaning gcd(X,Y)=1, in columns from Y=0 to Y<=X.

    13                                            63
    12                                         57
    11                                      45 56 62
    10                                   41    55
     9                                31 40    54 61
     8                             27    39    53
     7                          21 26 30 38 44 52
     6                       17          37    51
     5                    11 16 20 25    36 43 50 60
     4                  9    15    24    35    49
     3               5  8    14 19    29 34    48 59
     2            3     7    13    23    33    47
     1      0  1  2  4  6 10 12 18 22 28 32 42 46 58
    Y=0
       X=0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

Since gcd(0,K)=0 the X axis itself X=0 is never visited, and since gcd(K,K)=K the leading diagonal X=Y is not visited except X=1,Y=1.

The number of coprime pairs in each column is Euler's totient function phi(X), and starting N=0 at X=1,Y=1 means the values 0,1,2,4,6,10,etc horizontally along X=1 are the totient sums

     i=K
    sum   phi(i)
     i=1

The pattern of coprimes or not is the same going up a column as going down, since X,X-Y has the same coprimeness as X,Y. This means coprimes occur in pairs from X=3 onwards. (In X even the middle point Y=X/2 is not coprime since they have common factor 2, from X=4 onwards.) So there's an even number of points in each column from X=2 onwards and the totals horizontally along X=1 are even likewise.

The current implementation is pretty slack and is fairly slow on medium to large N, but the resulting pattern is interesting. Anything making a straight line etc in the path will probably have to be related to phi sums in some way.

FUNCTIONS

$path = Math::PlanePath::CoprimeColumns->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 0 and if $n < 0 then the return is an empty list.

SEE ALSO

Math::PlanePath, Math::PlanePath::PythagoreanTree

HOME PAGE

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

LICENSE

Copyright 2011 Kevin Ryde

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