-
-
-
-302
-303
-304
-
-
- # File 'lib/fraction_tree.rb', line 302
+
+
+
+
+
+
+
+
+
+ #eql? (rhs) ⇒ Boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Needed for intersection operations to work.
+
+
+
+
+
+
+
+
+ #hash ⇒ Object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #initialize (num) ⇒ Node
+
+
+
+
+
+
+ constructor
+
+
+
+
+
+
+
+
+
+
A new instance of Node.
+
+
+
+
+
+
+
+
+ #inspect ⇒ Object
+
+
+
+ (also: #to_s)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ #neighbors (r = 10**(self.class.decimal_power(number.numerator)+2)) ⇒ Array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Of [FractionTree::Node], sequence of Farey neighbors to self.
+
+
+
+
+
+
+
+
+ #parents ⇒ Array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
A pair of fraction tree nodes leading to the given number.
+
+
+
+
+
+
+
+
+ #path ⇒ Array
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Set of fraction tree nodes leading to the given number.
+
+
+
+
+
+
+
+
+
+
+
+
Constructor Details
+
+
+
+
+ #initialize (num) ⇒ Node
+
+
+
+
+
+
+
+
+
Returns a new instance of Node.
+
+
+
+
+
+
+
+
+
+
+
+
+
+16
+17
+18
+19
+
+
+ # File 'lib/fraction_tree/node.rb', line 16
+
+def initialize ( num )
+ ( @numerator , @denominator ) = fraction_pair ( num )
+ @number = num
+end
+
+
+
+
+
+
+
+
+
Instance Attribute Details
+
+
+
+
+
+
+ #denominator ⇒ Object
+
+
+
+
+
+
+
+
+
Returns the value of attribute denominator.
+
+
+
+
+
+
+
+
+
+
+
+
+
+10
+11
+12
+
+
+ # File 'lib/fraction_tree/node.rb', line 10
+
+def denominator
+ @denominator
+end
+
+
+
+
+
+
+
+
+
+
+ #number ⇒ Object
+
+
+
+ Also known as:
+ to_r
+
+
+
+
+
+
+
+
Returns the value of attribute number.
+
+
+
+
+
+
+
+
+
+
+
+
+
+10
+11
+12
+
+
+ # File 'lib/fraction_tree/node.rb', line 10
+
+def number
+ @number
+end
+
+
+
+
+
+
+
+
+
+
+ #numerator ⇒ Object
+
+
+
+
+
+
+
+
+
Returns the value of attribute numerator.
+
+
+
+
+
+
+
+
+
+
+
+
+
+10
+11
+12
+
+
+ # File 'lib/fraction_tree/node.rb', line 10
+
+def numerator
+ @numerator
+end
+
+
+
+
+
+
+
+
+
+
Class Method Details
+
+
+
+
+
+ .decimal_power (logarithmand) ⇒ Integer
+
+
+
+
+
+
+
+
+
Returns the decimal power of the provided number.
+
+
+
+
+
+
+
+
+
+
+84
+85
+86
+
+
+ # File 'lib/fraction_tree/node.rb', line 84
+
+def decimal_power ( logarithmand )
+ Math . log10 ( logarithmand . abs ) . floor
+end
+
+
+
+
+
+
+
+
+
+
Returns the fraction decoded from the given string.
+
+
+
+
+
+
+
+
+
+
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+
+
+ # File 'lib/fraction_tree/node.rb', line 28
+
+def decode ( string )
+ result = IDENTITY_MATRIX
+
+ string . split ( " " ) . each do | direction |
+ case direction
+ when " L " , " 0 " , " l "
+ result = result * LEFT_MATRIX
+ when " R " , " 1 " , " r "
+ result = result * RIGHT_MATRIX
+ end
+ end
+ FractionTree . node ( Rational ( result . row ( 1 ) . sum , result . row ( 0 ) . sum ) )
+end
+
+
+
+
+
+
+
+
+ .encode (number) ⇒ String
+
+
+
+
+
+
+
+
+
Returns the Stern-Brocot encoding of number.
+
+
+
+
+
+
+
+
+
+
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+
+
+ # File 'lib/fraction_tree/node.rb', line 46
+
+def encode ( number )
+ return nil if ( number . infinite? || number . zero? )
+
+ m = number . numerator
+ n = number . denominator
+
+ return " I " if m == n
+
+ " " . tap do | string |
+ while m != n
+ if m < n
+ string << " L "
+ n = n - m
+ else
+ string << " R "
+ m = m - n
+ end
+ end
+ end
+end
+
+
+
+
+
+
+
+
+ .plus_minus (num, diff) ⇒ Array
+
+
+
+
+
+
+
+
+
Returns pair of numbers less and greater than the provided number by provided difference.
+
+
+
+
+
+
+
+
+
+
+74
+75
+76
+
+
+ # File 'lib/fraction_tree/node.rb', line 74
+
+def plus_minus ( num , diff )
+ [ num - diff , num + diff ]
+end
+
+
+
+
+
+
+
+
+
Instance Method Details
+
+
+
+
+
+
+
Returns sum of self and another node.
+
+
+
+
+
+
+
+
+
+
+195
+196
+197
+
+
+ # File 'lib/fraction_tree/node.rb', line 195
+
+def + ( rhs )
+ tree . node ( Rational ( self . numerator + rhs . numerator , self . denominator + rhs . denominator ) )
+end
+
+
+
+
+
+
+
+
+
+
Returns difference of self and another node.
+
+
+
+
+
+
+
+
+
+
+204
+205
+206
+
+
+ # File 'lib/fraction_tree/node.rb', line 204
+
+def - ( rhs )
+ tree . node ( Rational ( ( self . numerator - rhs . numerator ) . abs , ( self . denominator - rhs . denominator ) . abs ) )
+end
+
+
+
+
+
+
+
+
+ #<=> (rhs) ⇒ Object
+
+
+
+
+
+
+
+
+
+
+
+213
+214
+215
+
+
+ # File 'lib/fraction_tree/node.rb', line 213
+
+def <=> ( rhs )
+ self . number <=> rhs . number
+end
+
+
+
+
+
+
+
+
+ #== (rhs) ⇒ Object
+
+
+
+
+
+
+
+
+
+
+
+217
+218
+219
+
+
+ # File 'lib/fraction_tree/node.rb', line 217
+
+def == ( rhs )
+ self . number == rhs . number
+end
+
+
+
+
+
+
+
+
+
+
+
Note:
+
+
return nil if bc - ad |= 1, for a/b, c/d
+
+
+
+
+
Returns child of self and given number.
+
+
+
+
+
+
+
+
+
+
+178
+179
+180
+
+
+ # File 'lib/fraction_tree/node.rb', line 178
+
+def child_with ( num )
+ tree . child_of ( number , num )
+end
+
+
+
+
+
+
+
+
+ #common_ancestors_with (num) ⇒ Array
+
+
+
+
+
+
+
+
+
Returns the ancestors shared by self and the given number.
+
+
+
+
+
+
+
+
-def + ( rhs )
- self . class . new ( self . numerator + rhs . numerator , self . denominator + rhs . denominator )
+
+156
+157
+158
+
+
+ # File 'lib/fraction_tree/node.rb', line 156
+
+def common_ancestors_with ( num )
+ path & tree . node ( num ) . path
end
@@ -603,29 +1630,91 @@
-
+
- #<=> (rhs) ⇒ Object
+ #descendancy_from (depth: 5) ⇒ Array
-
+
+
+
+
Returns of fraction tree nodes, descending from parents of number.
+
+
+
+
+
-279
-280
-281
+167
+168
+169
+170
- # File 'lib/fraction_tree.rb', line 279
+ # File 'lib/fraction_tree/node.rb', line 167
-def <=> ( rhs )
- self . weight <=> rhs . weight
+def descendancy_from ( depth: 5 )
+ ( parent1 , parent2 ) = parents
+ tree . descendants_of ( parent1 . number , parent2 . number , depth: )
end
@@ -633,29 +1722,66 @@
-
+
- #== (rhs) ⇒ Object
+ #encoding ⇒ String
-
+
+
+
+
Returns encoding of self.
+
+
+
+
+
-283
-284
-285
+186
+187
+188
- # File 'lib/fraction_tree.rb', line 283
+ # File 'lib/fraction_tree/node.rb', line 186
-def == ( rhs )
- self . weight == rhs . weight
+def encoding
+ @encoding ||= self . class . encode ( number )
end
@@ -701,15 +1827,15 @@
-292
-293
-294
+226
+227
+228
- # File 'lib/fraction_tree.rb', line 292
+ # File 'lib/fraction_tree/node.rb', line 226
def eql? ( rhs )
- rhs . instance_of? ( self . class ) && weight == rhs . weight
+ rhs . instance_of? ( self . class ) && number == rhs . number
end
@@ -731,14 +1857,14 @@
-296
-297
-298
-299
-300
+230
+231
+232
+233
+234
- # File 'lib/fraction_tree.rb', line 296
+ # File 'lib/fraction_tree/node.rb', line 230
def hash
p , q = 17 , 37
@@ -769,12 +1895,12 @@
-274
-275
-276
+208
+209
+210
- # File 'lib/fraction_tree.rb', line 274
+ # File 'lib/fraction_tree/node.rb', line 208
def inspect
" ( #{ numerator } / #{ denominator } ) "
@@ -782,6 +1908,296 @@
+
+
+
+
+
+ #neighbors (r = 10**(self.class.decimal_power(number.numerator)+2)) ⇒ Array
+
+
+
+
+
+
+
+
+
Returns of [FractionTree::Node], sequence of Farey neighbors to self. A Farey neighbor is a number c/d, who’s relationship to a/b is such that ad − bc = 1, when c/d < a/b and bc − ad = 1 when c/d > a/b.
+
+
+
+
+
+
+
+
+
+
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+
+
+ # File 'lib/fraction_tree/node.rb', line 136
+
+def neighbors ( r = 10 ** ( self . class . decimal_power ( number . numerator ) + 2 ) )
+ ratio = number . to_r
+ denominator = ratio . denominator
+
+ [ ] . tap do | collection |
+ ( 1 .. r - 1 ) . each do | i |
+ lower , upper = self . class . plus_minus ( ratio , Rational ( 1 , i * denominator ) )
+ collection << tree . node ( lower ) if tree . neighbors? ( ratio , lower )
+ collection << tree . node ( upper ) if tree . neighbors? ( ratio , upper )
+ end
+ end
+end
+
+
+
+
+
+
+
+
+ #parents ⇒ Array
+
+
+
+
+
+
+
+
+
Returns a pair of fraction tree nodes leading to the given number.
+
+
+
+
+
+
+
+
+
+
+125
+126
+127
+128
+
+
+ # File 'lib/fraction_tree/node.rb', line 125
+
+def parents
+ tmp = path
+ [ tmp [ - 2 ] , tmp [ - 2 .. - 1 ] . inject ( & :- ) ] . sort
+end
+
+
+
+
+
+
+
+
+ #path ⇒ Array
+
+
+
+
+
+
+
+
+
Returns set of fraction tree nodes leading to the given number.
+
+
+
+
+
+
+
+
+
+
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+
+
+ # File 'lib/fraction_tree/node.rb', line 94
+
+def path
+ return nil if infinite? || zero?
+
+ ln = tree . node ( FractionTree . left_node )
+ rn = tree . node ( FractionTree . right_node )
+ mn = ln + rn
+ return [ ln , rn , mn ] if mn == tree . node ( number )
+
+ result = IDENTITY_MATRIX
+ m = numerator
+ n = denominator
+ [ ] . tap do | p |
+ p << ln << rn << mn
+ while m != n
+ if m < n
+ result = result * LEFT_MATRIX
+ n = n - m
+ else
+ result = result * RIGHT_MATRIX
+ m = m - n
+ end
+ p << tree . node ( Rational ( result . row ( 1 ) . sum , result . row ( 0 ) . sum ) )
+ end
+ end
+end
+
+
+
@@ -789,9 +2205,9 @@
diff --git a/docs/KeyboardTree.html b/docs/KeyboardTree.html
deleted file mode 100644
index 6e1b803..0000000
--- a/docs/KeyboardTree.html
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
-
-
- Class: KeyboardTree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: KeyboardTree
-
-
-
-
-
-
-
- Inherits:
-
- FareyTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
-
-
-
-
-
-
Method Summary
-
-
Methods inherited from FareyTree
-
base_segment
-
-
-
-
-
-
-
-
-
-
-
base_segment , child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/Log2Tree.html b/docs/Log2Tree.html
deleted file mode 100644
index 2564577..0000000
--- a/docs/Log2Tree.html
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
-
-
- Class: Log2Tree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: Log2Tree
-
-
-
-
-
-
-
- Inherits:
-
- FareyTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
-
-
-
-
-
-
Method Summary
-
-
Methods inherited from FareyTree
-
base_segment
-
-
-
-
-
-
-
-
-
-
-
base_segment , child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/Numeric.html b/docs/Numeric.html
new file mode 100644
index 0000000..ea869e7
--- /dev/null
+++ b/docs/Numeric.html
@@ -0,0 +1,229 @@
+
+
+
+
+
+
+ Class: Numeric
+
+ — Documentation by YARD 0.9.36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: Numeric
+
+
+
+
+
+
+
+ Inherits:
+
+ Object
+
+
+ show all
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defined in:
+ lib/fraction_tree/extensions.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Instance Method Summary
+ collapse
+
+
+
+
+
+
+
+
+
Instance Method Details
+
+
+
+
+
+
+
Returns string Stern-Brocot decoded.
+
+
+
+
+
+
+
+
+
+
+26
+27
+28
+
+
+ # File 'lib/fraction_tree/extensions.rb', line 26
+
+def to_node
+ FractionTree . node ( self )
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/OctaveReducedTree.html b/docs/OctaveReducedTree.html
deleted file mode 100644
index 27bf738..0000000
--- a/docs/OctaveReducedTree.html
+++ /dev/null
@@ -1,209 +0,0 @@
-
-
-
-
-
-
- Class: OctaveReducedTree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: OctaveReducedTree
-
-
-
-
-
-
-
- Inherits:
-
- FractionTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
- Class Method Summary
- collapse
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
Class Method Details
-
-
-
-
-
- .base_segment ⇒ Object
-
-
-
-
-
-
-
-
-
-
-
-312
-313
-314
-
-
- # File 'lib/fraction_tree.rb', line 312
-
-def self . base_segment
- [ Node . new ( 1 , 1 ) , Node . new ( 2 , 1 ) ]
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/ScaleStepTree.html b/docs/ScaleStepTree.html
deleted file mode 100644
index da2601c..0000000
--- a/docs/ScaleStepTree.html
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
-
-
-
- Class: ScaleStepTree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: ScaleStepTree
-
-
-
-
-
-
-
- Inherits:
-
- FareyTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
-
-
-
-
-
-
Method Summary
-
-
Methods inherited from FareyTree
-
base_segment
-
-
-
-
-
-
-
-
-
-
-
base_segment , child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/ScaleTree.html b/docs/ScaleTree.html
deleted file mode 100644
index a4282a4..0000000
--- a/docs/ScaleTree.html
+++ /dev/null
@@ -1,140 +0,0 @@
-
-
-
-
-
-
- Class: ScaleTree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: ScaleTree
-
-
-
-
-
-
-
- Inherits:
-
- FractionTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
-
-
-
-
-
-
Method Summary
-
-
-
base_segment , child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/SternBrocotTree.html b/docs/SternBrocotTree.html
deleted file mode 100644
index 43ba2ea..0000000
--- a/docs/SternBrocotTree.html
+++ /dev/null
@@ -1,140 +0,0 @@
-
-
-
-
-
-
- Class: SternBrocotTree
-
- — Documentation by YARD 0.9.34
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Class: SternBrocotTree
-
-
-
-
-
-
-
- Inherits:
-
- FractionTree
-
-
- show all
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Defined in:
- lib/fraction_tree.rb
-
-
-
-
-
-
-
-
Constant Summary
-
-
Constants inherited
- from FractionTree
-
FractionTree::DEFAULT_TREE_DEPTH
-
-
-
-
-
-
-
-
-
-
-
-
-
Method Summary
-
-
-
base_segment , child_of , common_ancestors_between , descendancy_from , descendants_of , farey_neighbors , farey_neighbors? , numeric_sequence , parents_of , path_to , quotient_walk , sequence , tree
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/docs/String.html b/docs/String.html
new file mode 100644
index 0000000..adc0f54
--- /dev/null
+++ b/docs/String.html
@@ -0,0 +1,249 @@
+
+
+
+
+
+
+ Class: String
+
+ — Documentation by YARD 0.9.36
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Class: String
+
+
+
+
+
+
+
+ Inherits:
+
+ Object
+
+
+ show all
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Defined in:
+ lib/fraction_tree/extensions.rb
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Instance Method Summary
+ collapse
+
+
+
+
+
+
+
+
+
Instance Method Details
+
+
+
+
+
+
+
Returns string Stern-Brocot decoded.
+
+
+
+
+
+
+
+
+
+
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+
+
+ # File 'lib/fraction_tree/extensions.rb', line 6
+
+def to_node
+ if self . include? ( " . " )
+ number = self . to_d
+ numerator , denominator = number . numerator , number . denominator
+ elsif self . include? ( " / " )
+ ( numerator , denominator ) = self . split ( " / " ) . map ( & :to_i )
+ else
+ number = self . to_r
+ numerator , denominator = number . numerator , number . denominator
+ end
+ number = denominator . zero? ? Float :: INFINITY : Rational ( numerator , denominator )
+ FractionTree :: Node . new ( number )
+end
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/_index.html b/docs/_index.html
index 16046c4..5f7fc49 100644
--- a/docs/_index.html
+++ b/docs/_index.html
@@ -4,7 +4,7 @@
- Documentation by YARD 0.9.34
+ Documentation by YARD 0.9.36
@@ -52,7 +52,7 @@
- Documentation by YARD 0.9.34
+
Documentation by YARD 0.9.36
Alphabetic Index
@@ -80,11 +80,6 @@
Namespace Listing A-Z
F
-
-
-
-
-
-
N
@@ -131,16 +100,8 @@ Namespace Listing A-Z
-
-
-
-
-
diff --git a/docs/class_list.html b/docs/class_list.html
index d11fc96..bc57e5b 100644
--- a/docs/class_list.html
+++ b/docs/class_list.html
@@ -43,7 +43,7 @@
-Node < Object
FractionTree
+Node < Object
FractionTree Numeric < Object
Top Level Namespace String < Object
Top Level Namespace
diff --git a/docs/file.README.html b/docs/file.README.html
index 75ade22..b1a3fcd 100644
--- a/docs/file.README.html
+++ b/docs/file.README.html
@@ -6,7 +6,7 @@
File: README
- — Documentation by YARD 0.9.34
+ — Documentation by YARD 0.9.36
@@ -64,6 +64,21 @@ FractionTree
A collection of Stern-Brocot based models and methods.
+The Stern-Brocot algorithm describes a way of constructing sets of non-negative fractions arranged in a binary tree.
+
+Construction of a SB tree starts by using the fractions 0/1 and 1/0, where 1/0 denotes infinity. Subsequent fractions are derived by the algorithm, (m + m′)/(n + n′), where m/n is the left adjacent fraction and m′/n′ is the right adjacent fraction, and m/n < m′/n′. This sum is called the mediant.
+
+Given m/n = 0/1 and m′/n′ = 1/0, the first mediant sum, is:
+
+0/1 + 1/0 => (0 + 1)/(1 + 0) = 1/1
+
+Fractions constructed in this way, have the following properties:
+
+m/n < (m + m′)/(n + n′) < m′/n′
+
+m’n - mn’ = 1
+
+
Installing
gem install fraction - tree
@@ -79,20 +94,26 @@ License
Acknowledgments
diff --git a/docs/frames.html b/docs/frames.html
index 4f918f5..53734c2 100644
--- a/docs/frames.html
+++ b/docs/frames.html
@@ -2,13 +2,18 @@
- Documentation by YARD 0.9.34
+ Documentation by YARD 0.9.36
Oops!
diff --git a/docs/index.html b/docs/index.html
index b77b64b..81e54d7 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -6,7 +6,7 @@
File: README
- — Documentation by YARD 0.9.34
+ — Documentation by YARD 0.9.36
@@ -64,6 +64,21 @@ FractionTree
A collection of Stern-Brocot based models and methods.
+The Stern-Brocot algorithm describes a way of constructing sets of non-negative fractions arranged in a binary tree.
+
+Construction of a SB tree starts by using the fractions 0/1 and 1/0, where 1/0 denotes infinity. Subsequent fractions are derived by the algorithm, (m + m′)/(n + n′), where m/n is the left adjacent fraction and m′/n′ is the right adjacent fraction, and m/n < m′/n′. This sum is called the mediant.
+
+Given m/n = 0/1 and m′/n′ = 1/0, the first mediant sum, is:
+
+0/1 + 1/0 => (0 + 1)/(1 + 0) = 1/1
+
+Fractions constructed in this way, have the following properties:
+
+m/n < (m + m′)/(n + n′) < m′/n′
+
+m’n - mn’ = 1
+
+
Installing
gem install fraction - tree
@@ -79,20 +94,26 @@ License
Acknowledgments
diff --git a/docs/method_list.html b/docs/method_list.html
index 3508762..4d19ce3 100644
--- a/docs/method_list.html
+++ b/docs/method_list.html
@@ -54,7 +54,7 @@
-
#<=>
+
#-
FractionTree::Node
@@ -62,7 +62,7 @@
@@ -70,39 +70,55 @@
+
+
+
+
+
+
+
+
+
+
@@ -118,8 +134,8 @@
@@ -134,7 +150,7 @@
@@ -142,16 +158,16 @@
@@ -180,6 +196,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#numerator
@@ -198,7 +278,39 @@
+
+
+
+
+
+
#path
+
FractionTree::Node
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -206,7 +318,7 @@
@@ -214,7 +326,7 @@
@@ -222,7 +334,7 @@
@@ -230,7 +342,7 @@
@@ -238,8 +350,24 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/top-level-namespace.html b/docs/top-level-namespace.html
index e456f69..6aed644 100644
--- a/docs/top-level-namespace.html
+++ b/docs/top-level-namespace.html
@@ -6,7 +6,7 @@
Top Level Namespace
- — Documentation by YARD 0.9.34
+ — Documentation by YARD 0.9.36
@@ -84,7 +84,7 @@
Defined Under Namespace
-
Classes: FareyTree ,
FractionTree ,
KeyboardTree ,
Log2Tree ,
OctaveReducedTree ,
ScaleStepTree ,
ScaleTree ,
SternBrocotTree
+
Classes: FractionTree ,
Numeric ,
String
@@ -100,9 +100,9 @@
Defined Under Namespace
diff --git a/lib/fraction_tree/fraction_tree.rb b/lib/fraction_tree/fraction_tree.rb
index a070141..806c723 100644
--- a/lib/fraction_tree/fraction_tree.rb
+++ b/lib/fraction_tree/fraction_tree.rb
@@ -195,7 +195,8 @@ def descendants_of(parent1, parent2, depth: 5)
# => [(0/1), (1/3), (1/2), (2/3), (1/1), (3/2), (2/1), (3/1), (1/0)]
#
# @param depth [Integer] the number of iterations of the algorithm to run. The number of nodes returned will be greater
- # @param segment [Array] a tuple array of [FractionTree::Node] defining the segment of the tree to collect nodes.
+ # @param left_node [FractionTree::Node] the left starting node
+ # @param right_node [FractionTree::Node] the right starting node
#
def sequence(depth: 5, left_node: default_left_node, right_node: default_right_node)
[left_node]+_sequence(depth:, left_node:, right_node:)+[right_node]
diff --git a/lib/fraction_tree/node.rb b/lib/fraction_tree/node.rb
index fb5aa67..c23240f 100644
--- a/lib/fraction_tree/node.rb
+++ b/lib/fraction_tree/node.rb
@@ -68,7 +68,7 @@ def encode(number)
# @example
# FractionTree::Node.plus_minus(3, 2) => [1, 5]
# @param
- # number the base
+ # num the base
# diff the number subtracted and added to base
#
def plus_minus(num, diff)
@@ -91,8 +91,6 @@ def decimal_power(logarithmand)
# FractionTree.node(7/4r).path
# => [(0/1), (1/0), (1/1), (2/1), (3/2), (5/3), (7/4)]
#
- # @param find_parents [Boolean] list all ancestors or only immediate parents
- #
def path
return nil if infinite? || zero?
@@ -133,8 +131,7 @@ def parents
# @example
# FractionTree.node(3/2r).neighbors(10)
# => [(1/1), (2/1), (4/3), (5/3), (7/5), (8/5), (10/7), (11/7), (13/9), (14/9)]
- # @param number with neighbors
- # @param r, range of harmonic series to search
+ # @param r range of harmonic series to search
#
def neighbors(r = 10**(self.class.decimal_power(number.numerator)+2))
ratio = number.to_r
@@ -154,7 +151,7 @@ def neighbors(r = 10**(self.class.decimal_power(number.numerator)+2))
# FractionTree.node(4/3r).common_ancestors_with(7/4r)
# => [(0/1), (1/0), (1/1), (2/1), (3/2)]
#
- # @param number [Rational] other number sharing descendants with self
+ # @param num [Numeric] other number sharing descendants with self
#
def common_ancestors_with(num)
path & tree.node(num).path
@@ -165,7 +162,6 @@ def common_ancestors_with(num)
# FractionTree.node(5/4r).descendancy_from(depth: 3)
# => [(1/1), (7/6), (6/5), (11/9), (5/4), (14/11), (9/7), (13/10), (4/3)]
#
- # @param number [Rational] around which descendancy is focused
# @param depth [Integer] how many nodes to collect
#
def descendancy_from(depth: 5)