lib/dydx/algebra/operator/parts/formula.rb in dydx-0.0.2 vs lib/dydx/algebra/operator/parts/formula.rb in dydx-0.0.3

- old
+ new

@@ -1,34 +1,58 @@ module Dydx module Algebra module Operator module Parts module Formula - %w(+ -).each do |operator| + %w(+ -).map(&:to_sym).each do |operator| define_method(operator) do |x| if multiplication? && x.multiplication? if f == x.f f * g.send(operator, x.g) elsif g == x.g f.send(operator, x.f) * g else super(x) end + elsif ([self.operator, operator].sort == [:+, :-]) && ( f == x || g == x ) + if f == x + g + elsif g == x + f + end + elsif (self.operator == operator) && ( f == x || g == x ) + if f == x + f.send(operator, x).send(operator, g) + elsif g == x + f.send(operator, g.send(:+, x)) + end else super(x) end end end - %w(* /).each do |operator| + %w(* /).map(&:to_sym).each do |operator| define_method(operator) do |x| if exponentiation? && x.exponentiation? if f == x.f - f ^ g.send({'*'=>'+', '/'=>'-'}[operator], x.g) + f ^ g.send({'*'=>'+', '/'=>'-'}[operator.to_s], x.g) elsif g == x.g f.send(operator, x.f) ^ g else super(x) + end + elsif ([self.operator, operator].sort == [:*, :/]) && ( f == x || g == x ) + if f == x + g + elsif g == x + f + end + elsif (self.operator == operator) && ( f == x || g == x ) + if f == x + f.send(operator, x).send(operator, g) + elsif g == x + f.send(operator, g.send(:* , x)) end else super(x) end end