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

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 Y=1 are the totient sums

     i=K
    sum   phi(i)
     i=1

Anything making a straight line etc in the path will probably be related to totient sums in some way.

The pattern of coprimes or not within a column is the same read going up as going down, since X,X-Y has the same coprimeness as X,Y. This means coprimes occur in pairs from X=3 onwards. (When X is even the middle point Y=X/2 is not coprime since it has 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.

FUNCTIONS

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

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

BUGS

The current implementation is fairly slack and is slow on medium to large N. A table of cumulative totients is built and retained for the X column number used.

OEIS

This pattern is in Sloane's Online Encyclopedia of Integer Sequences in a couple of forms,

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

    A002088    cumulative totient, N along X axis
    A127368    by columns Y coordinate if coprime, 0 if not
    A054521    by columns 1 if coprime, 0 if not
    A054427    permutation coprime columns N -> RationalsTree SB N 

SEE ALSO

Math::PlanePath, Math::PlanePath::DiagonalRationals, Math::PlanePath::RationalsTree, Math::PlanePath::PythagoreanTree, Math::PlanePath::DivisibleColumns

HOME PAGE

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

LICENSE

Copyright 2011, 2012 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/>.