Math::...Columns(3pm)

πŸ“¦
version 129 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Math::PlanePath::CoprimeColumns πŸ’–

okay bestie, you found the perl man page for Math::PlanePath::CoprimeColumns (you'll see it filed under Math::...Columns(3pm) in the perl 3pm docs) β€” and honestly? it's giving number theory but make it a lattice. sit down, grab a strawberry πŸ“, we're doing this.


✨ NAME ✨

Math::PlanePath::CoprimeColumns β€” coprime X,Y by columns. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

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

look at that. three lines. iconic. no cap. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So this path walks points X,Y that are coprime β€” meaning they share no common factor, i.e. gcd(X,Y)=1 β€” and it visits them in columns, from Y=0 up to Y<=X. periodt.

   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(X,0)=0, the X axis itself is never visited β€” never ever, not once πŸ’€. and since gcd(K,K)=K, the leading diagonal X=Y isn't visited either, except for X=1,Y=1. the one exception that got the invite. πŸ™ˆ

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

                          i=K
  cumulative totient = sum   phi(i)
                          i=1

Anything that makes a straight line or whatever in the path is probably related to totient sums in some way. lowkey everything here is totient sums. ✨

The pattern of coprimes-or-not within a column is the same going up as going down, because X,X-Y has the same coprimeness as X,Y. that means coprimes occur in pairs from X=3 onwards. when X is even, the middle point Y=X/2 isn't 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 those cumulative totient totals horizontally along X=1 are therefore always even likewise. symmetry slay. πŸ’…

πŸ”₯ Direction Down πŸ”₯

Option direction => 'down' reverses the order within each column so it goes downwards to the X axis. it's the same shape, just flipped, main character energy:

    direction => "down"

     8 |                           22
     7 |                        18 23        numbering
     6 |                     12              downwards
     5 |                  10 13 19 24            |
     4 |                6    14    25            |
     3 |             4  7    15 20               v
     2 |          2     8    16    26
     1 |    0  1  3  5  9 11 17 21 27
    Y=0|
         +-----------------------------
         X=0  1  2  3  4  5  6  7  8  9

πŸŽ€ N Start πŸŽ€

The default is to number points starting N=0 as shown above. an optional n_start can give a different start with the same shape. for example to start at 1:

    n_start => 1

     8 |                           28
     7 |                        22 27
     6 |                     18
     5 |                  12 17 21 26
     4 |               10    16    25
     3 |             6  9    15 20
     2 |          4     8    14    24
     1 |    1  2  3  5  7 11 13 19 23
    Y=0|
         +------------------------------
         X=0  1  2  3  4  5  6  7  8  9

⭐ FUNCTIONS ⭐

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes. that's the family lore, iykyk. 🫢

  • "$path = Math::PlanePath::CoprimeColumns->new ()"
  • "$path = Math::PlanePath::CoprimeColumns->new (direction => $str, n_start => $n)"

Create and return a new path object. "direction" (a string) can be:

"up"       (the default)
"down"
  • "($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. no notes. πŸ™ˆ

  • "$bool = $path->xy_is_visited ($x,$y)"

Return true if "$x,$y" is visited. this means $x and $y have no common factor. it's tested with a GCD and is much faster than the full "xy_to_n()". speed demon behavior, we love to see it. πŸ”₯


πŸ’€ BUGS πŸ’€

The current implementation is fairly slack and is slow on medium to large N. A table of cumulative totients is built and retained up to the highest X column number used. so yeah, it's a little bit of a hoarder. sorry bestie. 😭


🌈 OEIS 🌈

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

<http://oeis.org/A002088> (etc)
n_start=0 (the default)
  A038567    X coordinate, reduced fractions denominator
  A020653    X-Y diff, fractions denominator by diagonals
               skipping N=0 initial 1/1

  A002088    N on X axis, cumulative totient
  A127368    by columns Y coordinate if coprime, 0 if not
  A054521    by columns 1 if coprime, 0 if not

  A054427    permutation columns N -> RationalsTree SB N X/Y<1
  A054428      inverse, SB X/Y<1 -> columns
  A121998    Y of skipped X,Y among 2<=Y<=X, those not coprime
  A179594    X column position of KxK square unvisited

n_start=1
  A038566    Y coordinate, reduced fractions numerator

  A002088    N on X=Y+1 diagonal, cumulative totient

the whole OEIS corner of this page is genuinely a mood board. πŸ‘‘


πŸ‘‘ 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, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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/>.


and that's the whole page, bestie, you ate it 🍽️✨ β€” this one's from perl v5.32.0, dated 2021-01-23, and it lives in the perl 3pm man pages. go forth and enumerate some coprime points, you gorgeous genius. πŸ¦‹πŸ’–πŸŒΈ