module Dydx::Helper
Constants
- INVERSE_OPE_RELATION
- SUPER_OPE_RELATION
Public Instance Methods
==(x)
click to toggle source
# File lib/dydx/helper.rb, line 127 def ==(x) to_s == x.to_s end
associative?()
click to toggle source
# File lib/dydx/helper.rb, line 106 def associative? [:+, :*].include?(self) end
combinable?(x, operator)
click to toggle source
TODO: Cyclomatic complexity for combinable? is too high. [17/6]
# 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
commutative?()
click to toggle source
# File lib/dydx/helper.rb, line 102 def commutative? [:+, :*].include?(self) end
distributable?(_operator)
click to toggle source
# File lib/dydx/helper.rb, line 84 def distributable?(_operator) end
distributive?(ope1, ope2)
click to toggle source
# File lib/dydx/helper.rb, line 43 def distributive?(ope1, ope2) [ope1.super, ope1.inv_super].include?(ope2) end
formula?(operator)
click to toggle source
# File lib/dydx/helper.rb, line 97 def formula?(operator) is_a?(Formula) && (@operator == operator) end
inv()
click to toggle source
# File lib/dydx/helper.rb, line 118 def inv INVERSE_OPE_RELATION[self] || self end
inv_super()
click to toggle source
# File lib/dydx/helper.rb, line 122 def inv_super self.super.inv end
inverse?(operator, x = nil)
click to toggle source
# 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)
click to toggle source
TODO: Cyclomatic complexity for combinable? is too high. [9/6]
# 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?()
click to toggle source
# File lib/dydx/helper.rb, line 35 def minus1? [-1, -1.0].include?(self) || (is_a?(Num) && n.minus1?) end
multiple_of?(x)
click to toggle source
TODO: Cyclomatic complexity for combinable? is too high. [7/6]
# 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?()
click to toggle source
# File lib/dydx/helper.rb, line 39 def negative? num? && self < 0 end
num?()
click to toggle source
# File lib/dydx/helper.rb, line 19 def num? is_a?(Num) || is_a?(Numeric) end
one?()
click to toggle source
# File lib/dydx/helper.rb, line 31 def one? [1, 1.0].include?(self) || (is_a?(Num) && n.one?) end
rest(f_or_g)
click to toggle source
# File lib/dydx/helper.rb, line 80 def rest(f_or_g) ([:f, :g] - [f_or_g]).first end
sub()
click to toggle source
# File lib/dydx/helper.rb, line 114 def sub SUPER_OPE_RELATION.invert[self] || self end
super()
click to toggle source
# File lib/dydx/helper.rb, line 110 def super SUPER_OPE_RELATION[self] || self end
to_numeric()
click to toggle source
# File lib/dydx/helper.rb, line 23 def to_numeric is_a?(Num) ? n : self end
zero?()
click to toggle source
# File lib/dydx/helper.rb, line 27 def zero? [0, 0.0].include?(self) || (is_a?(Num) && n.zero?) end