lib/dydx/algebra/formula.rb in dydx-0.0.7 vs lib/dydx/algebra/formula.rb in dydx-0.0.8

- old
+ new

@@ -28,29 +28,30 @@ alias_method :d, :differentiate def to_s if (multiplication? && (f.is_minus1? || g.is_minus1?) ) "( - #{g.to_s} )" - elsif multiplication? && g.divisor? + elsif multiplication? && g.inverse?(:*) "( #{f.to_s} / #{g.x.to_s} )" - elsif multiplication? && f.divisor? + elsif multiplication? && f.inverse?(:*) "( #{g.to_s} / #{f.x.to_s} )" - elsif addition? && g.subtrahend? + elsif addition? && g.inverse?(:+) "( #{f.to_s} - #{g.x.to_s} )" - elsif addition? && f.subtrahend? + elsif addition? && f.inverse?(:+) "( #{g.to_s} - #{f.x.to_s} )" else "( #{f.to_s} #{@operator} #{g.to_s} )" end end def include?(x) f == x || g == x end - def openable?(x) - x.is_num? && (f.is_num? || g.is_num?) + def openable?(operator, x) + distributive?(self.operator, operator) && + (f.combinable?(x, operator) || g.combinable?(x, operator)) end # TODO: interchangeable def ==(x) to_s == x.to_s @@ -73,6 +74,6 @@ @f, @g = @g, @f self end end end -end \ No newline at end of file +end