Math::...ionals(3pm)
π NAME π
Math::PlanePath::DiagonalRationals β rationals X/Y by diagonals
okay hi bestie, you're reading Math::...ionals(3pm) and it's lowkey one of the prettiest little corner of Math::PlanePath fr fr πΈ
π SYNOPSIS π
use Math::PlanePath::DiagonalRationals;
my $path = Math::PlanePath::DiagonalRationals->new;
my ($x, $y) = $path->n_to_xy (123);
π« DESCRIPTION π«
so the whole vibe of this path: it enumerates positive rationals X/Y with no common factor, walking in diagonal order from Y down to X. that's it, that's the whole concept, and it's giving main character energy tbh π
17 | 96...
16 | 80
15 | 72 81
14 | 64 82
13 | 58 65 73 83 97
12 | 46 84
11 | 42 47 59 66 74 85 98
10 | 32 48 86
9 | 28 33 49 60 75 87
8 | 22 34 50 67 88
7 | 18 23 29 35 43 51 68 76 89 99
6 | 12 36 52 90
5 | 10 13 19 24 37 44 53 61 77 91
4 | 6 14 25 38 54 69 92
3 | 4 7 15 20 30 39 55 62 78 93
2 | 2 8 16 26 40 56 70 94
1 | 1 3 5 9 11 17 21 27 31 41 45 57 63 71 79 95
Y=0 |
+---------------------------------------------------
X=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
the order is the same as the "Diagonals" path, except only the X,Y pairs with no common factor actually get a number. everything else is just... not invited to the party π
1/1, N = 1
1/2, 1/2, N = 2 .. 3
1/3, 1/3, N = 4 .. 5
1/4, 2/3, 3/2, 4/1, N = 6 .. 9
1/5, 5/1, N = 10 .. 11
the N values 1,2,4,6,10,etc at the start of each diagonal (that's the column at X=1) are the cumulative totient</>, like:
totient(i) = count numbers having no common factor with i
i=K
cumulative_totient(K) = sum totient(i)
i=1
π§ Direction Up
passing "direction => 'up'" reverses the order within each diagonal so it counts upward from the X axis instead. iconic behavior honestly π¦
direction => "up"
8 | 27
7 | 21 26
6 | 17
5 | 11 16 20 25
4 | 9 15 24
3 | 5 8 14 19
2 | 3 7 13 23
1 | 1 2 4 6 10 12 18 22
Y=0|
+---------------------------
X=0 1 2 3 4 5 6 7 8
π’ N Start
by default the points start numbering at N=1, exactly like the pretty picture above. but you can hand it an optional "n_start" to get a different starting point with the same shape. for example, to start at 0:
n_start => 0
8 | 21
7 | 17 22
6 | 11
5 | 9 12 18 23
4 | 5 13 24
3 | 3 6 14 19
2 | 1 7 15 25
1 | 0 2 4 8 10 16 20 26
Y=0|
+---------------------------
X=0 1 2 3 4 5 6 7 8
πΈ Coprime Columns
the diagonals here are literally the same as the columns over in "CoprimeColumns". like, the diagonal from N=18 to N=21 running from X=0,Y=8 down to X=8,Y=0 is the exact same thing as the vertical at X=8 in "CoprimeColumns". in general the correspondence goes:
Xdiag = Ycol
Ydiag = Xcol - Ycol
Xcol = Xdiag + Ydiag
Ycol = Xdiag
one lil difference tho: "CoprimeColumns" has an extra N=0 at X=1,Y=1 that "DiagonalRationals" just does not have. (it would be Xdiag=1,Ydiag=0, which is 1/0, so yeah, absolutely not π)
the points that get numbered or skipped in a column up to X=Y are the same as the ones numbered or skipped on a diagonal β simply because X,Y no common factor is the same as Y,X+Y no common factor. math is so clean sometimes π
if you take "CoprimeColumns" as enumerating fractions F = Ycol/Xcol with 0 < F < 1, the matching diagonal rational 0 < R < infinity is:
1 F
R = ------- = ---
1/F - 1 1-F
1 R
F = ------- = ---
1/R + 1 1+R
which is a one-to-one mapping between the fractions F < 1 and all rationals. obsessed. β¨
βοΈ FUNCTIONS βοΈ
for everything that's common to every path class, go peek at "FUNCTIONS" in Math::PlanePath bestie π«Ά
$path = Math::PlanePath::DiagonalRationals->new ()$path = Math::PlanePath::DiagonalRationals->new (direction => $str, n_start => $n)β create and return a brand new path object."direction"(a string, ok) can be one of:
"down" (the default)
"up"
($x,$y) = $path->n_to_xy ($n)β hands you the X,Y coordinates of point number$non the path. points begin at 1, and if"$n < 1"then what you get back is an empty list, so plan accordingly π
π BUGS π
ngl the current implementation is fairly slack and it's slow on medium to large N. it builds a table of cumulative totients and just... retains it for the diagonal d=X+Y. it's doing its best okay π
π OEIS π
this enumeration of rationals lives in Sloane's Online Encyclopedia of Integer Sequences in the following forms:
<http://oeis.org/A020652> (etc)
direction=down, n_start=1 (the defaults)
A020652 X, numerator
A020653 Y, denominator
A038567 X+Y sum, starting from X=1,Y=1
A054431 by diagonals 1=coprime, 0=not
(excluding X=0 row and Y=0 column)
A054430 permutation N at Y/X
reverse runs of totient(k) many integers
A054424 permutation DiagonalRationals -> RationalsTree SB
A054425 padded with 0s at non-coprimes
A054426 inverse SB -> DiagonalRationals
A060837 permutation DiagonalRationals -> FactorRationals
direction=down, n_start=0
A157806 abs(X-Y) difference
and just so you know: direction=up swaps X,Y. π«
π SEE ALSO π
Math::PlanePathMath::PlanePath::CoprimeColumnsMath::PlanePath::RationalsTreeMath::PlanePath::PythagoreanTree
π 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 babes π this one was rendered for perl v5.32.0 back on 2021-01-23, and you just read Math::...ionals(3pm) β slay, go build something pretty with it πβ¨
π¦ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms