.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Math::PlanePath::RationalsTree 3pm" .TH Math::PlanePath::RationalsTree 3pm "2014-08-30" "perl v5.20.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Math::PlanePath::RationalsTree \-\- rationals by tree .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Math::PlanePath::RationalsTree; \& my $path = Math::PlanePath::RationalsTree\->new (tree_type => \*(AqSB\*(Aq); \& my ($x, $y) = $path\->n_to_xy (123); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This path enumerates reduced rational fractions X/Y > 0, ie. X and Y having no common factor. .PP The rationals are traversed by rows of a binary tree which represents a coprime pair X,Y by steps of a subtraction-only greatest common divisor algorithm which proves them coprime. Or equivalently by bit runs with lengths which are the quotients in the division-based Euclidean \s-1GCD\s0 algorithm and which are also the terms in the continued fraction representation of X/Y. .PP The \s-1SB, CW, AYT, HCS,\s0 Bird and Drib trees all have the same set of X/Y rationals in a row, but in a different order due to different encodings of the N value. See the author's mathematical write-up for a proof that these are the only trees with a fixed set of matrices. .Sp .RS 4 .RE .PP The bit runs mean that N values are quite large for relatively modest sized rationals. For example in the \s-1SB\s0 tree 167/3 is N=288230376151711741, a 58\-bit number. The tendency is for the tree to make excursions out to large rationals while only slowly filling in small ones. The worst is the integer X/1 for which N has X many bits, and similarly 1/Y is Y bits. .PP See \fIexamples/rationals\-tree.pl\fR in the Math-PlanePath sources for a printout of all the trees. .SS "Stern-Brocot Tree" .IX Subsection "Stern-Brocot Tree" The default \f(CW\*(C`tree_type=>"SB"\*(C'\fR is the tree of Moritz Stern and Achille Brocot. .IX Xref "Stern, Moritz Brocot, Achille" .PP .Vb 9 \& depth N \& \-\-\-\-\- \-\-\-\-\-\-\- \& 0 1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& 1 2 to 3 1/2 2/1 \& / \e / \e \& 2 4 to 7 1/3 2/3 3/2 3/1 \& | | | | | | | | \& 3 8 to 15 1/4 2/5 3/5 3/4 4/3 5/3 5/2 4/1 .Ve .PP Within a row the fractions increase in value. Each row of the tree is a repeat of the previous row as first X/(X+Y) and then (X+Y)/Y. For example .PP .Vb 1 \& depth=1 1/2, 2/1 \& \& depth=2 1/3, 2/3 X/(X+Y) of previous row \& 3/2, 3/1 (X+Y)/Y of previous row .Ve .PP Plotting the N values by X,Y is as follows. The unused X,Y positions are where X and Y have a common factor. For example X=6,Y=2 has common factor 2 so is never reached. .PP .Vb 1 \& tree_type => "SB" \& \& 10 | 512 35 44 767 \& 9 | 256 33 39 40 46 383 768 \& 8 | 128 18 21 191 384 \& 7 | 64 17 19 20 22 95 192 49 51 \& 6 | 32 47 96 \& 5 | 16 9 10 23 48 25 26 55 \& 4 | 8 11 24 27 56 \& 3 | 4 5 12 13 28 29 60 \& 2 | 2 6 14 30 62 \& 1 | 1 3 7 15 31 63 127 255 511 1023 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP The X=1 vertical is the fractions 1/Y which is at the left of each tree row, at N value .PP .Vb 1 \& Nstart = 2^depth .Ve .PP The Y=1 horizontal is the X/1 integers at the end each row which is .PP .Vb 1 \& Nend = 2^(depth+1)\-1 .Ve .PP Numbering nodes of the tree by rows starting from 1 means N without the high 1 bit is the offset into the row. For example binary N=\*(L"1011\*(R" is \*(L"011\*(R"=3 into the row. Those bits after the high 1 are also the directions to follow down the tree to a node, with 0=left and 1=right. So N=\*(L"1011\*(R" binary goes from the root 0=left then twice 1=right to reach X/Y=3/4 at N=11 decimal. .SS "Stern-Brocot Mediant" .IX Subsection "Stern-Brocot Mediant" Writing the parents between the children as an \*(L"in-order\*(R" tree traversal to a given depth has all values in increasing order (the same as each row individually is in increasing order). .PP .Vb 4 \& 1/1 \& 1/2 | 2/1 \& 1/3 | 2/3 | 3/2 | 3/1 \& | | | | | | | \& \& 1/3 1/2 2/3 1/1 3/2 2/1 3/1 \& ^ \& | \& next level (1+3)/(1+2) = 4/3 mediant .Ve .PP New values at the next level of this flattening are a \*(L"mediant\*(R" (x1+x2)/(y1+y2) formed from the left and right parent. So the next level 4/3 shown is left parent 1/1 and right parent 3/2 giving mediant (1+3)/(1+2)=4/3. At the left end a preceding 0/1 is imagined. At the right end a following 1/0 is imagined, so as to have 1/(depth+1) and (depth+1)/1 at the ends for a total 2^depth many new values. .PP The turn sequence left or right along the row depth >= 2 is by a repeating \s-1LRRL\s0 pattern, except the first and last are always R. (See the author's mathematical write-up for details.) .PP .Vb 1 \& RRRL,LRRL,LRRL,LRRL,LRRL,LRRL,LRRL,LRRR # row N=32 to N=63 .Ve .SS "Calkin-Wilf Tree" .IX Subsection "Calkin-Wilf Tree" \&\f(CW\*(C`tree_type=>"CW"\*(C'\fR selects the tree of Calkin and Wilf, .IX Xref "Calkin, Neil Wilf, Herbert" .Sp .RS 4 Neil Calkin and Herbert Wilf, \*(L"Recounting the Rationals\*(R", American Mathematical Monthly, volume 107, number 4, April 2000, pages 360\-363. .Sp .RE .PP As noted above, the values within each row are the same as the Stern-Brocot, but in a different order. .PP .Vb 7 \& N=1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=2 to N=3 1/2 2/1 \& / \e / \e \& N=4 to N=7 1/3 3/2 2/3 3/1 \& | | | | | | | | \& N=8 to N=15 1/4 4/3 3/5 5/2 2/5 5/3 3/4 4/1 .Ve .PP Going by rows the denominator of one value becomes the numerator of the next. So at 4/3 the denominator 3 becomes the numerator of 3/5 to the right. These values are Stern's diatomic sequence. .PP Each row is symmetric in reciprocals, ie. reading from right to left is the reciprocals of reading left to right. The numerators read left to right are the denominators read right to left. .PP A node descends as .PP .Vb 3 \& X/Y \& / \e \& X/(X+Y) (X+Y)/Y .Ve .PP Taking these formulas in reverse up the tree shows how it relates to a subtraction-only greatest common divisor. At a given node the smaller of P or Q is subtracted from the bigger, .PP .Vb 3 \& P/(Q\-P) (P\-Q)/P \& / or \e \& P/Q P/Q .Ve .PP Plotting the N values by X,Y is as follows. The X=1 vertical and Y=1 horizontal are the same as the \s-1SB\s0 above, but the values in between are re-ordered. .PP .Vb 1 \& tree_type => "CW" \& \& 10 | 512 56 38 1022 \& 9 | 256 48 60 34 46 510 513 \& 8 | 128 20 26 254 257 \& 7 | 64 24 28 18 22 126 129 49 57 \& 6 | 32 62 65 \& 5 | 16 12 10 30 33 25 21 61 \& 4 | 8 14 17 29 35 \& 3 | 4 6 9 13 19 27 39 \& 2 | 2 5 11 23 47 \& 1 | 1 3 7 15 31 63 127 255 511 1023 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP At each node the left leg is X/(X+Y)\ <\ 1 and the right leg is (X+Y)/Y\ >\ 1, which means N is even above the X=Y diagonal and odd below. In general each right leg increments the integer part of the fraction, .PP .Vb 5 \& X/Y right leg each time \& (X+Y)/Y = 1 + X/Y \& (X+2Y)/Y = 2 + X/Y \& (X+3Y)/Y = 3 + X/Y \& etc .Ve .PP This means the integer part is the trailing 1\-bits of N, .PP .Vb 3 \& floor(X/Y) = count trailing 1\-bits of N \& eg. 7/2 is at N=23 binary "10111" \& which has 3 trailing 1\-bits for floor(7/2)=3 .Ve .PP N values for the \s-1SB\s0 and \s-1CW\s0 trees are converted by reversing bits except the highest. So at a given X,Y position .PP .Vb 2 \& SB N = 1abcde SB <\-> CW by reversing bits \& CW N = 1edcba except the high 1\-bit .Ve .PP For example at X=3,Y=4 the \s-1SB\s0 tree has N=11 = \*(L"1011\*(R" binary and the \s-1CW\s0 has N=14 binary \*(L"1110\*(R", a reversal of the bits below the high 1. .PP N to X/Y in the \s-1CW\s0 tree can be calculated keeping track of just an X,Y pair and descending to X/(X+Y) or (X+Y)/Y using the bits of N from high to low. The relationship between the \s-1SB\s0 and \s-1CW N\s0's means the same can be used to calculate the \s-1SB\s0 tree by taking the bits of N from low to high instead. .PP See also Math::PlanePath::ChanTree for a generalization of \s-1CW\s0 to ternary or higher trees, ie. descending to 3 or more children at each node. .SS "Yu-Ting and Andreev Tree" .IX Subsection "Yu-Ting and Andreev Tree" \&\f(CW\*(C`tree_type=>"AYT"\*(C'\fR selects the tree described independently by Yu-Ting and Andreev. .IX Xref "Andreev, D.N. Yu-Ting, Shen" .Sp .RS 4 Shen Yu-Ting, \*(L"A Natural Enumeration of Non-Negative Rational Numbers \&\*(-- An Informal Discussion\*(R", American Mathematical Monthly, 87, 1980, pages 25\-29. .Sp D. N. Andreev, \*(L"On a Wonderful Numbering of Positive Rational Numbers\*(R", Matematicheskoe Prosveshchenie, Ser. 3, 1, 1997, pages 126\-134 .RE .PP Their constructions are a one-to-one mapping between integer N and rational X/Y as a way of enumerating the rationals. This is not designed to be a tree as such, but the result is the same 2^level rows as the above trees. The X/Y values within each row are the same, but in a different order. .PP .Vb 7 \& N=1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=2 to N=3 2/1 1/2 \& / \e / \e \& N=4 to N=7 3/1 1/3 3/2 2/3 \& | | | | | | | | \& N=8 to N=15 4/1 1/4 4/3 3/4 5/2 2/5 5/3 3/5 .Ve .PP Each fraction descends as follows. The left is an increment and the right is reciprocal of the increment. .PP .Vb 3 \& X/Y \& / \e \& X/Y + 1 1/(X/Y + 1) .Ve .PP which means .PP .Vb 3 \& X/Y \& / \e \& (X+Y)/Y Y/(X+Y) .Ve .PP The left leg (X+Y)/Y is the same the \s-1CW\s0 has on its right leg. But Y/(X+Y) is not the same as the \s-1CW \s0(the other there being X/(X+Y)). .PP The left leg increments the integer part, so the integer part is given by (in a fashion similar to \s-1CW\s0 1\-bits above) .PP .Vb 2 \& floor(X/Y) = count trailing 0\-bits of N \& plus one extra if N=2^k .Ve .PP N=2^k is one extra because its trailing 0\-bits started from N=1 where floor(1/1)=1 whereas any other odd N starts from some floor(X/Y)=0. .PP The Y/(X+Y) right leg forms the Fibonacci numbers F(k)/F(k+1) at the end of each row, ie. at Nend=2^(level+1)\-1. And as noted by Andreev, successive right leg fractions N=4k+1 and N=4k+3 add up to 1, .IX Xref "Fibonacci numbers" .PP .Vb 2 \& X/Y at N=4k+1 + X/Y at N=4k+3 = 1 \& Eg. 2/5 at N=13 and 3/5 at N=15 add up to 1 .Ve .PP Plotting the N values by X,Y gives .PP .Vb 1 \& tree_type => "AYT" \& \& 10 | 513 41 43 515 \& 9 | 257 49 37 39 51 259 514 \& 8 | 129 29 31 131 258 \& 7 | 65 25 21 23 27 67 130 50 42 \& 6 | 33 35 66 \& 5 | 17 13 15 19 34 26 30 38 \& 4 | 9 11 18 22 36 \& 3 | 5 7 10 14 20 28 40 \& 2 | 3 6 12 24 48 \& 1 | 1 2 4 8 16 32 64 128 256 512 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP N=1,2,4,8,etc on the Y=1 horizontal is the X/1 integers at Nstart=2^level=2^X. N=1,3,5,9,etc in the X=1 vertical is the 1/Y fractions. Those fractions always immediately follow the corresponding integer, so N=Nstart+1=2^(Y\-1)+1 in that column. .PP In each node the left leg (X+Y)/Y > 1 and the right leg Y/(X+Y) < 1, which means odd N is above the X=Y diagonal and even N is below. .PP The tree structure corresponds to Johannes Kepler's tree of fractions (see Math::PlanePath::FractionsTree). That tree starts from 1/2 and makes fractions A/B with A"HCS"\*(C'\fR selects continued fraction terms coded as bit runs 1000...00 from high to low, as per Paul D. Hanna and independently Czyz and Self. .IX Xref "Hanna, Paul D. Czyz, Jerzy Self, Will" .Sp .RS 4 .Sp Jerzy Czyz and William Self, \*(L"The Rationals Are Countable: Euclid's Proof\*(R", The College Mathematics Journal, volume 34, number 5, November 2003, page 367. .Sp .RE .PP This arises also in a radix=1 variation of Jeffrey Shallit's digit-based continued fraction encoding. See \*(L"Radix 1\*(R" in Math::PlanePath::CfracDigits. .PP If the continued fraction of X/Y is .PP .Vb 9 \& 1 \& X/Y = a + \-\-\-\-\-\-\-\-\-\-\-\- a >= 0 \& 1 \& b + \-\-\-\-\-\-\-\-\-\-\- b,c,etc >= 1 \& 1 \& c + \-\-\-\-\-\-\- \& ... + 1 \& \-\-\- z >= 2 \& z .Ve .PP then the N value is bit runs of lengths a,b,c etc. .PP .Vb 3 \& N = 1000 1000 1000 ... 1000 \& \e\-\-/ \e\-\-/ \e\-\-/ \e\-\-/ \& a+1 b c z\-1 .Ve .PP Each group is 1 or more bits. The +1 in \*(L"a+1\*(R" makes the first group 1 or more bits, since a=0 occurs for any X/Y<=1. The \-1 in \*(L"z\-1\*(R" makes the last group 1 or more since z>=2. .PP .Vb 7 \& N=1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=2 to N=3 2/1 1/2 \& / \e / \e \& N=4 to N=7 3/1 3/2 1/3 2/3 \& | | | | | | | | \& N=8 to N=15 4/1 5/2 4/3 5/3 1/4 2/5 3/4 3/5 .Ve .PP The result is a bit reversal of the N values in the \s-1AYT\s0 tree. .PP .Vb 2 \& AYT N = binary "1abcde" AYT <\-> HCS bit reversal \& HCS N = binary "1edcba" .Ve .PP For example at X=4,Y=7 the \s-1AYT\s0 tree is N=11 binary \*(L"10111\*(R" whereas \s-1HCS\s0 there has N=30 binary \*(L"11110\*(R", a reversal of the bits below the high 1. .PP Plotting by X,Y gives .PP .Vb 1 \& tree_type => "HCS" \& \& 10 | 768 50 58 896 \& 9 | 384 49 52 60 57 448 640 \& 8 | 192 27 31 224 320 \& 7 | 96 25 26 30 29 112 160 41 42 \& 6 | 48 56 80 \& 5 | 24 13 15 28 40 21 23 44 \& 4 | 12 14 20 22 36 \& 3 | 6 7 10 11 18 19 34 \& 2 | 3 5 9 17 33 \& 1 | 1 2 4 8 16 32 64 128 256 512 \& Y=0 | \& +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP N=1,2,4,etc in the row Y=1 are powers\-of\-2, being integers X/1 having just a single group of bits N=1000..000. .PP N=1,3,6,12,etc in the column X=1 are 3*2^(Y\-1) corresponding to continued fraction 0\ +\ 1/Y so terms 0,Y making runs 1,Y\-1 and so bits N=11000...00. .PP The turn sequence left or right following successive X,Y points is the Thue-Morse sequence. A proof of this can be found in the author's mathematical write-up (above). .IX Xref "Thue-Morse" .PP .Vb 4 \& count 1\-bits in N+1 turn at N \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\- \& odd right \& even left .Ve .SS "Bird Tree" .IX Subsection "Bird Tree" \&\f(CW\*(C`tree_type=>"Bird"\*(C'\fR selects the Bird tree, .IX Xref "Hinze, Ralf" .Sp .RS 4 Ralf Hinze, \*(L"Functional Pearls: The Bird tree\*(R", Journal of Functional Programming, volume 19, issue 5, September 2009, pages 491\-508. \s-1DOI 10.1017/S0956796809990116 \&\s0 .RE .PP It's expressed recursively, illustrating Haskell programming features. The left subtree is the tree plus one and take the reciprocal. The right subtree is conversely the reciprocal first then add one, .PP .Vb 3 \& 1 1 \& \-\-\-\-\-\-\-\- and \-\-\-\- + 1 \& tree + 1 tree .Ve .PP which means Y/(X+Y) and (X+Y)/X taking N bits low to high. .PP .Vb 7 \& N=1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=2 to N=3 1/2 2/1 \& / \e / \e \& N=4 to N=7 2/3 1/3 3/1 3/2 \& | | | | | | | | \& N=8 to N=15 3/5 3/4 1/4 2/5 5/2 4/1 4/3 5/3 .Ve .PP Plotting by X,Y gives .PP .Vb 1 \& tree_type => "Bird" \& \& 10 | 682 41 38 597 \& 9 | 341 43 45 34 36 298 938 \& 8 | 170 23 16 149 469 \& 7 | 85 20 22 17 19 74 234 59 57 \& 6 | 42 37 117 \& 5 | 21 11 8 18 58 28 31 61 \& 4 | 10 9 29 30 50 \& 3 | 5 4 14 15 25 24 54 \& 2 | 2 7 12 27 52 \& 1 | 1 3 6 13 26 53 106 213 426 853 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP Notice that unlike the other trees N=1,2,5,10,etc in the X=1 vertical for fractions 1/Y is not the row start or end, but instead are on a zigzag through the middle of the tree binary N=1010...etc alternate 1 and 0 bits. The integers X/1 in the Y=1 vertical are similar, but N=11010...etc starting the alternation from a 1 in the second highest bit, since those integers are in the right hand half of the tree. .PP The Bird tree N values are related to the \s-1SB\s0 tree by inverting every second bit starting from the second after the high 1\-bit, .PP .Vb 3 \& Bird N=1abcdefg.. binary \& 101010.. xor, so b,d,f etc flip 0<\->1 \& SB N=1aBcDeFg.. to make B,D,F .Ve .PP For example 3/4 in the \s-1SB\s0 tree is at N=11 = binary 1011. Xor with 0010 for binary 1001 N=9 which is 3/4 in the Bird tree. The same xor goes back the other way Bird tree to \s-1SB\s0 tree. .PP This xoring is a mirroring in the tree, swapping left and right at each level. Only every second bit is inverted because mirroring twice puts it back to the ordinary way on even rows. .SS "Drib Tree" .IX Subsection "Drib Tree" \&\f(CW\*(C`tree_type=>"Drib"\*(C'\fR selects the Drib tree by Ralf Hinze. .IX Xref "Hinze, Ralf" .Sp .RS 4 .RE .PP It reverses the bits of N in the Bird tree (in a similar way that the \s-1SB\s0 and \&\s-1CW\s0 are bit reversals of each other). .PP .Vb 7 \& N=1 1/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=2 to N=3 1/2 2/1 \& / \e / \e \& N=4 to N=7 2/3 3/1 1/3 3/2 \& | | | | | | | | \& N=8 to N=15 3/5 5/2 1/4 4/3 3/4 4/1 2/5 5/3 .Ve .PP The descendants of each node are .PP .Vb 3 \& X/Y \& / \e \& Y/(X+Y) (X+Y)/X .Ve .PP The endmost fractions of each row are Fibonacci numbers, F(k)/F(k+1) on the left and F(k+1)/F(k) on the right. .IX Xref "Fibonacci numbers" .PP .Vb 1 \& tree_type => "Drib" \& \& 10 | 682 50 44 852 \& 9 | 426 58 54 40 36 340 683 \& 8 | 170 30 16 212 427 \& 7 | 106 18 22 24 28 84 171 59 51 \& 6 | 42 52 107 \& 5 | 26 14 8 20 43 19 31 55 \& 4 | 10 12 27 23 41 \& 3 | 6 4 11 15 25 17 45 \& 2 | 2 7 9 29 37 \& 1 | 1 3 5 13 21 53 85 213 341 853 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP In each node descent the left Y/(X+Y) < 1 and the right (X+Y)/X > 1, which means even N is above the X=Y diagonal and odd N is below. .PP Because Drib/Bird are bit reversals like \s-1CW/SB\s0 are bit reversals, the xor procedure described above which relates Bird<\->\s-1SB\s0 applies to Drib<\->\s-1CW,\s0 but working from the second lowest bit upwards, ie. xor binary \*(L"0..01010\*(R". For example 4/1 is at N=15 binary 1111 in the \s-1CW\s0 tree. Xor with 0010 for 1101 N=13 which is 4/1 in the Drib tree. .SS "L Tree" .IX Subsection "L Tree" \&\f(CW\*(C`tree_type=>"L"\*(C'\fR selects the L\-tree by Peter Luschny. .IX Xref "Luschny, Peter" .Sp .RS 4 .RE .PP It's a row-reversal of the \s-1CW\s0 tree with a shift to include zero as 0/1. .PP .Vb 7 \& N=0 0/1 \& \-\-\-\-\-\- \-\-\-\-\-\- \& N=1 to N=2 1/2 1/1 \& / \e / \e \& N=3 to N=8 2/3 3/2 1/3 2/1 \& | | | | | | | | \& N=9 to N=16 3/4 5/3 2/5 5/2 3/5 4/3 1/4 3/1 .Ve .PP Notice in the N=9 to N=16 row rationals 3/4 to 1/4 are the same as in the \s-1CW\s0 tree but read right-to-left. .PP .Vb 1 \& tree_type => "L" \& \& 10 | 1021 37 55 511 \& 9 | 509 45 33 59 47 255 1020 \& 8 | 253 25 19 127 508 \& 7 | 125 21 17 27 23 63 252 44 36 \& 6 | 61 31 124 \& 5 | 29 9 11 15 60 20 24 32 \& 4 | 13 7 28 16 58 \& 3 | 5 3 12 8 26 18 54 \& 2 | 1 4 10 22 46 \& 1 | 0 2 6 14 30 62 126 254 510 1022 2046 \& Y=0 | \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& X=0 1 2 3 4 5 6 7 8 9 10 .Ve .PP N=0,2,6,14,30,etc along the row at Y=1 are powers 2^(X+1)\-2. N=1,5,13,29,etc in the column at X=1 are similar powers 2^Y\-3. .SS "Common Characteristics" .IX Subsection "Common Characteristics" The \s-1SB, CW,\s0 Bird, Drib, \s-1AYT\s0 and \s-1HCS\s0 trees have the same set of rationals in each row, just in different orders. The properties of Stern's diatomic sequence mean that within a row the totals are .PP .Vb 1 \& row N=2^depth to N=2^(depth+1)\-1 inclusive \& \& sum X/Y = (3 * 2^depth \- 1) / 2 \& sum X = 3^depth \& sum 1/(X*Y) = 1 .Ve .PP For example the \s-1SB\s0 tree depth=2, N=4 to N=7, .PP .Vb 3 \& sum X/Y = 1/3 + 2/3 + 3/2 + 3/1 = 11/2 = (3*2^2\-1)/2 \& sum X = 1+2+3+3 = 9 = 3^2 \& sum 1/(X*Y) = 1/(1*3) + 1/(2*3) + 1/(3*2) + 1/(3*1) = 1 .Ve .PP Many permutations are conceivable within a row, but the ones here have some relationship to X/Y descendants, tree sub-forms or continued fractions. As an encoding of continued fraction terms by bit runs the combinations are .PP .Vb 5 \& bit encoding high to low low to high \& \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\- \& 0000 1111 runs SB CW \& 0101 1010 alternating Bird Drib \& 1000 1000 runs HCS AYT .Ve .PP A run of alternating 101010 ends where the next bit is the oppose of the expected alternating 0,1. This is a doubled bit 00 or 11. An electrical engineer would think of it as a phase shift. .SS "Minkowski Question Mark" .IX Subsection "Minkowski Question Mark" The Minkowski question mark function is a sum of the terms in the continued fraction representation of a real number. If q0,q1,q2,etc are those terms then the question mark function \*(L"?(r)\*(R" is .PP .Vb 3 \& 1 1 1 \& ?(r) = 2 * (1 \- \-\-\-\- * (1 \- \-\-\-\- * (1 \- \-\-\-\- * (1 \- ... \& 2^q0 2^q1 2^q2 \& \& 1 1 1 \& = 2 * (1 \- \-\-\-\- + \-\-\-\-\-\-\-\-\- \- \-\-\-\-\-\-\-\-\-\-\-\- + ... ) \& 2^q0 2^(q0+q1) 2^(q0+q1+q2) .Ve .PP For rational r the continued fraction q0,q1,q2,etc is finite and so the ?(r) sum is finite and rational. The pattern of + and \- in the terms gives runs of bits the same as the N values in the Stern-Brocot tree. The RationalsTree code can calculate the ?(r) function by .PP .Vb 4 \& rational r=X/Y \& N = xy_to_n(X,Y) tree_type=>"SB" \& depth = floor(log2(N)) # row containing N (depth=0 at top) \& Ndepth = 2^depth # start of row containing N \& \& 2*(N\-Ndepth) + 1 \& ?(r) = \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& Ndepth .Ve .PP The effect of N\-Ndepth is to remove the high 1\-bit, leaving an offset into the row. 2*(..)+1 appends an extra 1\-bit at the end. The division by Ndepth scales down from integer N to a fraction. .PP .Vb 2 \& N = 1abcdef integer, in binary \& ?(r) = a.bcdef1 binary fraction .Ve .PP For example ?(2/3) is X=2,Y=3 which is N=5 in the \s-1SB\s0 tree. It is at depth=2, Ndepth=2^2=4, and so ?(2/3)=(2*(5\-4)+1)/4=3/4. Or written in binary N=101 gives Ndepth=100 and N\-Ndepth=01 so 2*(N\-Ndepth)+1=011 and divide by Ndepth=100 for ?=0.11. .PP In practice this is not a very efficient way to handle the question function, since the bit runs in the N values may become quite large for relatively modest fractions. (Math::ContinuedFraction may be better, and also allows repeating terms from quadratic irrationals to be represented exactly.) .SS "Pythagorean Triples" .IX Subsection "Pythagorean Triples" Pythagorean triples A^2+B^2=C^2 can be generated by A=P^2\-Q^2, B=2*P*Q. If P>Q>1 with P,Q no common factor and one odd the other even then this gives all primitive triples, being primitive in the sense of A,B,C no common factor (\*(L"\s-1PQ\s0 Coordinates\*(R" in Math::PlanePath::PythagoreanTree). .PP In the Calkin-Wilf tree the parity of X,Y pairs are as follows. Pairs X,Y with one odd the other even are N=0 or 2 mod 3. .PP .Vb 5 \& CW tree X/Y \& \-\-\-\-\-\-\-\- \& N=0 mod 3 even/odd \& N=1 mod 3 odd/odd \& N=2 mod 3 odd/even .Ve .PP This occurs because the numerators are the Stern diatomic sequence and the denominators likewise but offset by 1. The Stern diatomic sequence is a repeating pattern even,odd,odd (eg. per \*(L"Odd and Even\*(R" in Math::NumSeq::SternDiatomic). .PP The X>Y pairs in the \s-1CW\s0 tree are the right leg of each node, which is N odd. so .PP .Vb 1 \& CW tree N=3 or 5 mod 6 gives X>Y one odd the other even \& \& index t=1,2,3,etc to enumerate such pairs \& N = 3*t if t odd \& 3*t\-1 if t even .Ve .PP 2 of each 6 points are used. In a given row it's width/3 but rounded up or down according to where the 3,5mod6 falls on the N=2^depth start, which is either floor or ceil according to depth odd or even, .IX Xref "Jacobsthal numbers" .PP .Vb 3 \& NumPQ(depth) = floor(2^depth / 3) for depth=even \& ceil (2^depth / 3) for depth=odd \& = 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, ... .Ve .PP These are the Jacobsthal numbers, which in binary are 101010...101 and 1010...1011. .PP For the other tree types the various bit transformations which map N positions between the trees can be applied to the above N=3or5 mod 6. The simplest is the L tree where the N offset and row reversal gives N=0or4 mod 6. .PP The \s-1SB\s0 tree is a bit reversal of the \s-1CW,\s0 as described above, and for the Pythagorean N this gives .PP .Vb 2 \& SB tree N=0 or 2 mod 2 and N="11...." in binary \& gives X>Y one odd the other even .Ve .PP N=\*(L"11...\*(R" binary is the bit reversal of the \s-1CW\s0 N=odd \*(L"1...1\*(R" condition. This bit pattern is those N in the second half of each row, which is where the X/Y > 1 rationals occur. The N=0or2 mod 3 condition is unchanged by the bit reversal. N=0or2 mod 3 precisely when bitreverse(N)=0or2 mod 3. .PP For \s-1SB\s0 whether it's odd/even or even/odd at N=0or2 mod 3 alternates between rows. The two are both wanted, they just happen to switch in each row. .PP .Vb 5 \& SB tree X/Y depth=even depth=odd \& \-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\- \& N=0 mod 3 odd/even even/odd \& N=1 mod 3 odd/odd odd/odd <\- exclude for Pythagorean \& N=2 mod 3 even/odd odd/even .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" See \*(L"\s-1FUNCTIONS\*(R"\s0 in Math::PlanePath for behaviour common to all path classes. .ie n .IP """$path = Math::PlanePath::RationalsTree\->new ()""" 4 .el .IP "\f(CW$path = Math::PlanePath::RationalsTree\->new ()\fR" 4 .IX Item "$path = Math::PlanePath::RationalsTree->new ()" .PD 0 .ie n .IP """$path = Math::PlanePath::RationalsTree\->new (tree_type => $str)""" 4 .el .IP "\f(CW$path = Math::PlanePath::RationalsTree\->new (tree_type => $str)\fR" 4 .IX Item "$path = Math::PlanePath::RationalsTree->new (tree_type => $str)" .PD Create and return a new path object. \f(CW\*(C`tree_type\*(C'\fR (a string) can be .Sp .Vb 7 \& "SB" Stern\-Brocot \& "CW" Calkin\-Wilf \& "AYT" Yu\-Ting, Andreev \& "HCS" \& "Bird" \& "Drib" \& "L" .Ve .ie n .IP """$n = $path\->n_start()""" 4 .el .IP "\f(CW$n = $path\->n_start()\fR" 4 .IX Item "$n = $path->n_start()" Return the first N in the path. This is 1 for \s-1SB, CW, AYT, HCS,\s0 Bird and Drib, but 0 for L. .ie n .IP """($n_lo, $n_hi) = $path\->rect_to_n_range ($x1,$y1, $x2,$y2)""" 4 .el .IP "\f(CW($n_lo, $n_hi) = $path\->rect_to_n_range ($x1,$y1, $x2,$y2)\fR" 4 .IX Item "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)" Return a range of N values which occur in a rectangle with corners at \&\f(CW$x1\fR,\f(CW$y1\fR and \f(CW$x2\fR,\f(CW$y2\fR. The range is inclusive. .Sp For reference, \f(CW$n_hi\fR can be quite large because within each row there's only one new X/1 integer and 1/Y fraction. So if X=1 or Y=1 is included then roughly \f(CW\*(C`$n_hi = 2**max(x,y)\*(C'\fR. If min(x,y) is bigger than 1 then it reduces a little to roughly 2**(max/min + min). .SS "Tree Methods" .IX Subsection "Tree Methods" Each point has 2 children, so the path is a complete binary tree. .IX Xref "Complete binary tree" .ie n .IP """@n_children = $path\->tree_n_children($n)""" 4 .el .IP "\f(CW@n_children = $path\->tree_n_children($n)\fR" 4 .IX Item "@n_children = $path->tree_n_children($n)" Return the two children of \f(CW$n\fR, or an empty list if \f(CW\*(C`$n < 1\*(C'\fR (ie. before the start of the path). .Sp This is simply \f(CW\*(C`2*$n, 2*$n+1\*(C'\fR. Written in binary the children are \f(CW$n\fR with an extra bit appended, a 0\-bit or a 1\-bit. .ie n .IP """$num = $path\->tree_n_num_children($n)""" 4 .el .IP "\f(CW$num = $path\->tree_n_num_children($n)\fR" 4 .IX Item "$num = $path->tree_n_num_children($n)" Return 2, since every node has two children. If \f(CW\*(C`$n<1\*(C'\fR, ie. before the start of the path, then return \f(CW\*(C`undef\*(C'\fR. .ie n .IP """$n_parent = $path\->tree_n_parent($n)""" 4 .el .IP "\f(CW$n_parent = $path\->tree_n_parent($n)\fR" 4 .IX Item "$n_parent = $path->tree_n_parent($n)" Return the parent node of \f(CW$n\fR. Or return \f(CW\*(C`undef\*(C'\fR if \f(CW\*(C`$n <= 1\*(C'\fR (the top of the tree). .Sp This is simply Nparent = floor(N/2), ie. strip the least significant bit from \f(CW$n\fR. (Undo what \f(CW\*(C`tree_n_children()\*(C'\fR appends.) .ie n .IP """$depth = $path\->tree_n_to_depth($n)""" 4 .el .IP "\f(CW$depth = $path\->tree_n_to_depth($n)\fR" 4 .IX Item "$depth = $path->tree_n_to_depth($n)" Return the depth of node \f(CW$n\fR, or \f(CW\*(C`undef\*(C'\fR if there's no point \f(CW$n\fR. The top of the tree at N=1 is depth=0, then its children depth=1, etc. .Sp This is simply floor(log2(N)) since the tree has 2 nodes per point. For example N=4 through N=7 are all depth=2. .Sp The L tree starts at N=0 and the calculation becomes floor(log2(N+1)) there. .ie n .IP """$n = $path\->tree_depth_to_n($depth)""" 4 .el .IP "\f(CW$n = $path\->tree_depth_to_n($depth)\fR" 4 .IX Item "$n = $path->tree_depth_to_n($depth)" .PD 0 .ie n .IP """$n = $path\->tree_depth_to_n_end($depth)""" 4 .el .IP "\f(CW$n = $path\->tree_depth_to_n_end($depth)\fR" 4 .IX Item "$n = $path->tree_depth_to_n_end($depth)" .PD Return the first or last N at tree level \f(CW$depth\fR in the path, or \f(CW\*(C`undef\*(C'\fR if nothing at that depth or not a tree. The top of the tree is depth=0. .Sp The structure of the tree means the first N is at \f(CW\*(C`2**$depth\*(C'\fR, or for the L tree \f(CW\*(C`2**$depth\ \-\ 1\*(C'\fR. The last N is \f(CW\*(C`2**($depth+1)\-1\*(C'\fR, or for the L tree \f(CW\*(C`2**($depth+1)\*(C'\fR. .SS "Tree Descriptive Methods" .IX Subsection "Tree Descriptive Methods" .ie n .IP """$num = $path\->tree_num_children_minimum()""" 4 .el .IP "\f(CW$num = $path\->tree_num_children_minimum()\fR" 4 .IX Item "$num = $path->tree_num_children_minimum()" .PD 0 .ie n .IP """$num = $path\->tree_num_children_maximum()""" 4 .el .IP "\f(CW$num = $path\->tree_num_children_maximum()\fR" 4 .IX Item "$num = $path->tree_num_children_maximum()" .PD Return 2 since every node has 2 children so that's both the minimum and maximum. .ie n .IP """$bool = $path\->tree_any_leaf()""" 4 .el .IP "\f(CW$bool = $path\->tree_any_leaf()\fR" 4 .IX Item "$bool = $path->tree_any_leaf()" Return false, since there are no leaf nodes in the tree. .SH "OEIS" .IX Header "OEIS" The trees are in Sloane's Online Encyclopedia of Integer Sequences in various forms, .Sp .RS 4 (etc) .RE .PP .Vb 7 \& tree_type=SB \& A007305 X, extra initial 0,1 \& A047679 Y \& A057431 X,Y pairs (initial extra 0/1,1/0) \& A007306 X+Y sum, Farey 0 to 1 part (extra 1,1) \& A153036 int(X/Y), integer part \& A088696 length of continued fraction SB left half (X/Y<1) \& \& tree_type=CW \& A002487 X and Y, Stern diatomic sequence (extra 0) \& A070990 Y\-X diff, Stern diatomic first diffs (less 0) \& A070871 X*Y product \& A007814 int(X/Y), integer part, count trailing 1\-bits \& which is count trailing 0\-bits of N+1 \& A086893 N position of Fibonacci F[n+1]/F[n], N = binary 1010..101 \& A061547 N position of Fibonacci F[n]/F[n+1], N = binary 11010..10 \& A047270 3or5 mod 6, being N positions of X>Y not both odd \& which can generate primitive Pythagorean triples \& \& tree_type=AYT \& A020650 X \& A020651 Y (Kepler numerator) \& A086592 X+Y sum (Kepler denominator) \& A135523 int(X/Y), integer part, \& count trailing 0\-bits plus 1 extra if N=2^k \& \& tree_type=HCS \& A229742 X, extra initial 0/1 \& A071766 Y \& A071585 X+Y sum \& \& tree_type=Bird \& A162909 X \& A162910 Y \& A081254 N of row Y=1, N = binary 1101010...10 \& A000975 N of column X=1, N = binary 101010...10 \& \& tree_type=Drib \& A162911 X \& A162912 Y \& A086893 N of row Y=1, N = binary 110101..0101 (ending 1) \& A061547 N of column X=1, N = binary 110101..010 (ending 0) \& \& tree_type=L \& A174981 X \& A002487 Y, same as CW X,Y, Stern diatomic \& A047233 0or4 mod 6, being N positions of X>Y not both odd \& which can generate primitive Pythagorean triples \& \& tree_type=SB,CW,AYT,HCS,Bird,Drib,L \& A008776 total X+Y in row, being 2*3^depth \& \& A000523 tree_n_to_depth(), being floor(log2(N)) \& \& A059893 permutation SB<\->CW, AYT<\->HCS, Bird<\->Drib \& reverse bits below highest \& A153153 permutation CW\->AYT, reverse and un\-Gray \& A153154 permutation AYT\->CW, reverse and Gray code \& A154437 permutation AYT\->Drib, Lamplighter low to high \& A154438 permutation Drib\->AYT, un\-Lamplighter low to high \& A003188 permutation SB\->HCS, Gray code shift+xor \& A006068 permutation HCS\->SB, Gray code inverse \& A154435 permutation HCS\->Bird, Lamplighter bit flips \& A154436 permutation Bird\->HCS, Lamplighter variant \& \& A054429 permutation SB,CW,Bird,Drib N at transpose Y/X, \& (mirror binary tree, runs 0b11..11 down to 0b10..00) \& A004442 permutation AYT N at transpose Y/X, from N=2 onwards \& (xor 1, ie. flip least significant bit) \& A063946 permutation HCS N at transpose Y/X, extra initial 0 \& (xor 2, ie. flip second least significant bit) \& \& A054424 permutation DiagonalRationals \-> SB \& A054426 permutation SB \-> DiagonalRationals \& A054425 DiagonalRationals \-> SB with 0s at non\-coprimes \& A054427 permutation coprimes \-> SB right hand X/Y>1 \& \& A044051 N+1 of those N where SB and CW have same X,Y \& same Bird<\->Drib and HCS<\->AYT \& begin N+1 of N binary palindrome below high 1\-bit .Ve .PP The sequences marked \*(L"extra ...\*(R" have one or two extra initial values over what the RationalsTree here gives, but are the same after that. And the Stern first differences \*(L"less ...\*(R" means it has one less term than what the code here gives. .SH "SEE ALSO" .IX Header "SEE ALSO" Math::PlanePath, Math::PlanePath::FractionsTree, Math::PlanePath::CfracDigits, Math::PlanePath::ChanTree .PP Math::PlanePath::CoprimeColumns, Math::PlanePath::DiagonalRationals, Math::PlanePath::FactorRationals, Math::PlanePath::GcdRationals, Math::PlanePath::PythagoreanTree .PP Math::NumSeq::SternDiatomic, Math::ContinuedFraction .SH "HOME PAGE" .IX Header "HOME PAGE" .SH "LICENSE" .IX Header "LICENSE" Copyright 2011, 2012, 2013 Kevin Ryde .PP This file is part of Math-PlanePath. .PP Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. .PP Math-PlanePath is distributed in the hope that it will be useful, but \&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE. \s0 See the \s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with Math-PlanePath. If not, see .