Module: Dydx::Helper
- Included in:
- Algebra::Formula, Algebra::Inverse, Algebra::Set::Base
- Defined in:
- lib/dydx/helper.rb
Constant Summary collapse
- SUPER_OPE_RELATION =
{ :+ => :*, :- => :/, :* => :**, :/ => :| }
- INVERSE_OPE_RELATION =
{ :+ => :-, :- => :+, :* => :/, :/ => :*, :** => :|, :| => :** }
Instance Method Summary collapse
- #==(x) ⇒ Object
-
#combinable?(x, operator) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high.
- #distributable?(_operator) ⇒ Boolean
- #distributive?(ope1, ope2) ⇒ Boolean
- #formula?(operator) ⇒ Boolean
- #inverse?(operator, x = nil) ⇒ Boolean
-
#like_term?(x) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high.
- #minus1? ⇒ Boolean
-
#multiple_of?(x) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high.
- #negative? ⇒ Boolean
- #num? ⇒ Boolean
- #one? ⇒ Boolean
- #rest(f_or_g) ⇒ Object
- #to_numeric ⇒ Object
- #zero? ⇒ Boolean
Instance Method Details
#==(x) ⇒ Object
127 128 129 |
# File 'lib/dydx/helper.rb', line 127 def ==(x) to_s == x.to_s end |
#combinable?(x, operator) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high. [17/6]
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dydx/helper.rb', line 48 def combinable?(x, operator) case operator when :+ (num? && x.num?) || (formula?(:*) && (f.num? || g.num?)) && x.num? || like_term?(x) || inverse?(:+, x) when :* self == x || (num? && x.num?) || inverse?(:*, x) when :** (num? && x.num?) || zero? || one? end end |
#distributable?(_operator) ⇒ Boolean
84 85 |
# File 'lib/dydx/helper.rb', line 84 def distributable?(_operator) end |
#distributive?(ope1, ope2) ⇒ Boolean
43 44 45 |
# File 'lib/dydx/helper.rb', line 43 def distributive?(ope1, ope2) [ope1.super, ope1.inv_super].include?(ope2) end |
#formula?(operator) ⇒ Boolean
97 98 99 |
# File 'lib/dydx/helper.rb', line 97 def formula?(operator) is_a?(Formula) && (@operator == operator) end |
#inverse?(operator, x = nil) ⇒ Boolean
87 88 89 90 91 92 93 94 95 |
# File 'lib/dydx/helper.rb', line 87 def inverse?(operator, x = nil) if is_a?(Algebra::Inverse) self.operator == operator && (self.x == x || x.nil?) elsif x.is_a?(Algebra::Inverse) self == x.x else false end end |
#like_term?(x) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high. [9/6]
65 66 67 68 69 70 |
# File 'lib/dydx/helper.rb', line 65 def like_term?(x) self == x || formula?(:*) && include?(x) || x.formula?(:*) && x.include?(self)|| (formula?(:*) && formula?(:*) && !([f, g] & [x.f, x.g]).empty?) end |
#minus1? ⇒ Boolean
35 36 37 |
# File 'lib/dydx/helper.rb', line 35 def minus1? [-1, -1.0].include?(self) || (is_a?(Num) && n.minus1?) end |
#multiple_of?(x) ⇒ Boolean
TODO: Cyclomatic complexity for combinable? is too high. [7/6]
73 74 75 76 77 78 |
# File 'lib/dydx/helper.rb', line 73 def multiple_of?(x) zero? || self == x || (num? && x.num? && self % x == 0) || (formula?(:*) && (f == x || g == x)) end |
#negative? ⇒ Boolean
39 40 41 |
# File 'lib/dydx/helper.rb', line 39 def negative? num? && self < 0 end |
#num? ⇒ Boolean
19 20 21 |
# File 'lib/dydx/helper.rb', line 19 def num? is_a?(Num) || is_a?(Numeric) end |
#one? ⇒ Boolean
31 32 33 |
# File 'lib/dydx/helper.rb', line 31 def one? [1, 1.0].include?(self) || (is_a?(Num) && n.one?) end |
#rest(f_or_g) ⇒ Object
80 81 82 |
# File 'lib/dydx/helper.rb', line 80 def rest(f_or_g) ([:f, :g] - [f_or_g]).first end |
#to_numeric ⇒ Object
23 24 25 |
# File 'lib/dydx/helper.rb', line 23 def to_numeric is_a?(Num) ? n : self end |
#zero? ⇒ Boolean
27 28 29 |
# File 'lib/dydx/helper.rb', line 27 def zero? [0, 0.0].include?(self) || (is_a?(Num) && n.zero?) end |